-
Notifications
You must be signed in to change notification settings - Fork 99
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
Don't send an empty limit query parameter for Channel#get_reactions #39
Conversation
Been talking about this one in the discord before submission. |
eb458d7
to
852958c
Compare
lib/discordrb/api/channel.rb
Outdated
@@ -201,7 +201,7 @@ def delete_user_reaction(token, channel_id, message_id, emoji, user_id) | |||
# https://discord.com/developers/docs/resources/channel#get-reactions | |||
def get_reactions(token, channel_id, message_id, emoji, before_id, after_id, limit = 100) | |||
emoji = URI.encode_www_form_component(emoji) unless emoji.ascii_only? | |||
query_string = "limit=#{limit}#{"&before=#{before_id}" if before_id}#{"&after=#{after_id}" if after_id}" | |||
query_string = "limit=#{limit || 100}#{"&before=#{before_id}" if before_id}#{"&after=#{after_id}" if after_id}" |
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 would prefer to see this as
query_string = URI.encode_www_form({ limit: limit, before: before_id, after: after_id }.compact)
Please squash this thanks
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.
lgtm so far. Just some nitpicky spec changes going forward. I'm aware some parts of the library also use these things I've criticised which is where you may have taken inspiration from, but it's on the agenda to go over the specs to make them more consistent, and document guidelines in a Contributing section
spec/api/channel_spec.rb
Outdated
let(:message_id) { double('message_id') } | ||
let(:before_id) { double('before_id') } | ||
let(:after_id) { double('after_id') } | ||
|
||
before do | ||
allow(message_id).to receive(:to_s).and_return('message_id') | ||
allow(before_id).to receive(:to_s).and_return('before_id') | ||
allow(after_id).to receive(:to_s).and_return('after_id') | ||
|
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.
and here
let(:message_id) { double('message_id') } | |
let(:before_id) { double('before_id') } | |
let(:after_id) { double('after_id') } | |
before do | |
allow(message_id).to receive(:to_s).and_return('message_id') | |
allow(before_id).to receive(:to_s).and_return('before_id') | |
allow(after_id).to receive(:to_s).and_return('after_id') | |
let(:message_id) { double('message_id', to_s: 'message_id') } | |
let(:before_id) { double('before_id', to_s: 'before_id') } | |
let(:after_id) { double('after_id', to_s: 'after_id') } | |
before |
spec/api/channel_spec.rb
Outdated
let(:token) { double('token') } | ||
let(:channel_id) { instance_double(String, 'channel_id') } | ||
|
||
before do | ||
allow(token).to receive(:to_s).and_return('bot_token') | ||
allow(channel_id).to receive(:to_s).and_return('channel_id') | ||
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.
We can move these method stubs inside the double initialiser
let(:token) { double('token') } | |
let(:channel_id) { instance_double(String, 'channel_id') } | |
before do | |
allow(token).to receive(:to_s).and_return('bot_token') | |
allow(channel_id).to receive(:to_s).and_return('channel_id') | |
end | |
let(:token) { double('token', to_s: 'bot_token') } | |
let(:channel_id) { instance_double(String, 'channel_id', to_s: 'channel_id') } |
spec/api/channel_spec.rb
Outdated
|
||
it 'sends requests' do | ||
Discordrb::API::Channel.get_reactions(token, channel_id, message_id, 'test', before_id, after_id, 27) | ||
expect(Discordrb::API).to have_received(:request) |
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.
while have_received
is valid spec'ing known as using spies, I'd prefer we stay consistent and put the expectations before the call
spec/api/channel_spec.rb
Outdated
|
||
it 'percent-encodes emoji' do | ||
Discordrb::API::Channel.get_reactions(token, channel_id, message_id, "\u{1F44D}", before_id, after_id, 27) | ||
expect(Discordrb::API).to have_received(:request) |
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.
same here
spec/api/channel_spec.rb
Outdated
|
||
it 'uses the maximum limit of 100 if nil is provided' do | ||
Discordrb::API::Channel.get_reactions(token, channel_id, message_id, 'test', before_id, after_id, nil) | ||
expect(Discordrb::API).to have_received(:request) |
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.
and here
spec/data/message_spec.rb
Outdated
it 'calls the API method' do | ||
message.reacted_with('\u{1F44D}', limit: 27) | ||
|
||
expect(Discordrb::API::Channel).to have_received(:get_reactions) |
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.
and here
spec/data/message_spec.rb
Outdated
it 'defaults to a limit of 100' do | ||
message.reacted_with('\u{1F44D}') | ||
|
||
expect(Discordrb::API::Channel).to have_received(:get_reactions) |
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.
ditto
spec/data/message_spec.rb
Outdated
|
||
message.reacted_with(emoji) | ||
|
||
expect(Discordrb::API::Channel).to have_received(:get_reactions) |
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.
ditto
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.
lgtm.
Was gonna say "let's see about CI" but it seems to be working now :)
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 one small fix and then things should be good to go!
Thank you! |
Summary
Fixes #38.
Discord tries to parse the
limit
parameter as an integer, if nothing is sent a HTTP 400 is returned. This sets a default to the maximum instead of the usual 25, to reduce the number of requests needed to get all users whenlimit: nil
is passed.Added
Specs for
Message#reacted_with
andAPI::Channel.get_reactions
Changed
limit
defaults to 100 instead of the empty string when limit is nil.