Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Patch 1/2] :: Add support to Marketplace endpoints #635

Merged
merged 9 commits into from
Dec 20, 2019
112 changes: 112 additions & 0 deletions src/main/java/org/kohsuke/github/GHMarketplaceAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package org.kohsuke.github;

import java.net.URL;

/**
* A Github Marketplace Account.
*
* @author Paulo Miguel Almeida
* @see GHMarketplaceListAccountBuilder#createRequest()
*/
public class GHMarketplaceAccount {

private GitHub root;
private String url;
private long id;
private String login;
private String email;
private String organizationBillingEmail;
private GHMarketplaceAccountType type;
private GHMarketplacePendingChange marketplacePendingChange;
private GHMarketplacePurchase marketplacePurchase;

/**
* Wrap up gh marketplace account.
*
* @param root
* the root
* @return an instance of the GHMarketplaceAccount class
*/
GHMarketplaceAccount wrapUp(GitHub root) {
this.root = root;
if (this.marketplacePendingChange != null)
this.marketplacePendingChange.wrapUp(this.root);

if (this.marketplacePurchase != null)
this.marketplacePurchase.wrapUp(this.root);

return this;
}

/**
* Gets url.
*
* @return the url
*/
public URL getUrl() {
return GitHub.parseURL(url);
}

/**
* Gets id.
*
* @return the id
*/
public long getId() {
return id;
}

/**
* Gets login.
*
* @return the login
*/
public String getLogin() {
return login;
}

/**
* Gets email.
*
* @return the email
*/
public String getEmail() {
return email;
}

/**
* Gets organization billing email.
*
* @return the organization billing email
*/
public String getOrganizationBillingEmail() {
return organizationBillingEmail;
}

/**
* Gets type.
*
* @return the type
*/
public GHMarketplaceAccountType getType() {
return type;
}

/**
* Gets marketplace pending change.
*
* @return the marketplace pending change
*/
public GHMarketplacePendingChange getMarketplacePendingChange() {
return marketplacePendingChange;
}

/**
* Gets marketplace purchase.
*
* @return the marketplace purchase
*/
public GHMarketplacePurchase getMarketplacePurchase() {
return marketplacePurchase;
}
}
22 changes: 22 additions & 0 deletions src/main/java/org/kohsuke/github/GHMarketplaceAccountType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.kohsuke.github;

import org.apache.commons.lang3.StringUtils;

import java.util.Locale;

/**
* GitHub Marketplace Account type.
*
* @author Paulo Miguel Almeida
* @see GHMarketplaceAccount
*/
public enum GHMarketplaceAccountType {
ORGANIZATION, USER;

/**
* Returns GitHub's internal representation of this event.
*/
String symbol() {
return StringUtils.capitalize(name().toLowerCase(Locale.ENGLISH));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package org.kohsuke.github;

import java.io.IOException;

/**
* Returns any accounts associated with a plan, including free plans
*
* @author Paulo Miguel Almeida
* @see GHMarketplacePlan#listAccounts()
*/
public class GHMarketplaceListAccountBuilder {
private final GitHub root;
private final Requester builder;
private final long planId;

GHMarketplaceListAccountBuilder(GitHub root, long planId) {
this.root = root;
this.builder = root.createRequest();
this.planId = planId;
}

/**
* Sorts the GitHub accounts by the date they were created or last updated. Can be one of created or updated.
* <p>
* If omitted, the default sorting strategy will be "CREATED"
*
* @param sort
* the sort strategy
* @return a GHMarketplaceListAccountBuilder
*/
public GHMarketplaceListAccountBuilder sort(Sort sort) {
this.builder.with("sort", sort);
return this;
}

/**
* Orders the GitHub accounts results, Can be one of asc or desc. Ignored without the sort parameter.
*
* @param direction
* the order strategy
* @return a GHMarketplaceListAccountBuilder
*/
public GHMarketplaceListAccountBuilder direction(GHDirection direction) {
this.builder.with("direction", direction);
return this;
}

/**
* The enum Sort.
*/
public enum Sort {
CREATED, UPDATED
}

/**
* List any accounts associated with the plan specified on construction with all the order/sort parameters set.
* <p>
* GitHub Apps must use a JWT to access this endpoint.
* <p>
* OAuth Apps must use basic authentication with their client ID and client secret to access this endpoint.
*
* @return a paged iterable instance of GHMarketplaceAccount
* @throws IOException
* on error
*/
public PagedIterable<GHMarketplaceAccount> createRequest() throws IOException {
return builder.asPagedIterable(String.format("/marketplace_listing/plans/%d/accounts", this.planId),
GHMarketplaceAccount[].class,
item -> item.wrapUp(root));
}

}
74 changes: 74 additions & 0 deletions src/main/java/org/kohsuke/github/GHMarketplacePendingChange.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package org.kohsuke.github;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import java.util.Date;

/**
* A Github Marketplace purchase pending change.
*
* @author Paulo Miguel Almeida
* @see GHMarketplaceListAccountBuilder#createRequest()
*/
public class GHMarketplacePendingChange {
private GitHub root;
private long id;
@SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Field comes from JSON deserialization")
private Long unitCount;
@SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Field comes from JSON deserialization")
private GHMarketplacePlan plan;
@SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Field comes from JSON deserialization")
private String effectiveDate;

/**
* Wrap up gh marketplace pending change.
*
* @param root
* the root
* @return an instance of the GHMarketplacePendingChange class
*/
GHMarketplacePendingChange wrapUp(GitHub root) {
this.root = root;
if (plan != null) { // sanity check
this.plan.wrapUp(this.root);
}
return this;
}

/**
* Gets id.
*
* @return the id
*/
public long getId() {
return id;
}

/**
* Gets unit count.
*
* @return the unit count
*/
public Long getUnitCount() {
return unitCount;
}

/**
* Gets plan.
*
* @return the plan
*/
public GHMarketplacePlan getPlan() {
return plan;
}

/**
* Gets effective date.
*
* @return the effective date
*/
public Date getEffectiveDate() {
return GitHub.parseDate(effectiveDate);
}

}
Loading