gems 0.0.8 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +24 -26
- data/lib/gems/client.rb +30 -1
- data/lib/gems/configuration.rb +5 -8
- data/lib/gems/request.rb +5 -1
- data/lib/gems/version.rb +1 -1
- data/spec/fixtures/unyank +1 -0
- data/spec/fixtures/yank +1 -0
- data/spec/gems/client_spec.rb +88 -0
- data/spec/helper.rb +8 -0
- metadata +6 -2
data/README.md
CHANGED
@@ -19,72 +19,70 @@ Usage Examples
|
|
19
19
|
require 'rubygems'
|
20
20
|
require 'gems'
|
21
21
|
|
22
|
-
# Returns some basic information about
|
22
|
+
# Returns some basic information about rails.
|
23
23
|
puts Gems.info 'rails'
|
24
24
|
|
25
|
-
# Returns an array of active gems that match the query
|
25
|
+
# Returns an array of active gems that match the query.
|
26
26
|
puts Gems.search 'cucumber'
|
27
27
|
|
28
|
-
# Returns an array of
|
28
|
+
# Returns an array of version details for coulda.
|
29
29
|
puts Gems.versions 'coulda'
|
30
30
|
|
31
|
-
# Returns the number of downloads by day for a particular gem version
|
32
|
-
#
|
31
|
+
# Returns the number of downloads by day for a particular gem version for the past 90 days.
|
32
|
+
# Defaults to the latest version if no version is specified.
|
33
33
|
puts Gems.downloads 'coulda', '0.6.3'
|
34
34
|
|
35
|
-
# Returns the number of downloads by day for a particular gem version
|
36
|
-
# for the past year
|
35
|
+
# Returns the number of downloads by day for a particular gem version for the past year.
|
37
36
|
puts Gems.downloads 'coulda', '0.6.3', Date.today - 365, Date.today
|
38
37
|
|
39
|
-
# Returns an array of gem dependency details for all versions of given gems
|
38
|
+
# Returns an array of gem dependency details for all versions of all the given gems.
|
40
39
|
puts Gems.dependencies ['rails', 'thor']
|
41
40
|
|
42
|
-
# Retrieve your API key using HTTP basic authentication
|
41
|
+
# Retrieve your API key using HTTP basic authentication.
|
43
42
|
Gems.configure do |config|
|
44
43
|
config.username = 'nick@gemcutter.org'
|
45
44
|
config.password = 'schwwwwing'
|
46
45
|
end
|
47
46
|
Gems.api_key
|
48
47
|
|
49
|
-
#
|
50
|
-
#
|
51
|
-
# You
|
48
|
+
# The following methods require authentication.
|
49
|
+
# By default, we load your API key from ~/.gem/credentails
|
50
|
+
# You can override this default by specifying a custom API key.
|
52
51
|
Gems.configure do |config|
|
53
52
|
config.key '701243f217cdf23b1370c7b66b65ca97'
|
54
53
|
end
|
55
54
|
|
56
|
-
# List all gems that you own
|
55
|
+
# List all gems that you own.
|
57
56
|
puts Gems.gems
|
58
57
|
|
59
|
-
# View all owners of a gem that you own
|
58
|
+
# View all owners of a gem that you own.
|
60
59
|
puts Gems.owners 'gemcutter'
|
61
60
|
|
62
|
-
# Add an owner to a RubyGem you own, giving that user permission to manage it
|
61
|
+
# Add an owner to a RubyGem you own, giving that user permission to manage it.
|
63
62
|
Gems.add_owner 'josh@technicalpickles.com', 'gemcutter'
|
64
63
|
|
65
|
-
# Remove a user's permission to manage a RubyGem you own
|
64
|
+
# Remove a user's permission to manage a RubyGem you own.
|
66
65
|
Gems.remove_owner 'josh@technicalpickles.com', 'gemcutter'
|
67
66
|
|
68
|
-
# List the webhooks registered under your account
|
67
|
+
# List the webhooks registered under your account.
|
69
68
|
puts Gems.web_hooks
|
70
69
|
|
71
|
-
# Add a webhook
|
70
|
+
# Add a webhook.
|
72
71
|
Gems.add_web_hook 'rails', 'http://example.com'
|
73
72
|
|
74
|
-
# Remove a webhook
|
73
|
+
# Remove a webhook.
|
75
74
|
Gems.remove_web_hook 'rails', 'http://example.com'
|
76
75
|
|
77
76
|
# Test fire a webhook.
|
78
77
|
Gems.fire_web_hook 'rails', 'http://example.com'
|
79
78
|
|
80
|
-
#
|
81
|
-
|
79
|
+
# Remove a gem from RubyGems.org's index.
|
80
|
+
# Defaults to the latest version if no version is specified.
|
81
|
+
Gems.yank 'bills', '0.0.1'
|
82
82
|
|
83
|
-
#
|
84
|
-
|
85
|
-
|
86
|
-
# Update a previously yanked gem back into RubyGems.org's index
|
87
|
-
Gems.unyank 'bills', '0.0.1', :platform => 'x86-darwin-10' [TODO]
|
83
|
+
# Update a previously yanked gem back into RubyGems.org's index.
|
84
|
+
# Defaults to the latest version if no version is specified.
|
85
|
+
Gems.unyank 'bills', '0.0.1'
|
88
86
|
|
89
87
|
Contributing
|
90
88
|
------------
|
data/lib/gems/client.rb
CHANGED
@@ -57,7 +57,8 @@ module Gems
|
|
57
57
|
# @return [Hashie::Mash]
|
58
58
|
# @example
|
59
59
|
# Gems.downloads 'coulda', '0.6.3', Date.today - 30, Date.today
|
60
|
-
def downloads(gem_name, gem_version, from=nil, to=Date.today)
|
60
|
+
def downloads(gem_name, gem_version=nil, from=nil, to=Date.today)
|
61
|
+
gem_version ||= info(gem_name).version
|
61
62
|
if from
|
62
63
|
get("/api/v1/versions/#{gem_name}-#{gem_version}/downloads/search", {:from => from.to_s, :to => to.to_s}, :json)
|
63
64
|
else
|
@@ -171,5 +172,33 @@ module Gems
|
|
171
172
|
def fire_web_hook(gem_name, url)
|
172
173
|
post("/api/v1/web_hooks/fire", {:gem_name => gem_name, :url => url}, :raw)
|
173
174
|
end
|
175
|
+
|
176
|
+
# Remove a gem from RubyGems.org's index
|
177
|
+
#
|
178
|
+
# @param gem_name [String] The name of a gem.
|
179
|
+
# @param gem_version [String] The version of a gem.
|
180
|
+
# @param options [Hash] A customizable set of options.
|
181
|
+
# @option options [String] :platform
|
182
|
+
# @return [String]
|
183
|
+
# @example
|
184
|
+
# Gems.yank("gemcutter", "0.2.1", {:platform => "x86-darwin-10"})
|
185
|
+
def yank(gem_name, gem_version=nil, options={})
|
186
|
+
gem_version ||= info(gem_name).version
|
187
|
+
delete("/api/v1/gems/yank", options.merge(:gem_name => gem_name, :version => gem_version), :raw)
|
188
|
+
end
|
189
|
+
|
190
|
+
# Update a previously yanked gem back into RubyGems.org's index
|
191
|
+
#
|
192
|
+
# @param gem_name [String] The name of a gem.
|
193
|
+
# @param gem_version [String] The version of a gem.
|
194
|
+
# @param options [Hash] A customizable set of options.
|
195
|
+
# @option options [String] :platform
|
196
|
+
# @return [String]
|
197
|
+
# @example
|
198
|
+
# Gems.unyank("gemcutter", "0.2.1", {:platform => "x86-darwin-10"})
|
199
|
+
def unyank(gem_name, gem_version=nil, options={})
|
200
|
+
gem_version ||= info(gem_name).version
|
201
|
+
put("/api/v1/gems/unyank", options.merge(:gem_name => gem_name, :version => gem_version), :raw)
|
202
|
+
end
|
174
203
|
end
|
175
204
|
end
|
data/lib/gems/configuration.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'gems/version'
|
2
|
+
require 'rubygems'
|
2
3
|
require 'yaml'
|
3
4
|
|
4
5
|
module Gems
|
@@ -12,19 +13,15 @@ module Gems
|
|
12
13
|
:username,
|
13
14
|
]
|
14
15
|
|
15
|
-
#
|
16
|
+
# Set the default response format appended to the path
|
16
17
|
#
|
17
18
|
# @note JSON is preferred over XML because it is more concise and faster to parse.
|
18
19
|
DEFAULT_FORMAT = :json
|
19
20
|
|
20
|
-
#
|
21
|
-
DEFAULT_KEY =
|
22
|
-
YAML.load(File.read(File.expand_path("~/.gem/credentials")))[:rubygems_api_key]
|
23
|
-
rescue Errno::ENOENT
|
24
|
-
nil
|
25
|
-
end
|
21
|
+
# Set the default credentials
|
22
|
+
DEFAULT_KEY = Gem.configuration.rubygems_api_key
|
26
23
|
|
27
|
-
#
|
24
|
+
# Set the default value sent in the 'User-Agent' header
|
28
25
|
DEFAULT_USER_AGENT = "Gems #{Gems::VERSION}".freeze
|
29
26
|
|
30
27
|
attr_accessor *VALID_OPTIONS_KEYS
|
data/lib/gems/request.rb
CHANGED
@@ -12,6 +12,10 @@ module Gems
|
|
12
12
|
request(:post, path, options, format)
|
13
13
|
end
|
14
14
|
|
15
|
+
def put(path, options={}, format=format)
|
16
|
+
request(:put, path, options, format)
|
17
|
+
end
|
18
|
+
|
15
19
|
private
|
16
20
|
|
17
21
|
def request(method, path, options, format)
|
@@ -19,7 +23,7 @@ module Gems
|
|
19
23
|
case method
|
20
24
|
when :delete, :get
|
21
25
|
request.url(formatted_path(path, format), options)
|
22
|
-
when :post
|
26
|
+
when :post, :put
|
23
27
|
request.path = formatted_path(path, format)
|
24
28
|
request.body = options unless options.empty?
|
25
29
|
end
|
data/lib/gems/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
Successfully unyanked gem: gems (0.0.8)
|
data/spec/fixtures/yank
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Successfully yanked gem: gems (0.0.8)
|
data/spec/gems/client_spec.rb
CHANGED
@@ -68,6 +68,22 @@ describe Gems::Client do
|
|
68
68
|
end
|
69
69
|
|
70
70
|
describe ".downloads" do
|
71
|
+
context "with no dates or version specified" do
|
72
|
+
before do
|
73
|
+
stub_get("/api/v1/gems/coulda.json").
|
74
|
+
to_return(:body => fixture("rails.json"))
|
75
|
+
stub_get("/api/v1/versions/coulda-3.0.9/downloads.json").
|
76
|
+
to_return(:body => fixture("downloads.json"))
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should return the number of downloads by day for a particular gem version" do
|
80
|
+
downloads = Gems.downloads 'coulda'
|
81
|
+
a_get("/api/v1/versions/coulda-3.0.9/downloads.json").
|
82
|
+
should have_been_made
|
83
|
+
downloads["2011-06-22"].should == 8
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
71
87
|
context "with no dates specified" do
|
72
88
|
before do
|
73
89
|
stub_get("/api/v1/versions/coulda-0.6.3/downloads.json").
|
@@ -276,4 +292,76 @@ describe Gems::Client do
|
|
276
292
|
fire_web_hook.should == "Successfully deployed webhook for gemcutter to http://example.com"
|
277
293
|
end
|
278
294
|
end
|
295
|
+
|
296
|
+
describe ".yank" do
|
297
|
+
context "with no version specified" do
|
298
|
+
before do
|
299
|
+
stub_get("/api/v1/gems/gems.json").
|
300
|
+
to_return(:body => fixture("rails.json"))
|
301
|
+
stub_delete("/api/v1/gems/yank").
|
302
|
+
with(:query => {:gem_name => "gems", :version => "3.0.9"}).
|
303
|
+
to_return(:body => fixture("yank"))
|
304
|
+
end
|
305
|
+
|
306
|
+
it "should remove a gem from RubyGems.org's index" do
|
307
|
+
yank = Gems.yank("gems")
|
308
|
+
a_delete("/api/v1/gems/yank").
|
309
|
+
with(:query => {:gem_name => "gems", :version => "3.0.9"}).
|
310
|
+
should have_been_made
|
311
|
+
yank.should == "Successfully yanked gem: gems (0.0.8)"
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
context "with a version specified" do
|
316
|
+
before do
|
317
|
+
stub_delete("/api/v1/gems/yank").
|
318
|
+
with(:query => {:gem_name => "gems", :version => "0.0.8"}).
|
319
|
+
to_return(:body => fixture("yank"))
|
320
|
+
end
|
321
|
+
|
322
|
+
it "should remove a gem from RubyGems.org's index" do
|
323
|
+
yank = Gems.yank("gems", "0.0.8")
|
324
|
+
a_delete("/api/v1/gems/yank").
|
325
|
+
with(:query => {:gem_name => "gems", :version => "0.0.8"}).
|
326
|
+
should have_been_made
|
327
|
+
yank.should == "Successfully yanked gem: gems (0.0.8)"
|
328
|
+
end
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
332
|
+
describe ".unyank" do
|
333
|
+
context "with no version specified" do
|
334
|
+
before do
|
335
|
+
stub_get("/api/v1/gems/gems.json").
|
336
|
+
to_return(:body => fixture("rails.json"))
|
337
|
+
stub_put("/api/v1/gems/unyank").
|
338
|
+
with(:body => {:gem_name => "gems", :version => "3.0.9"}).
|
339
|
+
to_return(:body => fixture("unyank"))
|
340
|
+
end
|
341
|
+
|
342
|
+
it "should update a previously yanked gem back into RubyGems.org's index" do
|
343
|
+
unyank = Gems.unyank("gems")
|
344
|
+
a_put("/api/v1/gems/unyank").
|
345
|
+
with(:body => {:gem_name => "gems", :version => "3.0.9"}).
|
346
|
+
should have_been_made
|
347
|
+
unyank.should == "Successfully unyanked gem: gems (0.0.8)"
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|
351
|
+
context "with a version specified" do
|
352
|
+
before do
|
353
|
+
stub_put("/api/v1/gems/unyank").
|
354
|
+
with(:body => {:gem_name => "gems", :version => "0.0.8"}).
|
355
|
+
to_return(:body => fixture("unyank"))
|
356
|
+
end
|
357
|
+
|
358
|
+
it "should update a previously yanked gem back into RubyGems.org's index" do
|
359
|
+
unyank = Gems.unyank("gems", "0.0.8")
|
360
|
+
a_put("/api/v1/gems/unyank").
|
361
|
+
with(:body => {:gem_name => "gems", :version => "0.0.8"}).
|
362
|
+
should have_been_made
|
363
|
+
unyank.should == "Successfully unyanked gem: gems (0.0.8)"
|
364
|
+
end
|
365
|
+
end
|
366
|
+
end
|
279
367
|
end
|
data/spec/helper.rb
CHANGED
@@ -18,6 +18,10 @@ def a_post(path)
|
|
18
18
|
a_request(:post, 'https://nick%40gemcutter.org:schwwwwing@rubygems.org' + path)
|
19
19
|
end
|
20
20
|
|
21
|
+
def a_put(path)
|
22
|
+
a_request(:put, 'https://nick%40gemcutter.org:schwwwwing@rubygems.org' + path)
|
23
|
+
end
|
24
|
+
|
21
25
|
def stub_delete(path)
|
22
26
|
stub_request(:delete, 'https://nick%40gemcutter.org:schwwwwing@rubygems.org' + path)
|
23
27
|
end
|
@@ -30,6 +34,10 @@ def stub_post(path)
|
|
30
34
|
stub_request(:post, 'https://nick%40gemcutter.org:schwwwwing@rubygems.org' + path)
|
31
35
|
end
|
32
36
|
|
37
|
+
def stub_put(path)
|
38
|
+
stub_request(:put, 'https://nick%40gemcutter.org:schwwwwing@rubygems.org' + path)
|
39
|
+
end
|
40
|
+
|
33
41
|
def fixture_path
|
34
42
|
File.expand_path('../fixtures', __FILE__)
|
35
43
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: gems
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0
|
5
|
+
version: 0.1.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Erik Michaels-Ober
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-07-
|
13
|
+
date: 2011-07-02 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -188,7 +188,9 @@ files:
|
|
188
188
|
- spec/fixtures/remove_web_hook
|
189
189
|
- spec/fixtures/search.json
|
190
190
|
- spec/fixtures/search.xml
|
191
|
+
- spec/fixtures/unyank
|
191
192
|
- spec/fixtures/web_hooks.json
|
193
|
+
- spec/fixtures/yank
|
192
194
|
- spec/gems/client_spec.rb
|
193
195
|
- spec/gems_spec.rb
|
194
196
|
- spec/helper.rb
|
@@ -238,7 +240,9 @@ test_files:
|
|
238
240
|
- spec/fixtures/remove_web_hook
|
239
241
|
- spec/fixtures/search.json
|
240
242
|
- spec/fixtures/search.xml
|
243
|
+
- spec/fixtures/unyank
|
241
244
|
- spec/fixtures/web_hooks.json
|
245
|
+
- spec/fixtures/yank
|
242
246
|
- spec/gems/client_spec.rb
|
243
247
|
- spec/gems_spec.rb
|
244
248
|
- spec/helper.rb
|