Class: Gems::V1::Client
- Inherits:
-
Object
- Object
- Gems::V1::Client
- Includes:
- Request
- Defined in:
- lib/gems/v1/client.rb
Instance Method Summary collapse
-
#add_owner(gem_name, owner) ⇒ String
Add an owner to a RubyGem you own, giving that user permission to manage it.
-
#add_web_hook(gem_name, url) ⇒ String
Create a webhook.
-
#api_key ⇒ String
Retrieve your API key using HTTP basic auth.
-
#dependencies(*gems) ⇒ Array
Returns an array of hashes for all versions of given gems.
-
#downloads(gem_name, gem_version = nil, from = nil, to = Date.today) ⇒ Hash
Returns the number of downloads by day for a particular gem version.
-
#fire_web_hook(gem_name, url) ⇒ String
Test fire a webhook.
-
#gems(user_handle = nil) ⇒ Array
List all gems that you own.
-
#info(gem_name) ⇒ Hash
Returns some basic information about the given gem.
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
-
#just_updated(options = {}) ⇒ Array
Returns the 50 most recently updated gems.
-
#latest(options = {}) ⇒ Array
Returns the 50 gems most recently added to RubyGems.org (for the first time).
-
#latest_version(gem_name) ⇒ Hash
Returns an hash of gem latest version.
-
#most_downloaded ⇒ Array
Returns an array containing the top 50 downloaded gem versions of all time.
-
#owners(gem_name) ⇒ Array
View all owners of a gem that you own.
-
#push(gem, host = Configuration::DEFAULT_HOST) ⇒ String
Submit a gem to RubyGems.org or another host.
-
#remove_owner(gem_name, owner) ⇒ String
Remove a user's permission to manage a RubyGem you own.
-
#remove_web_hook(gem_name, url) ⇒ String
Remove a webhook.
-
#reverse_dependencies(gem_name, options = {}) ⇒ Array
Returns an array of all the reverse dependencies to the given gem.
-
#search(query, options = {}) ⇒ Array<Hash>
Returns an array of active gems that match the query.
-
#total_downloads(gem_name = nil, gem_version = nil) ⇒ Hash
Returns the total number of downloads for a particular gem.
-
#unyank(gem_name, gem_version = nil, options = {}) ⇒ String
Update a previously yanked gem back into RubyGems.org's index.
-
#versions(gem_name) ⇒ Hash
Returns an array of gem version details.
-
#web_hooks ⇒ Hash
List the webhooks registered under your account.
-
#yank(gem_name, gem_version = nil, options = {}) ⇒ String
Remove a gem from RubyGems.org's index.
Methods included from Request
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 17 |
# File 'lib/gems/v1/client.rb', line 12 def initialize( = {}) = Gems..merge() Configuration::VALID_OPTIONS_KEYS.each do |key| send("#{key}=", [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
185 186 187 |
# File 'lib/gems/v1/client.rb', line 185 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
220 221 222 |
# File 'lib/gems/v1/client.rb', line 220 def add_web_hook(gem_name, url) post('/api/v1/web_hooks', :gem_name => gem_name, :url => url) end |
#api_key ⇒ String
Retrieve your API key using HTTP basic auth
282 283 284 |
# File 'lib/gems/v1/client.rb', line 282 def api_key get('/api/v1/api_key') end |
#dependencies(*gems) ⇒ Array
Returns an array of hashes for all versions of given gems
293 294 295 296 |
# File 'lib/gems/v1/client.rb', line 293 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
159 160 161 162 163 |
# File 'lib/gems/v1/client.rb', line 159 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
244 245 246 |
# File 'lib/gems/v1/client.rb', line 244 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
54 55 56 57 |
# File 'lib/gems/v1/client.rb', line 54 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
26 27 28 29 30 31 |
# File 'lib/gems/v1/client.rb', line 26 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
267 268 269 270 |
# File 'lib/gems/v1/client.rb', line 267 def just_updated( = {}) response = get('/api/v1/activity/just_updated.json', ) JSON.parse(response) end |
#latest(options = {}) ⇒ Array
Returns the 50 gems most recently added to RubyGems.org (for the first time)
255 256 257 258 |
# File 'lib/gems/v1/client.rb', line 255 def latest( = {}) response = get('/api/v1/activity/latest.json', ) JSON.parse(response) end |
#latest_version(gem_name) ⇒ Hash
Returns an hash of gem latest version
120 121 122 123 |
# File 'lib/gems/v1/client.rb', line 120 def latest_version(gem_name) response = get("/api/v1/versions/#{gem_name}/latest.json") JSON.parse(response) end |
#most_downloaded ⇒ Array
Returns an array containing the top 50 downloaded gem versions of all time
144 145 146 147 |
# File 'lib/gems/v1/client.rb', line 144 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
172 173 174 175 |
# File 'lib/gems/v1/client.rb', line 172 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
67 68 69 |
# File 'lib/gems/v1/client.rb', line 67 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
197 198 199 |
# File 'lib/gems/v1/client.rb', line 197 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
232 233 234 |
# File 'lib/gems/v1/client.rb', line 232 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.
306 307 308 309 |
# File 'lib/gems/v1/client.rb', line 306 def reverse_dependencies(gem_name, = {}) response = get("/api/v1/gems/#{gem_name}/reverse_dependencies.json", ) JSON.parse(response) end |
#search(query, options = {}) ⇒ Array<Hash>
Returns an array of active gems that match the query
42 43 44 45 |
# File 'lib/gems/v1/client.rb', line 42 def search(query, = {}) response = get('/api/v1/search.json', .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
133 134 135 136 |
# File 'lib/gems/v1/client.rb', line 133 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
96 97 98 99 |
# File 'lib/gems/v1/client.rb', line 96 def unyank(gem_name, gem_version = nil, = {}) gem_version ||= info(gem_name)['version'] put('/api/v1/gems/unyank', .merge(:gem_name => gem_name, :version => gem_version)) end |
#versions(gem_name) ⇒ Hash
Returns an array of gem version details
108 109 110 111 |
# File 'lib/gems/v1/client.rb', line 108 def versions(gem_name) response = get("/api/v1/versions/#{gem_name}.json") JSON.parse(response) end |
#web_hooks ⇒ Hash
List the webhooks registered under your account
207 208 209 210 |
# File 'lib/gems/v1/client.rb', line 207 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
81 82 83 84 |
# File 'lib/gems/v1/client.rb', line 81 def yank(gem_name, gem_version = nil, = {}) gem_version ||= info(gem_name)['version'] delete('/api/v1/gems/yank', .merge(:gem_name => gem_name, :version => gem_version)) end |