googleapis / signet

Signet is an OAuth 1.0 / OAuth 2.0 implementation.
Apache License 2.0
373 stars 164 forks source link

no implicit conversion of Fixnum into String #56

Closed fertobar closed 8 years ago

fertobar commented 9 years ago

Hi. I'm using Rails 4, & ruby 2.1 and I'm getting this error in SOAP connection: no implicit conversion of Fixnum into String

More details: rails (4.1.0) faraday (0.9.1)

google-ads-common (0.9.8)
  httpi (~> 1.1.0)
  savon (~> 1.2.0)
  signet (~> 0.6.0)
google-adwords-api (0.14.2)
  google-ads-common (~> 0.9.8)
google-dfp-api (0.9.4)
  google-ads-common (~> 0.9.4)

I notice that similar code works in Rails 3.2.20,and fails with Rails 4.1 , 4.2, and similar Rails 4

https://github.com/google/signet/blob/master/lib/signet/oauth_2/client.rb Line 748:

      def expires_at
        if @expires_at
          @expires_at
        elsif @issued_at && @expires_in
          return @issued_at + @expires_in #TODO: @issued_at is String, String + Fixnum fails. 
        else
          return nil
        end
      end

Related with issue: https://github.com/googleads/google-api-ads-ruby/issues/53#issuecomment-96950402

Any suggestion? thanks

coderberry commented 9 years ago

:+1:

bruzos commented 9 years ago

Same problem when using google-ruby-client in service Google::Apis::AnalyticsV3::AnalyticsService with Rails 4.2.2 and ruby 2.2.1. but not in rails console

The problem appear when I do:

auth.update_token!({
                    access_token: session[:gauth]['access_token'],
                    refresh_token: session[:gauth]['refresh_token'],
                    expires_in: session[:gauth]['expires_in'],
                    issued_at: session[:gauth]['issued_at']
                   })

'issued_at' is store at session var as string and signet wait for a Time object. I have solved it doing:

  auth.update_token!({
                    access_token: session[:gauth]['access_token'],
                    refresh_token: session[:gauth]['refresh_token'],
                    expires_in: session[:gauth]['expires_in'],
                    issued_at: Time.parse(session[:gauth]['issued_at'])
                   })

Maybe a extra control at @issued_at could avoid the error.

   return (@issued_at.is_a? String ? Time.parse(@issued_at) : @issued_at ) + @expires_in
Gataniel commented 9 years ago

This issue IMHO is in google-adwords-api. So you here is my PR fixing it https://github.com/Gataniel/google-api-ads-ruby/tree/fix-ads_common-saving-issued_at-as-a-string-instead-of-time

sqrrrl commented 8 years ago

Should be fixed in 0.7