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 Account *MarketplacePurchaseAccount `json:"account,omitempty"`
50
51 BillingCycle *string `json:"billing_cycle,omitempty"`
52 NextBillingDate *Timestamp `json:"next_billing_date,omitempty"`
53 UnitCount *int `json:"unit_count,omitempty"`
54 Plan *MarketplacePlan `json:"plan,omitempty"`
55 OnFreeTrial *bool `json:"on_free_trial,omitempty"`
56 FreeTrialEndsOn *Timestamp `json:"free_trial_ends_on,omitempty"`
57 UpdatedAt *Timestamp `json:"updated_at,omitempty"`
58 }
59
60
61 type MarketplacePendingChange struct {
62 EffectiveDate *Timestamp `json:"effective_date,omitempty"`
63 UnitCount *int `json:"unit_count,omitempty"`
64 ID *int64 `json:"id,omitempty"`
65 Plan *MarketplacePlan `json:"plan,omitempty"`
66 }
67
68
69 type MarketplacePlanAccount struct {
70 URL *string `json:"url,omitempty"`
71 Type *string `json:"type,omitempty"`
72 ID *int64 `json:"id,omitempty"`
73 Login *string `json:"login,omitempty"`
74 OrganizationBillingEmail *string `json:"organization_billing_email,omitempty"`
75 MarketplacePurchase *MarketplacePurchase `json:"marketplace_purchase,omitempty"`
76 MarketplacePendingChange *MarketplacePendingChange `json:"marketplace_pending_change,omitempty"`
77 }
78
79
80 type MarketplacePurchaseAccount struct {
81 URL *string `json:"url,omitempty"`
82 Type *string `json:"type,omitempty"`
83 ID *int64 `json:"id,omitempty"`
84 Login *string `json:"login,omitempty"`
85 OrganizationBillingEmail *string `json:"organization_billing_email,omitempty"`
86 Email *string `json:"email,omitempty"`
87 NodeID *string `json:"node_id,omitempty"`
88 }
89
90
91
92
93 func (s *MarketplaceService) ListPlans(ctx context.Context, opts *ListOptions) ([]*MarketplacePlan, *Response, error) {
94 uri := s.marketplaceURI("plans")
95 u, err := addOptions(uri, opts)
96 if err != nil {
97 return nil, nil, err
98 }
99
100 req, err := s.client.NewRequest("GET", u, nil)
101 if err != nil {
102 return nil, nil, err
103 }
104
105 var plans []*MarketplacePlan
106 resp, err := s.client.Do(ctx, req, &plans)
107 if err != nil {
108 return nil, resp, err
109 }
110
111 return plans, resp, nil
112 }
113
114
115
116
117 func (s *MarketplaceService) ListPlanAccountsForPlan(ctx context.Context, planID int64, opts *ListOptions) ([]*MarketplacePlanAccount, *Response, error) {
118 uri := s.marketplaceURI(fmt.Sprintf("plans/%v/accounts", planID))
119 u, err := addOptions(uri, opts)
120 if err != nil {
121 return nil, nil, err
122 }
123
124 req, err := s.client.NewRequest("GET", u, nil)
125 if err != nil {
126 return nil, nil, err
127 }
128
129 var accounts []*MarketplacePlanAccount
130 resp, err := s.client.Do(ctx, req, &accounts)
131 if err != nil {
132 return nil, resp, err
133 }
134
135 return accounts, resp, nil
136 }
137
138
139
140
141 func (s *MarketplaceService) GetPlanAccountForAccount(ctx context.Context, accountID int64) (*MarketplacePlanAccount, *Response, error) {
142 uri := s.marketplaceURI(fmt.Sprintf("accounts/%v", accountID))
143
144 req, err := s.client.NewRequest("GET", uri, nil)
145 if err != nil {
146 return nil, nil, err
147 }
148
149 var account *MarketplacePlanAccount
150 resp, err := s.client.Do(ctx, req, &account)
151 if err != nil {
152 return nil, resp, err
153 }
154
155 return account, resp, nil
156 }
157
158
159
160
161
162 func (s *MarketplaceService) ListMarketplacePurchasesForUser(ctx context.Context, opts *ListOptions) ([]*MarketplacePurchase, *Response, error) {
163 uri := "user/marketplace_purchases"
164 if s.Stubbed {
165 uri = "user/marketplace_purchases/stubbed"
166 }
167
168 u, err := addOptions(uri, opts)
169 if err != nil {
170 return nil, nil, err
171 }
172
173 req, err := s.client.NewRequest("GET", u, nil)
174 if err != nil {
175 return nil, nil, err
176 }
177
178 var purchases []*MarketplacePurchase
179 resp, err := s.client.Do(ctx, req, &purchases)
180 if err != nil {
181 return nil, resp, err
182 }
183 return purchases, resp, nil
184 }
185
186 func (s *MarketplaceService) marketplaceURI(endpoint string) string {
187 url := "marketplace_listing"
188 if s.Stubbed {
189 url = "marketplace_listing/stubbed"
190 }
191 return url + "/" + endpoint
192 }
193
View as plain text