Skip to content

Instantly share code, notes, and snippets.

@electronicbites
Created September 28, 2010 15:46
Show Gist options
  • Save electronicbites/601230 to your computer and use it in GitHub Desktop.
Save electronicbites/601230 to your computer and use it in GitHub Desktop.
user = User.all[100..120]
root_url = "www.wahwah.fm"
current_user = User.find(150)
jsonstring = "[#{user.collect { |u|
listenerhash = {:listenercount => u.listeners.count}
u.listeners.around_me(point1, point2).each_with_index do |listener, i|
listenerhash.merge!({i => {:name => listener.name}})
end
userhash = {
:name => u.name,
:userid => u.id,
:userpicture=> {:type => "picture/png", :href => root_url.without_last_slash + u.avatar.url(:mini)},
:userpicturethumb => {:type => "picture/png", :href => root_url.without_last_slash + u.avatar.url(:thumb)},
:userpicturelarge => {:type => "picture/png",:href => root_url.without_last_slash + u.avatar.url(:large)},
:favorite => current_user.favorite_user?(u),
:follower_count => u.follower_count,
:listener => listenerhash
}
userhash.merge!({:position => {:latitude => u.current_position.latitude,
:longitude => u.current_position.longitude,
:elevation => u.current_position.elevation.to_i}}) unless u.current_position.nil?
ActiveSupport::JSON.encode(userhash)
}* ','}]"
ActiveSupport::JSON.decode(jsonstring)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment