Skip to content

Instantly share code, notes, and snippets.

@aroth
Created February 28, 2011 03:17
Show Gist options
  • Save aroth/846890 to your computer and use it in GitHub Desktop.
Save aroth/846890 to your computer and use it in GitHub Desktop.
associate results within the 'uploads' key of a transloadit response (ruby/js)
$A( a.uploads ).each( function( upload, index ){
$H( a.results ).keys().each( function( key ){
a.results[ key ].each( function( r ){
if( r.original_id == upload.id ){
if( !upload['results'][key] ){
upload['results'][key] = {}
}
upload['results'][key] = r;
}
});
});
});
x = JSON.parse( params[:transloadit] )
x['uploads'].each_with_index do |upload, index|
x['results'].keys.each do |key|
x['results'][key].each do |r|
if( r['original_id'] == upload['id'] )
upload['results'] = {} if !upload['results']
upload['results'][key] = r
end
end
end
end
# x['uploads'].first['results'].keys
# [
# [0] "video_thumbs_96x72",
# [1] "video_thumbs_516x290",
# [2] "encode_flv",
# [3] "encode_mp4"
# ]
# x['fields']['media_timestamp']
# "2011-01-26 00:42:43 +0000"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment