Permalink
Browse files

Add methods to add, remove, and fire web hooks

  • Loading branch information...
1 parent 23706f3 commit 36c8c488cf5569da742c77e579596edd3cbc9d13 @sferik committed Jul 1, 2011
Showing with 122 additions and 29 deletions.
  1. +3 −3 README.md
  2. +54 −12 lib/gems/client.rb
  3. +1 −0 spec/fixtures/add_web_hook
  4. +1 −0 spec/fixtures/fire_web_hook
  5. +1 −0 spec/fixtures/remove_web_hook
  6. +62 −14 spec/gems/client_spec.rb
View
@@ -69,13 +69,13 @@ Usage Examples
puts Gems.web_hooks
# Add a webhook
- Gems.add_web_hook 'rails', 'http://example.com' [TODO]
+ Gems.add_web_hook 'rails', 'http://example.com'
# Remove a webhook
- Gems.remove_web_hook 'rails', 'http://example.com' [TODO]
+ Gems.remove_web_hook 'rails', 'http://example.com'
# Test fire a webhook.
- Gems.fire_web_hook 'rails', 'http://example.com' [TODO]
+ Gems.fire_web_hook 'rails', 'http://example.com'
# Submit a gem to RubyGems.org
Gems.push File.new 'gemcutter-0.2.1.gem' [TODO]
View
@@ -114,18 +114,6 @@ def owners(gem)
get("/api/v1/gems/#{gem}/owners", {}, :json)
end
- # List the webhooks registered under your account
- #
- # @return [Hashie::Mash]
- # @example
- # Gems.configure do |config|
- # config.key = '701243f217cdf23b1370c7b66b65ca97'
- # end
- # Gems.web_hooks
- def web_hooks
- get("/api/v1/web_hooks", {}, :json)
- end
-
# Add an owner to a RubyGem you own, giving that user permission to manage it
#
# @param gem [String] The name of a gem.
@@ -153,5 +141,59 @@ def add_owner(gem, owner)
def remove_owner(gem, owner)
delete("/api/v1/gems/#{gem}/owners", {:email => owner}, :raw)
end
+
+ # List the webhooks registered under your account
+ #
+ # @return [Hashie::Mash]
+ # @example
+ # Gems.configure do |config|
+ # config.key = '701243f217cdf23b1370c7b66b65ca97'
+ # end
+ # Gems.web_hooks
+ def web_hooks
+ get("/api/v1/web_hooks", {}, :json)
+ end
+
+ # Create a webhook
+ #
+ # @param gem [String] The name of a gem. Specify "*" to add the hook to all your gems.
+ # @param url [String] The URL of the web hook.
+ # @return [String]
+ # @example
+ # Gems.configure do |config|
+ # config.key = '701243f217cdf23b1370c7b66b65ca97'
+ # end
+ # Gems.add_web_hook("rails", "http://example.com")
+ def add_web_hook(gem, url)
+ post("/api/v1/web_hooks", {:gem_name => gem, :url => url}, :raw)
+ end
+
+ # Remove a webhook
+ #
+ # @param gem [String] The name of a gem. Specify "*" to remove the hook from all your gems.
+ # @param url [String] The URL of the web hook.
+ # @return [String]
+ # @example
+ # Gems.configure do |config|
+ # config.key = '701243f217cdf23b1370c7b66b65ca97'
+ # end
+ # Gems.remove_web_hook("rails", "http://example.com")
+ def remove_web_hook(gem, url)
+ delete("/api/v1/web_hooks/remove", {:gem_name => gem, :url => url}, :raw)
+ end
+
+ # Test fire a webhook
+ #
+ # @param gem [String] The name of a gem. Specify "*" to fire the hook for all your gems.
+ # @param url [String] The URL of the web hook.
+ # @return [String]
+ # @example
+ # Gems.configure do |config|
+ # config.key = '701243f217cdf23b1370c7b66b65ca97'
+ # end
+ # Gems.fire_web_hook("rails", "http://example.com")
+ def fire_web_hook(gem, url)
+ post("/api/v1/web_hooks/fire", {:gem_name => gem, :url => url}, :raw)
+ end
end
end
@@ -0,0 +1 @@
+Successfully created webhook for all gems to http://example.com
@@ -0,0 +1 @@
+Successfully deployed webhook for gemcutter to http://example.com
@@ -0,0 +1 @@
+Successfully removed webhook for all gems to http://example.com
@@ -166,20 +166,6 @@
end
end
- describe ".web_hooks" do
- before do
- stub_get("/api/v1/web_hooks.json").
- to_return(:body => fixture("web_hooks.json"))
- end
-
- it "should list the webhooks registered under your account" do
- web_hooks = Gems.web_hooks
- a_get("/api/v1/web_hooks.json").
- should have_been_made
- web_hooks.rails.first.url.should == "http://example.com"
- end
- end
-
describe ".add_owner" do
before do
stub_post("/api/v1/gems/gems/owners").
@@ -211,6 +197,68 @@
owner.should == "Owner removed successfully."
end
end
+
+ describe ".web_hooks" do
+ before do
+ stub_get("/api/v1/web_hooks.json").
+ to_return(:body => fixture("web_hooks.json"))
+ end
+
+ it "should list the webhooks registered under your account" do
+ web_hooks = Gems.web_hooks
+ a_get("/api/v1/web_hooks.json").
+ should have_been_made
+ web_hooks.rails.first.url.should == "http://example.com"
+ end
+ end
+
+ describe ".add_web_hook" do
+ before do
+ stub_post("/api/v1/web_hooks").
+ with(:body => {:gem_name => "*", :url => "http://example.com"}).
+ to_return(:body => fixture("add_web_hook"))
+ end
+
+ it "should add a web hook" do
+ add_web_hook = Gems.add_web_hook("*", "http://example.com")
+ a_post("/api/v1/web_hooks").
+ with(:body => {:gem_name => "*", :url => "http://example.com"}).
+ should have_been_made
+ add_web_hook.should == "Successfully created webhook for all gems to http://example.com"
+ end
+ end
+
+ describe ".remove_web_hook" do
+ before do
+ stub_delete("/api/v1/web_hooks/remove").
+ with(:query => {:gem_name => "*", :url => "http://example.com"}).
+ to_return(:body => fixture("remove_web_hook"))
+ end
+
+ it "should remove a web hook" do
+ remove_web_hook = Gems.remove_web_hook("*", "http://example.com")
+ a_delete("/api/v1/web_hooks/remove").
+ with(:query => {:gem_name => "*", :url => "http://example.com"}).
+ should have_been_made
+ remove_web_hook.should == "Successfully removed webhook for all gems to http://example.com"
+ end
+ end
+
+ describe ".fire_web_hook" do
+ before do
+ stub_post("/api/v1/web_hooks/fire").
+ with(:body => {:gem_name => "*", :url => "http://example.com"}).
+ to_return(:body => fixture("fire_web_hook"))
+ end
+
+ it "should fire a web hook" do
+ fire_web_hook = Gems.fire_web_hook("*", "http://example.com")
+ a_post("/api/v1/web_hooks/fire").
+ with(:body => {:gem_name => "*", :url => "http://example.com"}).
+ should have_been_made
+ fire_web_hook.should == "Successfully deployed webhook for gemcutter to http://example.com"
+ end
+ end
end
end
end

0 comments on commit 36c8c48

Please sign in to comment.