gems 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +0 -1
- data/README.md +3 -0
- data/gems.gemspec +0 -1
- data/lib/gems/client.rb +13 -3
- data/lib/gems/configuration.rb +8 -3
- data/lib/gems/connection.rb +5 -4
- data/lib/gems/request.rb +17 -11
- data/lib/gems/version.rb +1 -1
- data/spec/fixtures/gems-0.0.8.gem +0 -0
- data/spec/fixtures/push +1 -0
- data/spec/gems/client_spec.rb +31 -21
- data/spec/gems_spec.rb +2 -8
- data/spec/helper.rb +20 -16
- metadata +9 -16
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -76,6 +76,9 @@ Usage Examples
|
|
76
76
|
# Test fire a webhook.
|
77
77
|
Gems.fire_web_hook 'rails', 'http://example.com'
|
78
78
|
|
79
|
+
# Submit a gem to RubyGems.org.
|
80
|
+
Gems.push File.new 'gemcutter-0.2.1.gem'
|
81
|
+
|
79
82
|
# Remove a gem from RubyGems.org's index.
|
80
83
|
# Defaults to the latest version if no version is specified.
|
81
84
|
Gems.yank 'bills', '0.0.1'
|
data/gems.gemspec
CHANGED
@@ -11,7 +11,6 @@ Gem::Specification.new do |gem|
|
|
11
11
|
gem.add_development_dependency 'yard', '~> 0.7'
|
12
12
|
gem.add_runtime_dependency 'faraday', '~> 0.6.1'
|
13
13
|
gem.add_runtime_dependency 'faraday_middleware', '~> 0.6.5'
|
14
|
-
gem.add_runtime_dependency 'hashie', '~> 1.0.0'
|
15
14
|
gem.add_runtime_dependency 'multi_json', '~> 1.0.3'
|
16
15
|
gem.add_runtime_dependency 'multi_xml', '~> 0.2.2'
|
17
16
|
|
data/lib/gems/client.rb
CHANGED
@@ -58,7 +58,7 @@ module Gems
|
|
58
58
|
# @example
|
59
59
|
# Gems.downloads 'coulda', '0.6.3', Date.today - 30, Date.today
|
60
60
|
def downloads(gem_name, gem_version=nil, from=nil, to=Date.today)
|
61
|
-
gem_version ||= info(gem_name)
|
61
|
+
gem_version ||= info(gem_name)['version']
|
62
62
|
if from
|
63
63
|
get("/api/v1/versions/#{gem_name}-#{gem_version}/downloads/search", {:from => from.to_s, :to => to.to_s}, :json)
|
64
64
|
else
|
@@ -173,6 +173,16 @@ module Gems
|
|
173
173
|
post("/api/v1/web_hooks/fire", {:gem_name => gem_name, :url => url}, :raw)
|
174
174
|
end
|
175
175
|
|
176
|
+
# Submit a gem to RubyGems.org
|
177
|
+
#
|
178
|
+
# @param gem [File] A built gem.
|
179
|
+
# @return [String]
|
180
|
+
# @example
|
181
|
+
# Gems.push(File.new("pkg/gemcutter-0.2.1.gem"))
|
182
|
+
def push(gem)
|
183
|
+
post("/api/v1/gems", gem.read, :raw, 'application/octet-stream')
|
184
|
+
end
|
185
|
+
|
176
186
|
# Remove a gem from RubyGems.org's index
|
177
187
|
#
|
178
188
|
# @param gem_name [String] The name of a gem.
|
@@ -183,7 +193,7 @@ module Gems
|
|
183
193
|
# @example
|
184
194
|
# Gems.yank("gemcutter", "0.2.1", {:platform => "x86-darwin-10"})
|
185
195
|
def yank(gem_name, gem_version=nil, options={})
|
186
|
-
gem_version ||= info(gem_name)
|
196
|
+
gem_version ||= info(gem_name)['version']
|
187
197
|
delete("/api/v1/gems/yank", options.merge(:gem_name => gem_name, :version => gem_version), :raw)
|
188
198
|
end
|
189
199
|
|
@@ -197,7 +207,7 @@ module Gems
|
|
197
207
|
# @example
|
198
208
|
# Gems.unyank("gemcutter", "0.2.1", {:platform => "x86-darwin-10"})
|
199
209
|
def unyank(gem_name, gem_version=nil, options={})
|
200
|
-
gem_version ||= info(gem_name)
|
210
|
+
gem_version ||= info(gem_name)['version']
|
201
211
|
put("/api/v1/gems/unyank", options.merge(:gem_name => gem_name, :version => gem_version), :raw)
|
202
212
|
end
|
203
213
|
end
|
data/lib/gems/configuration.rb
CHANGED
@@ -7,6 +7,7 @@ module Gems
|
|
7
7
|
# An array of valid keys in the options hash when configuring a {Gems::Client}
|
8
8
|
VALID_OPTIONS_KEYS = [
|
9
9
|
:format,
|
10
|
+
:host,
|
10
11
|
:key,
|
11
12
|
:password,
|
12
13
|
:user_agent,
|
@@ -16,12 +17,15 @@ module Gems
|
|
16
17
|
# Set the default response format appended to the path
|
17
18
|
#
|
18
19
|
# @note JSON is preferred over XML because it is more concise and faster to parse.
|
19
|
-
DEFAULT_FORMAT = :json
|
20
|
+
DEFAULT_FORMAT = :json.freeze
|
21
|
+
|
22
|
+
# Set the default API endpoint
|
23
|
+
DEFAULT_HOST = ENV['RUBYGEMS_HOST'] ? ENV['RUBYGEMS_HOST'].freeze : 'https://rubygems.org'.freeze
|
20
24
|
|
21
25
|
# Set the default credentials
|
22
|
-
DEFAULT_KEY = Gem.configuration.rubygems_api_key
|
26
|
+
DEFAULT_KEY = Gem.configuration.rubygems_api_key.freeze
|
23
27
|
|
24
|
-
# Set the default
|
28
|
+
# Set the default 'User-Agent' HTTP header
|
25
29
|
DEFAULT_USER_AGENT = "Gems #{Gems::VERSION}".freeze
|
26
30
|
|
27
31
|
attr_accessor *VALID_OPTIONS_KEYS
|
@@ -46,6 +50,7 @@ module Gems
|
|
46
50
|
# Reset all configuration options to defaults
|
47
51
|
def reset
|
48
52
|
self.format = DEFAULT_FORMAT
|
53
|
+
self.host = DEFAULT_HOST
|
49
54
|
self.key = DEFAULT_KEY
|
50
55
|
self.password = nil
|
51
56
|
self.user_agent = DEFAULT_USER_AGENT
|
data/lib/gems/connection.rb
CHANGED
@@ -2,20 +2,21 @@ require 'faraday_middleware'
|
|
2
2
|
|
3
3
|
module Gems
|
4
4
|
module Connection
|
5
|
-
def connection(format=
|
5
|
+
def connection(content_length=nil, content_type=nil, format=foramt)
|
6
6
|
options = {
|
7
7
|
:headers => {
|
8
8
|
:user_agent => user_agent,
|
9
9
|
},
|
10
10
|
:ssl => {:verify => false},
|
11
|
-
:url =>
|
11
|
+
:url => host,
|
12
12
|
}
|
13
13
|
|
14
|
+
options[:headers].merge!({:content_length => content_length}) if content_length
|
15
|
+
options[:headers].merge!({:content_type => content_type}) if content_type
|
14
16
|
options[:headers].merge!({:authorization => key}) if key
|
15
17
|
|
16
18
|
connection = Faraday.new(options) do |connection|
|
17
|
-
connection.use Faraday::Request::UrlEncoded
|
18
|
-
connection.use Faraday::Response::Mashify
|
19
|
+
connection.use Faraday::Request::UrlEncoded unless content_type
|
19
20
|
case format.to_s.downcase
|
20
21
|
when 'json'
|
21
22
|
connection.use Faraday::Response::ParseJson
|
data/lib/gems/request.rb
CHANGED
@@ -1,31 +1,37 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
1
3
|
module Gems
|
2
4
|
module Request
|
3
|
-
def delete(path, options={}, format=format)
|
4
|
-
request(:delete, path, options, format)
|
5
|
+
def delete(path, options={}, format=format, content_type=nil)
|
6
|
+
request(:delete, path, options, format, content_type)
|
5
7
|
end
|
6
8
|
|
7
|
-
def get(path, options={}, format=format)
|
8
|
-
request(:get, path, options, format)
|
9
|
+
def get(path, options={}, format=format, content_type=nil)
|
10
|
+
request(:get, path, options, format, content_type)
|
9
11
|
end
|
10
12
|
|
11
|
-
def post(path, options={}, format=format)
|
12
|
-
request(:post, path, options, format)
|
13
|
+
def post(path, options={}, format=format, content_type=nil)
|
14
|
+
request(:post, path, options, format, content_type)
|
13
15
|
end
|
14
16
|
|
15
|
-
def put(path, options={}, format=format)
|
16
|
-
request(:put, path, options, format)
|
17
|
+
def put(path, options={}, format=format, content_type=nil)
|
18
|
+
request(:put, path, options, format, content_type)
|
17
19
|
end
|
18
20
|
|
19
21
|
private
|
20
22
|
|
21
|
-
def request(method, path, options, format)
|
22
|
-
|
23
|
+
def request(method, path, options, format, content_type)
|
24
|
+
content_length = case content_type
|
25
|
+
when 'application/octet-stream'
|
26
|
+
options.size
|
27
|
+
end
|
28
|
+
response = connection(content_length, content_type, format).send(method) do |request|
|
23
29
|
case method
|
24
30
|
when :delete, :get
|
25
31
|
request.url(formatted_path(path, format), options)
|
26
32
|
when :post, :put
|
27
33
|
request.path = formatted_path(path, format)
|
28
|
-
request.body = options unless options
|
34
|
+
request.body = options unless options == {}
|
29
35
|
end
|
30
36
|
end
|
31
37
|
response.body
|
data/lib/gems/version.rb
CHANGED
Binary file
|
data/spec/fixtures/push
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Successfully registered gem: gems (0.0.8)
|
data/spec/gems/client_spec.rb
CHANGED
@@ -2,14 +2,6 @@ require 'helper'
|
|
2
2
|
|
3
3
|
describe Gems::Client do
|
4
4
|
before do
|
5
|
-
Gems.configure do |config|
|
6
|
-
config.key = '701243f217cdf23b1370c7b66b65ca97'
|
7
|
-
config.username = 'nick@gemcutter.org'
|
8
|
-
config.password = 'schwwwwing'
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
after do
|
13
5
|
Gems.reset
|
14
6
|
end
|
15
7
|
|
@@ -26,7 +18,7 @@ describe Gems::Client do
|
|
26
18
|
info = Gems.info 'rails'
|
27
19
|
a_get("/api/v1/gems/rails.#{format}").
|
28
20
|
should have_been_made
|
29
|
-
info
|
21
|
+
info['name'].should == 'rails'
|
30
22
|
end
|
31
23
|
end
|
32
24
|
end
|
@@ -47,7 +39,7 @@ describe Gems::Client do
|
|
47
39
|
a_get("/api/v1/search.#{format}").
|
48
40
|
with(:query => {"query" => "cucumber"}).
|
49
41
|
should have_been_made
|
50
|
-
search.first
|
42
|
+
search.first['name'].should == 'cucumber'
|
51
43
|
end
|
52
44
|
end
|
53
45
|
end
|
@@ -63,7 +55,7 @@ describe Gems::Client do
|
|
63
55
|
versions = Gems.versions 'coulda'
|
64
56
|
a_get("/api/v1/versions/coulda.json").
|
65
57
|
should have_been_made
|
66
|
-
versions.first
|
58
|
+
versions.first['number'].should == '0.6.3'
|
67
59
|
end
|
68
60
|
end
|
69
61
|
|
@@ -80,7 +72,7 @@ describe Gems::Client do
|
|
80
72
|
downloads = Gems.downloads 'coulda'
|
81
73
|
a_get("/api/v1/versions/coulda-3.0.9/downloads.json").
|
82
74
|
should have_been_made
|
83
|
-
downloads[
|
75
|
+
downloads['2011-06-22'].should == 8
|
84
76
|
end
|
85
77
|
end
|
86
78
|
|
@@ -94,7 +86,7 @@ describe Gems::Client do
|
|
94
86
|
downloads = Gems.downloads 'coulda', '0.6.3'
|
95
87
|
a_get("/api/v1/versions/coulda-0.6.3/downloads.json").
|
96
88
|
should have_been_made
|
97
|
-
downloads[
|
89
|
+
downloads['2011-06-22'].should == 8
|
98
90
|
end
|
99
91
|
end
|
100
92
|
|
@@ -110,7 +102,7 @@ describe Gems::Client do
|
|
110
102
|
a_get("/api/v1/versions/coulda-0.6.3/downloads/search.json").
|
111
103
|
with(:query => {"from" => "2011-01-01", "to" => Date.today.to_s}).
|
112
104
|
should have_been_made
|
113
|
-
downloads[
|
105
|
+
downloads['2011-06-22'].should == 8
|
114
106
|
end
|
115
107
|
end
|
116
108
|
|
@@ -126,7 +118,7 @@ describe Gems::Client do
|
|
126
118
|
a_get("/api/v1/versions/coulda-0.6.3/downloads/search.json").
|
127
119
|
with(:query => {"from" => "2011-01-01", "to" => "2011-06-28"}).
|
128
120
|
should have_been_made
|
129
|
-
downloads[
|
121
|
+
downloads['2011-06-22'].should == 8
|
130
122
|
end
|
131
123
|
end
|
132
124
|
end
|
@@ -143,19 +135,23 @@ describe Gems::Client do
|
|
143
135
|
a_get("/api/v1/dependencies").
|
144
136
|
with(:query => {"gems" => "rails,thor"}).
|
145
137
|
should have_been_made
|
146
|
-
dependencies.first
|
138
|
+
dependencies.first[:number].should == "3.0.9"
|
147
139
|
end
|
148
140
|
end
|
149
141
|
|
150
142
|
describe ".api_key" do
|
151
143
|
before do
|
152
|
-
|
144
|
+
Gems.configure do |config|
|
145
|
+
config.username = 'nick@gemcutter.org'
|
146
|
+
config.password = 'schwwwwing'
|
147
|
+
end
|
148
|
+
stub_get("https://nick%40gemcutter.org:schwwwwing@rubygems.org/api/v1/api_key").
|
153
149
|
to_return(:body => fixture("api_key"))
|
154
150
|
end
|
155
151
|
|
156
152
|
it "should retrieve an API key" do
|
157
153
|
api_key = Gems.api_key
|
158
|
-
a_get("/api/v1/api_key").
|
154
|
+
a_get("https://nick%40gemcutter.org:schwwwwing@rubygems.org/api/v1/api_key").
|
159
155
|
should have_been_made
|
160
156
|
api_key.should == "701243f217cdf23b1370c7b66b65ca97"
|
161
157
|
end
|
@@ -174,7 +170,7 @@ describe Gems::Client do
|
|
174
170
|
gems = Gems.gems
|
175
171
|
a_get("/api/v1/gems.#{format}").
|
176
172
|
should have_been_made
|
177
|
-
gems.first
|
173
|
+
gems.first['name'].should == "congress"
|
178
174
|
end
|
179
175
|
end
|
180
176
|
end
|
@@ -193,7 +189,7 @@ describe Gems::Client do
|
|
193
189
|
owners = Gems.owners("gems")
|
194
190
|
a_get("/api/v1/gems/gems/owners.#{format}").
|
195
191
|
should have_been_made
|
196
|
-
owners.first
|
192
|
+
owners.first['email'].should == "sferik@gmail.com"
|
197
193
|
end
|
198
194
|
end
|
199
195
|
end
|
@@ -241,7 +237,7 @@ describe Gems::Client do
|
|
241
237
|
web_hooks = Gems.web_hooks
|
242
238
|
a_get("/api/v1/web_hooks.json").
|
243
239
|
should have_been_made
|
244
|
-
web_hooks
|
240
|
+
web_hooks['rails'].first['url'].should == "http://example.com"
|
245
241
|
end
|
246
242
|
end
|
247
243
|
|
@@ -293,6 +289,20 @@ describe Gems::Client do
|
|
293
289
|
end
|
294
290
|
end
|
295
291
|
|
292
|
+
describe ".push" do
|
293
|
+
before do
|
294
|
+
stub_post("/api/v1/gems").
|
295
|
+
to_return(:body => fixture("push"))
|
296
|
+
end
|
297
|
+
|
298
|
+
it "should submit a gem to RubyGems.org" do
|
299
|
+
push = Gems.push(File.new(File.expand_path("../../fixtures/gems-0.0.8.gem", __FILE__), "rb"))
|
300
|
+
a_post("/api/v1/gems").
|
301
|
+
should have_been_made
|
302
|
+
push.should == "Successfully registered gem: gems (0.0.8)"
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
296
306
|
describe ".yank" do
|
297
307
|
context "with no version specified" do
|
298
308
|
before do
|
data/spec/gems_spec.rb
CHANGED
@@ -3,14 +3,8 @@ require 'helper'
|
|
3
3
|
describe Gems do
|
4
4
|
context "when delegating to a client" do
|
5
5
|
before do
|
6
|
-
|
7
|
-
|
8
|
-
config.password = 'schwwwwing'
|
9
|
-
end
|
10
|
-
stub_get("/api/v1/gems/rails.json").to_return(:body => fixture("rails.json"))
|
11
|
-
end
|
12
|
-
|
13
|
-
after do
|
6
|
+
stub_get("/api/v1/gems/rails.json").
|
7
|
+
to_return(:body => fixture("rails.json"))
|
14
8
|
Gems.reset
|
15
9
|
end
|
16
10
|
|
data/spec/helper.rb
CHANGED
@@ -6,36 +6,40 @@ require 'gems'
|
|
6
6
|
require 'rspec'
|
7
7
|
require 'webmock/rspec'
|
8
8
|
|
9
|
-
def
|
10
|
-
|
9
|
+
def rubygems_url(url)
|
10
|
+
url =~ /^http/ ? url : 'https://rubygems.org' + url
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
14
|
-
a_request(:
|
13
|
+
def a_delete(url)
|
14
|
+
a_request(:delete, rubygems_url(url))
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
18
|
-
a_request(:
|
17
|
+
def a_get(url)
|
18
|
+
a_request(:get, rubygems_url(url))
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
22
|
-
a_request(:
|
21
|
+
def a_post(url)
|
22
|
+
a_request(:post, rubygems_url(url))
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
26
|
-
|
25
|
+
def a_put(url)
|
26
|
+
a_request(:put, rubygems_url(url))
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
30
|
-
stub_request(:
|
29
|
+
def stub_delete(url)
|
30
|
+
stub_request(:delete, rubygems_url(url))
|
31
31
|
end
|
32
32
|
|
33
|
-
def
|
34
|
-
stub_request(:
|
33
|
+
def stub_get(url)
|
34
|
+
stub_request(:get, rubygems_url(url))
|
35
35
|
end
|
36
36
|
|
37
|
-
def
|
38
|
-
stub_request(:
|
37
|
+
def stub_post(url)
|
38
|
+
stub_request(:post, rubygems_url(url))
|
39
|
+
end
|
40
|
+
|
41
|
+
def stub_put(url)
|
42
|
+
stub_request(:put, rubygems_url(url))
|
39
43
|
end
|
40
44
|
|
41
45
|
def fixture_path
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: gems
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.2.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Erik Michaels-Ober
|
@@ -112,39 +112,28 @@ dependencies:
|
|
112
112
|
version: 0.6.5
|
113
113
|
type: :runtime
|
114
114
|
version_requirements: *id009
|
115
|
-
- !ruby/object:Gem::Dependency
|
116
|
-
name: hashie
|
117
|
-
prerelease: false
|
118
|
-
requirement: &id010 !ruby/object:Gem::Requirement
|
119
|
-
none: false
|
120
|
-
requirements:
|
121
|
-
- - ~>
|
122
|
-
- !ruby/object:Gem::Version
|
123
|
-
version: 1.0.0
|
124
|
-
type: :runtime
|
125
|
-
version_requirements: *id010
|
126
115
|
- !ruby/object:Gem::Dependency
|
127
116
|
name: multi_json
|
128
117
|
prerelease: false
|
129
|
-
requirement: &
|
118
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
130
119
|
none: false
|
131
120
|
requirements:
|
132
121
|
- - ~>
|
133
122
|
- !ruby/object:Gem::Version
|
134
123
|
version: 1.0.3
|
135
124
|
type: :runtime
|
136
|
-
version_requirements: *
|
125
|
+
version_requirements: *id010
|
137
126
|
- !ruby/object:Gem::Dependency
|
138
127
|
name: multi_xml
|
139
128
|
prerelease: false
|
140
|
-
requirement: &
|
129
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
141
130
|
none: false
|
142
131
|
requirements:
|
143
132
|
- - ~>
|
144
133
|
- !ruby/object:Gem::Version
|
145
134
|
version: 0.2.2
|
146
135
|
type: :runtime
|
147
|
-
version_requirements: *
|
136
|
+
version_requirements: *id011
|
148
137
|
description: Ruby wrapper for the RubyGems.org API
|
149
138
|
email:
|
150
139
|
- sferik@gmail.com
|
@@ -178,10 +167,12 @@ files:
|
|
178
167
|
- spec/fixtures/dependencies
|
179
168
|
- spec/fixtures/downloads.json
|
180
169
|
- spec/fixtures/fire_web_hook
|
170
|
+
- spec/fixtures/gems-0.0.8.gem
|
181
171
|
- spec/fixtures/gems.json
|
182
172
|
- spec/fixtures/gems.xml
|
183
173
|
- spec/fixtures/owners.json
|
184
174
|
- spec/fixtures/owners.yaml
|
175
|
+
- spec/fixtures/push
|
185
176
|
- spec/fixtures/rails.json
|
186
177
|
- spec/fixtures/rails.xml
|
187
178
|
- spec/fixtures/remove_owner.json
|
@@ -230,10 +221,12 @@ test_files:
|
|
230
221
|
- spec/fixtures/dependencies
|
231
222
|
- spec/fixtures/downloads.json
|
232
223
|
- spec/fixtures/fire_web_hook
|
224
|
+
- spec/fixtures/gems-0.0.8.gem
|
233
225
|
- spec/fixtures/gems.json
|
234
226
|
- spec/fixtures/gems.xml
|
235
227
|
- spec/fixtures/owners.json
|
236
228
|
- spec/fixtures/owners.yaml
|
229
|
+
- spec/fixtures/push
|
237
230
|
- spec/fixtures/rails.json
|
238
231
|
- spec/fixtures/rails.xml
|
239
232
|
- spec/fixtures/remove_owner.json
|