Class: RubygemsHerald::Spider
- Inherits:
-
Object
- Object
- RubygemsHerald::Spider
- Defined in:
- lib/rubygems_herald/spider.rb
Instance Attribute Summary collapse
-
#gem ⇒ Object
Returns the value of attribute gem.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #body ⇒ Object
- #calculate_expiration ⇒ Object
- #data ⇒ Object
-
#initialize(name) ⇒ Spider
constructor
A new instance of Spider.
- #url ⇒ Object
Constructor Details
#initialize(name) ⇒ Spider
Returns a new instance of Spider.
5 6 7 |
# File 'lib/rubygems_herald/spider.rb', line 5 def initialize(name) self.name = name end |
Instance Attribute Details
#gem ⇒ Object
Returns the value of attribute gem.
3 4 5 |
# File 'lib/rubygems_herald/spider.rb', line 3 def gem @gem end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/rubygems_herald/spider.rb', line 3 def name @name end |
Instance Method Details
#body ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rubygems_herald/spider.rb', line 13 def body require 'net/http' uri = URI.parse(url) req = Net::HTTP::Get.new(uri.path) res = Net::HTTP.start(uri.host, uri.port) {|http| http.request(req) } res.body end |
#calculate_expiration ⇒ Object
30 31 32 |
# File 'lib/rubygems_herald/spider.rb', line 30 def calculate_expiration Time.now + RubygemsHerald.configuration.refresh_interval end |
#data ⇒ Object
24 25 26 27 28 |
# File 'lib/rubygems_herald/spider.rb', line 24 def data raw = body.parse_json raw['expires_at'] = calculate_expiration raw end |
#url ⇒ Object
9 10 11 |
# File 'lib/rubygems_herald/spider.rb', line 9 def url 'http://www.rubygems.org/api/v1/gems/' + name + '.json' end |