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

Cleanup client HTTP methods #88

Merged
merged 29 commits into from
Mar 9, 2016
Merged

Cleanup client HTTP methods #88

merged 29 commits into from
Mar 9, 2016

Conversation

jacegu
Copy link
Contributor

@jacegu jacegu commented Mar 7, 2016

Following up with the conversation @weppos had in Slack.

@jacegu jacegu self-assigned this Mar 7, 2016
@jacegu jacegu added this to the API v2 milestone Mar 7, 2016
@weppos
Copy link
Member

weppos commented Mar 7, 2016

@jacegu actually, my proposal is to keep the options, and add the data where necessary.

E.g.

def get(path, options = {})
  # ...

def post(path, data, options = {})
  # ...

@jacegu
Copy link
Contributor Author

jacegu commented Mar 7, 2016

Last commit is the smallest step to make remove the confusion about the unused parameters.

From here we can move forward and have the request body as a separate parameter in the request. If we do that the methods with an actual body would look like this:

def post(path, data, options = {})
  execute :post, path, data, options
end

while the methods without it would look like this:

def get(path, options = {})
  execute :get, path, {}, options
end

We would also have to change how we compose the HTTParty request in the request method as query and headers would no longer be part of the data parameter, but part of a fourth, newly added, one.

Finally we would have to revert all the:

attribute.merge(options)

inside each endpoint method to have data and options as separate parameters where appropriate.

Want to double check first that we want to move forward with this because it will be some work. It may be worth to consider if the change would benefit us when the time to replace HTTParty comes.

Thoughts?

@jacegu
Copy link
Contributor Author

jacegu commented Mar 7, 2016

That's how the client would look like with the change @weppos. Still need to undo all the attributes.merge(options). Build passes though... (Which makes me nervous).

# @return [HTTParty::Response]
def delete(path, options = {})
execute :delete, path, options
execute :delete, path, {}, options
Copy link
Member

Choose a reason for hiding this comment

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

Although the RFC doesn't mention the data payload for a DELETE action, it's common practice to consider DELETE to accept a payload. I would allow it, since I believe we use (or used) it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we are not accepting attributes in the delete methods we would have to change all delete calls from something like:

response = client.delete(Client.versioned("/%s/contacts/%s" % [account_id, contact_id]), options)

to (note the extra {} in place of attributes):

response = client.delete(Client.versioned("/%s/contacts/%s" % [account_id, contact_id]), {}, options)

Either that, or add the attributes to each delete endpoint switching:

def delete_contact(account_id, contact_id, options = {})

to

def delete_contact(account_id, contact_id, attributes = {}, options = {})

Copy link
Member

Choose a reason for hiding this comment

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

No, we should not add it to the method signature. We should use

response = client.delete(Client.versioned("/%s/contacts/%s" % [account_id, contact_id]), {}, options)

even if a nil value would seem more appropriate

response = client.delete(Client.versioned("/%s/contacts/%s" % [account_id, contact_id]), nil, options)

@weppos
Copy link
Member

weppos commented Mar 7, 2016

So far so good, @jacegu. It definitely looks cleaner to me.

@jacegu jacegu added ready-for-review Pull requests that are ready to be reviewed by other team members. and removed ready-for-review Pull requests that are ready to be reviewed by other team members. labels Mar 7, 2016
@jacegu
Copy link
Contributor Author

jacegu commented Mar 7, 2016

@weppos you can check where this is going. If you think it's ok we can go back to consider switching the default value of every attribute parameter from {} to nil.

@weppos
Copy link
Member

weppos commented Mar 7, 2016

@jacegu I'd leave options default to {}, but it makes sense to me to change data default to be nil as any other value could potentially be a valid non-empty value.

@jacegu
Copy link
Contributor Author

jacegu commented Mar 8, 2016

@weppos changing options' default value was never on the table. 👍 to changing data and attributes default value to nil.

@jacegu
Copy link
Contributor Author

jacegu commented Mar 8, 2016

@weppos I just had a thought: maybe when you were talking about options you actually meant attributes... I've stopped here for that reason.

The pending changes before calling this PR done, are doing what I did for the contacts for every other method that takes attributes. Will wait to verify that we are on the same page before moving forward.

@weppos
Copy link
Member

weppos commented Mar 8, 2016

@jacegu contacts look good to me. What I'd probably change, is to pass nil in the delete instead of {}. In other words, when the data is empty, we should pass nil and not {}.

I also wonder if it makes sense to set attributes as optional parameters in create/update. It doesn't make sense to create a contact with empty attributes, I'd remove the default value and leave them as mandatory arguments.

Does it make sense?

@jacegu
Copy link
Contributor Author

jacegu commented Mar 8, 2016

What I'd probably change, is to pass nil in the delete instead of {}

Missed that! Should had been changed.

I also wonder if it makes sense to set attributes as optional parameters in create/update. It doesn't make sense to create a contact with empty attributes, I'd remove the default value and leave them as mandatory arguments.

I agree.

Moving forward with this then. 👍

* master:
  Sync with other clients
  Revert doc formtting to match the rest of the project
  Add examples for TLD client use
  Add command to get extended attributes on a TLD
  Rename #transfer_out to #transfer_domain_out
  Rename #transfer to #transfer_domain
  Rename #renew to #renew_domain
  Rename #register to #register_domain
  Rename #check to #check_domain
  Add method for getting a TLD's details
@jacegu jacegu added the ready-for-review Pull requests that are ready to be reviewed by other team members. label Mar 8, 2016
# @return [HTTParty::Response]
def get(path, options = {})
execute :get, path, options
execute :get, path, {}, options
Copy link
Member

Choose a reason for hiding this comment

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

@jacegu I suppose it should be nil 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.

Thanks for spotting that. Couldn't get them all 😅

@weppos
Copy link
Member

weppos commented Mar 9, 2016

Thanks @jacegu, it definitely looks cleaner now that attributes and options are separated. Besides a nil value in the get that seems more appropriate to me, this is a :shipit: for me.

jacegu and others added 3 commits March 9, 2016 10:48
See b07da4fe4f1fd87aaf7a5900ecbf5b617dbfd8c4
* master:
  Fix some YARD issues
  Experiment with V2 static helpers
  Prepare for the beta
  rake 11.0 is yanked
  Remove unused exceptions
  Temporarily downgrade `rake`
  Revert 8384639
  Consistently refer to the underlying HTTP response as http_response
jacegu added a commit that referenced this pull request Mar 9, 2016
@jacegu jacegu merged commit dcd74a5 into master Mar 9, 2016
@jacegu jacegu deleted the cleanup/http-methods branch March 9, 2016 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement ready-for-review Pull requests that are ready to be reviewed by other team members.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants