Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@nando
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nando/2ae02aeefdc3784b37a5 to your computer and use it in GitHub Desktop.
Save nando/2ae02aeefdc3784b37a5 to your computer and use it in GitHub Desktop.
user ids from Redmine's memberships JSON
require 'json'
json = <<JSON
{
"memberships": [
{
"id": 3786,
"project": {
"id": 295,
"name": "Web Pública - UK"
},
"user": {
"id": 83,
"name": "Miriam"
},
"roles": [
{
"id": 3,
"name": "Jefe de proyecto"
}
]
},
{
"id": 4111,
"project": {
"id": 295,
"name": "Web Pública - UK"
},
"user": {
"id": 157,
"name": "Beatriz"
},
"roles": [
{
"id": 3,
"name": "Jefe de proyecto"
}
]
}
],
"total_count": 12,
"offset": 0,
"limit": 25
}
JSON
hash = JSON.parse(json)
puts hash['memberships'].inject({}) {|sum, elem| sum[elem['user']['id']] = elem['user']['name']; sum}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment