Created
October 24, 2012 09:18
-
-
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.
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
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