NCMB

package module
v0.0.0-...-d9e1f19 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2023 License: MIT Imports: 17 Imported by: 0

README

NCMB SDK for Golang

Usage

Install
go get -u github.com/NCMBMania/ncmb_go
Import
import (
    "github.com/NCMBMania/ncmb_go"
)
Initialize
ncmb := NCMB.Initialize("YOUR_APPLICATION_KEY", "YOUR_CLIENT_KEY")
User
Sign up
user, err := ncmb.SignUpByAccount(userName, password)
Log in by username
user, err := ncmb.Login(userName, password)
Log in by email address
user, err := ncmb.LoginWithMailAddress(mailAddress, password)
Request registration email
bol, err := ncmb.RequestSignUpEmail(mailAddress)
Reset password (only email auth)
bol, err := ncmb.RequestPasswordReset(mailAddress)
Logout
bol, err := ncmb.Logout()
DataStore
Save item
item := ncmb.Item("Hello")
item.Set("msg1", "Hello").Set("msg2", "World")
item.Set("num", 100)      // Int
item.Set("float", 1.23)   // Float

// Save item
bol, err := item.Save()
Get item data
msg1, err := item.GetString("msg1"))
msg3, err := item.GetString("msg3", "default") // 2nd argument is default value
bol, err := item.GetBool("bool") // true or false
num, err := item.GetNumber("num") // float64
ary, err := item.GetArray("ary") // []interface{}
obj, err := item.GetMap("map") // interface{}{}
geo, err := item.GetGeoPoint("geo") // GeoPoint
date, err := item.GetDate("date") // time.Time
other, err := item.Get("null") // interface{}
item.ObjectId // string
Query
Fetch data
query := ncmb.Query("Hello")
query.EqualTo("msg1", "Hello")
items, err := query.FetchAll()
if err != nil {
	fmt.Println(err)
}
fmt.Println(items[0].GetDate("createDate"))

Supported operands.

  • func EqualTo(key string, value interface{})
  • func NotEqualTo(key string, value interface{})
  • func LessThan(key string, value interface{})
  • func LessThanOrEqualTo(key string, value interface{})
  • func GreaterThan(key string, value interface{})
  • func GreaterThanOrEqualTo(key string, value interface{})
  • func In(key string, value interface{})
  • func NotIn(key string, value interface{})
  • func Exists(key string, value interface{})
  • func RegularExpression(key string, value string)
  • func InArray(key string, value interface{})
  • func NotInArray(key string, value interface{})
  • func AllInArray(key string, value interface{})
  • func Near(key string, value GeoPoint)
  • func WithinKilometers(key string, value GeoPoint, distance float64)
  • func WithinMiles(key string, value GeoPoint, distance float64)
  • func WithinRadians(key string, value GeoPoint, distance float64)
  • func WithinSquare(key string, southWest GeoPoint, northEast GeoPoint)
GeoPoint
Add GeoPoint as data
item := ncmb.Item("Hello")
geo := ncmb.GeoPiint(35.6585805, 139.7454329)
item.Set("geo", geo)
bol, err := item.Save()

License

MIT.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToRoleObjects

func ToRoleObjects(ary []Role) []map[string]string

func ToUserbjects

func ToUserbjects(ary []User) []map[string]string

Types

type Acl

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

func (*Acl) GetPublicReadAccess

func (acl *Acl) GetPublicReadAccess() bool

func (*Acl) GetPublicWriteAccess

func (acl *Acl) GetPublicWriteAccess() bool

func (*Acl) GetRoleReadAccess

func (acl *Acl) GetRoleReadAccess(role string) bool

func (*Acl) GetRoleWriteAccess

func (acl *Acl) GetRoleWriteAccess(role string) bool

func (*Acl) GetUserReadAccess

func (acl *Acl) GetUserReadAccess(user *User) bool

func (*Acl) GetUserWriteAccess

func (acl *Acl) GetUserWriteAccess(user *User) bool

func (*Acl) SetPublicReadAccess

func (acl *Acl) SetPublicReadAccess(b bool) *Acl

func (*Acl) SetPublicWriteAccess

func (acl *Acl) SetPublicWriteAccess(b bool) *Acl

func (*Acl) SetRoleReadAccess

func (acl *Acl) SetRoleReadAccess(role string, b bool) *Acl

func (*Acl) SetRoleWriteAccess

func (acl *Acl) SetRoleWriteAccess(role string, b bool) *Acl

func (*Acl) SetUserReadAccess

func (acl *Acl) SetUserReadAccess(user *User, b bool) *Acl

func (*Acl) SetUserWriteAccess

func (acl *Acl) SetUserWriteAccess(user *User, b bool) *Acl

func (*Acl) Sets

func (acl *Acl) Sets(valueMap map[string]map[string]bool)

func (Acl) ToJSON

func (acl Acl) ToJSON() (map[string]map[string]bool, error)

type AddRemoveOperation

type AddRemoveOperation struct {
	Op      string        `json:"__op"`
	Objects []interface{} `json:"objects"`
}

type ExecOptions

type ExecOptions struct {
	ClassName         string
	Fields            *map[string]interface{}
	ObjectId          *string
	Queries           *map[string]interface{}
	AdditionalHeaders *map[string]string
	Path              *string
	Multipart         bool
	IsScript          bool
	Bytes             *[]byte
}

type File

type File struct {
	Bytes []byte
	Item
	// contains filtered or unexported fields
}

func (*File) Delete

func (file *File) Delete() (bool, error)

func (*File) Download

func (file *File) Download() ([]byte, error)

func (*File) GetDate

func (file *File) GetDate(key string, defaultValue ...time.Time) (time.Time, error)

func (*File) Update

func (file *File) Update() (bool, error)

func (*File) Upload

func (file *File) Upload() (bool, error)

type GeoPoint

type GeoPoint struct {
	Type      string  `json:"__type"`
	Latitude  float64 `json:"latitude"`
	Longitude float64 `json:"longitude"`
}

type Installation

type Installation struct {
	Item
	// contains filtered or unexported fields
}

func (*Installation) Create

func (installation *Installation) Create() (bool, error)

func (*Installation) Save

func (installation *Installation) Save() (bool, error)

func (*Installation) Update

func (installation *Installation) Update() (bool, error)

type Item

type Item struct {
	ClassName string
	ObjectId  string
	// contains filtered or unexported fields
}

func (*Item) Add

func (item *Item) Add(key string, object interface{}) *Item

func (*Item) AddUnique

func (item *Item) AddUnique(key string, object interface{}) *Item

func (*Item) Create

func (item *Item) Create() (bool, error)

func (*Item) Delete

func (item *Item) Delete() (bool, error)

func (*Item) Fetch

func (item *Item) Fetch() (bool, error)

func (*Item) Fields

func (item *Item) Fields() map[string]interface{}

func (*Item) Get

func (item *Item) Get(key string) interface{}

func (*Item) GetAcl

func (item *Item) GetAcl() (Acl, error)

func (*Item) GetArray

func (item *Item) GetArray(key string, defaultValue ...[]interface{}) ([]interface{}, error)

func (*Item) GetBool

func (item *Item) GetBool(key string, defaultValue ...bool) (bool, error)

func (*Item) GetClassName

func (item *Item) GetClassName() string

func (*Item) GetDate

func (item *Item) GetDate(key string, defaultValue ...time.Time) (time.Time, error)

func (*Item) GetGeoPoint

func (item *Item) GetGeoPoint(key string, defaultValue ...GeoPoint) (GeoPoint, error)

func (*Item) GetItem

func (item *Item) GetItem(key string, defaultValue ...Item) (Item, error)

func (*Item) GetMap

func (item *Item) GetMap(key string, defaultValue ...map[string]interface{}) (map[string]interface{}, error)

func (*Item) GetNumber

func (item *Item) GetNumber(key string, defaultValue ...float64) (float64, error)

func (*Item) GetObjectId

func (item *Item) GetObjectId() string

func (*Item) GetString

func (item *Item) GetString(key string, defaultValue ...string) (string, error)

func (*Item) Increment

func (item *Item) Increment(key string, amount ...int) *Item

func (*Item) Remove

func (item *Item) Remove(key string, object interface{}) *Item

func (*Item) Save

func (item *Item) Save() (bool, error)

func (*Item) Set

func (item *Item) Set(key string, value interface{}) *Item

func (*Item) SetAcl

func (item *Item) SetAcl(acl Acl) *Item

func (*Item) Sets

func (item *Item) Sets(hash map[string]interface{}) *Item

func (*Item) ToPointer

func (item *Item) ToPointer() map[string]interface{}

func (*Item) Update

func (item *Item) Update() (bool, error)

type ItemDate

type ItemDate struct {
	Type string `json:"__type"`
	Iso  string `json:"iso"`
}

type NCMB

type NCMB struct {
	ApplicationKey string
	ClientKey      string
	SessionToken   string
}

func Initialize

func Initialize(applicationKey string, clientKey string) NCMB

func (*NCMB) Acl

func (ncmb *NCMB) Acl() Acl

func (*NCMB) File

func (ncmb *NCMB) File(fileName string) File

func (*NCMB) GeoPoint

func (ncmb *NCMB) GeoPoint(latitude float64, longitude float64) GeoPoint

func (*NCMB) Installation

func (ncmb *NCMB) Installation() Installation

func (*NCMB) Item

func (ncmb *NCMB) Item(className string) Item

func (*NCMB) Login

func (ncmb *NCMB) Login(userName string, password string) (*User, error)

func (*NCMB) LoginWithMailAddress

func (ncmb *NCMB) LoginWithMailAddress(mailAddress string, password string) (*User, error)

func (*NCMB) Logout

func (ncmb *NCMB) Logout() (bool, error)

func (*NCMB) Push

func (ncmb *NCMB) Push() Push

func (*NCMB) Query

func (ncmb *NCMB) Query(className string) Query

func (*NCMB) RequestPasswordReset

func (ncmb *NCMB) RequestPasswordReset(mailAddress string) (bool, error)

func (*NCMB) RequestSignUpEmail

func (ncmb *NCMB) RequestSignUpEmail(mailAddress string) (bool, error)

func (*NCMB) Role

func (ncmb *NCMB) Role(name string) Role

func (*NCMB) SignUpByAccount

func (ncmb *NCMB) SignUpByAccount(userName string, password string) (*User, error)

type NCMBError

type NCMBError struct {
	Code  string `json:"code"`
	Error string `json:"error"`
}

type PathOptions

type PathOptions struct {
	ObjectId   *string
	DefinePath *string
}

type Push

type Push struct {
	Item
	// contains filtered or unexported fields
}

func (*Push) Save

func (push *Push) Save() (bool, error)

type Query

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

func (*Query) AllInArray

func (query *Query) AllInArray(key string, value interface{}) *Query

func (*Query) EqualTo

func (query *Query) EqualTo(key string, value interface{}) *Query

func (*Query) Exists

func (query *Query) Exists(key string, value interface{}) *Query

func (*Query) FetchAll

func (query *Query) FetchAll() ([]Item, error)

func (*Query) GreaterThan

func (query *Query) GreaterThan(key string, value interface{}) *Query

func (*Query) GreaterThanOrEqualTo

func (query *Query) GreaterThanOrEqualTo(key string, value interface{}) *Query

func (*Query) In

func (query *Query) In(key string, value interface{}) *Query

func (*Query) InArray

func (query *Query) InArray(key string, value interface{}) *Query

func (*Query) Include

func (query *Query) Include(key string) *Query

func (*Query) LessThan

func (query *Query) LessThan(key string, value interface{}) *Query

func (*Query) LessThanOrEqualTo

func (query *Query) LessThanOrEqualTo(key string, value interface{}) *Query

func (*Query) Limit

func (query *Query) Limit(num int) *Query

func (*Query) Near

func (query *Query) Near(key string, value GeoPoint) *Query

func (*Query) NotEqualTo

func (query *Query) NotEqualTo(key string, value interface{}) *Query

func (*Query) NotIn

func (query *Query) NotIn(key string, value interface{}) *Query

func (*Query) NotInArray

func (query *Query) NotInArray(key string, value interface{}) *Query

func (*Query) Order

func (query *Query) Order(key string, descending ...bool) *Query

func (*Query) RegularExpression

func (query *Query) RegularExpression(key string, value string) *Query

func (*Query) RelatedTo

func (query *Query) RelatedTo(object RelatedItem, key string) *Query

func (*Query) WithinKilometers

func (query *Query) WithinKilometers(key string, value GeoPoint, distance float64) *Query

func (*Query) WithinMiles

func (query *Query) WithinMiles(key string, value GeoPoint, distance float64) *Query

func (*Query) WithinRadians

func (query *Query) WithinRadians(key string, value GeoPoint, distance float64) *Query

func (*Query) WithinSquare

func (query *Query) WithinSquare(key string, southWest GeoPoint, northEast GeoPoint) *Query

type RelatedItem

type RelatedItem interface {
	GetClassName() string
	GetObjectId() string
}

type Request

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

func (*Request) Data

func (request *Request) Data(data *map[string]interface{}) ([]byte, error)

func (*Request) Delete

func (request *Request) Delete(options ...ExecOptions) ([]byte, error)

func (*Request) Exec

func (request *Request) Exec(method string, params ExecOptions) ([]byte, error)

func (*Request) Get

func (request *Request) Get(options ...ExecOptions) ([]byte, error)

func (*Request) Gets

func (request *Request) Gets(options ...ExecOptions) ([]byte, error)

func (*Request) Post

func (request *Request) Post(options ...ExecOptions) ([]byte, error)

func (*Request) Put

func (request *Request) Put(options ...ExecOptions) ([]byte, error)

type Role

type Role struct {
	Roles []Role

	Users []User

	Item
	// contains filtered or unexported fields
}

func (*Role) AddRole

func (role *Role) AddRole(r Role) *Role

func (*Role) AddUser

func (role *Role) AddUser(u User) *Role

func (*Role) Create

func (role *Role) Create() (bool, error)

func (*Role) FetchRole

func (role *Role) FetchRole() ([]Role, error)

func (*Role) FetchUser

func (role *Role) FetchUser() ([]User, error)

func (*Role) Fields

func (role *Role) Fields() (map[string]interface{}, error)

func (*Role) GetClassName

func (role *Role) GetClassName() string

func (*Role) GetObjectId

func (role *Role) GetObjectId() string

func (*Role) Save

func (role *Role) Save() (bool, error)

func (*Role) ToPointer

func (role *Role) ToPointer() map[string]string

func (*Role) Update

func (role *Role) Update() (bool, error)

type Signature

type Signature struct {
	IsScript bool
	// contains filtered or unexported fields
}

func (*Signature) Fqdn

func (signature *Signature) Fqdn() string

func (*Signature) Generate

func (signature *Signature) Generate(method string, className string, options UrlOptions) (string, error)

func (*Signature) Headers

func (signature *Signature) Headers(signatureString string) map[string]string

func (*Signature) Initialize

func (s *Signature) Initialize()

func (*Signature) Path

func (signature *Signature) Path(className string, options PathOptions) string

func (*Signature) QueryString

func (signature *Signature) QueryString(queries *map[string]interface{}) (string, error)

func (*Signature) Url

func (signature *Signature) Url(className string, options UrlOptions) (string, error)

type UrlOptions

type UrlOptions struct {
	ObjectId   *string
	DefinePath *string
	Queries    *map[string]interface{}
}

type User

type User struct {
	Item
	// contains filtered or unexported fields
}

func (*User) GetClassName

func (user *User) GetClassName() string

func (*User) GetObjectId

func (user *User) GetObjectId() string

func (*User) Login

func (user *User) Login() (*User, error)

func (*User) LoginWithMailAddress

func (user *User) LoginWithMailAddress() (*User, error)

func (*User) Logout

func (user *User) Logout() (bool, error)

func (*User) RequestPasswordReset

func (user *User) RequestPasswordReset() (bool, error)

func (*User) RequestSignUpEmail

func (user *User) RequestSignUpEmail() (bool, error)

func (*User) Save

func (user *User) Save() (bool, error)

func (*User) SignUpByAccount

func (user *User) SignUpByAccount() (*User, error)

func (*User) ToPointer

func (user *User) ToPointer() map[string]string

Jump to

Keyboard shortcuts

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