Skip to content

Instantly share code, notes, and snippets.

@amazedkoumei
Created December 22, 2012 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amazedkoumei/4361091 to your computer and use it in GitHub Desktop.
Save amazedkoumei/4361091 to your computer and use it in GitHub Desktop.
# 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