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
Conversation
@Nullable | ||
private Map<String, String> headers; | ||
@Nullable | ||
private JSONObject body; |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log an error here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
++
There was a problem hiding this 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} |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { | ||
|
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this 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
Goals ⚽
Implementation 🚧
ApiRequest
to allow a better way to build requestspost
fromConnectionManager
in favor ofexecute
ButtonUtil
for utility methods used in multiple placesPostOrderTask
to report ordersTesting 🔍