Skip to content

Commit

Permalink
Merge pull request #95 from bunq/add-constructor-with-request-field-b…
Browse files Browse the repository at this point in the history
…unq/sdk_java#50

Add constructor with request field #50
  • Loading branch information
OGKevin authored Jun 7, 2018
2 parents ad655b1 + 52d1fad commit 53d5a48
Show file tree
Hide file tree
Showing 93 changed files with 4,818 additions and 573 deletions.
18 changes: 18 additions & 0 deletions src/main/java/com/bunq/sdk/model/core/BunqModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.google.gson.stream.JsonReader;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

abstract public class BunqModel {
Expand All @@ -30,6 +31,16 @@ abstract public class BunqModel {
*/
private static final int INDEX_FIRST = 0;

/**
* String format constants.
*/
private static final String STRING_EMPTY = "";

/**
* Regex constants.
*/
private static final String REGEX_FIELD_FOR_REQUEST = "(_field_for_request)";

/**
* Gson builder for serialization.
*/
Expand Down Expand Up @@ -179,4 +190,11 @@ protected static Integer determineMonetaryAccountId(Integer id) {
return id;
}
}

protected static byte[] determineAllRequestByte(HashMap<String, Object> requestMap) {
String requestString = gson.toJson(requestMap).toString();

return requestString.replaceAll(REGEX_FIELD_FOR_REQUEST, STRING_EMPTY).getBytes();
}

}
17 changes: 16 additions & 1 deletion src/main/java/com/bunq/sdk/model/generated/endpoint/Avatar.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ public class Avatar extends BunqModel {
@SerializedName("image")
private List<Image> image;

/**
* The public UUID of the public attachment from which an avatar image must be created.
*/
@Expose
@SerializedName("attachment_public_uuid_field_for_request")
private String attachmentPublicUuidFieldForRequest;

public Avatar() {
this(null);
}

public Avatar(String attachmentPublicUuid) {
this.attachmentPublicUuidFieldForRequest = attachmentPublicUuid;
}

/**
* @param attachmentPublicUuid The public UUID of the public attachment from which an avatar
* image must be created.
Expand All @@ -67,7 +82,7 @@ public static BunqResponse<String> create(String attachmentPublicUuid, Map<Strin
HashMap<String, Object> requestMap = new HashMap<>();
requestMap.put(FIELD_ATTACHMENT_PUBLIC_UUID, attachmentPublicUuid);

byte[] requestBytes = gson.toJson(requestMap).getBytes();
byte[] requestBytes = determineAllRequestByte(requestMap);
BunqResponseRaw responseRaw = apiClient.post(ENDPOINT_URL_CREATE, requestBytes, customHeaders);

return processForUuid(responseRaw);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ public class BillingContractSubscription extends BunqModel {
@SerializedName("sub_status")
private String subStatus;

/**
* The subscription type of the user. Can be one of PERSON_LIGHT_V1, PERSON_MORE_V1,
* PERSON_FREE_V1, PERSON_PREMIUM_V1, COMPANY_V1, or COMPANY_V2.
*/
@Expose
@SerializedName("subscription_type_field_for_request")
private String subscriptionTypeFieldForRequest;

public BillingContractSubscription() {
this(null);
}

public BillingContractSubscription(String subscriptionType) {
this.subscriptionTypeFieldForRequest = subscriptionType;
}

/**
* @param subscriptionType The subscription type of the user. Can be one of PERSON_LIGHT_V1,
* PERSON_MORE_V1, PERSON_FREE_V1, PERSON_PREMIUM_V1, COMPANY_V1, or COMPANY_V2.
Expand All @@ -111,7 +127,7 @@ public static BunqResponse<Integer> create(String subscriptionType, Map<String,
HashMap<String, Object> requestMap = new HashMap<>();
requestMap.put(FIELD_SUBSCRIPTION_TYPE, subscriptionType);

byte[] requestBytes = gson.toJson(requestMap).getBytes();
byte[] requestBytes = determineAllRequestByte(requestMap);
BunqResponseRaw responseRaw = apiClient.post(String.format(ENDPOINT_URL_CREATE, determineUserId()), requestBytes, customHeaders);

return processForId(responseRaw);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
package com.bunq.sdk.model.generated.endpoint;

import com.bunq.sdk.model.core.BunqModel;
import com.bunq.sdk.model.core.MonetaryAccountReference;
import com.bunq.sdk.model.generated.object.AttachmentPublic;
import com.bunq.sdk.model.generated.object.LabelMonetaryAccount;
import com.bunq.sdk.model.generated.object.Pointer;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import com.google.gson.stream.JsonReader;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;

import java.util.List;
import java.util.Map;

/**
* bunq.me public profile of the user.
Expand All @@ -37,7 +33,7 @@ public class BunqMeFundraiserProfile extends BunqModel {
*/
@Expose
@SerializedName("alias")
private MonetaryAccountReference alias;
private LabelMonetaryAccount alias;

/**
* The description of the bunq.me fundraiser profile.
Expand All @@ -58,7 +54,7 @@ public class BunqMeFundraiserProfile extends BunqModel {
*/
@Expose
@SerializedName("pointer")
private MonetaryAccountReference pointer;
private Pointer pointer;

/**
* The status of the bunq.me fundraiser profile, can be ACTIVE or DEACTIVATED.
Expand All @@ -74,6 +70,21 @@ public class BunqMeFundraiserProfile extends BunqModel {
@SerializedName("redirect_url")
private String redirectUrl;

/**
* The pointer (url) which will be used to access the bunq.me fundraiser profile.
*/
@Expose
@SerializedName("pointer_field_for_request")
private Pointer pointerFieldForRequest;

public BunqMeFundraiserProfile() {
this(null);
}

public BunqMeFundraiserProfile(Pointer pointer) {
this.pointerFieldForRequest = pointer;
}

/**
* The color chosen for the bunq.me fundraiser profile in hexadecimal format.
*/
Expand All @@ -89,11 +100,11 @@ public void setColor(String color) {
* The LabelMonetaryAccount with the public information of the User and the MonetaryAccount that
* created the bunq.me fundraiser profile.
*/
public MonetaryAccountReference getAlias() {
public LabelMonetaryAccount getAlias() {
return this.alias;
}

public void setAlias(MonetaryAccountReference alias) {
public void setAlias(LabelMonetaryAccount alias) {
this.alias = alias;
}

Expand Down Expand Up @@ -122,11 +133,11 @@ public void setAttachment(List<AttachmentPublic> attachment) {
/**
* The pointer (url) which will be used to access the bunq.me fundraiser profile.
*/
public MonetaryAccountReference getPointer() {
public Pointer getPointer() {
return this.pointer;
}

public void setPointer(MonetaryAccountReference pointer) {
public void setPointer(Pointer pointer) {
this.pointer = pointer;
}

Expand Down
32 changes: 30 additions & 2 deletions src/main/java/com/bunq/sdk/model/generated/endpoint/BunqMeTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,34 @@ public class BunqMeTab extends BunqModel {
@SerializedName("result_inquiries")
private List<BunqMeTabResultInquiry> resultInquiries;

/**
* The bunq.me entry containing the payment information.
*/
@Expose
@SerializedName("bunqme_tab_entry_field_for_request")
private BunqMeTabEntry bunqmeTabEntryFieldForRequest;

/**
* The status of the bunq.me. Ignored in POST requests but can be used for cancelling the
* bunq.me by setting status as CANCELLED with a PUT request.
*/
@Expose
@SerializedName("status_field_for_request")
private String statusFieldForRequest;

public BunqMeTab() {
this(null, null);
}

public BunqMeTab(BunqMeTabEntry bunqmeTabEntry) {
this(bunqmeTabEntry, null);
}

public BunqMeTab(BunqMeTabEntry bunqmeTabEntry, String status) {
this.bunqmeTabEntryFieldForRequest = bunqmeTabEntry;
this.statusFieldForRequest = status;
}

/**
* @param bunqmeTabEntry The bunq.me entry containing the payment information.
* @param status The status of the bunq.me. Ignored in POST requests but can be used for
Expand All @@ -117,7 +145,7 @@ public static BunqResponse<Integer> create(BunqMeTabEntry bunqmeTabEntry, Intege
requestMap.put(FIELD_BUNQME_TAB_ENTRY, bunqmeTabEntry);
requestMap.put(FIELD_STATUS, status);

byte[] requestBytes = gson.toJson(requestMap).getBytes();
byte[] requestBytes = determineAllRequestByte(requestMap);
BunqResponseRaw responseRaw = apiClient.post(String.format(ENDPOINT_URL_CREATE, determineUserId(), determineMonetaryAccountId(monetaryAccountId)), requestBytes, customHeaders);

return processForId(responseRaw);
Expand Down Expand Up @@ -153,7 +181,7 @@ public static BunqResponse<Integer> update(Integer bunqMeTabId, Integer monetary
HashMap<String, Object> requestMap = new HashMap<>();
requestMap.put(FIELD_STATUS, status);

byte[] requestBytes = gson.toJson(requestMap).getBytes();
byte[] requestBytes = determineAllRequestByte(requestMap);
BunqResponseRaw responseRaw = apiClient.put(String.format(ENDPOINT_URL_UPDATE, determineUserId(), determineMonetaryAccountId(monetaryAccountId), bunqMeTabId), requestBytes, customHeaders);

return processForId(responseRaw);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
package com.bunq.sdk.model.generated.endpoint;

import com.bunq.sdk.model.core.BunqModel;
import com.bunq.sdk.model.core.MonetaryAccountReference;
import com.bunq.sdk.model.generated.object.Amount;
import com.bunq.sdk.model.generated.object.BunqMeMerchantAvailable;
import com.bunq.sdk.model.generated.object.LabelMonetaryAccount;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import com.google.gson.stream.JsonReader;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;

import java.util.List;
import java.util.Map;

/**
* bunq.me tabs allows you to create a payment request and share the link through e-mail, chat,
Expand Down Expand Up @@ -48,7 +44,7 @@ public class BunqMeTabEntry extends BunqModel {
*/
@Expose
@SerializedName("alias")
private MonetaryAccountReference alias;
private LabelMonetaryAccount alias;

/**
* The description for the bunq.me. Maximum 9000 characters.
Expand Down Expand Up @@ -78,6 +74,46 @@ public class BunqMeTabEntry extends BunqModel {
@SerializedName("merchant_available")
private List<BunqMeMerchantAvailable> merchantAvailable;

/**
* The Amount requested to be paid. Can be optional.
*/
@Expose
@SerializedName("amount_inquired_field_for_request")
private Amount amountInquiredFieldForRequest;

/**
* The description for the bunq.me. Maximum 9000 characters. Field is required but can be an
* empty string.
*/
@Expose
@SerializedName("description_field_for_request")
private String descriptionFieldForRequest;

/**
* The URL which the user is sent to after making a payment.
*/
@Expose
@SerializedName("redirect_url_field_for_request")
private String redirectUrlFieldForRequest;

public BunqMeTabEntry() {
this(null, null, null);
}

public BunqMeTabEntry(String description) {
this(description, null, null);
}

public BunqMeTabEntry(String description, Amount amountInquired) {
this(description, amountInquired, null);
}

public BunqMeTabEntry(String description, Amount amountInquired, String redirectUrl) {
this.amountInquiredFieldForRequest = amountInquired;
this.descriptionFieldForRequest = description;
this.redirectUrlFieldForRequest = redirectUrl;
}

/**
* The uuid of the bunq.me.
*/
Expand All @@ -104,11 +140,11 @@ public void setAmountInquired(Amount amountInquired) {
* The LabelMonetaryAccount with the public information of the User and the MonetaryAccount that
* created the bunq.me link.
*/
public MonetaryAccountReference getAlias() {
public LabelMonetaryAccount getAlias() {
return this.alias;
}

public void setAlias(MonetaryAccountReference alias) {
public void setAlias(LabelMonetaryAccount alias) {
this.alias = alias;
}

Expand Down
Loading

0 comments on commit 53d5a48

Please sign in to comment.