Class: RubyGems
- Inherits:
-
Object
- Object
- RubyGems
- Defined in:
- lib/gemterms/ruby_gems.rb
Instance Attribute Summary collapse
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #data(name) ⇒ Object
-
#get(path, data = {}, content_type = 'application/x-www-form-urlencoded') ⇒ Object
May raise SourceUnavailableError if the source can’t be accessed.
-
#initialize(uri) ⇒ RubyGems
constructor
A new instance of RubyGems.
-
#versions(name) ⇒ Hash
Version data for the given named gem.
Constructor Details
#initialize(uri) ⇒ RubyGems
Returns a new instance of RubyGems.
13 14 15 16 |
# File 'lib/gemterms/ruby_gems.rb', line 13 def initialize(uri) @connection = nil @uri = uri.kind_of?(URI::Generic) ? uri : URI(uri.to_s) end |
Instance Attribute Details
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
7 8 9 |
# File 'lib/gemterms/ruby_gems.rb', line 7 def uri @uri end |
Instance Method Details
#data(name) ⇒ Object
9 10 11 |
# File 'lib/gemterms/ruby_gems.rb', line 9 def data(name) YAML.load(self.get("/api/v1/gems/#{name}.yaml")) end |
#get(path, data = {}, content_type = 'application/x-www-form-urlencoded') ⇒ Object
May raise SourceUnavailableError if the source can’t be accessed
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/gemterms/ruby_gems.rb', line 19 def get(path, data={}, content_type='application/x-www-form-urlencoded') begin request = Net::HTTP::Get.new(path) request.add_field 'Connection', 'keep-alive' request.add_field 'Keep-Alive', '30' request.add_field 'User-Agent', 'github.com/jonathannen/gemfresh' response = connection.request request response.body rescue StandardError => se # For now we assume this is an unavailable repo raise SourceUnavailableError.new(se.) end end |
#versions(name) ⇒ Hash
Returns version data for the given named gem.
36 37 38 |
# File 'lib/gemterms/ruby_gems.rb', line 36 def versions(name) YAML.load(self.get("/api/v1/versions/#{name}.yaml")) end |