Created
December 22, 2012 21:03
-
-
Save amazedkoumei/4361120 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
# method define | |
["Favorite", "Archive"].each do |name| | |
define_method("toggle#{name}") do |bookmark, &block| | |
key = name.downcase | |
value = bookmark[key] # boolean | |
# make parameter | |
if value | |
v = "0" | |
else | |
v = "1" | |
end | |
parameters = { | |
key => v | |
} | |
begin | |
update(bookmark[:id], parameters) do | |
@bookmarks.each do |b| | |
b[key] = !value if b[:id] == bookmark[:id] | |
end | |
block.call() unless block.nil? | |
end | |
rescue => e | |
block.call("#{e}") unless block.nil? | |
end | |
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() unless block.nil? | |
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