Created
February 28, 2011 03:17
-
-
Save aroth/846890 to your computer and use it in GitHub Desktop.
associate results within the 'uploads' key of a transloadit response (ruby/js)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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; | |
} | |
}); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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