Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
# 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