gosf

package module
v0.0.0-...-99a042c Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2021 License: MIT Imports: 8 Imported by: 0

README

GoSalesforce

Go version Salesforce Client

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client Type

func NewClient

func NewClient(config *Config, logger Logger) *Client

NewClient returns a Client instance.

func (*Client) CreaetSobject

func (c *Client) CreaetSobject(sobjectName string, sobject interface{}) (id string, err error)

CreaetSobject creates sobject by given sobject name and entity.

func (*Client) DeleteSobject

func (c *Client) DeleteSobject(sobjectName, sobjectID string) error

DeleteSobject deletes sobject by given sobject name and id.

func (*Client) Do

func (c *Client) Do(op Operator) error

Do uses op Operator to make request, send it to salesforce, receieve response and pass it to the Operator to handle.

func (*Client) GetSobject

func (c *Client) GetSobject(sobjectName, sobjectID string, target interface{}) error

GetSobject get sobject by given sobject name and id, use target to receive the result.

func (*Client) QuerySobject

func (c *Client) QuerySobject(op *OpQuery) (result *QueryResult, err error)

QuerySobject query sobject or sobjects by given op OpQuery. See also OpQuery.

func (*Client) Resources

func (c *Client) Resources() (resources map[string]string, err error)

Resources shows resources under current version.

func (*Client) SobjectInfo

func (c *Client) SobjectInfo() (info map[string]interface{}, err error)

SobjectInfo shows the basic information of given sobject name.

func (*Client) UpdateSobject

func (c *Client) UpdateSobject(sobjectName, sobjectID string, sobject interface{}) error

UpdateSobject updates sobject by given sobject name, id and entity contains changes.

func (*Client) Versions

func (c *Client) Versions() (versions []*Version, err error)

Versions shows all availabel ssalesforce rest api versions.

type Config

type Config struct {
	// auth
	Host         string `json:"host"`
	ClientID     string `json:"client_id"`
	ClientSecret string `json:"client_secret"`
	Username     string `json:"username"`
	Password     string `json:"password"`
	ExpiresIn    int    `json:"expires_in"`

	// api
	APIVersion int `json:"api_version"`

	// proxy url
	ProxyURL string `json:"proxy_url"`
}

Config type

type Logger

type Logger interface {
	Print(v ...interface{})
	Printf(format string, v ...interface{})
}

Logger inteface

type OpQuery

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

OpQuery is a request for quering SObject. Set which Sobject type and fileds to query by Select() and From() is necessary. The reset operations below is optional:

  • OrderDesc(), OrderAsc(), OrderReset(), OrderNullFirst(), OrderNullLast() to control ORDER key.
  • Limit() to control LIMIT key

See the methods' doc for more details.

func NewOpQuery

func NewOpQuery(sobjectName string) *OpQuery

NewOpQuery returns a OpQuery instance with given sobjectName.

func (*OpQuery) From

func (op *OpQuery) From(sobjectName string) *OpQuery

From defines which SObject will be query.

func (*OpQuery) Handle

func (op *OpQuery) Handle(resp *http.Response) error

Handle success response from salesforce.

func (*OpQuery) Limit

func (op *OpQuery) Limit(n int) *OpQuery

Limit defines the max records will be return. if n==0, will treat it as a signal to reset limitation to unlimited.

func (*OpQuery) Make

func (op *OpQuery) Make(ctx *RequestCtx) (*Request, error)

Make request by given request context.

func (*OpQuery) OrderAsc

func (op *OpQuery) OrderAsc(field string) *OpQuery

OrderAsc defines the order column to sort results ascendant.

func (*OpQuery) OrderDesc

func (op *OpQuery) OrderDesc(field string) *OpQuery

OrderDesc defines the order column to sort results descendant.

func (*OpQuery) OrderNullFirst

func (op *OpQuery) OrderNullFirst() *OpQuery

OrderNullFirst make null null column value first in query results when given order column.

func (*OpQuery) OrderNullLast

func (op *OpQuery) OrderNullLast() *OpQuery

OrderNullLast make null column value last in query results when given order column.

func (*OpQuery) OrderReset

func (op *OpQuery) OrderReset() *OpQuery

OrderReset resets the order statment=="".

func (*OpQuery) Select

func (op *OpQuery) Select(fields ...string) *OpQuery

Select defines which columns of SObject will be return in result.

func (*OpQuery) Where

func (op *OpQuery) Where(field string, condition interface{}) *OpQuery

Where defines what condition will be appended to the query.

type Operator

type Operator interface {
	// Make request by given request context.
	Make(*RequestCtx) (*Request, error)
	// Handle success response from salesforce.
	Handle(*http.Response) error
}

Operator can make a *http.Request instance according to given request ctx for http.Client to send request to salesforce or returns an error. It can also handle the response responded from salesforce.

type QueryResult

type QueryResult struct {
	TotalSize int           `json:"totalSize"`
	Done      bool          `json:"done"`
	Records   []interface{} `json:"records"`
}

QueryResult is the result of a query operation.

func (*QueryResult) Parse

func (r *QueryResult) Parse(targets interface{}) error

Parse parses the result.

type Request

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

Request can make a http.Request instance which contains json-format body if data provided.

func NewRequest

func NewRequest(method, urlStr string, data interface{}) *Request

NewRequest returns a new Request given a method, URL, and optional data.

type RequestCtx

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

RequestCtx holds the host and api version informations.

func (*RequestCtx) BaseURL

func (ctx *RequestCtx) BaseURL() string

BaseURL returns the base URL of salesforce restful api. Assume host is "https://instance.salesforce.com", baseURL will be "https://instance.salesforce.com/services/data"

func (*RequestCtx) QueryURL

func (ctx *RequestCtx) QueryURL(q string) string

QueryURL returns the URL with query SOQL statments, like: "https://instance.salesforce.com/services/data/v24.0/query?q=SELECT+Id,+Name+FROM+User"

func (*RequestCtx) SobjectURL

func (ctx *RequestCtx) SobjectURL() string

SobjectURL returns the URL can work with SObjects, like: "https://instance.salesforce.com/services/data/v36.0/sobjects"

func (*RequestCtx) SobjectURLWithID

func (ctx *RequestCtx) SobjectURLWithID(sobjectName, sobjectID string) string

SobjectURLWithID returns the URL with specific sobject and id. Assume the given sobject is 'User' and id is '00e28000001K04LAA1', the return URL will be: "https://instance.salesforce.com/services/data/v36.0/sobjects/User/00e28000001K04LAA1"

func (*RequestCtx) SobjectURLWithName

func (ctx *RequestCtx) SobjectURLWithName(sobjectName string) string

SobjectURLWithName returns the URL with specific sobject. Assume the given sobject is 'User', the return URL will be: "https://instance.salesforce.com/services/data/v36.0/sobjects/User"

func (*RequestCtx) VersionURL

func (ctx *RequestCtx) VersionURL() string

VersionURL returns the URL with version, like: "https://instance.salesforce.com/services/data/v36.0"

type Version

type Version struct {
	Label   string `json:"label"`
	URL     string `json:"url"`
	Version string `json:"version"`
}

Version type. An array with elements describe the versions of salesforce rest api.

Jump to

Keyboard shortcuts

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