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

Search for subscriptions, customers and credit card verifications. #43

Closed
wants to merge 18 commits into from

Conversation

feda12
Copy link
Contributor

@feda12 feda12 commented Oct 3, 2017

No description provided.

Copy link
Owner

@sorentwo sorentwo left a comment

Choose a reason for hiding this comment

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

Again, a really impressive amount of work. The overall strategy and structure is great, just needs some cleanup!

@@ -81,6 +81,30 @@ case Customer.create(%{company: "Whale Corp"}) do
end
```

Here is how to use the search endpoints:
Copy link
Owner

Choose a reason for hiding this comment

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

Please add some space between the paragraph and the code block.

@doc """
To search for credit card verifications, pass a map of search parameters.

See README for examples.
Copy link
Owner

Choose a reason for hiding this comment

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

I'd prefer to have the examples in the docs, not just the README.


See README for examples.

Example:
Copy link
Owner

Choose a reason for hiding this comment

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

This should be prefixed with ##


Example:

{:ok, verifications} = CreditCardVerification.search(%{customer: %{id: %{is: "1231231"}}})
Copy link
Owner

Choose a reason for hiding this comment

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

This needs to be indented four spaces, it also requires the full module name (Braintree.CreditCardVerification)

"""
@spec new(Map.t | [Map.t]) :: t | [t]
def new(%{"credit_card_verification" => map}),
do: new(map)
Copy link
Owner

Choose a reason for hiding this comment

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

We don't use the newline + do: style anywhere else, so I'd prefer to be consistent and use the do/end style. Some day soon auto-formatting will make this a non issue, but we're not there yet!

lib/search.ex Outdated

# Credit card verification is an odd case because path to endpoints is different
# from the object name in the XML
defp fetch_ids_chunk(ids, "verifications"=resource, initializer, opts) when is_list(ids) do
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think it's necessary to bind to resource here, instead just post directly to "verifications/advanced_search".

@@ -164,6 +164,20 @@ defmodule Braintree.Subscription do
end

@doc """
To search for subscriptions, pass a map of search parameters.

See README for examples.
Copy link
Owner

Choose a reason for hiding this comment

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

Again, better to put one example in here. The "Example" needs to be fixed up as above too.

@@ -40,6 +40,7 @@ defmodule Braintree.XML.Decoder do

case attributes do
[type: "array"] -> %{name => transform({attributes, values})}
[type: "collection"] -> %{name => transform({attributes, values})}
_ -> %{name => transform(values)}
Copy link
Owner

Choose a reason for hiding this comment

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

The _ indention here is even funnier now. As you're adding the new case it would be nice to pull it back.

@@ -72,6 +73,10 @@ defmodule Braintree.XML.Decoder do
defp transform({[type: "array"], elements}),
do: Enum.map(without_nil(elements), &(elem(transform(&1), 1)))

defp transform({[type: "collection"], elements}) do
Copy link
Owner

Choose a reason for hiding this comment

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

Apparently we do use do: some places. Sorry about the inconsistency. Better to keep the do/end as you have it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do believe that in some cases, do: is cleaner. I'll let you decide.

defp only_collection(elements),
do: elements
|> without_nil()
|> Enum.reject(fn e -> elem(e, 1) != [] end)
Copy link
Owner

Choose a reason for hiding this comment

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

Let's avoid single character variables. This could use pattern matching rather than the elem function too: fn {_, value} -> value != [] end)

Copy link
Contributor Author

@feda12 feda12 left a comment

Choose a reason for hiding this comment

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

All clean! Thanks for the feedback, it is much appreciated!

lib/http.ex Outdated
def resolve_unprocessable_entity_error(%{"api_error_response" => api_error_response}),
do: Error.new(api_error_response)
def resolve_unprocessable_entity_error(%{"unprocessable_entity" => api_response}),
do: :unprocessable_entity
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the API response:
<unprocessable-entity />

My thinking was that there is no valuable data in there thus this approach. Let me know what you think.

lib/search.ex Outdated
end
end

defp ids(payload, resource, initializer, opts) when is_map(payload) do
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Braintree's search is confusing by itself, but yes I agree. I am renaming this.

@@ -72,6 +73,10 @@ defmodule Braintree.XML.Decoder do
defp transform({[type: "array"], elements}),
do: Enum.map(without_nil(elements), &(elem(transform(&1), 1)))

defp transform({[type: "collection"], elements}) do
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do believe that in some cases, do: is cleaner. I'll let you decide.

lib/search.ex Outdated
@@ -0,0 +1,55 @@
defmodule Braintree.Search do
@moduledoc """
This module performs advanced search on a resource.
Copy link
Owner

Choose a reason for hiding this comment

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

There shouldn't be any indentation within the moduledoc.

lib/http.ex Outdated
defp resolve_unprocessable_entity_error(%{"api_error_response" => api_error_response}),
do: Error.new(api_error_response)
defp resolve_unprocessable_entity_error(%{"unprocessable_entity" => _}),
do: :unprocessable_entity
Copy link
Owner

Choose a reason for hiding this comment

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

Really this is multiple error types, it could simply be resolve_error_response.

Let's go with Error.new(%{message: "Unprocessable Entity"}) to return something consistent. Also, please use do/end here.

@sorentwo
Copy link
Owner

sorentwo commented Oct 5, 2017

This has been merged locally (so I could squash the various fixup commits). Thanks again for all your work!

@sorentwo sorentwo closed this Oct 5, 2017
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.

2 participants