|
| 1 | +// Copyright 2013 The go-github AUTHORS. All rights reserved. |
| 2 | +// |
| 3 | +// Use of this source code is governed by a BSD-style |
| 4 | +// license that can be found in the LICENSE file. |
| 5 | + |
| 6 | +package github |
| 7 | + |
| 8 | +import ( |
| 9 | + "context" |
| 10 | + "fmt" |
| 11 | +) |
| 12 | + |
| 13 | +// MarketplaceService handles communication with the marketplace related |
| 14 | +// methods of the GitHub API. |
| 15 | +// |
| 16 | +// GitHub API docs: https://developer.github.com/v3/apps/marketplace/ |
| 17 | +type MarketplaceService service |
| 18 | + |
| 19 | +// MarketplacePlan represents a GitHub Apps Marketplace Listing Plan. |
| 20 | +type MarketplacePlan struct { |
| 21 | + URL *string `json:"url"` |
| 22 | + AccountsURL *string `json:"accounts_url"` |
| 23 | + ID *int `json:"id"` |
| 24 | + Name *string `json:"name"` |
| 25 | + Description *string `json:"description"` |
| 26 | + MonthlyPriceInCents *int `json:"monthly_price_in_cents"` |
| 27 | + YearlyPriceInCents *int `json:"yearly_price_in_cents"` |
| 28 | + PriceModel *string `json:"price_model"` |
| 29 | + UnitName *string `json:"unit_name"` |
| 30 | + Bullets *[]string `json:"bullets"` |
| 31 | +} |
| 32 | + |
| 33 | +// MarketplacePurchase represents a GitHub Apps Marketplace Purchase. |
| 34 | +type MarketplacePurchase struct { |
| 35 | + BillingCycle *string `json:"billing_cycle"` |
| 36 | + NextBillingDate *string `json:"next_billing_date"` |
| 37 | + UnitCount *int `json:"unit_count"` |
| 38 | + Plan *MarketplacePlan `json:"plan"` |
| 39 | +} |
| 40 | + |
| 41 | +// MarketplacePlanAccount represents a GitHub Account (user or organization) on a specific plan |
| 42 | +type MarketplacePlanAccount struct { |
| 43 | + URL *string `json:"url"` |
| 44 | + AccountType *string `json:"type"` |
| 45 | + ID *int `json:"id"` |
| 46 | + Login *string `json:"login"` |
| 47 | + Email *string `json:"email"` |
| 48 | + OrganizationBillingEmail *string `json:"organization_billing_email"` |
| 49 | + MarketplacePurchase *MarketplacePurchase `json:"marketplace_purchase"` |
| 50 | +} |
| 51 | + |
| 52 | +// ListPlans lists all plans for your Marketplace listing |
| 53 | +// |
| 54 | +// GitHub API docs: https://developer.github.com/v3/apps/marketplace/#list-all-plans-for-your-marketplace-listing |
| 55 | +func (s *MarketplaceService) ListPlans(ctx context.Context, stubbed bool, opt *ListOptions) ([]*MarketplacePlan, *Response, error) { |
| 56 | + u, err := addOptions(fmt.Sprintf("%v/plans", marketplaceURI(stubbed)), opt) |
| 57 | + if err != nil { |
| 58 | + return nil, nil, err |
| 59 | + } |
| 60 | + |
| 61 | + req, err := s.client.NewRequest("GET", u, nil) |
| 62 | + if err != nil { |
| 63 | + return nil, nil, err |
| 64 | + } |
| 65 | + |
| 66 | + // TODO: remove custom Accept header when this API fully launches. |
| 67 | + req.Header.Set("Accept", mediaTypeMarketplacePreview) |
| 68 | + |
| 69 | + var i []*MarketplacePlan |
| 70 | + resp, err := s.client.Do(ctx, req, &i) |
| 71 | + if err != nil { |
| 72 | + return nil, resp, err |
| 73 | + } |
| 74 | + |
| 75 | + return i, resp, nil |
| 76 | +} |
| 77 | + |
| 78 | +// ListPlanAccounts lists all GitHub accounts (user or organization) on a specific plan |
| 79 | +// |
| 80 | +// GitHub API docs: https://developer.github.com/v3/apps/marketplace/#list-all-github-accounts-user-or-organization-on-a-specific-plan |
| 81 | +func (s *MarketplaceService) ListPlanAccounts(ctx context.Context, planID int, stubbed bool, opt *ListOptions) ([]*MarketplacePlanAccount, *Response, error) { |
| 82 | + u, err := addOptions(fmt.Sprintf("%v/plans/%v/accounts", marketplaceURI(stubbed), planID), opt) |
| 83 | + if err != nil { |
| 84 | + return nil, nil, err |
| 85 | + } |
| 86 | + |
| 87 | + req, err := s.client.NewRequest("GET", u, nil) |
| 88 | + if err != nil { |
| 89 | + return nil, nil, err |
| 90 | + } |
| 91 | + |
| 92 | + // TODO: remove custom Accept header when this API fully launches. |
| 93 | + req.Header.Set("Accept", mediaTypeMarketplacePreview) |
| 94 | + |
| 95 | + var i []*MarketplacePlanAccount |
| 96 | + resp, err := s.client.Do(ctx, req, &i) |
| 97 | + if err != nil { |
| 98 | + return nil, resp, err |
| 99 | + } |
| 100 | + |
| 101 | + return i, resp, nil |
| 102 | +} |
| 103 | + |
| 104 | +func marketplaceURI(stubbed bool) string { |
| 105 | + if stubbed { |
| 106 | + return "apps/marketplace_listing/stubbed" |
| 107 | + } |
| 108 | + return "apps/marketplace_listing" |
| 109 | +} |
0 commit comments