Skip to content

Instantly share code, notes, and snippets.

@amazedkoumei
Created December 22, 2012 21:03
Show Gist options
  • Save amazedkoumei/4361120 to your computer and use it in GitHub Desktop.
Save amazedkoumei/4361120 to your computer and use it in GitHub Desktop.
ブログ貼付用
# 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