gems 0.0.6 → 0.0.7

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 CHANGED
@@ -60,10 +60,10 @@ Usage Examples
60
60
  puts Gems.owners 'gemcutter'
61
61
 
62
62
  # Add an owner to a RubyGem you own, giving that user permission to manage it
63
- Gems.add_owner 'josh@technicalpickles.com', 'gemcutter' [TODO]
63
+ Gems.add_owner 'josh@technicalpickles.com', 'gemcutter'
64
64
 
65
65
  # Remove a user's permission to manage a RubyGem you own
66
- Gems.remove_owner 'josh@technicalpickles.com', 'gemcutter' [TODO]
66
+ Gems.remove_owner 'josh@technicalpickles.com', 'gemcutter'
67
67
 
68
68
  # List the webhooks registered under your account
69
69
  puts Gems.web_hooks
@@ -77,7 +77,7 @@ module Gems
77
77
 
78
78
  # Retrieve your API key using HTTP basic auth
79
79
  #
80
- # @return String
80
+ # @return [String]
81
81
  # @example
82
82
  # Gems.configure do |config|
83
83
  # config.username = 'nick@gemcutter.org'
@@ -125,5 +125,33 @@ module Gems
125
125
  def web_hooks
126
126
  get("/api/v1/web_hooks", {}, :json)
127
127
  end
128
+
129
+ # Add an owner to a RubyGem you own, giving that user permission to manage it
130
+ #
131
+ # @param gem [String] The name of a gem.
132
+ # @param owner [String] The email address of the user you want to add.
133
+ # @return [String]
134
+ # @example
135
+ # Gems.configure do |config|
136
+ # config.key = '701243f217cdf23b1370c7b66b65ca97'
137
+ # end
138
+ # Gems.add_owner("gemcutter", "josh@technicalpickles.com")
139
+ def add_owner(gem, owner)
140
+ post("/api/v1/gems/#{gem}/owners", {:email => owner}, :raw)
141
+ end
142
+
143
+ # Remove a user's permission to manage a RubyGem you own
144
+ #
145
+ # @param gem [String] The name of a gem.
146
+ # @param owner [String] The email address of the user you want to remove.
147
+ # @return [String]
148
+ # @example
149
+ # Gems.configure do |config|
150
+ # config.key = '701243f217cdf23b1370c7b66b65ca97'
151
+ # end
152
+ # Gems.remove_owner("gemcutter", "josh@technicalpickles.com")
153
+ def remove_owner(gem, owner)
154
+ delete("/api/v1/gems/#{gem}/owners", {:email => owner}, :raw)
155
+ end
128
156
  end
129
157
  end
@@ -1,14 +1,28 @@
1
1
  module Gems
2
2
  module Request
3
+ def delete(path, options={}, format=format)
4
+ request(:delete, path, options, format)
5
+ end
6
+
3
7
  def get(path, options={}, format=format)
4
8
  request(:get, path, options, format)
5
9
  end
6
10
 
11
+ def post(path, options={}, format=format)
12
+ request(:post, path, options, format)
13
+ end
14
+
7
15
  private
8
16
 
9
17
  def request(method, path, options, format)
10
18
  response = connection(format).send(method) do |request|
11
- request.url(formatted_path(path, format), options)
19
+ case method
20
+ when :delete, :get
21
+ request.url(formatted_path(path, format), options)
22
+ when :post
23
+ request.path = formatted_path(path, format)
24
+ request.body = options unless options.empty?
25
+ end
12
26
  end
13
27
  response.body
14
28
  end
@@ -1,3 +1,3 @@
1
1
  module Gems
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -0,0 +1 @@
1
+ Owner added successfully.
@@ -0,0 +1 @@
1
+ Owner removed successfully.
@@ -179,6 +179,38 @@ describe Gems::Client do
179
179
  web_hooks.rails.first.url.should == "http://example.com"
180
180
  end
181
181
  end
182
+
183
+ describe ".add_owner" do
184
+ before do
185
+ stub_post("/api/v1/gems/gems/owners").
186
+ with(:body => {:email => "sferik@gmail.com"}).
187
+ to_return(:body => fixture("add_owner.json"))
188
+ end
189
+
190
+ it "should add an owner to a RubyGem" do
191
+ owner = Gems.add_owner("gems", "sferik@gmail.com")
192
+ a_post("/api/v1/gems/gems/owners").
193
+ with(:body => {:email => "sferik@gmail.com"}).
194
+ should have_been_made
195
+ owner.should == "Owner added successfully."
196
+ end
197
+ end
198
+
199
+ describe ".remove_owner" do
200
+ before do
201
+ stub_delete("/api/v1/gems/gems/owners").
202
+ with(:query => {:email => "sferik@gmail.com"}).
203
+ to_return(:body => fixture("remove_owner.json"))
204
+ end
205
+
206
+ it "should remove an owner from a RubyGem" do
207
+ owner = Gems.remove_owner("gems", "sferik@gmail.com")
208
+ a_delete("/api/v1/gems/gems/owners").
209
+ with(:query => {:email => "sferik@gmail.com"}).
210
+ should have_been_made
211
+ owner.should == "Owner removed successfully."
212
+ end
213
+ end
182
214
  end
183
215
  end
184
216
  end
@@ -6,14 +6,30 @@ require 'gems'
6
6
  require 'rspec'
7
7
  require 'webmock/rspec'
8
8
 
9
+ def a_delete(path)
10
+ a_request(:delete, 'https://nick%40gemcutter.org:schwwwwing@rubygems.org' + path)
11
+ end
12
+
9
13
  def a_get(path)
10
14
  a_request(:get, 'https://nick%40gemcutter.org:schwwwwing@rubygems.org' + path)
11
15
  end
12
16
 
17
+ def a_post(path)
18
+ a_request(:post, 'https://nick%40gemcutter.org:schwwwwing@rubygems.org' + path)
19
+ end
20
+
21
+ def stub_delete(path)
22
+ stub_request(:delete, 'https://nick%40gemcutter.org:schwwwwing@rubygems.org' + path)
23
+ end
24
+
13
25
  def stub_get(path)
14
26
  stub_request(:get, 'https://nick%40gemcutter.org:schwwwwing@rubygems.org' + path)
15
27
  end
16
28
 
29
+ def stub_post(path)
30
+ stub_request(:post, 'https://nick%40gemcutter.org:schwwwwing@rubygems.org' + path)
31
+ end
32
+
17
33
  def fixture_path
18
34
  File.expand_path('../fixtures', __FILE__)
19
35
  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.6
5
+ version: 0.0.7
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-30 00:00:00 -07:00
13
+ date: 2011-07-01 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -171,6 +171,7 @@ files:
171
171
  - lib/gems/connection.rb
172
172
  - lib/gems/request.rb
173
173
  - lib/gems/version.rb
174
+ - spec/fixtures/add_owner.json
174
175
  - spec/fixtures/api_key
175
176
  - spec/fixtures/coulda.json
176
177
  - spec/fixtures/dependencies
@@ -180,6 +181,7 @@ files:
180
181
  - spec/fixtures/owners.json
181
182
  - spec/fixtures/rails.json
182
183
  - spec/fixtures/rails.xml
184
+ - spec/fixtures/remove_owner.json
183
185
  - spec/fixtures/search.json
184
186
  - spec/fixtures/search.xml
185
187
  - spec/fixtures/web_hooks.json
@@ -215,6 +217,7 @@ signing_key:
215
217
  specification_version: 3
216
218
  summary: Ruby wrapper for the RubyGems.org API
217
219
  test_files:
220
+ - spec/fixtures/add_owner.json
218
221
  - spec/fixtures/api_key
219
222
  - spec/fixtures/coulda.json
220
223
  - spec/fixtures/dependencies
@@ -224,6 +227,7 @@ test_files:
224
227
  - spec/fixtures/owners.json
225
228
  - spec/fixtures/rails.json
226
229
  - spec/fixtures/rails.xml
230
+ - spec/fixtures/remove_owner.json
227
231
  - spec/fixtures/search.json
228
232
  - spec/fixtures/search.xml
229
233
  - spec/fixtures/web_hooks.json