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

no implicit conversion of string to integer error #169

Open
mfrederickson opened this issue Feb 26, 2016 · 2 comments
Open

no implicit conversion of string to integer error #169

mfrederickson opened this issue Feb 26, 2016 · 2 comments

Comments

@mfrederickson
Copy link

It's a simple response,

[
  {"id":7,"type":"Tech","displayName":"Redacted Carter"},
  {"id":9,"type":"Tech","displayName":"Michael Redacted"}
]

with a simple model

class Tech < JsonApiClient::Resource
  self.site = "https://helpdesk/helpdesk/WebObjects/Helpdesk.woa/ra"

  connection_options[:ssl] = { verify: false }
  connection_options[:params] = { "apiKey" => 'Redacted' }

  self.connection do |conn|
    conn.use Faraday::Response::Logger
  end

  def self.table_name 
    "Techs"
  end
end
$ rails c
Running via Spring preloader in process 31863
Loading development environment (Rails 4.2.5.1)
2.1.5 :001 > Tech.all
I, [2016-02-25T15:12:05.971271 #31863]  INFO -- : get https://helpdesk/helpdesk/WebObjects/Helpdesk.woa/ra/Techs?apiKey=Redacted
D, [2016-02-25T15:12:05.971415 #31863] DEBUG -- request: User-Agent: "Faraday v0.9.2"
Content-Type: "application/vnd.api+json"
Accept: "application/vnd.api+json"
I, [2016-02-25T15:12:05.993385 #31863]  INFO -- Status: 200
D, [2016-02-25T15:12:05.993495 #31863] DEBUG -- response: server: "Apache-Coyote/1.1"
x-webobjects-loadaverage: "47"
x-webobjects-servlet: "YES"
content-type: "application/json;charset=UTF-8"
content-length: "951"
date: "Fri, 26 Feb 2016 00:12:33 GMT"
connection: "close"
TypeError: no implicit conversion of String into Integer
    from /usr/local/rvm/gems/ruby-2.1.5/gems/json_api_client-1.1.1/lib/json_api_client/parsers/parser.rb:59:in `fetch'
    from /usr/local/rvm/gems/ruby-2.1.5/gems/json_api_client-1.1.1/lib/json_api_client/parsers/parser.rb:59:in `handle_json_api'
    from /usr/local/rvm/gems/ruby-2.1.5/gems/json_api_client-1.1.1/lib/json_api_client/parsers/parser.rb:11:in `block in parse'
    from /usr/local/rvm/gems/ruby-2.1.5/gems/json_api_client-1.1.1/lib/json_api_client/parsers/parser.rb:8:in `tap'
    from /usr/local/rvm/gems/ruby-2.1.5/gems/json_api_client-1.1.1/lib/json_api_client/parsers/parser.rb:8:in `parse'
    from /usr/local/rvm/gems/ruby-2.1.5/gems/json_api_client-1.1.1/lib/json_api_client/query/requestor.rb:63:in `request'
    from /usr/local/rvm/gems/ruby-2.1.5/gems/json_api_client-1.1.1/lib/json_api_client/query/requestor.rb:26:in `get'
    from /usr/local/rvm/gems/ruby-2.1.5/gems/json_api_client-1.1.1/lib/json_api_client/query/builder.rb:95:in `find'
    from /usr/local/rvm/gems/ruby-2.1.5/gems/json_api_client-1.1.1/lib/json_api_client/query/builder.rb:83:in `to_a'

What am I doing wrong?

@mfrederickson
Copy link
Author

I suppose the API that I'm hitting isn't conforming to the JSON API... the specs say that the response must be an object { } that contains a data key... Bummer, I was really hoping to use this gem...

@groyoh
Copy link

groyoh commented Feb 28, 2016

@mfrederickson Indeed, the response you receive is not a JSONAPI response:

  1. The response does not match the schema of JSONAPI
  2. The content type states that it's not a JSONAPI response e.g. content-type: "application/json;charset=UTF-8"

Maybe the gem could raise a proper error when the content-type is not valid.

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

2 participants