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