Skip to content

Commit

Permalink
Minor formatting fixes. (bunq#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
OGKevin committed Aug 17, 2018
1 parent 2569218 commit 94eb7a8
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 75 deletions.
151 changes: 76 additions & 75 deletions src/main/java/com/bunq/sdk/http/BunqHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,99 +4,100 @@
import java.util.Map;

public enum BunqHeader {
ATTACHMENT_DESCRIPTION("X-Bunq-Attachment-Description"),
CACHE_CONTROL("Cache-Control", "no-cache"),
CLIENT_AUTHENTICATION("X-Bunq-Client-Authentication"),
CLIENT_ENCRYPTION_HMAC("X-Bunq-Client-Encryption-Hmac"),
CLIENT_ENCRYPTION_IV("X-Bunq-Client-Encryption-Iv"),
CLIENT_ENCRYPTION_KEY("X-Bunq-Client-Encryption-Key"),
CLIENT_REQUEST_ID("X-Bunq-Client-Request-Id"),
CLIENT_RESPONSE_ID("X-Bunq-Client-Response-Id", "Could not determine response id."),
CLIENT_SIGNATURE("X-Bunq-Client-Signature"),
CONTENT_TYPE("Content-Type"),
GEOLOCATION("X-Bunq-Geolocation", "0 0 0 0 000"),
LANGUAGE("X-Bunq-Language", "en_US"),
REGION("X-Bunq-Region", "nl_NL"),
SERVER_SIGNATURE("X-Bunq-Server-Signature"),
USER_AGENT("User-Agent", "bunq-sdk-java/0.13.1");

private static final String PREFIX = "X-Bunq-";

private final String header;
private final String defaultValue;

BunqHeader(String header) {
this(header, null);
ATTACHMENT_DESCRIPTION("X-Bunq-Attachment-Description"),
CACHE_CONTROL("Cache-Control", "no-cache"),
CLIENT_AUTHENTICATION("X-Bunq-Client-Authentication"),
CLIENT_ENCRYPTION_HMAC("X-Bunq-Client-Encryption-Hmac"),
CLIENT_ENCRYPTION_IV("X-Bunq-Client-Encryption-Iv"),
CLIENT_ENCRYPTION_KEY("X-Bunq-Client-Encryption-Key"),
CLIENT_REQUEST_ID("X-Bunq-Client-Request-Id"),
CLIENT_RESPONSE_ID("X-Bunq-Client-Response-Id", "Could not determine response id."),
CLIENT_SIGNATURE("X-Bunq-Client-Signature"),
CONTENT_TYPE("Content-Type"),
GEOLOCATION("X-Bunq-Geolocation", "0 0 0 0 000"),
LANGUAGE("X-Bunq-Language", "en_US"),
REGION("X-Bunq-Region", "nl_NL"),
SERVER_SIGNATURE("X-Bunq-Server-Signature"),
USER_AGENT("User-Agent", "bunq-sdk-java/0.13.1");

private static final String PREFIX = "X-Bunq-";

private final String header;
private final String defaultValue;

BunqHeader(String header) {
this(header, null);
}

BunqHeader(String header, String defaultValue) {
this.header = header;
this.defaultValue = defaultValue;
}

public static BunqHeader parseHeaderOrNull(String value) {
for (BunqHeader header : values()) {
if (header.equals(value)) {
return header;
}
}

BunqHeader(String header, String defaultValue) {
this.header = header;
this.defaultValue = defaultValue;
}
return null;
}

public static BunqHeader parseHeaderOrNull(String value) {
for (BunqHeader header:values()) {
if (header.equals(value)) {
return header;
}
}
public String getHeaderName() {
return header;
}

return null;
}
public String getDefaultValue() {
return defaultValue;
}

public String getHeaderName() {
return header;
private String getHeaderValueOrDefault(String value) {
if (value != null) {
return value;
}

public String getDefaultValue() {
return defaultValue;
}
return getDefaultValue();
}

private String getHeaderValueOrDefault(String value) {
if (value != null) {
return value;
}
public void addTo(Map<String, String> headers, String value) {
headers.put(getHeaderName(), getHeaderValueOrDefault(value));
}

return getDefaultValue();
}
public void addTo(BunqRequestBuilder requestBuilder) {
addTo(requestBuilder, null);
}

public void addTo(Map<String, String> headers, String value) {
headers.put(getHeaderName(), getHeaderValueOrDefault(value));
}
public void addTo(BunqRequestBuilder requestBuilder, String value) {
requestBuilder.addHeader(getHeaderName(), getHeaderValueOrDefault(value));
}

public void addTo(BunqRequestBuilder requestBuilder) {
addTo(requestBuilder, null);
}
public boolean equals(String header) {
return getHeaderName().equalsIgnoreCase(header);
}

public void addTo(BunqRequestBuilder requestBuilder, String value) {
requestBuilder.addHeader(getHeaderName(), getHeaderValueOrDefault(value));
}
public boolean isBunq() {
return getHeaderName().startsWith(PREFIX);
}

public boolean equals(String header) {
return getHeaderName().equalsIgnoreCase(header);
private String findKeyOrNull(Collection<String> keys) {
for (String key : keys) {
if (this.equals(key)) {
return key;
}
}

public boolean isBunq() {
return getHeaderName().startsWith(PREFIX);
}
return null;
}

private String findKeyOrNull(Collection<String> keys) {
for (String key:keys) {
if (this.equals(key)) {
return key;
}
}
public String getHeaderValueOrDefault(Map<String, String> headers) {
String key = findKeyOrNull(headers.keySet());

return null;
if (key != null && headers.get(key) != null) {
return headers.get(key);
}

public String getHeaderValueOrDefault(Map<String, String> headers) {
String key = findKeyOrNull(headers.keySet());

if (key != null && headers.get(key) != null) {
return headers.get(key);
}
return getDefaultValue();
}

return getDefaultValue();
}
}
1 change: 1 addition & 0 deletions src/main/java/com/bunq/sdk/http/BunqRequestBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,5 @@ public BunqRequestBody getBody() {
public List<BunqBasicHeader> getAllHeader() {
return this.allHeader;
}

}
1 change: 1 addition & 0 deletions src/test/java/com/bunq/sdk/http/BunqHeaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,5 @@ public void addToMap() {
assertEquals(HEADER_VALUE_GEOLOCATION, headers.get(BunqHeader.GEOLOCATION.getHeaderName()));
assertEquals(HEADER_VALUE_USER_AGENT, headers.get(BunqHeader.USER_AGENT.getHeaderName()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,5 @@ private String uploadAvatar(byte[] file_contents) {

return AttachmentPublic.create(allCustomHeader, file_contents).getValue();
}

}

0 comments on commit 94eb7a8

Please sign in to comment.