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

Added reportOrder to ButtonMerchant #25

Merged
merged 4 commits into from Jun 26, 2019
Merged

Conversation

Jon6193
Copy link
Contributor

@Jon6193 Jon6193 commented Jun 25, 2019

Goals ⚽

  • Add reportOrder to ButtonMerchant

Implementation 🚧

  • Added ApiRequest to allow a better way to build requests
  • Removed post from ConnectionManager in favor of execute
  • Added ButtonUtil for utility methods used in multiple places
  • Added PostOrderTask to report orders

Testing 🔍

  • Updated tests

@Jon6193 Jon6193 requested review from ecgreb and kirtanp98 June 25, 2019 20:30
@Nullable
private Map<String, String> headers;
@Nullable
private JSONObject body;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we default to an empty header map and empty JSON body? This would remove the need for null checks in ConnectionManagerImpl.

public class ApiRequestTest {

@Test
public void apiRequest_verifyDefaultValues() {
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about dropping apiRequest_ prefix from all tests? Seems unnecessary given the file is called ApiRequestTest 😂

@@ -151,4 +161,107 @@ public void postUserActivity_validateRequest() throws Exception {
assertEquals("AUG", requestBody.getString("currency"));
assertEquals("merchant-library", requestBody.getString("source"));
}

@Test
public void postOrder_validateRequest() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about breaking this down into smaller tests for different elements in the payload?

connectionManager.post("/", null);
connectionManager.executeRequest(new ApiRequest.Builder(ApiRequest.RequestMethod.POST,
"/")
.build()
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like an unfortunate line wrap..

messageDigest.update(bytes, 0, bytes.length);
return new String(messageDigest.digest());
} catch (NoSuchAlgorithmException ignored) {

Copy link
Contributor

Choose a reason for hiding this comment

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

Log an error here?

Copy link
Contributor

Choose a reason for hiding this comment

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

++

Copy link
Contributor

@najmsheikh najmsheikh left a comment

Choose a reason for hiding this comment

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

Some nitpicks here and there but otherwise great stuff 👍🏽

import java.util.Map;

/**
* Api request model for {@link ConnectionManager}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: API*

/**
* Util class with helper methods
*/
final class ButtonUtil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since it's a utility class, you may want to add a private default constructor to prevent instantiation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really needed because you can't call any of the methods on the class even if it was instantiated

messageDigest.update(bytes, 0, bytes.length);
return new String(messageDigest.digest());
} catch (NoSuchAlgorithmException ignored) {

Copy link
Contributor

Choose a reason for hiding this comment

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

++

/**
* Asynchronous task used to report order to the Button API.
*/
class PostOrderTask extends Task {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you misspelled AsyncTask 😛
/s

Copy link
Contributor Author

Choose a reason for hiding this comment

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

LOL

private final Order order;
private final DeviceManager deviceManager;

PostOrderTask(@Nullable Listener listener, ButtonApi buttonApi, Order order,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I would move the nullable listener to end of the argument list

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just being consistent at this point with the other tasks

* Represents an order placed by the user to be tracked using ButtonMerchant.trackOrder(order).
* Represents an order placed by the user to be tracked using
* {@link ButtonMerchant#trackOrder(Context, Order, UserActivityListener)} and
* {@link ButtonMerchant#reportOrder(Context, Order, OrderListener)}
*/
public class Order {
Copy link
Contributor

Choose a reason for hiding this comment

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

Methods with javadocs that have the @Deprecated annotation need a pairing @deprecated javadoc annotation. Otherwise they will not be marked deprecated when we generate the docs.

/**
* Callbacks for report order
*
* @see ButtonMerchant#reportOrder(android.content.Context, Order, OrderListener)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: For consistency with other javadoc headers, replace the full package qualification of Context with an import

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Checkstyle will throw an unused import error


@Nullable
@WorkerThread
Void postOrder(Order order, String applicationId, String sourceToken,
Copy link

Choose a reason for hiding this comment

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

Why postOrder and not reportOrder?
Edit: I see reportOrder else where so I don't know what this method is

Copy link
Contributor Author

@Jon6193 Jon6193 Jun 26, 2019

Choose a reason for hiding this comment

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

The naming convention throughout the entire ButtonApi class is requestMethod + endpoint. reportOrder is the public facing method

Copy link

@romero-ios romero-ios left a comment

Choose a reason for hiding this comment

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

Looks like a network layer refactor was done - I only have one question

@Jon6193 Jon6193 merged commit 6bc83df into master Jun 26, 2019
@Jon6193 Jon6193 deleted the jon/post-order-api-request branch June 26, 2019 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants