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

Latest Changes for 2019-10-10 (usage, measured units, etc) #104

Merged
merged 1 commit into from
Jul 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,147 changes: 1,021 additions & 126 deletions openapi/api.yaml

Large diffs are not rendered by default.

168 changes: 168 additions & 0 deletions src/main/java/com/recurly/v3/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,87 @@ public Item reactivateItem(String itemId) {
return this.makeRequest("PUT", path, returnType);
}

/**
* List a site's measured units
*
* @see <a href="https://developers.recurly.com/api/v2019-10-10#operation/list_measured_unit">list_measured_unit api documentation</a>
* @param queryParams The {@link QueryParams} for this endpoint.
* @return A list of the site's measured units.
*/
public Pager<MeasuredUnit> listMeasuredUnit(QueryParams queryParams) {
final String url = "/measured_units";
final HashMap<String, String> urlParams = new HashMap<String, String>();
if (queryParams == null) queryParams = new QueryParams();
final HashMap<String, Object> paramsMap = queryParams.getParams();
final String path = this.interpolatePath(url, urlParams);
Type parameterizedType = TypeToken.getParameterized(Pager.class, MeasuredUnit.class).getType();
return new Pager<>(path, paramsMap, this, parameterizedType);
}

/**
* Create a new measured unit
*
* @see <a href="https://developers.recurly.com/api/v2019-10-10#operation/create_measured_unit">create_measured_unit api documentation</a>
* @param body The body of the request.
* @return A new measured unit.
*/
public MeasuredUnit createMeasuredUnit(MeasuredUnitCreate body) {
final String url = "/measured_units";
final HashMap<String, String> urlParams = new HashMap<String, String>();
final String path = this.interpolatePath(url, urlParams);
Type returnType = MeasuredUnit.class;
return this.makeRequest("POST", path, body, returnType);
}

/**
* Fetch a measured unit
*
* @see <a href="https://developers.recurly.com/api/v2019-10-10#operation/get_measured_unit">get_measured_unit api documentation</a>
* @param measuredUnitId Measured unit ID or name. For ID no prefix is used e.g. `e28zov4fw0v2`. For name use prefix `name-`, e.g. `name-Storage`.
* @return An item.
*/
public MeasuredUnit getMeasuredUnit(String measuredUnitId) {
final String url = "/measured_units/{measured_unit_id}";
final HashMap<String, String> urlParams = new HashMap<String, String>();
urlParams.put("measured_unit_id", measuredUnitId);
final String path = this.interpolatePath(url, urlParams);
Type returnType = MeasuredUnit.class;
return this.makeRequest("GET", path, returnType);
}

/**
* Update a measured unit
*
* @see <a href="https://developers.recurly.com/api/v2019-10-10#operation/update_measured_unit">update_measured_unit api documentation</a>
* @param measuredUnitId Measured unit ID or name. For ID no prefix is used e.g. `e28zov4fw0v2`. For name use prefix `name-`, e.g. `name-Storage`.
* @param body The body of the request.
* @return The updated measured_unit.
*/
public MeasuredUnit updateMeasuredUnit(String measuredUnitId, MeasuredUnitUpdate body) {
final String url = "/measured_units/{measured_unit_id}";
final HashMap<String, String> urlParams = new HashMap<String, String>();
urlParams.put("measured_unit_id", measuredUnitId);
final String path = this.interpolatePath(url, urlParams);
Type returnType = MeasuredUnit.class;
return this.makeRequest("PUT", path, body, returnType);
}

/**
* Remove a measured unit
*
* @see <a href="https://developers.recurly.com/api/v2019-10-10#operation/remove_measured_unit">remove_measured_unit api documentation</a>
* @param measuredUnitId Measured unit ID or name. For ID no prefix is used e.g. `e28zov4fw0v2`. For name use prefix `name-`, e.g. `name-Storage`.
* @return A measured unit.
*/
public MeasuredUnit removeMeasuredUnit(String measuredUnitId) {
final String url = "/measured_units/{measured_unit_id}";
final HashMap<String, String> urlParams = new HashMap<String, String>();
urlParams.put("measured_unit_id", measuredUnitId);
final String path = this.interpolatePath(url, urlParams);
Type returnType = MeasuredUnit.class;
return this.makeRequest("DELETE", path, returnType);
}

/**
* List a site's invoices
*
Expand Down Expand Up @@ -1789,6 +1870,93 @@ public Pager<CouponRedemption> listSubscriptionCouponRedemptions(String subscrip
return new Pager<>(path, paramsMap, this, parameterizedType);
}

/**
* List a subscription add-on's usage records
*
* @see <a href="https://developers.recurly.com/api/v2019-10-10#operation/list_usage">list_usage api documentation</a>
* @param subscriptionId Subscription ID or UUID. For ID no prefix is used e.g. `e28zov4fw0v2`. For UUID use prefix `uuid-`, e.g. `uuid-123457890`.
* @param addOnId Add-on ID or code. For ID no prefix is used e.g. `e28zov4fw0v2`. For code use prefix `code-`, e.g. `code-gold`.
* @param queryParams The {@link QueryParams} for this endpoint.
* @return A list of the subscription add-on's usage records.
*/
public Pager<Usage> listUsage(String subscriptionId, String addOnId, QueryParams queryParams) {
final String url = "/subscriptions/{subscription_id}/add_ons/{add_on_id}/usage";
final HashMap<String, String> urlParams = new HashMap<String, String>();
urlParams.put("subscription_id", subscriptionId);
urlParams.put("add_on_id", addOnId);
if (queryParams == null) queryParams = new QueryParams();
final HashMap<String, Object> paramsMap = queryParams.getParams();
final String path = this.interpolatePath(url, urlParams);
Type parameterizedType = TypeToken.getParameterized(Pager.class, Usage.class).getType();
return new Pager<>(path, paramsMap, this, parameterizedType);
}

/**
* Log a usage record on this subscription add-on
*
* @see <a href="https://developers.recurly.com/api/v2019-10-10#operation/create_usage">create_usage api documentation</a>
* @param subscriptionId Subscription ID or UUID. For ID no prefix is used e.g. `e28zov4fw0v2`. For UUID use prefix `uuid-`, e.g. `uuid-123457890`.
* @param addOnId Add-on ID or code. For ID no prefix is used e.g. `e28zov4fw0v2`. For code use prefix `code-`, e.g. `code-gold`.
* @param body The body of the request.
* @return The created usage record.
*/
public Usage createUsage(String subscriptionId, String addOnId, UsageCreate body) {
final String url = "/subscriptions/{subscription_id}/add_ons/{add_on_id}/usage";
final HashMap<String, String> urlParams = new HashMap<String, String>();
urlParams.put("subscription_id", subscriptionId);
urlParams.put("add_on_id", addOnId);
final String path = this.interpolatePath(url, urlParams);
Type returnType = Usage.class;
return this.makeRequest("POST", path, body, returnType);
}

/**
* Get a usage record
*
* @see <a href="https://developers.recurly.com/api/v2019-10-10#operation/get_usage">get_usage api documentation</a>
* @param usageId Usage Record ID.
* @return The usage record.
*/
public Usage getUsage(String usageId) {
final String url = "/usage/{usage_id}";
final HashMap<String, String> urlParams = new HashMap<String, String>();
urlParams.put("usage_id", usageId);
final String path = this.interpolatePath(url, urlParams);
Type returnType = Usage.class;
return this.makeRequest("GET", path, returnType);
}

/**
* Update a usage record
*
* @see <a href="https://developers.recurly.com/api/v2019-10-10#operation/update_usage">update_usage api documentation</a>
* @param usageId Usage Record ID.
* @param body The body of the request.
* @return The updated usage record.
*/
public Usage updateUsage(String usageId, UsageCreate body) {
final String url = "/usage/{usage_id}";
final HashMap<String, String> urlParams = new HashMap<String, String>();
urlParams.put("usage_id", usageId);
final String path = this.interpolatePath(url, urlParams);
Type returnType = Usage.class;
return this.makeRequest("PUT", path, body, returnType);
}

/**
* Delete a usage record.
*
* @see <a href="https://developers.recurly.com/api/v2019-10-10#operation/remove_usage">remove_usage api documentation</a>
* @param usageId Usage Record ID.
*/
public void removeUsage(String usageId) {
final String url = "/usage/{usage_id}";
final HashMap<String, String> urlParams = new HashMap<String, String>();
urlParams.put("usage_id", usageId);
final String path = this.interpolatePath(url, urlParams);
this.makeRequest("DELETE", path);
}

/**
* List a site's transactions
*
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/recurly/v3/QueryParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,8 @@ public void setRelatedType(final String relatedType) {
public void setRefund(final String refund) {
this.add("refund", refund);
}

public void setBillingStatus(final String billingStatus) {
this.add("billing_status", billingStatus);
}
}
2 changes: 2 additions & 0 deletions src/main/java/com/recurly/v3/exception/ExceptionFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public static <T extends RecurlyException> T getExceptionClass(Response response
return (T) new BadGatewayException(message, null);
case 503:
return (T) new ServiceUnavailableException(message, null);
case 504:
return (T) new TimeoutException(message, null);
case 304:
return (T) new NotModifiedException(message, null);
case 400:
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/recurly/v3/exception/TimeoutException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* This file is automatically created by Recurly's OpenAPI generation process and thus any edits you
* make by hand will be lost. If you wish to make a change to this file, please create a Github
* issue explaining the changes you need and we will usher them to the appropriate places.
*/
package com.recurly.v3.exception;

import com.recurly.v3.resources.ErrorMayHaveTransaction;

public class TimeoutException extends ServerException {

public TimeoutException(String message, ErrorMayHaveTransaction e) {
super(message, e);
}
}
114 changes: 114 additions & 0 deletions src/main/java/com/recurly/v3/requests/AddOnCreate.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public class AddOnCreate extends Request {
@Expose
private String accountingCode;

/** Whether the add-on type is fixed, or usage-based. */
@SerializedName("add_on_type")
@Expose
private String addOnType;

/**
* The unique identifier for the add-on within its plan. If `item_code`/`item_id` is part of the
* request then `code` must be absent. If `item_code`/`item_id` is not present `code` is required.
Expand Down Expand Up @@ -68,6 +73,24 @@ public class AddOnCreate extends Request {
@Expose
private String itemId;

/**
* System-generated unique identifier for a measured unit to be associated with the add-on. Either
* `measured_unit_id` or `measured_unit_name` are required when `add_on_type` is `usage`. If
* `measured_unit_id` and `measured_unit_name` are both present, `measured_unit_id` will be used.
*/
@SerializedName("measured_unit_id")
@Expose
private String measuredUnitId;

/**
* Name of a measured unit to be associated with the add-on. Either `measured_unit_id` or
* `measured_unit_name` are required when `add_on_type` is `usage`. If `measured_unit_id` and
* `measured_unit_name` are both present, `measured_unit_id` will be used.
*/
@SerializedName("measured_unit_name")
@Expose
private String measuredUnitName;

/**
* Describes your add-on and will appear in subscribers' invoices. If `item_code`/`item_id` is
* part of the request then `name` must be absent. If `item_code`/`item_id` is not present `name`
Expand Down Expand Up @@ -129,6 +152,20 @@ public class AddOnCreate extends Request {
@Expose
private List<Tier> tiers;

/**
* The percentage taken of the monetary amount of usage tracked. This can be up to 4 decimal
* places. A value between 0.0 and 100.0. Required if `add_on_type` is usage and `usage_type` is
* percentage. Must be omitted otherwise. `usage_percentage` does not support tiers.
*/
@SerializedName("usage_percentage")
@Expose
private Float usagePercentage;

/** Type of usage, required if `add_on_type` is `usage`. */
@SerializedName("usage_type")
@Expose
private String usageType;

/**
* Accounting code for invoice line items for this add-on. If no value is provided, it defaults to
* add-on's code. If `item_code`/`item_id` is part of the request then `accounting_code` must be
Expand All @@ -147,6 +184,16 @@ public void setAccountingCode(final String accountingCode) {
this.accountingCode = accountingCode;
}

/** Whether the add-on type is fixed, or usage-based. */
public String getAddOnType() {
return this.addOnType;
}

/** @param addOnType Whether the add-on type is fixed, or usage-based. */
public void setAddOnType(final String addOnType) {
this.addOnType = addOnType;
}

/**
* The unique identifier for the add-on within its plan. If `item_code`/`item_id` is part of the
* request then `code` must be absent. If `item_code`/`item_id` is not present `code` is required.
Expand Down Expand Up @@ -244,6 +291,44 @@ public void setItemId(final String itemId) {
this.itemId = itemId;
}

/**
* System-generated unique identifier for a measured unit to be associated with the add-on. Either
* `measured_unit_id` or `measured_unit_name` are required when `add_on_type` is `usage`. If
* `measured_unit_id` and `measured_unit_name` are both present, `measured_unit_id` will be used.
*/
public String getMeasuredUnitId() {
return this.measuredUnitId;
}

/**
* @param measuredUnitId System-generated unique identifier for a measured unit to be associated
* with the add-on. Either `measured_unit_id` or `measured_unit_name` are required when
* `add_on_type` is `usage`. If `measured_unit_id` and `measured_unit_name` are both present,
* `measured_unit_id` will be used.
*/
public void setMeasuredUnitId(final String measuredUnitId) {
this.measuredUnitId = measuredUnitId;
}

/**
* Name of a measured unit to be associated with the add-on. Either `measured_unit_id` or
* `measured_unit_name` are required when `add_on_type` is `usage`. If `measured_unit_id` and
* `measured_unit_name` are both present, `measured_unit_id` will be used.
*/
public String getMeasuredUnitName() {
return this.measuredUnitName;
}

/**
* @param measuredUnitName Name of a measured unit to be associated with the add-on. Either
* `measured_unit_id` or `measured_unit_name` are required when `add_on_type` is `usage`. If
* `measured_unit_id` and `measured_unit_name` are both present, `measured_unit_id` will be
* used.
*/
public void setMeasuredUnitName(final String measuredUnitName) {
this.measuredUnitName = measuredUnitName;
}

/**
* Describes your add-on and will appear in subscribers' invoices. If `item_code`/`item_id` is
* part of the request then `name` must be absent. If `item_code`/`item_id` is not present `name`
Expand Down Expand Up @@ -366,4 +451,33 @@ public List<Tier> getTiers() {
public void setTiers(final List<Tier> tiers) {
this.tiers = tiers;
}

/**
* The percentage taken of the monetary amount of usage tracked. This can be up to 4 decimal
* places. A value between 0.0 and 100.0. Required if `add_on_type` is usage and `usage_type` is
* percentage. Must be omitted otherwise. `usage_percentage` does not support tiers.
*/
public Float getUsagePercentage() {
return this.usagePercentage;
}

/**
* @param usagePercentage The percentage taken of the monetary amount of usage tracked. This can
* be up to 4 decimal places. A value between 0.0 and 100.0. Required if `add_on_type` is
* usage and `usage_type` is percentage. Must be omitted otherwise. `usage_percentage` does
* not support tiers.
*/
public void setUsagePercentage(final Float usagePercentage) {
this.usagePercentage = usagePercentage;
}

/** Type of usage, required if `add_on_type` is `usage`. */
public String getUsageType() {
return this.usageType;
}

/** @param usageType Type of usage, required if `add_on_type` is `usage`. */
public void setUsageType(final String usageType) {
this.usageType = usageType;
}
}
Loading