1
2
3
4
5
6 package github
7
8 import (
9 "context"
10 "fmt"
11 )
12
13
14
15
16
17 type MarketplaceService struct {
18 client *Client
19
20
21
22
23
24
25 Stubbed bool
26 }
27
28
29 type MarketplacePlan struct {
30 URL *string `json:"url,omitempty"`
31 AccountsURL *string `json:"accounts_url,omitempty"`
32 ID *int64 `json:"id,omitempty"`
33 Number *int `json:"number,omitempty"`
34 Name *string `json:"name,omitempty"`
35 Description *string `json:"description,omitempty"`
36 MonthlyPriceInCents *int `json:"monthly_price_in_cents,omitempty"`
37 YearlyPriceInCents *int `json:"yearly_price_in_cents,omitempty"`
38
39 PriceModel *string `json:"price_model,omitempty"`
40 UnitName *string `json:"unit_name,omitempty"`
41 Bullets *[]string `json:"bullets,omitempty"`
42
43 State *string `json:"state,omitempty"`
44 HasFreeTrial *bool `json:"has_free_trial,omitempty"`
45 }
46
47
48 type MarketplacePurchase struct {
49
50 BillingCycle *string `json:"billing_cycle,omitempty"`
51 NextBillingDate *Timestamp `json:"next_billing_date,omitempty"`
52 UnitCount *int `json:"unit_count,omitempty"`
53 Plan *MarketplacePlan `json:"plan,omitempty"`
54 OnFreeTrial *bool `json:"on_free_trial,omitempty"`
55 FreeTrialEndsOn *Timestamp `json:"free_trial_ends_on,omitempty"`
56 UpdatedAt *Timestamp `json:"updated_at,omitempty"`
57 }
58
59
60 type MarketplacePendingChange struct {
61 EffectiveDate *Timestamp `json:"effective_date,omitempty"`
62 UnitCount *int `json:"unit_count,omitempty"`
63 ID *int64 `json:"id,omitempty"`
64 Plan *MarketplacePlan `json:"plan,omitempty"`
65 }
66
67
68 type MarketplacePlanAccount struct {
69 URL *string `json:"url,omitempty"`
70 Type *string `json:"type,omitempty"`
71 ID *int64 `json:"id,omitempty"`
72 Login *string `json:"login,omitempty"`
73 OrganizationBillingEmail *string `json:"organization_billing_email,omitempty"`
74 MarketplacePurchase *MarketplacePurchase `json:"marketplace_purchase,omitempty"`
75 MarketplacePendingChange *MarketplacePendingChange `json:"marketplace_pending_change,omitempty"`
76 }
77
78
79
80
81 func (s *MarketplaceService) ListPlans(ctx context.Context, opts *ListOptions) ([]*MarketplacePlan, *Response, error) {
82 uri := s.marketplaceURI("plans")
83 u, err := addOptions(uri, opts)
84 if err != nil {
85 return nil, nil, err
86 }
87
88 req, err := s.client.NewRequest("GET", u, nil)
89 if err != nil {
90 return nil, nil, err
91 }
92
93 var plans []*MarketplacePlan
94 resp, err := s.client.Do(ctx, req, &plans)
95 if err != nil {
96 return nil, resp, err
97 }
98
99 return plans, resp, nil
100 }
101
102
103
104
105 func (s *MarketplaceService) ListPlanAccountsForPlan(ctx context.Context, planID int64, opts *ListOptions) ([]*MarketplacePlanAccount, *Response, error) {
106 uri := s.marketplaceURI(fmt.Sprintf("plans/%v/accounts", planID))
107 u, err := addOptions(uri, opts)
108 if err != nil {
109 return nil, nil, err
110 }
111
112 req, err := s.client.NewRequest("GET", u, nil)
113 if err != nil {
114 return nil, nil, err
115 }
116
117 var accounts []*MarketplacePlanAccount
118 resp, err := s.client.Do(ctx, req, &accounts)
119 if err != nil {
120 return nil, resp, err
121 }
122
123 return accounts, resp, nil
124 }
125
126
127
128
129 func (s *MarketplaceService) GetPlanAccountForAccount(ctx context.Context, accountID int64) (*MarketplacePlanAccount, *Response, error) {
130 uri := s.marketplaceURI(fmt.Sprintf("accounts/%v", accountID))
131
132 req, err := s.client.NewRequest("GET", uri, nil)
133 if err != nil {
134 return nil, nil, err
135 }
136
137 var account *MarketplacePlanAccount
138 resp, err := s.client.Do(ctx, req, &account)
139 if err != nil {
140 return nil, resp, err
141 }
142
143 return account, resp, nil
144 }
145
146
147
148
149
150 func (s *MarketplaceService) ListMarketplacePurchasesForUser(ctx context.Context, opts *ListOptions) ([]*MarketplacePurchase, *Response, error) {
151 uri := "user/marketplace_purchases"
152 if s.Stubbed {
153 uri = "user/marketplace_purchases/stubbed"
154 }
155
156 u, err := addOptions(uri, opts)
157 if err != nil {
158 return nil, nil, err
159 }
160
161 req, err := s.client.NewRequest("GET", u, nil)
162 if err != nil {
163 return nil, nil, err
164 }
165
166 var purchases []*MarketplacePurchase
167 resp, err := s.client.Do(ctx, req, &purchases)
168 if err != nil {
169 return nil, resp, err
170 }
171 return purchases, resp, nil
172 }
173
174 func (s *MarketplaceService) marketplaceURI(endpoint string) string {
175 url := "marketplace_listing"
176 if s.Stubbed {
177 url = "marketplace_listing/stubbed"
178 }
179 return url + "/" + endpoint
180 }
181
View as plain text