Search code examples
rubyiterationoctokit

no implicit conversion of Symbol into Integer: Octokit


This is just an example of the reponse body

{
  "users": [
    {
      "login": "octocat",
      "id": 1,
      "node_id": "MDQ6VXNlcjE=",
      "avatar_url": "https://github.com/images/error/octocat_happy.gif",
      "gravatar_id": "",
      "url": "https://api.github.com/users/octocat",
      "html_url": "https://github.com/octocat",
      "followers_url": "https://api.github.com/users/octocat/followers",
      "following_url": "https://api.github.com/users/octocat/following{/other_user}",
      "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
      "organizations_url": "https://api.github.com/users/octocat/orgs",
      "repos_url": "https://api.github.com/users/octocat/repos",
      "events_url": "https://api.github.com/users/octocat/events{/privacy}",
      "received_events_url": "https://api.github.com/users/octocat/received_events",
      "type": "User",
      "site_admin": false
    }
  ],
  "teams": [
    {
      "id": 1,
      "node_id": "MDQ6VGVhbTE=",
      "url": "https://api.github.com/teams/1",
      "html_url": "https://github.com/orgs/github/teams/justice-league",
      "name": "Justice League",
      "slug": "justice-league",
      "description": "A great team.",
      "privacy": "closed",
      "permission": "admin",
      "members_url": "https://api.github.com/teams/1/members{/member}",
      "repositories_url": "https://api.github.com/teams/1/repos",
      "parent": null
    }
  ]
}
 client.pull_request_reviewer("healtheintent/hcc_reference_service", 129).each do |comment|
    username = comment[:user][:login]
end

This is the code I am using to iterate the given response. But its returning "no implicit conversion of Symbol into Integer "

Can someone please tell me how I iterate the given body


Solution

  • your "path" of accessing the content (comment[:user][:login]) does absolutely not match your datastructure.

    1. its users not user
    2. the root object is a hash, not an array
    3. you have a nested array, which you are not iterating over

    maybe you want this

    client.pull_request_reviewer("healtheintent/hcc_reference_service", 129)[:users].each do |user|
        username = user[:login]
    
    

    the reason you are getting a "no implicit conversion of Symbol into Integer" is, because you are using the [] notation on an array, but giving it a symbol as key/index (because you wrongly assumed to be a hash)