icity_sdk

package module
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 9, 2021 License: MIT Imports: 15 Imported by: 1

README

iCity SDK

Go Reference

一个基于 Golang 的 iCity SDK。

使用

package main

import  icity "github.com/WingLim/icity-sdk"

func main() {
	user := icity.Login("username", "password")
	user.NewDiary("", "Todoy~", icity.Public)
}

API

登陆/登出
  • 登陆
Login(username, password string, saveCookies bool) *User
  • 登出
Logout(user *User) error
日记
type Diary struct {
	// 日记 ID
	ID       string 
	// 发布的用户的昵称
	Nickname string 
	// 用户 ID
	UserId   string
	
	// 日记标题
	Title    string 
	// 日记内容
	Content  string 
	// 发布地点
	Location string 
	// 发布时间
	Date     time.Time
}
日记权限
const (
    // 公开
    Public DiaryPrivacy = iota + 1
    // 仅好友
    OnlyFriend
    // 私密
    Private
)
  • 发布日记
user.NewDiary(title, content string, privacy DiaryPrivacy) Response

// 发布状态
Response.Success

// 发布的日记的 ID
Response.ActivityToken
  • 删除日记
user.DeleteDiary(diaryID string) Response

// 删除状态
Response.Success

// 删除的日记的 ID
Response.ActivityToken
  • 喜欢日记
// true: 成功
// false: 失败
user.Like(diaryID string) bool
  • 取消喜欢
// true: 成功
// false: 失败 
user.Unlike(diaryID string) bool
评论
type Comment struct {
	// 发布评论的用户的昵称
	Nickname string
	// 用户 ID
	UserID   string
	// 评论内容
	Content  string 
	// 发布时间
	Date     time.Time
}
  • 发布评论
user.NewComment(diaryID, comment string) Response

// 发布状态
Response.Success

// 发布的评论的 ID
Response.ActivityToken
  • 删除评论
user.DeleteComment(commentID, diaryID string) Response

// 删除状态
Response.Success

// 删除的评论的 ID
Response.ActivityToken
  • 回复评论
user.ReplyComment(userID, diaryID, comment string) Response

// 发布状态
Response.Success

// 发布的评论的 ID
Response.ActivityToken
  • 获取评论
user.GetComments(diaryID string) []Comment
用户
type User struct {
	// 用户名
	Username string
	// 用户密码
	Password string
	
	// 用户 ID
	UserID   string
	// 昵称
	Nickname string
	// 关于我
	Bio      string
	// 所在地
	Location string
    
	// 隐私设置
	SettingsPrivacy SettingsPrivacy
}
  • 关注用户
// true: 成功
// false: 失败 
user.Follow(userID string) bool
  • 取消关注用户
// true: 成功
// false: 失败 
user.Unfollow(userID string) bool
  • 设置昵称
// true: 成功
// false: 失败 
user.SetNickName(nickname string) bool
  • 设置简介
// true: 成功
// false: 失败 
user.SetBio(bio string) bool
  • 设置所在地
// true: 成功
// false: 失败 
user.SetLocation(location string) bool
社交账号
  • 微博
// true: 成功
// false: 失败 
user.SetSocialWeibo(weibo string) bool

...

更多社交账号设置请看 settings_social.go

隐私设置
type SettingsPrivacy struct {
	// 新日记默认权限
	DefaultPrivacy DiaryPrivacy

	// 隐身模式
	InvisibleMode InvisibleType

	// 日记是否发布到世界
	UnWorld WorldType
    
	// 谁可以看
	// 关于我
	AboutMe ViewAccess

	// 我的朋友列表
	Followings ViewAccess

	// 我的关注者列表
	Followers ViewAccess
    
	// 互动设置
	// 评论我的日记
	AllowComment ViewAccess

	// 喜欢我的日记
	AllowLike ViewAccess

	// 给我发私信
	AllowMessage ViewAccess
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Logout

func Logout(user *User) error

Logout logouts user from iCity

func WriteConfig

func WriteConfig(config *Config, filepath string) (err error)

Types

type Comment

type Comment struct {
	Nickname string
	UserID   string
	Content  string
	Date     time.Time
}

type Config

type Config struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

func ReadConfig

func ReadConfig(filepath string) (config Config, err error)

type Diary

type Diary struct {
	ID       string
	Nickname string
	UserID   string

	Title    string
	Content  string
	Location string
	Date     time.Time
}

type DiaryPrivacy

type DiaryPrivacy int
const (
	Public DiaryPrivacy = iota + 1
	OnlyFriend
	Private
)

func (DiaryPrivacy) Data

func (p DiaryPrivacy) Data() string

func (DiaryPrivacy) String

func (p DiaryPrivacy) String() string
type Header struct {
	Key   string
	Value string
}

type InvisibleType

type InvisibleType int
const (
	// NotInvisible shows all your diaries to everyone.
	NotInvisible InvisibleType = iota + 1

	// ToStrangers shows your diaries to your friends.
	ToStrangers

	// ToAll show your diaries to yourself.
	ToAll
)

func (InvisibleType) Data

func (i InvisibleType) Data() string

func (InvisibleType) String

func (i InvisibleType) String() string

type Option added in v0.1.1

type Option func(*Options)

func WithSaveCookies added in v0.1.1

func WithSaveCookies(filepath string) Option

type Options added in v0.1.1

type Options struct {
	Cookies     []*http.Cookie
	CookiesPath string
}

type Response

type Response struct {
	// Success is operation status.
	Success bool `json:"success"`

	// ActivityToken is the id of diary.
	ActivityToken string `json:"activity_token"`
}

type Setting

type Setting struct {
	Key   string
	Value string
}

type SettingsPrivacy

type SettingsPrivacy struct {
	// DefaultPrivacy sets your new diary default access.
	DefaultPrivacy DiaryPrivacy

	// InvisibleMode sets invisible mode.
	InvisibleMode InvisibleType

	// UnWorld sets if your diary publish to world
	UnWorld WorldType

	// AboutMe sets who can access your about me page.
	AboutMe ViewAccess

	// Followings sets who can access your followings list.
	Followings ViewAccess

	// Followers sets who can access your followers list.
	Followers ViewAccess

	// AllowComment sets who can comment your diary.
	AllowComment ViewAccess

	// Allow Like sets who can like your diary.
	AllowLike ViewAccess

	// AllowMessage sets who can send you private message.
	AllowMessage ViewAccess
}

type User

type User struct {
	Username string
	Password string

	UserID   string
	Nickname string
	Bio      string
	Location string

	SettingsPrivacy SettingsPrivacy
	// contains filtered or unexported fields
}

func Login

func Login(username, password string, opts ...Option) *User

Login logins user to iCity. If set true to saveCookies, then will write cookies to cookies.json, then will login to iCity with exists cookies.

func LoginWithConfig

func LoginWithConfig(filepath string, opts ...Option) *User

func NewUser

func NewUser(username, password string) *User

NewUser creates a User instance.

func (*User) DeleteComment

func (user *User) DeleteComment(commentID, diaryID string) (deleteResp Response)

DeleteComment deletes a comment by comment id.

func (*User) DeleteDiary

func (user *User) DeleteDiary(diaryId string) (deleteResp Response)

DeleteDiary deletes the diary with given diary id.

func (*User) Follow

func (user *User) Follow(userID string) bool

Follow follows one user by user id.

func (*User) GetComments

func (user *User) GetComments(diaryID string) []Comment

GetComments gets diary comments by diary id.

func (*User) GetMessages added in v0.7.0

func (user *User) GetMessages()

func (*User) GetMessagesList added in v0.7.0

func (user *User) GetMessagesList()

func (*User) GetMoreMessages added in v0.2.0

func (user *User) GetMoreMessages()

func (*User) GetWorld

func (user *User) GetWorld() []Diary

func (*User) Like

func (user *User) Like(diaryId string) bool

Like likes a diary with given diary id.

func (*User) NewComment

func (user *User) NewComment(diaryID, comment string) (newResp Response)

NewComment creates a new comment of a diary by diary id.

func (*User) NewDiary

func (user *User) NewDiary(title, content string, privacy DiaryPrivacy) (newResp Response)

NewDiary creates a new diary with title, content and privacy.

func (*User) ReplyComment

func (user *User) ReplyComment(userID, diaryID, comment string) Response

ReplyComment replies user by user id and diary id.

func (*User) SetAboutMeAccess

func (user *User) SetAboutMeAccess(setting ViewAccess) bool

SetAboutMeAccess sets AboutMe access.

func (*User) SetAllowComment

func (user *User) SetAllowComment(setting ViewAccess) bool

SetAllowComment sets AllowComment access.

func (*User) SetAllowLike

func (user *User) SetAllowLike(setting ViewAccess) bool

SetAllowLike sets AllowLike access.

func (*User) SetAllowMessage

func (user *User) SetAllowMessage(setting ViewAccess) bool

SetAllowMessage sets AllowMessage access.

func (*User) SetBio

func (user *User) SetBio(bio string) bool

func (*User) SetDefaultPrivacy

func (user *User) SetDefaultPrivacy(setting DiaryPrivacy) bool

SetDefaultPrivacy sets DefaultPrivacy access.

func (*User) SetFollowersAccess

func (user *User) SetFollowersAccess(setting ViewAccess) bool

SetFollowersAccess sets Followers access.

func (*User) SetFollowingsAccess

func (user *User) SetFollowingsAccess(setting ViewAccess) bool

SetFollowingsAccess sets Followings access.

func (*User) SetInvisibleMode

func (user *User) SetInvisibleMode(setting InvisibleType) bool

SetInvisibleMode sets InvisibleMode.

func (*User) SetLocation

func (user *User) SetLocation(location string) bool

func (*User) SetNickName

func (user *User) SetNickName(nickname string) bool

func (*User) SetOnlyFriend

func (user *User) SetOnlyFriend(id string) bool

SetOnlyFriend sets diary privacy to OnlyFriend.

func (*User) SetPrivate

func (user *User) SetPrivate(id string) bool

SetPrivate sets diary privacy to Private.

func (*User) SetPublic

func (user *User) SetPublic(id string) bool

SetPublic sets diary privacy to Public.

func (*User) SetSocialBattlenet

func (user *User) SetSocialBattlenet(battlenet string) bool

func (*User) SetSocialDribbble

func (user *User) SetSocialDribbble(dribbble string) bool

func (*User) SetSocialFacebook

func (user *User) SetSocialFacebook(facebook string) bool

func (*User) SetSocialGithub

func (user *User) SetSocialGithub(github string) bool

func (*User) SetSocialHomePage

func (user *User) SetSocialHomePage(homepage string) bool

func (*User) SetSocialInstagram

func (user *User) SetSocialInstagram(instagram string) bool

func (*User) SetSocialLink1

func (user *User) SetSocialLink1(link1 string) bool

func (*User) SetSocialLink2

func (user *User) SetSocialLink2(link2 string) bool

func (*User) SetSocialLink3

func (user *User) SetSocialLink3(link3 string) bool

func (*User) SetSocialNS

func (user *User) SetSocialNS(ns string) bool

func (*User) SetSocialNintendo

func (user *User) SetSocialNintendo(nintendo string) bool

func (*User) SetSocialPSN

func (user *User) SetSocialPSN(psn string) bool

func (*User) SetSocialPixiv

func (user *User) SetSocialPixiv(pixiv string) bool

func (*User) SetSocialQQ

func (user *User) SetSocialQQ(qq string) bool

func (*User) SetSocialSteam

func (user *User) SetSocialSteam(steam string) bool

func (*User) SetSocialTelegram

func (user *User) SetSocialTelegram(telegram string) bool

func (*User) SetSocialTumblr

func (user *User) SetSocialTumblr(tumblr string) bool

func (*User) SetSocialTwitter

func (user *User) SetSocialTwitter(twitter string) bool

func (*User) SetSocialWechat

func (user *User) SetSocialWechat(wechat string) bool

func (*User) SetSocialWeibo

func (user *User) SetSocialWeibo(weibo string) bool

func (*User) SetSocialXBox

func (user *User) SetSocialXBox(xbox string) bool

func (*User) SetUnWorld

func (user *User) SetUnWorld(setting WorldType) bool

SetUnWorld sets UnWorld type.

func (*User) Unfollow

func (user *User) Unfollow(userID string) bool

Unfollow unfollows one user by user id.

func (*User) Unlike

func (user *User) Unlike(diaryId string) bool

Unlike unlikes a diary with given diary id.

type ViewAccess

type ViewAccess int
const (
	// Everyone means everyone on iCity have access.
	Everyone ViewAccess = iota + 1

	// Friend means only your friend have access.
	Friend

	// Self means only yourself have access.
	Self
)

func (ViewAccess) Data

func (v ViewAccess) Data() string

func (ViewAccess) String

func (v ViewAccess) String() string

type WorldType

type WorldType int
const (
	// Show publishes your diary to world.
	Show WorldType = iota

	// NotShow doesn't publish your diary to world.
	NotShow
)

func (WorldType) Data

func (w WorldType) Data() string

func (WorldType) String

func (w WorldType) String() string

Directories

Path Synopsis
constant

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL