Created
July 23, 2009 17:04
-
-
Save dirceu-jr/153240 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
require 'rubygems' | |
require 'typhoeus' | |
require 'json' | |
class Migreme | |
include Typhoeus | |
remote_defaults :on_success => lambda {|response| response.body}, | |
:on_failure => lambda {|response| puts "error code: #{response.code}"}, | |
:base_uri => "http://migre.me" | |
define_remote_method :add, :path => '/api.xml?url=http://:urlid' | |
end | |
# here's and example of memoization | |
migreme_api = [] | |
100.times do |i| | |
migreme_api << Migreme.add(:urlid => i) | |
end | |
# this next part will actually make the call. However, it only makes one | |
# http request and parses the response once. The rest are memoized. | |
migreme_api.each {|s| puts s} | |
# <item> | |
# <title>XML Migre.me</title> | |
# <error>1</error> | |
# <errormessage>Limite de 30 URLs por hora excedido. Por favor, aguarde alguns minutos</errormessage> | |
# <created_at>Thu, 23 Jul 2009 14:02:03 -0300</created_at> | |
# <source>api</source> | |
# <date>2009-07-23 14:02:03</date> | |
# <id></id> | |
# <url>http://99</url> | |
# <migre>http://migre.me/</migre> | |
# <category>free</category> | |
# </item> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment