Class: Gems::Client

Inherits:
Object
  • Object
show all
Includes:
Connection, Request
Defined in:
lib/gems/client.rb

Instance Method Summary collapse

Methods included from Request

#get

Methods included from Connection

#connection

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



11
12
13
14
15
16
# File 'lib/gems/client.rb', line 11

def initialize(options={})
  options = Gems.options.merge(options)
  Configuration::VALID_OPTIONS_KEYS.each do |key|
    send("#{key}=", options[key])
  end
end

Instance Method Details

#dependencies(*gems) ⇒ Array

Returns an array of hashes for all versions of given gems

Examples:

Gems.dependencies 'rails', 'thor'

Parameters:

  • gems (Array)

    A list of gem names

Returns:

  • (Array)


71
72
73
# File 'lib/gems/client.rb', line 71

def dependencies(*gems)
  get("/api/v1/dependencies", {:gems => gems.join(',')}, :marshal)
end

#downloads(gem, version, options = {}) ⇒ Hashie::Mash

Returns the number of downloads by day for a particular gem version

Examples:

Gems.downloads 'coulda', '0.6.3'

Parameters:

  • gem (String)

    The name of a gem.

  • version (String)

    The version of a gem.

  • options (Hash) (defaults to: {})

    A customizable set of options.

Returns:

  • (Hashie::Mash)


61
62
63
# File 'lib/gems/client.rb', line 61

def downloads(gem, version, options={})
  get("/api/v1/versions/#{gem}-#{version}/downloads", options, :json)
end

#info(gem, options = {}) ⇒ Hashie::Mash

Returns some basic information about the given gem

Examples:

Gems.info 'rails'

Parameters:

  • gem (String)

    The name of a gem.

  • options (Hash) (defaults to: {})

    A customizable set of options.

Returns:

  • (Hashie::Mash)


25
26
27
28
# File 'lib/gems/client.rb', line 25

def info(gem, options={})
  response = get("/api/v1/gems/#{gem}", options)
  format.to_s.downcase == 'xml' ? response['rubygem'] : response
end

#search(query, options = {}) ⇒ Array<Hashie::Mash>

Returns an array of active gems that match the query

Examples:

Gems.search 'cucumber'

Parameters:

  • query (String)

    A term to search for.

  • options (Hash) (defaults to: {})

    A customizable set of options.

Returns:

  • (Array<Hashie::Mash>)


37
38
39
40
# File 'lib/gems/client.rb', line 37

def search(query, options={})
  response = get("/api/v1/search", options.merge(:query => query))
  format.to_s.downcase == 'xml' ? response['rubygems'] : response
end

#versions(gem, options = {}) ⇒ Hashie::Mash

Returns an array of gem version details

Examples:

Gems.versions 'coulda'

Parameters:

  • gem (String)

    The name of a gem.

  • options (Hash) (defaults to: {})

    A customizable set of options.

Returns:

  • (Hashie::Mash)


49
50
51
# File 'lib/gems/client.rb', line 49

def versions(gem, options={})
  get("/api/v1/versions/#{gem}", options, :json)
end