post_commit 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -7,6 +7,7 @@ Post commit allows you to notify several services with simple and elegant DSL. I
7
7
  * FriendFeed
8
8
  * LightHouse
9
9
  * Twitter
10
+ * URL
10
11
 
11
12
  = Usage
12
13
 
@@ -75,6 +76,21 @@ The Twitter hook supports public and direct messages.
75
76
  post "Mary, check this out! http://example.com", :type => :direct_message, :screen_name => "marydoe"
76
77
  post "Mary, check this out! http://example.com", :type => :direct_message, :user_id => 12345
77
78
 
79
+ == URL
80
+
81
+ To send a message to an arbitrary URL, use the <tt>:url</tt>.
82
+
83
+ post_commit :url do
84
+ post "http://example.com", :status => "pending", :id => 1234, :service => "yourapp"
85
+ end
86
+
87
+ If you need a basic authorization, just inform the <tt>username</tt> and <tt>password</tt>.
88
+
89
+ post_commit :url do
90
+ authorize :username => "johndoe", :password => "mypass"
91
+ post "http://example.com", :status => "running", :id => 1234, :service => "yourapp"
92
+ end
93
+
78
94
  = Creating new hooks
79
95
 
80
96
  To create a new hook, you can extend the <tt>PostCommit::Hooks::Base</tt> class, to bootstrap your own class.
@@ -87,7 +103,8 @@ To create a new hook, you can extend the <tt>PostCommit::Hooks::Base</tt> class,
87
103
  end
88
104
  end
89
105
 
90
- To register this new hook, you just have to call the <tt>PostCommit::Hooks.register</tt> method.
106
+ Your new hook will be register automatically. By downcasing the class name. So, <tt>LightHouse</tt> will be registered as <tt>:lighthouse</tt>.
107
+ To register this hook will other name, you just have to call the <tt>PostCommit::Hooks.register</tt> method.
91
108
 
92
109
  PostCommit::Hooks.register :email, Email
93
110
 
@@ -104,11 +121,27 @@ You can use the <tt>credentials</tt> attribute to retrieve these settings.
104
121
  = To-Do
105
122
 
106
123
  * Receive post commits
124
+ * URL hook must post JSON and XML data
125
+ * Create IRC hook
126
+ * Create Jabber hook
127
+ * Create email hook
107
128
 
108
129
  = Maintainer
109
130
 
110
131
  * Nando Vieira - http://simplesideias.com.br
111
132
 
133
+ = Contributing
134
+
135
+ Once you've made your great commits:
136
+
137
+ 1. Fork[http://help.github.com/forking/] the project at http://github.com/fnando/post_commit
138
+ 2. Create a topic branch - <tt>git checkout -b my_branch</tt>
139
+ 3. Push to your branch - <tt>git push origin my_branch</tt>
140
+ 4. Create an Issue[http://github.com/fnando/post_commit/issues] with a link to your branch
141
+ 5. That's it!
142
+
143
+ Please respect the indentation rules. And always use 2 spaces.
144
+
112
145
  = License
113
146
 
114
147
  (The MIT License)
@@ -17,6 +17,10 @@ module PostCommit
17
17
  @credentials = {}
18
18
  end
19
19
 
20
+ def self.inherited(base)
21
+ PostCommit::Hooks.register base.name.split("::").last.downcase.to_sym, base
22
+ end
23
+
20
24
  # Set up the authorization for the current notifier.
21
25
  # Each notifier can have its own authorization options.
22
26
  def authorize(options = {})
@@ -0,0 +1,39 @@
1
+ module PostCommit
2
+ module Hooks
3
+ # To send an URL post commit, you have to set up your URL and, optionally, username and password.
4
+ #
5
+ # post_commit :url do
6
+ # post "http://example.com", :message => "Post commit"
7
+ # end
8
+ #
9
+ # If you need to authorize your request with basic auth, you can set your username and password.
10
+ #
11
+ # post_commit :url do
12
+ # authorize :username => "johndoe", :password => "mypass"
13
+ # post "http://example.com", :message => "Post commit"
14
+ # end
15
+ class URL < Base
16
+ # Post data to an arbitrary URL. The data should a one-depth hash.
17
+ #
18
+ # post "http://example.com", :message => "Post commit", :service => "yourapp"
19
+ def post(url, params = {})
20
+ @uri = URI.parse(url)
21
+ http = Net::HTTP.new(uri.host, uri.port)
22
+
23
+ @request = Net::HTTP::Post.new(uri.path)
24
+ @request.basic_auth credentials[:username], credentials[:password] if credentials[:username]
25
+ @request.form_data = params
26
+
27
+ @response = http.request(@request)
28
+
29
+ if response.code =~ /^2\d+/
30
+ true
31
+ else
32
+ false
33
+ end
34
+ rescue Exception
35
+ false
36
+ end
37
+ end
38
+ end
39
+ end
@@ -2,7 +2,7 @@ module PostCommit
2
2
  module Version
3
3
  MAJOR = "0"
4
4
  MINOR = "1"
5
- PATCH = "0"
5
+ PATCH = "1"
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
8
8
  end
data/lib/post_commit.rb CHANGED
@@ -11,14 +11,9 @@ require "post_commit/hooks/campfire"
11
11
  require "post_commit/hooks/friend_feed"
12
12
  require "post_commit/hooks/light_house"
13
13
  require "post_commit/hooks/twitter"
14
+ require "post_commit/hooks/url"
14
15
  require "post_commit/version"
15
16
 
16
- PostCommit::Hooks.register :basecamp, PostCommit::Hooks::Basecamp
17
- PostCommit::Hooks.register :campfire, PostCommit::Hooks::Campfire
18
- PostCommit::Hooks.register :friendfeed, PostCommit::Hooks::FriendFeed
19
- PostCommit::Hooks.register :lighthouse, PostCommit::Hooks::LightHouse
20
- PostCommit::Hooks.register :twitter, PostCommit::Hooks::Twitter
21
-
22
17
  # Send a notification to the specified service. This method is just
23
18
  # a shorcut to the PostCommit::Hooks module.
24
19
  #
@@ -0,0 +1,51 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ describe PostCommit::Hooks::URL do
4
+ before do
5
+ @url = "http://example.com/some/url"
6
+ end
7
+
8
+ it "should instantiate hook" do
9
+ hook = post_commit(:url) {}
10
+ hook.should be_an_instance_of(PostCommit::Hooks::URL)
11
+ end
12
+
13
+ it "should recover from unknown exceptions" do
14
+ Net::HTTP.should_receive(:new).and_raise(Exception)
15
+ subject.post(@url, :message => "Some message").should be_false
16
+ end
17
+
18
+ it "should set authorization headers" do
19
+ @url = "http://johndoe:mypass@example.com/some/url"
20
+ FakeWeb.register_uri(:post, @url, :status => ["200", "OK"])
21
+
22
+ subject.authorize :username => "johndoe", :password => "mypass"
23
+ subject.post(@url, :message => "Some message")
24
+
25
+ subject.request["authorization"].should == subject.request.send(:basic_encode, "johndoe", "mypass")
26
+ end
27
+
28
+ it "should be posted" do
29
+ FakeWeb.register_uri(:post, @url, :status => ["200", "OK"])
30
+ subject.post(@url, :message => "Some message")
31
+ FakeWeb.should have_requested(:post, @url)
32
+ end
33
+
34
+ it "should be successful with any success status" do
35
+ FakeWeb.register_uri(:post, @url, [
36
+ {:status => ["200", "OK"]},
37
+ {:status => ["201", "Created"]}
38
+ ])
39
+
40
+ subject.post(@url, :message => "Some message").should be_true
41
+ subject.post(@url, :message => "Some message").should be_true
42
+ end
43
+
44
+ it "should set post data" do
45
+ subject.post(@url, :message => "Some message", :id => 1234)
46
+ body = CGI.parse(subject.request.body)
47
+
48
+ body["message"].to_s.should == "Some message"
49
+ body["id"].to_s.should == "1234"
50
+ end
51
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: post_commit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
@@ -42,6 +42,7 @@ files:
42
42
  - lib/post_commit/hooks/friend_feed.rb
43
43
  - lib/post_commit/hooks/light_house.rb
44
44
  - lib/post_commit/hooks/twitter.rb
45
+ - lib/post_commit/hooks/url.rb
45
46
  - lib/post_commit/version.rb
46
47
  - spec/post_commit/base_spec.rb
47
48
  - spec/post_commit/basecamp_spec.rb
@@ -49,6 +50,7 @@ files:
49
50
  - spec/post_commit/friend_feed_spec.rb
50
51
  - spec/post_commit/light_house_spec.rb
51
52
  - spec/post_commit/twitter_spec.rb
53
+ - spec/post_commit/url_spec.rb
52
54
  - spec/resources/controllers.rb
53
55
  - spec/resources/responses/campfire.json
54
56
  - spec/resources/responses/friendfeed.json
@@ -90,5 +92,6 @@ test_files:
90
92
  - spec/post_commit/friend_feed_spec.rb
91
93
  - spec/post_commit/light_house_spec.rb
92
94
  - spec/post_commit/twitter_spec.rb
95
+ - spec/post_commit/url_spec.rb
93
96
  - spec/resources/controllers.rb
94
97
  - spec/spec_helper.rb