lean

package module
v0.0.0-...-5586a9f Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2016 License: MIT Imports: 11 Imported by: 0

README

Lean cloud go SDK

Leancloud go语言SDK,根据Leancloud公布的Restful API封装,并且使用godep管理依赖。

使用:

go get github.com/johnzeng/leancloud-go-sdk
cd $GOPATH/src/github.com/johnzeng/leancloud-go-sdk
godep restore
go install

目前支持的功能:

  • Object create
  • Object get by id
  • Object delete by id
  • Object update by id
  • Object query support
  • cql query support
  • requestSmsCode, verifySmsCode(需要在控制台设置开放这两个接口)
  • push notification(待测试)
  • 支持LeanTime,LeanPointer,LeanByte, LeanRelation, LeanFile类型。
  • User,Installation, Role等系统结构体的集成

具体使用方法请参考对应的test文件。里面每个test都是完整的请求。

Todo:

  • Cloud function 支持
  • 事件流API
  • 实时通信API
  • 数据Schema
  • 统计数据API

Documentation

Index

Constants

View Source
const (
	//v1.1 api classes url base
	//all url will not end with /,should append it by yourself
	UrlBase         = "https://api.leancloud.cn/1.1"
	ClasssesUrlBase = UrlBase + "/classes"
)
View Source
const (
	VoiceSMS = "void"
	TextSMS  = "sms"
)

Variables

This section is empty.

Functions

func NewClient

func NewClient(appId, appKey, masterKey string) *leanClient

create a new lean client. You only need one client in a go application application will not check your keys if you don't call API that needs it

Types

type ACLMap

type ACLMap map[string]bool

type AVObject

type AVObject interface {
	// contains filtered or unexported methods
}

type Agent

type Agent struct {
	// contains filtered or unexported fields
}

func (*Agent) Do

func (this *Agent) Do() error

func (*Agent) ScanResponse

func (this *Agent) ScanResponse(ret interface{}) error

func (*Agent) UseMasterKey

func (this *Agent) UseMasterKey() *Agent

if you wanna use master key, use it

func (*Agent) UseSessionToken

func (this *Agent) UseSessionToken(token string) *Agent

func (*Agent) UseSignature

func (this *Agent) UseSignature() *Agent

if you wanna use signature instead of key directlly , use this

type AndroidData

type AndroidData struct {
	Alert  string `json:"alert"`
	Title  string `json:"title"`
	Silent bool   `json:"silent,omitempty"`
	//this should be empty unless you have a custom Receiver
	Action string `json:"action,omitempty"`
}

You can still add more keys into this struct using this struct as a anonymous field

type Collection

type Collection struct {
	// contains filtered or unexported fields
}

func (Collection) Create

func (this Collection) Create(obj interface{}) *Agent

create an object

func (Collection) DeleteObjectById

func (this Collection) DeleteObjectById(objectId string) *QueryAgent

you can also specialfy the query parameter, if you don't provide the id, you will delete the objects by query

func (Collection) GetObjectById

func (this Collection) GetObjectById(objectId string) *Agent

get an object by objectId

func (Collection) Query

func (this Collection) Query() *QueryAgent

func (Collection) Scan

func (this Collection) Scan(cursor, key string) *QueryAgent

leave cursor and key empty if they are empty

func (Collection) UpdateObjectById

func (this Collection) UpdateObjectById(objectId string, obj interface{}) *UpdateAgent

you can also specialfy the query parameter, if you don't provide the id, you will update the object by query

type ComplexData

type ComplexData struct {
	//the interface should be a IOSData or any struct with an anonymous file of IOSData
	IOS interface{} `json:"ios,omitempty"`
	//the interface should be a AndroidData or any struct with an anonymous file of AndroidData
	Android AndroidData  `json:"android,omitempty"`
	WP      WinPhoneData `json:"wp,omitempty"`
}

type File

type File struct {
	LeanClassesBase
	Name     string                 `json:"name,omitempty"`
	FileType string                 `json:"mime_type,omitempty"`
	Key      string                 `json:"key,omitempty"`
	Type     string                 `json:"__type,omitempty"`
	Url      string                 `json:"url,omitempty"`
	Bucket   string                 `json:"bucket,omitempty"`
	MetaData map[string]interface{} `json:"metaData,omitempty"`
}

be attention that EmailVerified and MobilePhoneVerified can be nil

type IOSData

type IOSData struct {
	//Alert can be eiterh a string or a IOSLocalAlert
	Alert    interface{} `json:"alter"`
	Category string      `json:"category,omitempty"`
	//Badge can be either a int or a "Increment"
	Badge            interface{} `json:"badge,omitempty"`
	Sound            string      `json:"sound,omitempty"`
	ContentAvailable int         `json:"content-available,omitempty"`
	MutableContent   int         `json:"mutable-content,omitempty"`
}

You can still add more keys into this struct using this struct as a anonymous field

type IOSLocalAlert

type IOSLocalAlert struct {
	Title          string   `json:"title,omitempty"`
	TitleLocKey    string   `json:"title-loc-key,omitempty"`
	SubTitle       string   `json:"sub-title,omitempty"`
	SubTitleLocKey string   `json:"sub=title-loc-key,omitempty"`
	Body           string   `json:"body,omitempty"`
	ActionLocKey   string   `json:"action-loc-key,omitempty"`
	LocKey         string   `json:"loc-key,omitempty"`
	LocArgs        []string `json:"loc-args,omitempty"`
	LauchImage     string   `json:"lauch-image,omitempty"`
}

type IOSStandardData

type IOSStandardData struct {
	//Alert in IOSData should be a IOSLocalAlert
	Aps IOSData `json:"aps"`
}

You can still add more keys into this struct using this struct as a anonymous field

type Installation

type Installation struct {
	LeanClassesBase
	Badage          string   `json:"badge,omitempty"`
	Channels        []string `json:"channels,omitempty"`
	DeviceProfile   string   `json:"deviceProfile,omitempty"`
	DeviceToken     string   `json:"deviceToken,omitempty"`
	DeviceType      string   `json:"deviceType,omitempty"`
	ID              string   `json:"ID,omitempty"`
	InstallationId  string   `json:"installationId,omitempty"`
	SubscriptionUri string   `json:"subscriptionUri,omitempty"`
	TimeZone        string   `json:"timeZone,omitempty"`
}

type LeanByte

type LeanByte struct {
	// contains filtered or unexported fields
}
{
 "__type": "Bytes",
 "base64": "5b6I5aSa55So5oi36KGo56S65b6I5Zac5qyi5oiR5Lus55qE5paH5qGj6aOO5qC877yM5oiR5Lus5bey5bCGIExlYW5DbG91ZCDmiYDmnInmlofmoaPnmoQgTWFya2Rvd24g5qC85byP55qE5rqQ56CB5byA5pS+5Ye65p2l44CC"
}

func NewLeanByte

func NewLeanByte(in []byte) LeanByte

func (*LeanByte) GetBytes

func (this *LeanByte) GetBytes() *[]byte

func (LeanByte) MarshalJSON

func (t LeanByte) MarshalJSON() ([]byte, error)

func (*LeanByte) UnmarshalJSON

func (t *LeanByte) UnmarshalJSON(i []byte) error

convet json into TimeStamp, we take only the unix timestamp seconds

type LeanClassesBase

type LeanClassesBase struct {
	ObjectId  string            `json:"objectId,omitempty"`
	CreatedAt *LeanTime         `json:"createdAt,omitempty"`
	UpdatedAt *LeanTime         `json:"updatedAt,omitempty"`
	ACL       map[string]ACLMap `json:"ACL,omitempty"`
}

type LeanFile

type LeanFile struct {
	File
	Id string
}

func (LeanFile) MarshalJSON

func (t LeanFile) MarshalJSON() ([]byte, error)

func (*LeanFile) UnmarshalJSON

func (t *LeanFile) UnmarshalJSON(i []byte) error

type LeanPointer

type LeanPointer struct {
	// contains filtered or unexported fields
}
{
 "__type": "Pointer",
 "className": "Post",
 "objectId": "55a39634e4b0ed48f0c1845c"
}

func (LeanPointer) MarshalJSON

func (t LeanPointer) MarshalJSON() ([]byte, error)

type LeanRelation

type LeanRelation struct {
	ClassName string `json:'className'`
}

relation can only modify by AddRelation or RemoveRelation. and the api return only this struct

type LeanTime

type LeanTime struct {
	time.Time
}

func NewLeanTime

func NewLeanTime(t time.Time) LeanTime

func (LeanTime) MarshalJSON

func (t LeanTime) MarshalJSON() ([]byte, error)

2015-07-14T02:31:50.100Z convet TimeStamp into json, we take only the unix timestamp seconds

func (*LeanTime) UnmarshalJSON

func (t *LeanTime) UnmarshalJSON(i []byte) error

convet json into TimeStamp, we take only the unix timestamp seconds

type Push

type Push struct {
	LeanClassesBase
	Channels           []string    `json:"channels,omitempty"`
	Data               interface{} `json:"data"`
	ExpirationInterval int         `json:"expirationInterval,omitempty"`
	ExpirationTime     int         `json:"expirationTime,omitempty"`
	Prod               string      `json:"prod,omitempty"`
	PushTime           time.Time   `json:"pushTime,omitempty"`
	Where              interface{} `json:"where,omitempty"`
}

type QueryAgent

type QueryAgent struct {
	Agent
}

func (*QueryAgent) Limit

func (this *QueryAgent) Limit(l int) *QueryAgent

func (*QueryAgent) Order

func (this *QueryAgent) Order(s string) *QueryAgent

func (*QueryAgent) Skip

func (this *QueryAgent) Skip(s int) *QueryAgent

func (*QueryAgent) WithCount

func (this *QueryAgent) WithCount() *QueryAgent

func (*QueryAgent) WithCql

func (this *QueryAgent) WithCql(cql string) *QueryAgent

func (*QueryAgent) WithKeys

func (this *QueryAgent) WithKeys(key string) *QueryAgent

func (*QueryAgent) WithQuery

func (this *QueryAgent) WithQuery(q *query.Query) *QueryAgent

type RequestMobilePhoneVerify

type RequestMobilePhoneVerify struct {
	Number  string `json:"mobilePhoneNumber"`
	TTL     int    `json:"ttl,omitempty"`
	AppName string `json:"name,omitempty"`
	Op      string `json:"op,omitempty"`
	SmsType string `json:"smsType,omitempty"`
}

Number is the phone number TTL is default to 10 minutes AppName is default to the app name of you lean cloud application Op is default to verifying SmsType is default to TextSMS, set SmsType to VoiceSMS if you wanna send a voice sms

type UpdateAgent

type UpdateAgent struct {
	QueryAgent
}

type User

type User struct {
	LeanClassesBase
	Salt                string                 `json:"salt,omitemptyy"`
	Email               string                 `json:"email, omitempty"`
	SessionToken        string                 `json:"sessionToken, omitempty"`
	Passowrd            string                 `json:"password,omitempty"`
	Username            string                 `json:"username,omitempty"`
	EmailVerified       *bool                  `json:"emailVerified, omitempty"`
	MobilePhoneNumber   string                 `json:"mobilePhoneNumber, omitempty"`
	AuthData            map[string]interface{} `json:"authData, omitempty"`
	MobilePhoneVerified *bool                  `json:"mobilePhoneVerified, omitempty"`
}

be attention that EmailVerified and MobilePhoneVerified can be nil

type WinPhoneData

type WinPhoneData struct {
	Alert   string `json:"alert"`
	Title   string `json:"title"`
	WpParam string `json:"wp-param"`
}

don't add custome key because wp doesn't support it

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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