Skip to content

Batch api - #461

Merged
iamharish merged 8 commits into
masterfrom
batch-api
Aug 28, 2017
Merged

iamharish merged 8 commits into
masterfrom
batch-api

Conversation

@iamharish

Copy link
Copy Markdown
Contributor

No description provided.

@boxcla

boxcla commented Aug 24, 2017

Copy link
Copy Markdown

Verified that @iamharish has signed the CLA. Thanks for the pull request!

requests.add(createAppUserRequest);

//Get Root Folder Request
URL getRootFolderURL = BoxFolder.FOLDER_INFO_URL_TEMPLATE.build(api.getBaseURL(), 0);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what will happen if more than 20 request?
What about the non-whitelisted request?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API will throw an error. No special handling in the SDK

* Batch URL Template.
*/
public static final URLTemplate BATCH_URL_TEMPLATE = new URLTemplate("batch");
private static final Logger LOGGER = Logger.getLogger(BoxAPIRequest.class.getName());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BatchAPIRequest?

Iterator<JsonValue> responseIterator = responseJSON.get("responses").asArray().iterator();
while (responseIterator.hasNext()) {
JsonObject jsonResponse = responseIterator.next().asObject();
BoxAPIResponse response = null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible the batch API will throw 500?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally. That will be thrown as BoxAPIException

private static final int BUFFER_SIZE = 8192;

private final HttpURLConnection connection;
private final Map<String, String> headers;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not it be in the BoxBatchAPIResponse?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reusing BoxAPIResponse. It's an existing class. No need for special BoxBatchAPIResponse as the response will be same but a list instead of one response

* @param responseCode http response code
* @param headers map of headers
*/
public BoxAPIResponse(int responseCode, Map<String, String> headers) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reusing BoxAPIResponse. It's an existing class. No need for special BoxBatchAPIResponse as the response will be same but a list instead of one response

/**
* File URL Template.
*/
public static final URLTemplate FILE_URL_TEMPLATE = new URLTemplate("files/%s");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure making them all public is a good idea, they should be only accessible internally to Batch class right? Why open them all to public?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why should the URLs be only private? It's not a data we have to hide

* Gets a JSON string containing any pending changes to this object that can be sent back to the Box API.
* @return a JSON string containing the pending changes.
*/
public JsonObject getPendingChangesAsJsonObject() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this do?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a new method in BoxJSONRequest which can take in JsonObject. This method can be used along with that to set body for a PUT request

/**
* Get response as Json Object.
* @return response as JsonObject
*/

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Java SDK deals with strings instead of JsonObject making it hard for devs who want to read contents in a response that's JSON, unless it's cast to a resource element. This method gives that feature

InputStreamReader reader = new InputStreamReader(this.getBody(), StandardCharsets.UTF_8);
StringBuilder builder = new StringBuilder();
char[] buffer = new char[BUFFER_SIZE];
InputStreamReader reader = new InputStreamReader(this.getBody(), StandardCharsets.UTF_8);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space / tab

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's correct. I have this enclosed in an else block now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants