-
Notifications
You must be signed in to change notification settings - Fork 14
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
API v2 #27
base: master
Are you sure you want to change the base?
API v2 #27
Conversation
a09a8d4
to
d79f44f
Compare
d79f44f
to
e08c827
Compare
parsed_url = URI.parse(url) | ||
params = parsed_url.query ? Rack::Utils.parse_query(parsed_url.query) : {} | ||
params['include'] = joined_or_null(includes) if includes | ||
fields.each do |name, val| | ||
params["fields[#{name}]"] = val | ||
end if fields | ||
params["page[count]"] = (count || 10) unless count_not_passed |
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 desugars to:
if not count_not_passed
params["page[count]"] = (count || 10)
end
When this method is:
- Called with
count
set to3
, thencount_not_passed == false
,count == 3
. This setsparams["page[count]"]
to3 || 10
, which evaluates to3
. - Called with
count
set tonil
, thencount_not_passed == false
,count == nil
. This setsparams["page[count]"]
tonil || 10
, which evaluates to10
. - Called without
count
, thencount_not_passed == true
,count == nil
. This doesn't setparams["page[count]"]
at all.
It looks like the intent is to provide three choices?
- Use the
count
specified. - Use default
count
. - Omit
count
.
If this triple-choice is to stay, I recommend turning the rest of the optional arguments into keyword args. Depending on the minimum Ruby version supported, we could either use real Ruby keyword args, or simulate them with a hash, as is a long-time traditional in older versions of Ruby.
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.
Great catch and great explanation! Looking at the python lib I don't even think we need to provide a default. I will update the logic to:
- Use the count specified.
- Omit count.
Although this The instance-variant of |
Do you think it is worth creating a separate PR to address that? Also wondering if there is a ruby gem that we could want to use. |
Yes, the author of that snippet has created a separate Edit: Yes, this can be addressed in another PR. |
I assume all changes to |
Yep! (Thanks for the reminder 😉) |
3009ed2
to
ec467c7
Compare
Co-authored-by: Wil Lee <[email protected]>
Update Ruby lib to APIv2.
The generation code lives in https://github.com/Patreon/patreon_py/pull/18680
Note to reviewer
It should be easier to look at each commit individually.
Inspiration: Patreon/patreon-python#28