Skip to content

Instantly share code, notes, and snippets.

@richardvenneman
Created October 24, 2012 09:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save richardvenneman/3945037 to your computer and use it in GitHub Desktop.
Save richardvenneman/3945037 to your computer and use it in GitHub Desktop.
I use this method to retrieve some JSON and prepare the objects for NanoStore.
def self.update(username, &block)
BW::HTTP.get("#{Constants::API_endpoint}/events/#{username}") do |response|
if response.ok?
events = BW::JSON.parse(response.body)
::Event.delete
events.each { |e|
eventdata = e.each_with_object({}){ |(k,v), h| h[k.to_sym] = v }
eventData.each { |k,v| eventData.delete(k) if v.nil? }
::Event.create(eventData)
}
block.call if block
else
alert = UIAlertView.alloc.initWithTitle('Events error',
message:'There was an error getting your events.',
delegate:nil,
cancelButtonTitle:'OK',
otherButtonTitles:nil)
alert.show
block.call(true) if block
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment