Class: Gems::Client

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

Instance Method Summary collapse

Methods included from Request

#delete, #get, #post, #put

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

#add_owner(gem_name, owner) ⇒ String

Add an owner to a RubyGem you own, giving that user permission to manage it

Examples:

Gems.add_owner 'gemcutter', '[email protected]'

Parameters:

  • gem_name (String)

    The name of a gem.

  • owner (String)

    The email address of the user you want to add.

Returns:

  • (String)

Requires Authentication:

  • true


184
185
186
# File 'lib/gems/client.rb', line 184

def add_owner(gem_name, owner)
  post("/api/v1/gems/#{gem_name}/owners", :email => owner)
end

#add_web_hook(gem_name, url) ⇒ String

Create a webhook

Examples:

Gems.add_web_hook 'rails', 'http://example.com'

Parameters:

  • gem_name (String)

    The name of a gem. Specify "*" to add the hook to all gems.

  • url (String)

    The URL of the web hook.

Returns:

  • (String)

Requires Authentication:

  • true


219
220
221
# File 'lib/gems/client.rb', line 219

def add_web_hook(gem_name, url)
  post('/api/v1/web_hooks', :gem_name => gem_name, :url => url)
end

#api_keyString

Retrieve your API key using HTTP basic auth

Examples:

Gems.configure do |config|
  config.username = '[email protected]'
  config.password = 'schwwwwing'
end
Gems.api_key

Returns:

  • (String)

Requires Authentication:

  • true


281
282
283
# File 'lib/gems/client.rb', line 281

def api_key
  get('/api/v1/api_key')
end

#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)

Requires Authentication:

  • false


292
293
294
295
# File 'lib/gems/client.rb', line 292

def dependencies(*gems)
  response = get('/api/v1/dependencies', :gems => gems.join(','))
  Marshal.load(response)
end

#downloads(gem_name, gem_version = nil, from = nil, to = Date.today) ⇒ Hash

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

Examples:

Gems.downloads 'coulda', '0.6.3', Date.today - 30, Date.today

Parameters:

  • gem_name (String)

    The name of a gem.

  • gem_version (String) (defaults to: nil)

    The version of a gem.

  • from (Date) (defaults to: nil)

    Search start date.

  • to (Date) (defaults to: Date.today)

    Search end date.

Returns:

  • (Hash)

Requires Authentication:

  • false


158
159
160
161
162
# File 'lib/gems/client.rb', line 158

def downloads(gem_name, gem_version = nil, from = nil, to = Date.today)
  gem_version ||= info(gem_name)['version']
  response = from ? get("/api/v1/versions/#{gem_name}-#{gem_version}/downloads/search.json", :from => from.to_s, :to => to.to_s) : get("/api/v1/versions/#{gem_name}-#{gem_version}/downloads.json")
  JSON.parse(response)
end

#fire_web_hook(gem_name, url) ⇒ String

Test fire a webhook

Examples:

Gems.fire_web_hook 'rails', 'http://example.com'

Parameters:

  • gem_name (String)

    The name of a gem. Specify "*" to fire the hook for all gems.

  • url (String)

    The URL of the web hook.

Returns:

  • (String)

Requires Authentication:

  • true


243
244
245
# File 'lib/gems/client.rb', line 243

def fire_web_hook(gem_name, url)
  post('/api/v1/web_hooks/fire', :gem_name => gem_name, :url => url)
end

#gems(user_handle = nil) ⇒ Array

List all gems that you own

Examples:

Gems.gems

Parameters:

  • user_handle (String) (defaults to: nil)

    The handle of a user.

Returns:

  • (Array)

Requires Authentication:

  • true


53
54
55
56
# File 'lib/gems/client.rb', line 53

def gems(user_handle = nil)
  response = user_handle ? get("/api/v1/owners/#{user_handle}/gems.json") : get('/api/v1/gems.json')
  JSON.parse(response)
end

#info(gem_name) ⇒ Hash

Returns some basic information about the given gem

Examples:

Gems.info 'rails'

Parameters:

  • gem_name (String)

    The name of a gem.

Returns:

  • (Hash)

Requires Authentication:

  • false


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

def info(gem_name)
  response = get("/api/v1/gems/#{gem_name}.json")
  JSON.parse(response)
rescue JSON::ParserError
  {}
end

#just_updated(options = {}) ⇒ Array

Returns the 50 most recently updated gems

Examples:

Gem.just_updated

Parameters:

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

    A customizable set of options.

Returns:

  • (Array)

Requires Authentication:

  • false


266
267
268
269
# File 'lib/gems/client.rb', line 266

def just_updated(options = {})
  response = get('/api/v1/activity/just_updated.json', options)
  JSON.parse(response)
end

#latest(options = {}) ⇒ Array

Returns the 50 gems most recently added to RubyGems.org (for the first time)

Examples:

Gem.latest

Parameters:

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

    A customizable set of options.

Returns:

  • (Array)

Requires Authentication:

  • false


254
255
256
257
# File 'lib/gems/client.rb', line 254

def latest(options = {})
  response = get('/api/v1/activity/latest.json', options)
  JSON.parse(response)
end

#latest_version(gem_name) ⇒ Hash

Returns an hash of gem latest version

Examples:

Gems.latest_version 'coulda'

Parameters:

  • gem_name (String)

    The name of a gem.

Returns:

  • (Hash)

Requires Authentication:

  • false


119
120
121
122
# File 'lib/gems/client.rb', line 119

def latest_version(gem_name)
  response = get("/api/v1/versions/#{gem_name}/latest.json")
  JSON.parse(response)
end

#most_downloadedArray

Returns an array containing the top 50 downloaded gem versions of all time

Examples:

Gems.most_downloaded

Returns:

  • (Array)

Requires Authentication:

  • false


143
144
145
146
# File 'lib/gems/client.rb', line 143

def most_downloaded
  response = get('/api/v1/downloads/all.json')
  JSON.parse(response)['gems']
end

#owners(gem_name) ⇒ Array

View all owners of a gem that you own

Examples:

Gems.owners 'gemcutter'

Parameters:

  • gem_name (String)

    The name of a gem.

Returns:

  • (Array)

Requires Authentication:

  • true


171
172
173
174
# File 'lib/gems/client.rb', line 171

def owners(gem_name)
  response = get("/api/v1/gems/#{gem_name}/owners.json")
  JSON.parse(response)
end

#push(gem, host = Configuration::DEFAULT_HOST) ⇒ String

Submit a gem to RubyGems.org or another host

Examples:

Gems.push File.new 'pkg/gemcutter-0.2.1.gem'

Parameters:

  • gem (File)

    A built gem.

  • host (String) (defaults to: Configuration::DEFAULT_HOST)

    A RubyGems compatible host to use.

Returns:

  • (String)

Requires Authentication:

  • true


66
67
68
# File 'lib/gems/client.rb', line 66

def push(gem, host = Configuration::DEFAULT_HOST)
  post('/api/v1/gems', gem.read, 'application/octet-stream', host)
end

#remove_owner(gem_name, owner) ⇒ String

Remove a user's permission to manage a RubyGem you own

Examples:

Gems.remove_owner 'gemcutter', '[email protected]'

Parameters:

  • gem_name (String)

    The name of a gem.

  • owner (String)

    The email address of the user you want to remove.

Returns:

  • (String)

Requires Authentication:

  • true


196
197
198
# File 'lib/gems/client.rb', line 196

def remove_owner(gem_name, owner)
  delete("/api/v1/gems/#{gem_name}/owners", :email => owner)
end

#remove_web_hook(gem_name, url) ⇒ String

Remove a webhook

Examples:

Gems.remove_web_hook 'rails', 'http://example.com'

Parameters:

  • gem_name (String)

    The name of a gem. Specify "*" to remove the hook from all gems.

  • url (String)

    The URL of the web hook.

Returns:

  • (String)

Requires Authentication:

  • true


231
232
233
# File 'lib/gems/client.rb', line 231

def remove_web_hook(gem_name, url)
  delete('/api/v1/web_hooks/remove', :gem_name => gem_name, :url => url)
end

#reverse_dependencies(gem_name, options = {}) ⇒ Array

Returns an array of all the reverse dependencies to the given gem.

Examples:

Gems.reverse_dependencies 'money'

Parameters:

  • gem_name (String)

    The name of a gem

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

    A customizable set of options.

Returns:

  • (Array)

Requires Authentication:

  • false


305
306
307
308
# File 'lib/gems/client.rb', line 305

def reverse_dependencies(gem_name, options = {})
  response = get("/api/v1/gems/#{gem_name}/reverse_dependencies.json", options)
  JSON.parse(response)
end

#search(query, options = {}) ⇒ Array<Hash>

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.

Options Hash (options):

  • :page (Integer)

Returns:

  • (Array<Hash>)

Requires Authentication:

  • false


41
42
43
44
# File 'lib/gems/client.rb', line 41

def search(query, options = {})
  response = get('/api/v1/search.json', options.merge(:query => query))
  JSON.parse(response)
end

#total_downloads(gem_name = nil, gem_version = nil) ⇒ Hash

Returns the total number of downloads for a particular gem

Examples:

Gems.total_downloads 'rails_admin', '0.0.1'

Parameters:

  • gem_name (String) (defaults to: nil)

    The name of a gem.

  • gem_version (String) (defaults to: nil)

    The version of a gem.

Returns:

  • (Hash)

Requires Authentication:

  • false


132
133
134
135
# File 'lib/gems/client.rb', line 132

def total_downloads(gem_name = nil, gem_version = nil)
  response = gem_name ? get("/api/v1/downloads/#{gem_name}-#{gem_version || info(gem_name)['version']}.json") : get('/api/v1/downloads.json')
  JSON.parse(response, :symbolize_names => true)
end

#unyank(gem_name, gem_version = nil, options = {}) ⇒ String

Update a previously yanked gem back into RubyGems.org's index

Examples:

Gems.unyank "gemcutter", "0.2.1", {:platform => "x86-darwin-10"}

Parameters:

  • gem_name (String)

    The name of a gem.

  • gem_version (String) (defaults to: nil)

    The version of a gem.

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

    A customizable set of options.

Options Hash (options):

  • :platform (String)

Returns:

  • (String)

Requires Authentication:

  • true


95
96
97
98
# File 'lib/gems/client.rb', line 95

def unyank(gem_name, gem_version = nil, options = {})
  gem_version ||= info(gem_name)['version']
  put('/api/v1/gems/unyank', options.merge(:gem_name => gem_name, :version => gem_version))
end

#versions(gem_name) ⇒ Hash

Returns an array of gem version details

Examples:

Gems.versions 'coulda'

Parameters:

  • gem_name (String)

    The name of a gem.

Returns:

  • (Hash)

Requires Authentication:

  • false


107
108
109
110
# File 'lib/gems/client.rb', line 107

def versions(gem_name)
  response = get("/api/v1/versions/#{gem_name}.json")
  JSON.parse(response)
end

#web_hooksHash

List the webhooks registered under your account

Examples:

Gems.web_hooks

Returns:

  • (Hash)

Requires Authentication:

  • true


206
207
208
209
# File 'lib/gems/client.rb', line 206

def web_hooks
  response = get('/api/v1/web_hooks.json')
  JSON.parse(response)
end

#yank(gem_name, gem_version = nil, options = {}) ⇒ String

Remove a gem from RubyGems.org's index

Examples:

Gems.yank "gemcutter", "0.2.1", {:platform => "x86-darwin-10"}

Parameters:

  • gem_name (String)

    The name of a gem.

  • gem_version (String) (defaults to: nil)

    The version of a gem.

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

    A customizable set of options.

Options Hash (options):

  • :platform (String)

Returns:

  • (String)

Requires Authentication:

  • true


80
81
82
83
# File 'lib/gems/client.rb', line 80

def yank(gem_name, gem_version = nil, options = {})
  gem_version ||= info(gem_name)['version']
  delete('/api/v1/gems/yank', options.merge(:gem_name => gem_name, :version => gem_version))
end