saasquatch

package module
v0.0.0-...-664e769 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2016 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HOST = "http://app.referralsaasquatch.com"
)

Variables

View Source
var (
	ErrNoSuchCode        = errors.New("referral: no such code")
	ErrInvalidRedemption = errors.New("reward: invalid redemption due to zero amount or exceed redeemable credit")
	ErrBadRequest        = errors.New("saasquatch: bad request")
)

Functions

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range. API error responses are expected to have either no response body, or a JSON response body that maps to ErrorResponse. Any other response body will be silently ignored.

Types

type Account

type Account struct {
	Id           string        `json:"id"`
	Currency     string        `json:"currency"`
	Subscription *Subscription `json:"subscription,omitempty"`
	Referral     *Referral     `json:"referral,omitempty"`
}

type AccountsServices

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

func (*AccountsServices) CreateOrUpdateAccount

func (s *AccountsServices) CreateOrUpdateAccount(payload Account) (*Account, error)

func (*AccountsServices) LookupAccount

func (s *AccountsServices) LookupAccount(accountId string) (*Account, error)

type BalanceDebitted

type BalanceDebitted struct {
	CreditRedeemed  int    `json:"creditRedeemed"`
	CreditAvailable int    `json:"creditAvailable"`
	Unit            string `json:"unit"`
}

type Client

type Client struct {
	BaseURL *url.URL

	Referral       *ReferralService
	ReferralCode   *ReferralCodeService
	Accounts       *AccountsServices
	Users          *UsersServices
	RewardBalances *RewardBalancesServices
	// contains filtered or unexported fields
}

A Client manages communication with the SaaSquatch API.

func NewClient

func NewClient(httpClient *http.Client, tenantAlias, apiKey string) *Client

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) error

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response body will be written to v, without attempting to first decode it.

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, in which case it is resolved relative to the BaseURL of the Client. Relative URLs should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as the request body.

type DebitRewardOptions

type DebitRewardOptions struct {
	AccountId string `json:"accountId"`
	Unit      string `json:"unit"`
	Amount    int    `json:"amount"`
}

type ErrorResponse

type ErrorResponse struct {
	Response     *http.Response // HTTP response that caused this error
	StatusCode   int            `json:"statusCode"`
	Message      string         `json:"message"`
	ApiErrorCode string         `json:"apiErrorCode"`
}

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type FraudSignal

type FraudSignal struct {
	Message string `json:"message"`
	Score   int    `json:"score"`
}

type FraudSignals

type FraudSignals struct {
	Name  FraudSignal `json:"name"`
	Ip    FraudSignal `json:"ip"`
	Email FraudSignal `json:"email"`
	Rate  FraudSignal `json:"rate"`
}

type ListReferralsOptions

type ListReferralsOptions struct {
	ReferringAccountId       string `url:"referringAccountId,omitempty"`
	ReferringUserId          string `url:"referringUserId,omitempty"`
	DateReferralPaid         string `url:"dateReferralPaid,omitempty"`
	DateReferralEnded        string `url:"dateReferralEnded,omitempty"`
	ReferredModerationStatus string `url:"referredModerationStatus,omitempty"`
	ReferrerModerationStatus string `url:"referrerModerationStatus,omitempty"`
	Limit                    int    `url:"limit,omitempty"`
	Offset                   int    `url:"offset,omitempty"`
}

type ListReferralsResult

type ListReferralsResult struct {
	Count      int              `json:"count"`
	TotalCount int              `json:"totalCount"`
	Referrals  []ReferralObject `json:"referrals"`
}

type ListRewardOptions

type ListRewardOptions struct {
	AccountId         string `url:"accountId"`
	UserId            string `url:"userId,omitempty"`
	RewardTypeFilter  string `url:"rewardTypeFilter,omitempty"`
	FeatureTypeFilter string `url:"featureTypeFilter,omitempty"`
}

type MobileWidget

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

func NewMobileWidget

func NewMobileWidget(tn *Tenant, uid, email, firstName string) *MobileWidget

func (MobileWidget) BuildUrl

func (mw MobileWidget) BuildUrl() (string, error)

func (*MobileWidget) WithAccount

func (mw *MobileWidget) WithAccount(aid string) *MobileWidget

func (*MobileWidget) WithEmail

func (mw *MobileWidget) WithEmail(email string) *MobileWidget

func (*MobileWidget) WithFirstName

func (mw *MobileWidget) WithFirstName(name string) *MobileWidget

func (*MobileWidget) WithLastName

func (mw *MobileWidget) WithLastName(name string) *MobileWidget

func (*MobileWidget) WithLocale

func (mw *MobileWidget) WithLocale(locale string) *MobileWidget

func (*MobileWidget) WithPayment

func (mw *MobileWidget) WithPayment(pid string) *MobileWidget

type Referral

type Referral struct {
	Code string `json:"code"`
}

type ReferralCode

type ReferralCode struct {
	Code         string `json:"code"`
	DateCreated  int    `json:"dateCreated"`
	ReferrerName string `json:"referrerName"`
	Reward       Reward `json:"reward"`
}

type ReferralCodeService

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

func (*ReferralCodeService) LookupReferralCode

func (s *ReferralCodeService) LookupReferralCode(cd string) (*ReferralCode, error)

type ReferralObject

type ReferralObject struct {
	Id                       string          `json:"id"`
	ReferredUser             *ReferredUser   `json:"referredUser"`
	ReferrerUser             *ReferredUser   `json:"referrerUser"`
	ReferredReward           *ReferredReward `json:"referredReward"`
	ReferrerReward           *ReferredReward `json:"referrerReward"`
	ModerationStatus         string          `json:"moderationStatus"`
	ReferredModerationStatus string          `json:"referredModerationStatus"`
	ReferrerModerationStatus string          `json:"referrerModerationStatus"`
	FraudSignals             *FraudSignals   `json:"fraudSignals,omitempty"`
	DateReferralStarted      int             `json:"dateReferralStarted"`
	DateReferralPaid         int             `json:"dateReferralPaid"`
	DateReferralEnded        int             `json:"dateReferralEnded"`
	DateModerated            int             `json:"dateModerated"`
}

type ReferralService

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

func (*ReferralService) ListReferrals

type ReferredReward

type ReferredReward struct {
	Id              string `json:"id"`
	Type            string `json:"type"`
	DateGiven       int    `json:"dateGiven"`
	DateExpires     int    `json:"dateExpires"`
	DateCancelled   int    `json:"dateCancelled"`
	Cancellable     bool   `json:"cancellable"`
	RewardSource    string `json:"rewardSource"`
	Unit            string `json:"unit"`
	DiscountPercent int    `json:"discountPercent"`
	FeatureType     string `json:"featureType"`
	Name            string `json:"name"`
	Description     string `json:"description"`
	Quantity        int    `json:"quantity"`
	AssignedCredit  int    `json:"assignedCredit"`
	RedeemedCredit  int    `json:"redeemedCredit"`
	Currency        string `json:"currency"`
}

type ReferredUser

type ReferredUser struct {
	Id             string `json:"id"`
	AccountId      string `json:"accountId"`
	ReferralCode   string `json:"referralCode"`
	Email          string `json:"email"`
	ImageUrl       string `json:"imageUrl"`
	FirstName      string `json:"firstName"`
	LastName       string `json:"lastName"`
	FirstSeenIP    string `json:"firstSeenIP"`
	LastSeenIP     string `json:"lastSeenIP"`
	DateCreated    int    `json:"dateCreated"`
	EmailHash      string `json:"emailHash"`
	ReferralSource string `json:"referralSource"`
	Locale         string `json:"locale"`
}

type Reward

type Reward struct {
	Type                  string `json:"type"`
	Unit                  string `json:"unit"`
	Credit                int    `json:"credit"`
	DiscountPercent       int    `json:"discountPercent"`
	MonthsDiscountIsValid int    `json:"monthsDiscountIsValid"`

	//Only works with types FEATURE
	FeatureType string `json:"featureType,omitempty"`
	Name        string `json:"name,omitempty"`
	Description string `json:"description,omitempty"`
	Quantity    int    `json:"quantity,omitempty"`
}

type RewardBalances

type RewardBalances struct {
	Type                    string `json:"type"`
	Unit                    string `json:"unit,omitempty"`
	Count                   int    `json:"count,omitempty"`
	FeatureType             string `json:"featureType,omitempty"`
	TotalAssignedCredit     int    `json:"totalAssignedCredit,omitempty"`
	TotalRedeemedCredit     int    `json:"totalRedeemedCredit,omitempty"`
	TotalDiscountPercent    int    `json:"totalDiscountPercent,omitempty"`
	ReferredDiscountPercent int    `json:"referredDiscountPercent,omitempty"`
	ReferrerDiscountPercent int    `json:"referrerDiscountPercent,omitempty"`
}

type RewardBalancesServices

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

func (*RewardBalancesServices) DebitRewardBalance

func (s *RewardBalancesServices) DebitRewardBalance(opt DebitRewardOptions) (*BalanceDebitted, error)

func (*RewardBalancesServices) ListRewardBalances

func (s *RewardBalancesServices) ListRewardBalances(opt ListRewardOptions) ([]RewardBalances, error)

type Subscription

type Subscription struct {
	Status               string  `json:"status"`
	BillingIntervalType  string  `json:"billingIntervalType,omitempty"`
	BillingIntervalValue int     `json:"billingIntervalValue,omitempty"`
	Value                float32 `json:"value,omitempty"`
}

type Tenant

type Tenant struct {
	Alias      string
	ApiKey     string
	SecureMode bool
}

func NewTenant

func NewTenant(alias, apiKey string) *Tenant

func (*Tenant) DisableSecureMode

func (tn *Tenant) DisableSecureMode() *Tenant

func (Tenant) NewMobileWidget

func (tn Tenant) NewMobileWidget(uid, email, firstName string) *MobileWidget

type User

type User struct {
	Id           string `json:"id"`
	AccountId    string `json:"accountId"`
	ReferralCode string `json:"referralCode,omitempty"`
	Email        string `json:"email"`
	ImageUrl     string `json:"imageUrl,omitempty"`
	FirstName    string `json:"firstName"`
	LastName     string `json:"lastName"`
}

type UsersServices

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

func (*UsersServices) CreateOrUpdateUser

func (s *UsersServices) CreateOrUpdateUser(payload User) (*User, error)

func (*UsersServices) LookupUser

func (s *UsersServices) LookupUser(accountId, userId string) (*User, error)

Jump to

Keyboard shortcuts

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