Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
synapticloop committed Jul 29, 2016
2 parents 90d1193 + c0ee9d6 commit 6956bc2
Showing 1 changed file with 36 additions and 34 deletions.
70 changes: 36 additions & 34 deletions src/main/java/synapticloop/b2/request/BaseB2Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

/*
* Copyright (c) 2016 Synapticloop.
*
*
* All rights reserved.
*
* This code may contain contributions from other parties which, where
* applicable, will be listed in the default build file for the project
*
* This code may contain contributions from other parties which, where
* applicable, will be listed in the default build file for the project
* ~and/or~ in a file named CONTRIBUTORS.txt in the root of the project.
*
* This source code and any derived binaries are covered by the terms and
* conditions of the Licence agreement ("the Licence"). You may not use this
* source code or any derived binaries except in compliance with the Licence.
* A copy of the Licence is available in the file named LICENSE.txt shipped with
*
* This source code and any derived binaries are covered by the terms and
* conditions of the Licence agreement ("the Licence"). You may not use this
* source code or any derived binaries except in compliance with the Licence.
* A copy of the Licence is available in the file named LICENSE.txt shipped with
* this source code or binaries.
*/

Expand Down Expand Up @@ -46,6 +46,8 @@
import synapticloop.b2.exception.B2ApiException;
import synapticloop.b2.response.B2AuthorizeAccountResponse;

import static org.apache.http.entity.ContentType.APPLICATION_JSON;

public abstract class BaseB2Request {
private static final Logger LOGGER = LoggerFactory.getLogger(BaseB2Request.class);

Expand Down Expand Up @@ -87,7 +89,7 @@ protected BaseB2Request(CloseableHttpClient client, final String url) {
/**
* Instantiate the base B2 request which adds headers with the authorization
* token.
*
*
* @param client Shared HTTP client
* @param b2AuthorizeAccountResponse the authorize account response
* @param url Fully qualified request URI
Expand All @@ -99,7 +101,7 @@ protected BaseB2Request(CloseableHttpClient client, B2AuthorizeAccountResponse b
/**
* Instantiate the base B2 request which adds headers with the authorization
* token.
*
*
* @param client Shared HTTP client
* @param b2AuthorizeAccountResponse the authorize account response
* @param url Fully qualified request URI
Expand All @@ -115,7 +117,7 @@ protected BaseB2Request(CloseableHttpClient client, B2AuthorizeAccountResponse b

/**
* Add header to request replacing previous if any
*
*
* @param key the key to add
* @param value the value to add
*/
Expand All @@ -125,7 +127,7 @@ protected void addHeader(String key, String value) {

/**
* Add query parameter to request replacing previous if any
*
*
* @param key the key to add
* @param value the value to add
*/
Expand All @@ -135,7 +137,7 @@ protected void addParameter(String key, String value) {

/**
* Add property to JSON request body
*
*
* @param key the key to add
* @param value the value to add
*/
Expand All @@ -145,9 +147,9 @@ protected void addProperty(String key, Object value) {

/**
* Execute an HTTP HEAD request and return the response for further parsing
*
*
* @return the response object
*
*
* @throws B2ApiException if something went wrong with the call
* @throws IOException if there was an error communicating with the API service
*/
Expand Down Expand Up @@ -175,7 +177,7 @@ protected CloseableHttpResponse executeHead() throws B2ApiException, IOException

/**
* Execute a GET request, returning the data stream from the response.
*
*
* @return The response from the GET request
*
* @throws B2ApiException if there was an error with the request
Expand Down Expand Up @@ -205,9 +207,9 @@ protected CloseableHttpResponse executeGet() throws B2ApiException, IOException

/**
* Execute a POST request returning the response data as a String
*
*
* @return the response data as a string
*
*
* @throws B2ApiException if there was an error with the call, most notably
* a non OK status code (i.e. not 200)
* @throws IOException if there was an error communicating with the API service
Expand Down Expand Up @@ -236,11 +238,11 @@ protected CloseableHttpResponse executePost() throws B2ApiException, IOException

/**
* Execute a POST request with the contents of a file.
*
*
* @param entity Content to write
*
*
* @return the string representation of the response
*
*
* @throws B2ApiException if there was an error with the call, most notably
* a non OK status code (i.e. not 200)
* @throws IOException if there was an error communicating with the API service
Expand All @@ -265,9 +267,9 @@ protected CloseableHttpResponse executePost(HttpEntity entity) throws B2ApiExcep
/**
* Convert the stringData and integerData Maps to JSON format, to be included
* in the POST body of the request.
*
*
* @return the JSON string of the data
*
*
* @throws IOException if there was an error converting the data.
*/
protected String convertPostData() throws IOException {
Expand All @@ -285,11 +287,11 @@ protected String convertPostData() throws IOException {
}

/**
* Return the URI for this request, which adds any parameters found in the
* Return the URI for this request, which adds any parameters found in the
* 'parameters' data structure
*
*
* @return The URI for this request, with properly encoded parameters
*
*
* @throws IOException If there was an error building the URI
*/
protected URI buildUri() throws IOException {
Expand All @@ -308,15 +310,15 @@ protected URI buildUri() throws IOException {
}

/**
* Set the headers safely, go through the headers Map and add them to the http
* request with properly encode values. If they already exist on the http
* Set the headers safely, go through the headers Map and add them to the http
* request with properly encode values. If they already exist on the http
* request, it will be ignored.
*
*
* To override what headers are set, this should be done in the constructor
* of the base request object.
*
*
* @param request The HTTP request to set the headers on
*
*
* @throws B2ApiException if there was an error setting the headers
*/
protected void setHeaders(HttpUriRequest request) throws B2ApiException {
Expand Down Expand Up @@ -344,9 +346,9 @@ protected CloseableHttpResponse execute(final HttpUriRequest request) throws IOE
/**
* Obfuscate the data by removing the accountId and replacing it with the
* string "[redacted]"
*
*
* @param data the data to obfuscate
*
*
* @return the obfuscated data
*/
private Object obfuscateData(String key, Object data) {
Expand Down

0 comments on commit 6956bc2

Please sign in to comment.