Skip to content

Commit 9da487d

Browse files
authored
Merge pull request hub4j#635 from PauloMigAlmeida/marketplace_endpoints
[Patch 1/2] :: Add support to Marketplace endpoints
2 parents 78fb860 + c7123b0 commit 9da487d

31 files changed

Lines changed: 2084 additions & 0 deletions

File tree

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
package org.kohsuke.github;
2+
3+
import java.net.URL;
4+
5+
/**
6+
* A Github Marketplace Account.
7+
*
8+
* @author Paulo Miguel Almeida
9+
* @see GHMarketplaceListAccountBuilder#createRequest()
10+
*/
11+
public class GHMarketplaceAccount {
12+
13+
private GitHub root;
14+
private String url;
15+
private long id;
16+
private String login;
17+
private String email;
18+
private String organizationBillingEmail;
19+
private GHMarketplaceAccountType type;
20+
private GHMarketplacePendingChange marketplacePendingChange;
21+
private GHMarketplacePurchase marketplacePurchase;
22+
23+
/**
24+
* Wrap up gh marketplace account.
25+
*
26+
* @param root
27+
* the root
28+
* @return an instance of the GHMarketplaceAccount class
29+
*/
30+
GHMarketplaceAccount wrapUp(GitHub root) {
31+
this.root = root;
32+
if (this.marketplacePendingChange != null)
33+
this.marketplacePendingChange.wrapUp(this.root);
34+
35+
if (this.marketplacePurchase != null)
36+
this.marketplacePurchase.wrapUp(this.root);
37+
38+
return this;
39+
}
40+
41+
/**
42+
* Gets url.
43+
*
44+
* @return the url
45+
*/
46+
public URL getUrl() {
47+
return GitHub.parseURL(url);
48+
}
49+
50+
/**
51+
* Gets id.
52+
*
53+
* @return the id
54+
*/
55+
public long getId() {
56+
return id;
57+
}
58+
59+
/**
60+
* Gets login.
61+
*
62+
* @return the login
63+
*/
64+
public String getLogin() {
65+
return login;
66+
}
67+
68+
/**
69+
* Gets email.
70+
*
71+
* @return the email
72+
*/
73+
public String getEmail() {
74+
return email;
75+
}
76+
77+
/**
78+
* Gets organization billing email.
79+
*
80+
* @return the organization billing email
81+
*/
82+
public String getOrganizationBillingEmail() {
83+
return organizationBillingEmail;
84+
}
85+
86+
/**
87+
* Gets type.
88+
*
89+
* @return the type
90+
*/
91+
public GHMarketplaceAccountType getType() {
92+
return type;
93+
}
94+
95+
/**
96+
* Gets marketplace pending change.
97+
*
98+
* @return the marketplace pending change
99+
*/
100+
public GHMarketplacePendingChange getMarketplacePendingChange() {
101+
return marketplacePendingChange;
102+
}
103+
104+
/**
105+
* Gets marketplace purchase.
106+
*
107+
* @return the marketplace purchase
108+
*/
109+
public GHMarketplacePurchase getMarketplacePurchase() {
110+
return marketplacePurchase;
111+
}
112+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.kohsuke.github;
2+
3+
import org.apache.commons.lang3.StringUtils;
4+
5+
import java.util.Locale;
6+
7+
/**
8+
* GitHub Marketplace Account type.
9+
*
10+
* @author Paulo Miguel Almeida
11+
* @see GHMarketplaceAccount
12+
*/
13+
public enum GHMarketplaceAccountType {
14+
ORGANIZATION, USER;
15+
16+
/**
17+
* Returns GitHub's internal representation of this event.
18+
*/
19+
String symbol() {
20+
return StringUtils.capitalize(name().toLowerCase(Locale.ENGLISH));
21+
}
22+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package org.kohsuke.github;
2+
3+
import java.io.IOException;
4+
5+
/**
6+
* Returns any accounts associated with a plan, including free plans
7+
*
8+
* @author Paulo Miguel Almeida
9+
* @see GHMarketplacePlan#listAccounts()
10+
*/
11+
public class GHMarketplaceListAccountBuilder {
12+
private final GitHub root;
13+
private final Requester builder;
14+
private final long planId;
15+
16+
GHMarketplaceListAccountBuilder(GitHub root, long planId) {
17+
this.root = root;
18+
this.builder = root.createRequest();
19+
this.planId = planId;
20+
}
21+
22+
/**
23+
* Sorts the GitHub accounts by the date they were created or last updated. Can be one of created or updated.
24+
* <p>
25+
* If omitted, the default sorting strategy will be "CREATED"
26+
*
27+
* @param sort
28+
* the sort strategy
29+
* @return a GHMarketplaceListAccountBuilder
30+
*/
31+
public GHMarketplaceListAccountBuilder sort(Sort sort) {
32+
this.builder.with("sort", sort);
33+
return this;
34+
}
35+
36+
/**
37+
* Orders the GitHub accounts results, Can be one of asc or desc. Ignored without the sort parameter.
38+
*
39+
* @param direction
40+
* the order strategy
41+
* @return a GHMarketplaceListAccountBuilder
42+
*/
43+
public GHMarketplaceListAccountBuilder direction(GHDirection direction) {
44+
this.builder.with("direction", direction);
45+
return this;
46+
}
47+
48+
/**
49+
* The enum Sort.
50+
*/
51+
public enum Sort {
52+
CREATED, UPDATED
53+
}
54+
55+
/**
56+
* List any accounts associated with the plan specified on construction with all the order/sort parameters set.
57+
* <p>
58+
* GitHub Apps must use a JWT to access this endpoint.
59+
* <p>
60+
* OAuth Apps must use basic authentication with their client ID and client secret to access this endpoint.
61+
*
62+
* @return a paged iterable instance of GHMarketplaceAccount
63+
* @throws IOException
64+
* on error
65+
*/
66+
public PagedIterable<GHMarketplaceAccount> createRequest() throws IOException {
67+
return builder.asPagedIterable(String.format("/marketplace_listing/plans/%d/accounts", this.planId),
68+
GHMarketplaceAccount[].class,
69+
item -> item.wrapUp(root));
70+
}
71+
72+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package org.kohsuke.github;
2+
3+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
4+
5+
import java.util.Date;
6+
7+
/**
8+
* A Github Marketplace purchase pending change.
9+
*
10+
* @author Paulo Miguel Almeida
11+
* @see GHMarketplaceListAccountBuilder#createRequest()
12+
*/
13+
public class GHMarketplacePendingChange {
14+
private GitHub root;
15+
private long id;
16+
@SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Field comes from JSON deserialization")
17+
private Long unitCount;
18+
@SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Field comes from JSON deserialization")
19+
private GHMarketplacePlan plan;
20+
@SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Field comes from JSON deserialization")
21+
private String effectiveDate;
22+
23+
/**
24+
* Wrap up gh marketplace pending change.
25+
*
26+
* @param root
27+
* the root
28+
* @return an instance of the GHMarketplacePendingChange class
29+
*/
30+
GHMarketplacePendingChange wrapUp(GitHub root) {
31+
this.root = root;
32+
if (plan != null) { // sanity check
33+
this.plan.wrapUp(this.root);
34+
}
35+
return this;
36+
}
37+
38+
/**
39+
* Gets id.
40+
*
41+
* @return the id
42+
*/
43+
public long getId() {
44+
return id;
45+
}
46+
47+
/**
48+
* Gets unit count.
49+
*
50+
* @return the unit count
51+
*/
52+
public Long getUnitCount() {
53+
return unitCount;
54+
}
55+
56+
/**
57+
* Gets plan.
58+
*
59+
* @return the plan
60+
*/
61+
public GHMarketplacePlan getPlan() {
62+
return plan;
63+
}
64+
65+
/**
66+
* Gets effective date.
67+
*
68+
* @return the effective date
69+
*/
70+
public Date getEffectiveDate() {
71+
return GitHub.parseDate(effectiveDate);
72+
}
73+
74+
}

0 commit comments

Comments
 (0)