class RubyGems

Attributes

uri[R]

Public Class Methods

new(uri) click to toggle source
# 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

Public Instance Methods

data(name) click to toggle source
# 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') click to toggle source

May raise SourceUnavailableError if the source can’t be accessed

# 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.message)
  end
end
versions(name) click to toggle source

@param [ String ] name The name of the gem to access.

@return [ Hash ] version data for the given named gem

# File lib/gemterms/ruby_gems.rb, line 36
def versions(name)
  YAML.load(self.get("/api/v1/versions/#{name}.yaml"))
end

Private Instance Methods

connection() click to toggle source

A persistent connection

# File lib/gemterms/ruby_gems.rb, line 42
def connection
  return @connection unless @connection.nil?
  @connection = Net::HTTP.new self.uri.host, self.uri.port
  @connection.use_ssl = (uri.scheme == 'https')
  @connection.start 
  @connection
end