Documentation ¶
Index ¶
- Constants
- Variables
- type Action
- type Client
- func (c *Client) GetEventsUrl() string
- func (c *Client) GetLabelUrl(userId string) string
- func (c *Client) GetScoreUrl(userId string) string
- func (c *Client) HttpRequest(method string, url string, params map[string]interface{}) (*Response, error)
- func (c *Client) SetApiKey(key string)
- func (c *Client) SetApiUrl(url string)
- func (c *Client) SetApiVersion(version int)
- func (c *Client) SetTimeout(timeout time.Duration)
- func (c *Client) UserAgent() string
- type Config
- type Label
- type Reason
- type Response
- type Sift
- func (s *Sift) Label(userID string, params map[string]interface{}) (*Response, error)
- func (s *Sift) Score(userID string) (*Response, error)
- func (s *Sift) Track(event string, params map[string]interface{}, args map[string]interface{}) (*Response, error)
- func (s *Sift) UnLabel(userID string) (*Response, error)
- type Trigger
Constants ¶
const ( API_URL = "https://api.siftscience.com" TIMEOUT = time.Duration(2) // In seconds VERSION = "0.0.1" API_VERSION = 203 ENV_PRODUCTION = "production" ENV_SANDBOX = "sandbox" )
Variables ¶
var ( // NoContentStatusCodes - Here as helper to define if request was successful or not NoContentStatusCodes = map[int]string{204: "", 304: ""} // AvailableMethods - List of all methods that Sift Science API accepts AvailableMethods = map[string]string{"GET": "get", "POST": "post", "DELETE": "delete"} // ErrorCodes A successful API request will respond with an HTTP 200. An invalid API // request will respond with an HTTP 400. The response body will be a JSON // object describing why the request failed. // These are JSON error response codes in case you need them ErrorCodes = map[int]string{ -4: "Service currently unavailable. Please try again later.", -3: "Server-side timeout processing request. Please try again later.", -2: "Unexpected server-side error", -1: "Unexpected server-side error", 0: "Success", 51: "Invalid API Key. Please check your credentials and try again.", 52: "Invalid characters in field name", 53: "Invalid characters in field value", 54: "Specified user_id has no scoreable events", 55: "Missing required field", 56: "Invalid JSON in request", 57: "Invalid HTTP body", 60: "Rate limited; too many events have been received in a short period of time", 104: "Invalid API version", 105: "Not a valid reserved field", } )
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action struct { ID string `json:"id,omitempty"` Action struct { ID string `json:"id,omitempty"` } `json:"action,omitempty"` Entity struct { ID string `json:"id,omitempty"` } Time time.Duration `json:"time,omitempty"` Triggers []Trigger `json:"triggers,omitempty"` }
Action -
type Client ¶
type Client struct {
Config `json:"config"`
}
Client - Designed to be as connection point between code and Sift Science API
func (*Client) GetEventsUrl ¶
GetEventsUrl - Returning full url to sift science events API
func (*Client) GetLabelUrl ¶
GetScoreUrl - Returning full url to sift science label API
func (*Client) GetScoreUrl ¶
GetScoreUrl - Returning full url to sift science score API
func (*Client) HttpRequest ¶
func (c *Client) HttpRequest(method string, url string, params map[string]interface{}) (*Response, error)
HttpRequest - Doing HTTP requests towards sift science API Should be used only if there's no other choice. There are helper methods defined in sift.go for tracking, labeling, etc...
func (*Client) SetApiKey ¶
SetApiKey - Set Sift API key. You can find your keys at https://siftscience.com/console/developer/api-keys Pay closer attention to Production/Sandbox Mode as keys are different.
func (*Client) SetApiUrl ¶
SetApiUrl - Set Sift API Url. Should not be modified unless you know what you're doing. Default API Url can be seen in constants.go
func (*Client) SetApiVersion ¶
SetApiVersion - Set Sift API version. Default API Url can be seen in constants.go
func (*Client) SetTimeout ¶
SetTimeout - Set new API request timeout. Default API Timeout can be seen in constants.go
type Config ¶
type Config struct { ApiUrl string `json:"api_url"` ApiVersion int `json:"api_version"` ApiKey string `json:"api_key"` Timeout time.Duration `json:"timeout"` }
Config - Configuration struct used once per Sift Environment
type Label ¶
type Label struct { IsBad bool `json:"is_bad,omitempty"` Time time.Duration `json:"time,omitempty"` Reasons []string `json:"reasons,omitempty"` Description string `json:"description,omitempty"` }
Label -
type Reason ¶
type Reason struct { Name string `json:"name,omitempty"` Value string `json:"value,omitempty"` Details struct { Users string `json:"users,omitempty"` } `json:"details,omitempty"` }
Reason -
type Response ¶
type Response struct { // Used for debugging purposes I guess.... HTTPStatus string `json:"-"` HTTPStatusCode int `json:"-"` HTTPStatusHeader http.Header `json:"-"` HTTPResponseBody string `json:"-"` Status int `json:"status,omitempty"` UserID string `json:"user_id,omitempty"` ErrorMessage string `json:"error_message,omitempty"` Time time.Duration `json:"time,omitempty"` Score float64 `json:"score,omitempty"` Request string `json:"request,omitempty"` Actions []Action `json:"actions,omitempty"` LatestLabel Label `json:"latest_label,omitempty"` Reasons []Reason `json:"reasons,omitempty"` }
Response -
type Sift ¶
type Sift struct {
Client
}
func NewFromJSON ¶
NewFromJSON - Decode JSON file into new Sift client.