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

gem http failing with ArgumentError #3

Closed
alexandreh92 opened this issue Sep 30, 2022 · 5 comments
Closed

gem http failing with ArgumentError #3

alexandreh92 opened this issue Sep 30, 2022 · 5 comments

Comments

@alexandreh92
Copy link

alexandreh92 commented Sep 30, 2022

Hi, thanks for your gem, I really apreciate your job here.

I'm trying to use this gem but http gem is failing in lib/push/client.rb:259:

Here's the trace:

Traceback (most recent call last):
	12: from /Users/alexandre/.rvm/gems/ruby-2.7.4/gems/expo-server-sdk-0.1.4/lib/push/client.rb:188:in `block (2 levels) in send'
	11: from /Users/alexandre/.rvm/gems/ruby-2.7.4/gems/connection_pool-2.2.5/lib/connection_pool.rb:59:in `with'
	10: from /Users/alexandre/.rvm/gems/ruby-2.7.4/gems/connection_pool-2.2.5/lib/connection_pool.rb:59:in `handle_interrupt'
	 9: from /Users/alexandre/.rvm/gems/ruby-2.7.4/gems/connection_pool-2.2.5/lib/connection_pool.rb:60:in `block in with'
	 8: from /Users/alexandre/.rvm/gems/ruby-2.7.4/gems/connection_pool-2.2.5/lib/connection_pool.rb:78:in `checkout'
	 7: from /Users/alexandre/.rvm/gems/ruby-2.7.4/gems/connection_pool-2.2.5/lib/connection_pool/timed_stack.rb:68:in `pop'
	 6: from /Users/alexandre/.rvm/gems/ruby-2.7.4/gems/connection_pool-2.2.5/lib/connection_pool/timed_stack.rb:68:in `synchronize'
	 5: from /Users/alexandre/.rvm/gems/ruby-2.7.4/gems/connection_pool-2.2.5/lib/connection_pool/timed_stack.rb:69:in `block in pop'
	 4: from /Users/alexandre/.rvm/gems/ruby-2.7.4/gems/connection_pool-2.2.5/lib/connection_pool/timed_stack.rb:69:in `loop'
	 3: from /Users/alexandre/.rvm/gems/ruby-2.7.4/gems/connection_pool-2.2.5/lib/connection_pool/timed_stack.rb:73:in `block (2 levels) in pop'
	 2: from /Users/alexandre/.rvm/gems/ruby-2.7.4/gems/connection_pool-2.2.5/lib/connection_pool/timed_stack.rb:169:in `try_create'
	 1: from /Users/alexandre/.rvm/gems/ruby-2.7.4/gems/expo-server-sdk-0.1.4/lib/push/client.rb:259:in `block in connect'
/Users/alexandre/.rvm/gems/ruby-2.7.4/gems/http-5.1.0/lib/http/chainable.rb:182:in `headers': wrong number of arguments (given 2, expected 1) (ArgumentError)
ArgumentError: wrong number of arguments (given 2, expected 1)
from /Users/alexandre/.rvm/gems/ruby-2.7.4/gems/http-5.1.0/lib/http/chainable.rb:182:in `headers'

Code:

def send_message!(token)
  client = Expo::Push::Client.new(access_token: token)

  push_message = client.notification
                        .to(token)
                        .sound('default')
                        .body(body)

  client.send!([push_message])
end

EDIT: Got it working by changing:

- client = Expo::Push::Client.new(access_token: token)
+ client = Expo::Push::Client.new
@SleeplessByte
Copy link
Owner

Great. I'll check the case with providing an access token.

@pvign
Copy link
Contributor

pvign commented Jun 30, 2023

Hi @SleeplessByte,
I faced the same issue than @alexandreh92.
After digging a little bit it appears that the flaw is here: http.headers('Authorization', "Bearer #{access_token}")
(L259)
According to the http wiki here, http.headers accepts an hash while 2 arguments are passed here.
I replaced this line with:
http.headers('Authorization' => "Bearer #{access_token}") if access_token and it seems to work as expected.
It could also be replaced by http.auth("Bearer #{access_token}") if access_token according to this page.
I am a newbie in Rails then I might missed something but otherwise I'll be happy to do a Pull Request if you think it is the right way.
Cheers

@SleeplessByte
Copy link
Owner

Hi @SleeplessByte,
I faced the same issue than @alexandreh92.
After digging a little bit it appears that the flaw is here: http.headers('Authorization', "Bearer #{access_token}")
(L259)
According to the http wiki here, http.headers accepts an hash while 2 arguments are passed here.
I replaced this line with:
http.headers('Authorization' => "Bearer #{access_token}") if access_token and it seems to work as expected.
It could also be replaced by http.auth("Bearer #{access_token}") if access_token according to this page.
I am a newbie in Rails then I might missed something but otherwise I'll be happy to do a Pull Request if you think it is the right way.
Cheers

Would love a PR!

@pvign
Copy link
Contributor

pvign commented Jun 30, 2023

Hi @SleeplessByte,
I faced the same issue than @alexandreh92.
After digging a little bit it appears that the flaw is here: http.headers('Authorization', "Bearer #{access_token}")
(L259)
According to the http wiki here, http.headers accepts an hash while 2 arguments are passed here.
I replaced this line with:
http.headers('Authorization' => "Bearer #{access_token}") if access_token and it seems to work as expected.
It could also be replaced by http.auth("Bearer #{access_token}") if access_token according to this page.
I am a newbie in Rails then I might missed something but otherwise I'll be happy to do a Pull Request if you think it is the right way.
Cheers

Would love a PR!

I've just submitted #6

Thanks for your fast answer and your work on this gem 🙏

@SleeplessByte
Copy link
Owner

I'll review tomorrow. If you don't have a response by Sunday, please feel free to ping me!

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

No branches or pull requests

3 participants