Class: RubygemsHerald::Spider

Inherits:
Object
  • Object
show all
Defined in:
lib/rubygems_herald/spider.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#gemObject

Returns the value of attribute gem.



3
4
5
# File 'lib/rubygems_herald/spider.rb', line 3

def gem
  @gem
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/rubygems_herald/spider.rb', line 3

def name
  @name
end

Instance Method Details

#bodyObject



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_expirationObject



30
31
32
# File 'lib/rubygems_herald/spider.rb', line 30

def calculate_expiration
  Time.now + RubygemsHerald.configuration.refresh_interval
end

#dataObject



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

#urlObject



9
10
11
# File 'lib/rubygems_herald/spider.rb', line 9

def url
  'http://www.rubygems.org/api/v1/gems/' + name + '.json'
end