This repository has been archived by the owner on Mar 6, 2023. It is now read-only.
forked from jazibjohar/intercom-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
company.go
108 lines (90 loc) · 3.9 KB
/
company.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package intercom
import "fmt"
// CompanyService handles interactions with the API through a CompanyRepository.
type CompanyService struct {
Repository CompanyRepository
}
// CompanyList holds a list of Companies and paging information
type CompanyList struct {
Pages PageParams
Companies []Company
ScrollParam string `json:"scroll_param,omitempty"`
}
// 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 Company struct {
ID string `json:"id,omitempty"`
CompanyID string `json:"company_id,omitempty"`
Name string `json:"name,omitempty"`
RemoteCreatedAt int64 `json:"remote_created_at,omitempty"`
LastRequestAt int64 `json:"last_request_at,omitempty"`
CreatedAt int64 `json:"created_at,omitempty"`
UpdatedAt int64 `json:"updated_at,omitempty"`
SessionCount int64 `json:"session_count,omitempty"`
MonthlySpend int64 `json:"monthly_spend,omitempty"`
UserCount int64 `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:"-"`
}
// CompanyIdentifiers to identify a Company using the API
type CompanyIdentifiers struct {
ID string `url:"-"`
CompanyID string `url:"company_id,omitempty"`
Name string `url:"name,omitempty"`
}
// The Plan a Company is on
type Plan struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
}
type companyListParams struct {
PageParams
SegmentID string `url:"segment_id,omitempty"`
TagID string `url:"tag_id,omitempty"`
}
// FindByID finds a Company using their Intercom ID
func (c *CompanyService) FindByID(id string) (Company, error) {
return c.findWithIdentifiers(CompanyIdentifiers{ID: id})
}
// FindByCompanyID finds a Company using their CompanyID
// CompanyID is a customer-defined field
func (c *CompanyService) FindByCompanyID(companyID string) (Company, error) {
return c.findWithIdentifiers(CompanyIdentifiers{CompanyID: companyID})
}
// FindByName finds a Company using their Name
func (c *CompanyService) FindByName(name string) (Company, error) {
return c.findWithIdentifiers(CompanyIdentifiers{Name: name})
}
func (c *CompanyService) findWithIdentifiers(identifiers CompanyIdentifiers) (Company, error) {
return c.Repository.find(identifiers)
}
// List Companies
func (c *CompanyService) List(params PageParams) (CompanyList, error) {
return c.Repository.list(companyListParams{PageParams: params})
}
// List Companies by Segment
func (c *CompanyService) ListBySegment(segmentID string, params PageParams) (CompanyList, error) {
return c.Repository.list(companyListParams{PageParams: params, SegmentID: segmentID})
}
// List Companies by Tag
func (c *CompanyService) ListByTag(tagID string, params PageParams) (CompanyList, error) {
return c.Repository.list(companyListParams{PageParams: params, TagID: tagID})
}
// List all Companies for App via Scroll API
func (c *CompanyService) Scroll(scrollParam string) (CompanyList, error) {
return c.Repository.scroll(scrollParam)
}
// Save a new Company, or update an existing one.
func (c *CompanyService) Save(user *Company) (Company, error) {
return c.Repository.save(user)
}
func (c Company) String() string {
return fmt.Sprintf("[intercom] company { id: %s name: %s, company_id: %s }", c.ID, c.Name, c.CompanyID)
}
func (p Plan) String() string {
return fmt.Sprintf("[intercom] company_plan { id: %s name: %s }", p.ID, p.Name)
}