dirs (owner)

Revisions

gist: 153240 Download_button fork
public
Public Clone URL: git://gist.github.com/153240.git
Embed All Files: show embed
oops.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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>