Documentation ¶
Overview ¶
Package intercom-go provides a thin client for the Intercom API: http://doc.intercom.io/api/.
The first step to using Intercom's Go client is to create a client object, using your App ID and Api Key from your [settings](http://app.intercom.io/apps/api_keys).
import ( "github.com/intercom/intercom-go" ) ic := intercom.NewClient("appID", "apiKey")
The client can be configured with different options by calls to Option:
ic.Option(intercom.TraceHTTP(true)) // turn http tracing on ic.Option(intercom.BaseURI("http://intercom.dev")) // change the base uri used, useful for testing ic.Option(intercom.SetHTTPClient(myHTTPClient)) // set a new HTTP client
Errors ¶
Errors may be returned from some calls. Errors returned from the API will implement `intercom.IntercomError` and can be checked:
_, err := ic.Users.FindByEmail("doesnotexist@intercom.io") if herr, ok := err.(intercom.IntercomError); ok && herr.GetCode() == "not_found" { fmt.Print(herr) }
HTTP Client ¶
The HTTP Client used by this package can be swapped out for one of your choosing, with your own configuration, it just needs to implement the HTTPClient interface:
type HTTPClient interface { Get(string, interface{}) ([]byte, error) Post(string, interface{}) ([]byte, error) Delete(string, interface{}) ([]byte, error) }
The client will probably need to work with `appId`, `apiKey` and `baseURI` values. See the provided client for an example. Then create an Intercom Client and inject the HTTPClient:
ic := intercom.Client{} ic.Option(intercom.SetHTTPClient(myHTTPClient)) // ready to go!
On Bools ¶
Due to the way Go represents the zero value for a bool, it's necessary to pass pointers to bool instead in some places. The helper `intercom.Bool(true)` creates these for you.
Pagination ¶
For many resources, pagination should be applied through the use of a PageParams object passed into List() functions.
pageParams := PageParams{ Page: 2, PerPage: 10, } ic.Users.List(pageParams)
Index ¶
- func BaseURI(baseURI string) option
- func Bool(value bool) *bool
- func SetHTTPClient(httpClient interfaces.HTTPClient) option
- func TraceHTTP(trace bool) option
- type Admin
- type AdminAPI
- type AdminList
- type AdminRepository
- type AdminService
- type Client
- type Company
- type CompanyAPI
- type CompanyIdentifiers
- type CompanyList
- type CompanyRepository
- type CompanyService
- func (c *CompanyService) FindByCompanyID(companyID string) (Company, error)
- func (c *CompanyService) FindByID(id string) (Company, error)
- func (c *CompanyService) FindByName(name string) (Company, error)
- func (c *CompanyService) List(params PageParams) (CompanyList, error)
- func (c *CompanyService) ListBySegment(segmentID string, params PageParams) (CompanyList, error)
- func (c *CompanyService) ListByTag(tagID string, params PageParams) (CompanyList, error)
- func (c *CompanyService) Save(user *Company) (Company, error)
- type Contact
- type ContactAPI
- type ContactList
- type ContactRepository
- type ContactService
- func (c *ContactService) Convert(contact *Contact, user *User) (User, error)
- func (c *ContactService) Create(contact *Contact) (Contact, error)
- func (c *ContactService) Delete(contact *Contact) (Contact, error)
- func (c *ContactService) FindByID(id string) (Contact, error)
- func (c *ContactService) FindByUserID(userID string) (Contact, error)
- func (c *ContactService) List(params PageParams) (ContactList, error)
- func (c *ContactService) ListByEmail(email string, params PageParams) (ContactList, error)
- func (c *ContactService) ListBySegment(segmentID string, params PageParams) (ContactList, error)
- func (c *ContactService) ListByTag(tagID string, params PageParams) (ContactList, error)
- func (c *ContactService) Update(contact *Contact) (Contact, error)
- type Event
- type EventAPI
- type EventRepository
- type EventService
- type IntercomError
- type LocationData
- type PageParams
- type Plan
- type Segment
- type SegmentAPI
- type SegmentList
- type SegmentPersonType
- type SegmentRepository
- type SegmentService
- type SocialProfile
- type SocialProfileList
- type Tag
- type TagAPI
- type TagList
- type TagRepository
- type TagService
- type Tagging
- type TaggingList
- type User
- type UserAPI
- type UserAvatar
- type UserCompany
- type UserIdentifiers
- type UserList
- type UserRepository
- type UserService
- func (u *UserService) Delete(id string) (User, error)
- func (u *UserService) FindByEmail(email string) (User, error)
- func (u *UserService) FindByID(id string) (User, error)
- func (u *UserService) FindByUserID(userID string) (User, error)
- func (u *UserService) List(params PageParams) (UserList, error)
- func (u *UserService) ListBySegment(segmentID string, params PageParams) (UserList, error)
- func (u *UserService) ListByTag(tagID string, params PageParams) (UserList, error)
- func (u *UserService) Save(user *User) (User, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BaseURI ¶
func BaseURI(baseURI string) option
BaseURI sets a base URI for the HTTP Client to use. Defaults to "https://api.intercom.io". Typically this would be used during testing to point to a stubbed service.
func Bool ¶
Bool is a helper method to create *bool. *bool is preferred to bool because it allows distinction between false and absence.
func SetHTTPClient ¶
func SetHTTPClient(httpClient interfaces.HTTPClient) option
SetHTTPClient sets a HTTPClient for the Intercom Client to use. Useful for customising timeout behaviour etc.
Types ¶
type Admin ¶
type Admin struct { ID json.Number `json:"id"` Type string `json:"type"` Name string `json:"name"` Email string `json:"email"` }
Admin represents an Admin in Intercom.
func (Admin) IsNobodyAdmin ¶
IsNobodyAdmin is a helper function to determine if the Admin is 'Nobody'.
type AdminAPI ¶
type AdminAPI struct {
// contains filtered or unexported fields
}
AdminAPI implements AdminRepository
type AdminList ¶
type AdminList struct {
Admins []Admin
}
AdminList represents an object holding list of Admins
type AdminRepository ¶
type AdminRepository interface {
// contains filtered or unexported methods
}
AdminRepository defines the interface for working with Admins through the API.
type AdminService ¶
type AdminService struct {
Repository AdminRepository
}
AdminService handles interactions with the API through an AdminRepository.
func (*AdminService) List ¶
func (c *AdminService) List() (AdminList, error)
List lists the Admins associated with your App.
type Client ¶
type Client struct { // Services for interacting with various resources in Intercom. Admins AdminService Companies CompanyService Contacts ContactService Events EventService Segments SegmentService Tags TagService Users UserService // Mappings for resources to API constructs AdminRepository AdminRepository CompanyRepository CompanyRepository ContactRepository ContactRepository EventRepository EventRepository SegmentRepository SegmentRepository TagRepository TagRepository UserRepository UserRepository // AppID For Intercom. AppID string // APIKey for Intercom's API. See http://app.intercom.io/apps/api_keys. APIKey string // HTTP Client used to interact with the API. HTTPClient interfaces.HTTPClient // contains filtered or unexported fields }
A Client manages interacting with the Intercom API.
type Company ¶
type Company struct { ID string `json:"id,omitempty"` CompanyID string `json:"company_id,omitempty"` Name string `json:"name,omitempty"` RemoteCreatedAt int32 `json:"remote_created_at,omitempty"` LastRequestAt int32 `json:"last_request_at,omitempty"` CreatedAt int32 `json:"created_at,omitempty"` UpdatedAt int32 `json:"updated_at,omitempty"` SessionCount int32 `json:"session_count,omitempty"` MonthlySpend int32 `json:"monthly_spend,omitempty"` UserCount int32 `json:"user_count,omitempty"` Tags *TagList `json:"tags,omitempty"` Segments *SegmentList `json:"segments,omitempty"` Plan *Plan `json:"plan,omitempty"` CustomAttributes map[string]interface{} `json:"custom_attributes,omitempty"` Remove *bool `json:"-"` }
Company represents a Company in Intercom Not all of the fields are writeable to the API, non-writeable fields are stripped out from the request. Please see the API documentation for details.
type CompanyAPI ¶
type CompanyAPI struct {
// contains filtered or unexported fields
}
CompanyAPI implements CompanyRepository
type CompanyIdentifiers ¶
type CompanyIdentifiers struct { ID string `url:"-"` CompanyID string `url:"company_id,omitempty"` Name string `url:"name,omitempty"` }
CompanyIdentifiers to identify a Company using the API
type CompanyList ¶
type CompanyList struct { Pages PageParams Companies []Company }
CompanyList holds a list of Companies and paging information
type CompanyRepository ¶
type CompanyRepository interface {
// contains filtered or unexported methods
}
CompanyRepository defines the interface for working with Companies through the API.
type CompanyService ¶
type CompanyService struct {
Repository CompanyRepository
}
CompanyService handles interactions with the API through a CompanyRepository.
func (*CompanyService) FindByCompanyID ¶
func (c *CompanyService) FindByCompanyID(companyID string) (Company, error)
FindByCompanyID finds a Company using their CompanyID CompanyID is a customer-defined field
func (*CompanyService) FindByID ¶
func (c *CompanyService) FindByID(id string) (Company, error)
FindByID finds a Company using their Intercom ID
func (*CompanyService) FindByName ¶
func (c *CompanyService) FindByName(name string) (Company, error)
FindByName finds a Company using their Name
func (*CompanyService) List ¶
func (c *CompanyService) List(params PageParams) (CompanyList, error)
List Companies
func (*CompanyService) ListBySegment ¶
func (c *CompanyService) ListBySegment(segmentID string, params PageParams) (CompanyList, error)
List Companies by Segment
func (*CompanyService) ListByTag ¶
func (c *CompanyService) ListByTag(tagID string, params PageParams) (CompanyList, error)
List Companies by Tag
type Contact ¶
type Contact struct { ID string `json:"id,omitempty"` Email string `json:"email,omitempty"` UserID string `json:"user_id,omitempty"` Name string `json:"name,omitempty"` Avatar *UserAvatar `json:"avatar,omitempty"` LocationData *LocationData `json:"location_data,omitempty"` LastRequestAt int32 `json:"last_request_at,omitempty"` CreatedAt int32 `json:"created_at,omitempty"` UpdatedAt int32 `json:"updated_at,omitempty"` SessionCount int32 `json:"session_count,omitempty"` LastSeenIP string `json:"last_seen_ip,omitempty"` SocialProfiles *SocialProfileList `json:"social_profiles,omitempty"` UnsubscribedFromEmails *bool `json:"unsubscribed_from_emails,omitempty"` UserAgentData string `json:"user_agent_data,omitempty"` Tags *TagList `json:"tags,omitempty"` Segments *SegmentList `json:"segments,omitempty"` Companies *CompanyList `json:"companies,omitempty"` CustomAttributes map[string]interface{} `json:"custom_attributes,omitempty"` UpdateLastRequestAt *bool `json:"update_last_request_at,omitempty"` NewSession *bool `json:"new_session,omitempty"` }
Contact represents a Contact within Intercom. Not all of the fields are writeable to the API, non-writeable fields are stripped out from the request. Please see the API documentation for details.
type ContactAPI ¶
type ContactAPI struct {
// contains filtered or unexported fields
}
ContactAPI implements ContactRepository
type ContactList ¶
type ContactList struct { Pages PageParams Contacts []Contact }
ContactList holds a list of Contacts and paging information
type ContactRepository ¶
type ContactRepository interface {
// contains filtered or unexported methods
}
ContactRepository defines the interface for working with Contacts through the API.
type ContactService ¶
type ContactService struct {
Repository ContactRepository
}
ContactService handles interactions with the API through a ContactRepository.
func (*ContactService) Convert ¶
func (c *ContactService) Convert(contact *Contact, user *User) (User, error)
Convert Contact to User
func (*ContactService) Create ¶
func (c *ContactService) Create(contact *Contact) (Contact, error)
Create Contact
func (*ContactService) Delete ¶
func (c *ContactService) Delete(contact *Contact) (Contact, error)
Delete Contact
func (*ContactService) FindByID ¶
func (c *ContactService) FindByID(id string) (Contact, error)
FindByID looks up a Contact by their Intercom ID.
func (*ContactService) FindByUserID ¶
func (c *ContactService) FindByUserID(userID string) (Contact, error)
FindByUserID looks up a Contact by their UserID (automatically generated server side).
func (*ContactService) List ¶
func (c *ContactService) List(params PageParams) (ContactList, error)
List all Contacts for App.
func (*ContactService) ListByEmail ¶
func (c *ContactService) ListByEmail(email string, params PageParams) (ContactList, error)
ListByEmail looks up a list of Contacts by their Email.
func (*ContactService) ListBySegment ¶
func (c *ContactService) ListBySegment(segmentID string, params PageParams) (ContactList, error)
List Contacts by Segment.
func (*ContactService) ListByTag ¶
func (c *ContactService) ListByTag(tagID string, params PageParams) (ContactList, error)
List Contacts By Tag.
type Event ¶
type Event struct { Email string `json:"email,omitempty"` UserID string `json:"user_id,omitempty"` EventName string `json:"event_name,omitempty"` CreatedAt int32 `json:"created_at,omitempty"` Metadata map[string]interface{} `json:"metadata,omitempty"` }
An Event represents a new event that happens to a User.
type EventAPI ¶
type EventAPI struct {
// contains filtered or unexported fields
}
EventAPI implements EventRepository
type EventRepository ¶
type EventRepository interface {
// contains filtered or unexported methods
}
EventRepository defines the interface for working with Events through the API.
type EventService ¶
type EventService struct {
Repository EventRepository
}
EventService handles interactions with the API through an EventRepository.
type IntercomError ¶
type IntercomError interface { Error() string GetStatusCode() int GetCode() string GetMessage() string }
IntercomError is a known error from the Intercom API
type LocationData ¶
type LocationData struct { CityName string `json:"city_name,omitempty"` ContinentCode string `json:"continent_code,omitempty"` CountryName string `json:"country_name,omitempty"` Latitude float64 `json:"latitude,omitempty"` Longitude float64 `json:"longitude,omitempty"` PostalCode string `json:"postal_code,omitempty"` RegionName string `json:"region_name,omitempty"` Timezone string `json:"timezone,omitempty"` CountryCode string `json:"country_code,omitempty"` }
LocationData represents the location for a User.
func (LocationData) String ¶
func (l LocationData) String() string
type PageParams ¶
type PageParams struct { Page int32 `json:"page" url:"page,omitempty"` PerPage int32 `json:"per_page" url:"per_page,omitempty"` TotalPages int32 `json:"total_pages" url:"-"` }
PageParams determine paging information to and from the API
type Segment ¶
type Segment struct { ID string `json:"id,omitempty"` Name string `json:"name,omitempty"` CreatedAt int32 `json:"created_at,omitempty"` UpdatedAt int32 `json:"updated_at,omitempty"` PersonType SegmentPersonType `json:"person_type,omitempty"` }
Segment represents an Segment in Intercom.
type SegmentAPI ¶
type SegmentAPI struct {
// contains filtered or unexported fields
}
SegmentAPI implements SegmentRepository
type SegmentList ¶
type SegmentList struct {
Segments []Segment `json:"segments,omitempty"`
}
SegmentList, an object holding a list of Segments
type SegmentPersonType ¶
type SegmentPersonType int
const ( USER SegmentPersonType = iota CONTACT )
func (SegmentPersonType) String ¶
func (segmentPersonType SegmentPersonType) String() string
type SegmentRepository ¶
type SegmentRepository interface {
// contains filtered or unexported methods
}
SegmentRepository defines the interface for working with Segments through the API.
type SegmentService ¶
type SegmentService struct {
Repository SegmentRepository
}
SegmentService handles interactions with the API through a SegmentRepository.
func (*SegmentService) Find ¶
func (t *SegmentService) Find(id string) (Segment, error)
Find a particular Segment in the App
func (*SegmentService) List ¶
func (t *SegmentService) List() (SegmentList, error)
List all Segments for the App
type SocialProfile ¶
type SocialProfile struct { Name string `json:"name,omitempty"` ID string `json:"id,omitempty"` Username string `json:"username,omitempty"` URL string `json:"url,omitempty"` }
SocialProfile represents a social account for a User.
func (SocialProfile) String ¶
func (s SocialProfile) String() string
type SocialProfileList ¶
type SocialProfileList struct {
SocialProfiles []SocialProfile `json:"social_profiles,omitempty"`
}
SocialProfile list is a list of SocialProfiles for a User.
type TagAPI ¶
type TagAPI struct {
// contains filtered or unexported fields
}
TagAPI implements TagRepository
type TagList ¶
type TagList struct {
Tags []Tag `json:"tags,omitempty"`
}
TagList, an object holding a list of Tags
type TagRepository ¶
type TagRepository interface {
// contains filtered or unexported methods
}
TagRepository defines the interface for working with Tags through the API.
type TagService ¶
type TagService struct {
Repository TagRepository
}
TagService handles interactions with the API through a TagRepository.
func (*TagService) Save ¶
func (t *TagService) Save(tag *Tag) (Tag, error)
Save a new Tag for the App.
func (*TagService) Tag ¶
func (t *TagService) Tag(taggingList *TaggingList) (Tag, error)
Tag Users or Companies using a TaggingList.
type Tagging ¶
type Tagging struct { ID string `json:"id,omitempty"` UserID string `json:"user_id,omitempty"` Email string `json:"email,omitempty"` CompanyID string `json:"company_id,omitempty"` Untag *bool `json:"untag,omitempty"` }
A Tagging is an object identifying a User or Company to be tagged, that can optionally be set to untag.
type TaggingList ¶
type TaggingList struct { Name string `json:"name,omitempty"` Users []Tagging `json:"users,omitempty"` Companies []Tagging `json:"companies,omitempty"` }
TaggingList is an object used to Tag Users and Companies. The Name should be that of the Tag required, and Users and Companies are lists of Taggings
type User ¶
type User struct { ID string `json:"id,omitempty"` Email string `json:"email,omitempty"` UserID string `json:"user_id,omitempty"` Anonymous *bool `json:"anonymous,omitempty"` Name string `json:"name,omitempty"` Pseudonym string `json:"pseudonym,omitempty"` Avatar *UserAvatar `json:"avatar,omitempty"` LocationData *LocationData `json:"location_data,omitempty"` SignedUpAt int32 `json:"signed_up_at,omitempty"` RemoteCreatedAt int32 `json:"remote_created_at,omitempty"` LastRequestAt int32 `json:"last_request_at,omitempty"` CreatedAt int32 `json:"created_at,omitempty"` UpdatedAt int32 `json:"updated_at,omitempty"` SessionCount int32 `json:"session_count,omitempty"` LastSeenIP string `json:"last_seen_ip,omitempty"` SocialProfiles *SocialProfileList `json:"social_profiles,omitempty"` UnsubscribedFromEmails *bool `json:"unsubscribed_from_emails,omitempty"` UserAgentData string `json:"user_agent_data,omitempty"` Tags *TagList `json:"tags,omitempty"` Segments *SegmentList `json:"segments,omitempty"` Companies *CompanyList `json:"companies,omitempty"` CustomAttributes map[string]interface{} `json:"custom_attributes,omitempty"` UpdateLastRequestAt *bool `json:"update_last_request_at,omitempty"` NewSession *bool `json:"new_session,omitempty"` LastSeenUserAgent string `json:"last_seen_user_agent,omitempty"` }
User represents a User within Intercom. Not all of the fields are writeable to the API, non-writeable fields are stripped out from the request. Please see the API documentation for details.
type UserAPI ¶
type UserAPI struct {
// contains filtered or unexported fields
}
UserAPI implements UserRepository
type UserAvatar ¶
type UserAvatar struct {
ImageURL string `json:"image_url,omitempty"`
}
UserAvatar represents an avatar for a User.
func (UserAvatar) String ¶
func (a UserAvatar) String() string
type UserCompany ¶
type UserCompany struct { ID string `json:"id,omitempty"` Name string `json:"name,omitempty"` Remove *bool `json:"remove,omitempty"` }
A Company the User belongs to used to update Companies on a User.
type UserIdentifiers ¶
type UserIdentifiers struct { ID string `url:"-"` UserID string `url:"user_id,omitempty"` Email string `url:"email,omitempty"` }
UserIdentifiers are used to identify Users in Intercom.
type UserList ¶
type UserList struct { Pages PageParams Users []User }
UserList holds a list of Users and paging information
type UserRepository ¶
type UserRepository interface {
// contains filtered or unexported methods
}
UserRepository defines the interface for working with Users through the API.
type UserService ¶
type UserService struct {
Repository UserRepository
}
UserService handles interactions with the API through a UserRepository.
func (*UserService) FindByEmail ¶
func (u *UserService) FindByEmail(email string) (User, error)
FindByEmail looks up a User by their Email.
func (*UserService) FindByID ¶
func (u *UserService) FindByID(id string) (User, error)
FindByID looks up a User by their Intercom ID.
func (*UserService) FindByUserID ¶
func (u *UserService) FindByUserID(userID string) (User, error)
FindByUserID looks up a User by their UserID (customer supplied).
func (*UserService) List ¶
func (u *UserService) List(params PageParams) (UserList, error)
List all Users for App.
func (*UserService) ListBySegment ¶
func (u *UserService) ListBySegment(segmentID string, params PageParams) (UserList, error)
List Users by Segment.
func (*UserService) ListByTag ¶
func (u *UserService) ListByTag(tagID string, params PageParams) (UserList, error)
List Users By Tag.