Created
December 22, 2012 21:01
-
-
Save amazedkoumei/4361091 to your computer and use it in GitHub Desktop.
This file contains 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
# TODO: meta | |
def toggleFavorite(bookmark, &block) | |
favorite = bookmark[:favorite] | |
if favorite | |
f = "0" | |
else | |
f = "1" | |
end | |
parameters = { | |
:favorite => f | |
} | |
begin | |
update(bookmark[:id], parameters) do | |
@bookmarks.each do |b| | |
b[:favorite] = !favorite if b[:id] == bookmark[:id] | |
end | |
block.call() if block | |
end | |
rescue => e | |
block.call() if block | |
App.alert("Fail to Update") | |
end | |
end | |
# TODO: meta | |
def toggleArchive(bookmark, &block) | |
archive = bookmark[:archive] | |
if archive | |
a = "0" | |
else | |
a = "1" | |
end | |
parameters = { | |
:archive => a | |
} | |
begin | |
update(bookmark[:id], parameters) do | |
@bookmarks.each do |b| | |
b[:archive] = !archive if b[:id] == bookmark[:id] | |
end | |
block.call() if block | |
end | |
rescue => e | |
block.call() if block | |
App.alert("Fail to Update") | |
end | |
end | |
# FIXME: rename | |
def update(bookmarkId, parameters, &block) | |
@client.postPath("bookmarks/#{bookmarkId}", parameters:parameters, | |
# operation: AFHTTPRequestOperation | |
# responseObject: id | |
success:lambda do |operation, responseObject| | |
begin | |
if operation.response.statusCode == 200 | |
block.call() if block | |
else | |
raise NetworkException | |
end | |
rescue => e | |
raise NetworkException | |
end | |
end, | |
failure:lambda do |operation, error| | |
raise NetworkException | |
end | |
) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment