Skip to content

Instantly share code, notes, and snippets.

@dirceu-jr
Created July 23, 2009 17:04
Show Gist options
  • Save dirceu-jr/153240 to your computer and use it in GitHub Desktop.
Save dirceu-jr/153240 to your computer and use it in GitHub Desktop.
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