gems 0.0.5 → 0.0.6
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 +19 -15
- data/lib/gems/client.rb +35 -3
- data/lib/gems/configuration.rb +9 -1
- data/lib/gems/version.rb +1 -1
- data/spec/fixtures/web_hooks.json +1 -0
- data/spec/gems/client_spec.rb +70 -8
- metadata +4 -2
data/README.md
CHANGED
@@ -29,22 +29,26 @@ Usage Examples
|
|
29
29
|
puts Gems.versions 'coulda'
|
30
30
|
|
31
31
|
# Returns the number of downloads by day for a particular gem version
|
32
|
+
# for the past 90 days
|
32
33
|
puts Gems.downloads 'coulda', '0.6.3'
|
33
34
|
|
35
|
+
# Returns the number of downloads by day for a particular gem version
|
36
|
+
# for the past year
|
37
|
+
puts Gems.downloads 'coulda', '0.6.3', Date.today - 365, Date.today
|
38
|
+
|
34
39
|
# Returns an array of gem dependency details for all versions of given gems
|
35
40
|
puts Gems.dependencies ['rails', 'thor']
|
36
41
|
|
37
|
-
#
|
42
|
+
# Retrieve your API key using HTTP basic authentication
|
38
43
|
Gems.configure do |config|
|
39
|
-
config.format = :xml
|
40
44
|
config.username = 'nick@gemcutter.org'
|
41
45
|
config.password = 'schwwwwing'
|
42
46
|
end
|
43
|
-
|
44
|
-
# Retrieve your API key using HTTP basic auth
|
45
47
|
Gems.api_key
|
46
48
|
|
47
|
-
#
|
49
|
+
# You can also find your API key at https://rubygems.org/profile/edit
|
50
|
+
# We will attempt to load your API key from ~/.gem/credentails
|
51
|
+
# You may also specify a custom API key
|
48
52
|
Gems.configure do |config|
|
49
53
|
config.key '701243f217cdf23b1370c7b66b65ca97'
|
50
54
|
end
|
@@ -53,34 +57,34 @@ Usage Examples
|
|
53
57
|
puts Gems.gems
|
54
58
|
|
55
59
|
# View all owners of a gem that you own
|
56
|
-
puts Gems.owners 'gemcutter'
|
60
|
+
puts Gems.owners 'gemcutter'
|
57
61
|
|
58
62
|
# Add an owner to a RubyGem you own, giving that user permission to manage it
|
59
|
-
|
63
|
+
Gems.add_owner 'josh@technicalpickles.com', 'gemcutter' [TODO]
|
60
64
|
|
61
65
|
# Remove a user's permission to manage a RubyGem you own
|
62
|
-
|
66
|
+
Gems.remove_owner 'josh@technicalpickles.com', 'gemcutter' [TODO]
|
63
67
|
|
64
68
|
# List the webhooks registered under your account
|
65
|
-
puts Gems.web_hooks
|
69
|
+
puts Gems.web_hooks
|
66
70
|
|
67
71
|
# Add a webhook
|
68
|
-
|
72
|
+
Gems.add_web_hook 'rails', 'http://example.com' [TODO]
|
69
73
|
|
70
74
|
# Remove a webhook
|
71
|
-
|
75
|
+
Gems.remove_web_hook 'rails', 'http://example.com' [TODO]
|
72
76
|
|
73
77
|
# Test fire a webhook.
|
74
|
-
|
78
|
+
Gems.fire_web_hook 'rails', 'http://example.com' [TODO]
|
75
79
|
|
76
80
|
# Submit a gem to RubyGems.org
|
77
|
-
|
81
|
+
Gems.push File.new 'gemcutter-0.2.1.gem' [TODO]
|
78
82
|
|
79
83
|
# Remove a gem from RubyGems.org's index
|
80
|
-
|
84
|
+
Gems.yank 'bills', '0.0.1', :platform => 'x86-darwin-10' [TODO]
|
81
85
|
|
82
86
|
# Update a previously yanked gem back into RubyGems.org's index
|
83
|
-
|
87
|
+
Gems.unyank 'bills', '0.0.1', :platform => 'x86-darwin-10' [TODO]
|
84
88
|
|
85
89
|
Contributing
|
86
90
|
------------
|
data/lib/gems/client.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'date'
|
1
2
|
require 'gems/configuration'
|
2
3
|
require 'gems/connection'
|
3
4
|
require 'gems/request'
|
@@ -51,11 +52,17 @@ module Gems
|
|
51
52
|
#
|
52
53
|
# @param gem [String] The name of a gem.
|
53
54
|
# @param version [String] The version of a gem.
|
55
|
+
# @param from [Date] Search start date.
|
56
|
+
# @param to [Date] Search end date.
|
54
57
|
# @return [Hashie::Mash]
|
55
58
|
# @example
|
56
|
-
# Gems.downloads 'coulda', '0.6.3'
|
57
|
-
def downloads(gem, version)
|
58
|
-
|
59
|
+
# Gems.downloads 'coulda', '0.6.3', Date.today - 30, Date.today
|
60
|
+
def downloads(gem, version, from=nil, to=Date.today)
|
61
|
+
if from
|
62
|
+
get("/api/v1/versions/#{gem}-#{version}/downloads/search", {:from => from.to_s, :to => to.to_s}, :json)
|
63
|
+
else
|
64
|
+
get("/api/v1/versions/#{gem}-#{version}/downloads", {}, :json)
|
65
|
+
end
|
59
66
|
end
|
60
67
|
|
61
68
|
# Returns an array of hashes for all versions of given gems
|
@@ -93,5 +100,30 @@ module Gems
|
|
93
100
|
response = get("/api/v1/gems")
|
94
101
|
format.to_s.downcase == 'xml' ? response['rubygems'] : response
|
95
102
|
end
|
103
|
+
|
104
|
+
# View all owners of a gem that you own
|
105
|
+
#
|
106
|
+
# @param gem [String] The name of a gem.
|
107
|
+
# @return [Array]
|
108
|
+
# @example
|
109
|
+
# Gems.configure do |config|
|
110
|
+
# config.key = '701243f217cdf23b1370c7b66b65ca97'
|
111
|
+
# end
|
112
|
+
# Gems.owners('gemcutter')
|
113
|
+
def owners(gem)
|
114
|
+
get("/api/v1/gems/#{gem}/owners", {}, :json)
|
115
|
+
end
|
116
|
+
|
117
|
+
# List the webhooks registered under your account
|
118
|
+
#
|
119
|
+
# @return [Hashie::Mash]
|
120
|
+
# @example
|
121
|
+
# Gems.configure do |config|
|
122
|
+
# config.key = '701243f217cdf23b1370c7b66b65ca97'
|
123
|
+
# end
|
124
|
+
# Gems.web_hooks
|
125
|
+
def web_hooks
|
126
|
+
get("/api/v1/web_hooks", {}, :json)
|
127
|
+
end
|
96
128
|
end
|
97
129
|
end
|
data/lib/gems/configuration.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'gems/version'
|
2
|
+
require 'yaml'
|
2
3
|
|
3
4
|
module Gems
|
4
5
|
module Configuration
|
@@ -16,6 +17,13 @@ module Gems
|
|
16
17
|
# @note JSON is preferred over XML because it is more concise and faster to parse.
|
17
18
|
DEFAULT_FORMAT = :json
|
18
19
|
|
20
|
+
# Attempt to automatically load credentials
|
21
|
+
DEFAULT_KEY = begin
|
22
|
+
YAML.load(File.read(File.expand_path("~/.gem/credentials")))[:rubygems_api_key]
|
23
|
+
rescue Errno::ENOENT
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
|
19
27
|
# The value sent in the 'User-Agent' header if none is set
|
20
28
|
DEFAULT_USER_AGENT = "Gems #{Gems::VERSION}".freeze
|
21
29
|
|
@@ -41,7 +49,7 @@ module Gems
|
|
41
49
|
# Reset all configuration options to defaults
|
42
50
|
def reset
|
43
51
|
self.format = DEFAULT_FORMAT
|
44
|
-
self.key =
|
52
|
+
self.key = DEFAULT_KEY
|
45
53
|
self.password = nil
|
46
54
|
self.user_agent = DEFAULT_USER_AGENT
|
47
55
|
self.username = nil
|
data/lib/gems/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
{"all gems":[{"url":"http://gemwhisperer.heroku.com","failure_count":1}],"rails":[{"url":"http://example.com","failure_count": 0}]}
|
data/spec/gems/client_spec.rb
CHANGED
@@ -61,16 +61,50 @@ describe Gems::Client do
|
|
61
61
|
end
|
62
62
|
|
63
63
|
describe ".downloads" do
|
64
|
-
|
65
|
-
|
66
|
-
|
64
|
+
context "with no dates specified" do
|
65
|
+
before do
|
66
|
+
stub_get("/api/v1/versions/coulda-0.6.3/downloads.json").
|
67
|
+
to_return(:body => fixture("downloads.json"))
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should return the number of downloads by day for a particular gem version" do
|
71
|
+
downloads = Gems.downloads 'coulda', '0.6.3'
|
72
|
+
a_get("/api/v1/versions/coulda-0.6.3/downloads.json").
|
73
|
+
should have_been_made
|
74
|
+
downloads["2011-06-22"].should == 8
|
75
|
+
end
|
67
76
|
end
|
68
77
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
78
|
+
context "with from date specified" do
|
79
|
+
before do
|
80
|
+
stub_get("/api/v1/versions/coulda-0.6.3/downloads/search.json").
|
81
|
+
with(:query => {"from" => "2011-01-01", "to" => Date.today.to_s}).
|
82
|
+
to_return(:body => fixture("downloads.json"))
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should return the number of downloads by day for a particular gem version" do
|
86
|
+
downloads = Gems.downloads 'coulda', '0.6.3', Date.parse('2011-01-01')
|
87
|
+
a_get("/api/v1/versions/coulda-0.6.3/downloads/search.json").
|
88
|
+
with(:query => {"from" => "2011-01-01", "to" => Date.today.to_s}).
|
89
|
+
should have_been_made
|
90
|
+
downloads["2011-06-22"].should == 8
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context "with from and to dates specified" do
|
95
|
+
before do
|
96
|
+
stub_get("/api/v1/versions/coulda-0.6.3/downloads/search.json").
|
97
|
+
with(:query => {"from" => "2011-01-01", "to" => "2011-06-28"}).
|
98
|
+
to_return(:body => fixture("downloads.json"))
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should return the number of downloads by day for a particular gem version" do
|
102
|
+
downloads = Gems.downloads 'coulda', '0.6.3', Date.parse('2011-01-01'), Date.parse('2011-06-28')
|
103
|
+
a_get("/api/v1/versions/coulda-0.6.3/downloads/search.json").
|
104
|
+
with(:query => {"from" => "2011-01-01", "to" => "2011-06-28"}).
|
105
|
+
should have_been_made
|
106
|
+
downloads["2011-06-22"].should == 8
|
107
|
+
end
|
74
108
|
end
|
75
109
|
end
|
76
110
|
|
@@ -117,6 +151,34 @@ describe Gems::Client do
|
|
117
151
|
gems.first.name.should == "congress"
|
118
152
|
end
|
119
153
|
end
|
154
|
+
|
155
|
+
describe ".owners" do
|
156
|
+
before do
|
157
|
+
stub_get("/api/v1/gems/gems/owners.json").
|
158
|
+
to_return(:body => fixture("owners.json"))
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should list all owners of a gem" do
|
162
|
+
owners = Gems.owners("gems")
|
163
|
+
a_get("/api/v1/gems/gems/owners.json").
|
164
|
+
should have_been_made
|
165
|
+
owners.first.email.should == "sferik@gmail.com"
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
describe ".web_hooks" do
|
170
|
+
before do
|
171
|
+
stub_get("/api/v1/web_hooks.json").
|
172
|
+
to_return(:body => fixture("web_hooks.json"))
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should list the webhooks registered under your account" do
|
176
|
+
web_hooks = Gems.web_hooks
|
177
|
+
a_get("/api/v1/web_hooks.json").
|
178
|
+
should have_been_made
|
179
|
+
web_hooks.rails.first.url.should == "http://example.com"
|
180
|
+
end
|
181
|
+
end
|
120
182
|
end
|
121
183
|
end
|
122
184
|
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.0.6
|
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-06-
|
13
|
+
date: 2011-06-30 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -182,6 +182,7 @@ files:
|
|
182
182
|
- spec/fixtures/rails.xml
|
183
183
|
- spec/fixtures/search.json
|
184
184
|
- spec/fixtures/search.xml
|
185
|
+
- spec/fixtures/web_hooks.json
|
185
186
|
- spec/gems/client_spec.rb
|
186
187
|
- spec/gems_spec.rb
|
187
188
|
- spec/helper.rb
|
@@ -225,6 +226,7 @@ test_files:
|
|
225
226
|
- spec/fixtures/rails.xml
|
226
227
|
- spec/fixtures/search.json
|
227
228
|
- spec/fixtures/search.xml
|
229
|
+
- spec/fixtures/web_hooks.json
|
228
230
|
- spec/gems/client_spec.rb
|
229
231
|
- spec/gems_spec.rb
|
230
232
|
- spec/helper.rb
|