-
Notifications
You must be signed in to change notification settings - Fork 257
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
Define a consistent return value for update
actions
#171
Conversation
update
actions
params: { company_id: vid }, | ||
body: { "properties" => properties } | ||
) | ||
end |
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.
Example of adding a new .update!
endpoint that returns a Hubspot::Response
.
@@ -7,7 +7,8 @@ def get_json(path, opts) | |||
url = generate_url(path, opts) | |||
response = get(url, format: :json) | |||
log_request_and_response url, response | |||
handle_response(response) | |||
raise(Hubspot::RequestError.new(response)) unless response.success? | |||
response.parsed_response |
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.
To keep these changes isolated, get_json
still returns a hash as we focus on making update
s consistent.
let(:company){ Hubspot::Company.new(example_company_hash) } | ||
let(:params){ {name: "Acme Cogs", domain: "abccogs.com"} } | ||
subject{ company.update!(params) } | ||
describe ".update!" do |
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.
These changes:
- updates the test to remove the use of
its
(which is deprecated but still available to us as we've pulled in therspec-its
gem) - updates the test to be self-reliant by creating and deleting any necessary data.
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.
Nice, how far is the code base from removing rspec-its
as a dependency?
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 are about 10 spec files that use its
heavily. It will take some time to get there.
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 a step in the right direction.
let(:company){ Hubspot::Company.new(example_company_hash) } | ||
let(:params){ {name: "Acme Cogs", domain: "abccogs.com"} } | ||
subject{ company.update!(params) } | ||
describe ".update!" do |
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.
Nice, how far is the code base from removing rspec-its
as a dependency?
Sounds like a good approach! |
@adimichele @MattMSumner Excellent, thank you! I'll wait for @cbisnett to add his thoughts before proceeding any further. |
@adimichele Is it okay if I proceed with these changes? This change is blocking work as we'll want future work to follow this model of returning a Or, do you know when @cbisnett will be back from holiday? I'd prefer to have his buy-in as well unless you're comfortable with moving forward. |
Yes, don’t want you blocked so please go ahead!
On Sat, Dec 29, 2018 at 11:08 AM Stephanie ***@***.***> wrote:
@adimichele <https://github.com/adimichele> Is it okay if I proceed with
these changes? This change is blocking work as we'll want future work to
follow this model of returning a Hubspot::Response.
Or, do you know when @cbisnett <https://github.com/cbisnett> will be back
from holiday? I'd prefer to have his buy-in as well unless you're
comfortable with moving forward.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#171 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABIm-CRuc_kj5eoeDhR7FPR5ol1_dIGcks5u95N6gaJpZM4ZcoY0>
.
--
Sent from my mobile device
|
Sorry for the delayed response. I don't think returning the parsed JSON is a good approach for two reasons:
Returning a Hash with the result of the parsed JSON means that you can't chain any methods to the end of For these reasons (and some other minor reasons) I think the correct implementation here is to return the instance. I've got an idea for how to implement a base resource class that would support being able to read all of the properties returned by the API which seems like the main reason for returning the JSON. I'll take a few minutes today to build this and submit a PR so everyone can review it. |
I created PR #176 with a basic implementation for how I fee much of this should be refactored. |
Closing this PR in favor of pursuing a design that returns an object that represents the resource (ex: |
What does an
update
action return?Depending on which class you're using, calling
.update!
or#update!
will vary between returning a hash or an instance of the class.How can we make this consistent and give our users the best experience?
I'd like to suggest that we always return a
Hubspot::Response
object that contains the parsed JSONand avoid parsing the HubSpot API response to a domain object, (ex:
Deal
).My thought process behind this approach:
.update!
action and remove existing instance#update!
methods.If everyone likes this approach, next steps include:
update
actions that return a class instance are not using the response fromConnection.put_json
update
actions that return a class instance to be class level methods that return aHubspot::Response
.GET
,POST
, andDELETE
actions