Permalink
Browse files

Implement new service hook: RapidPush

  • Loading branch information...
1 parent e1e828f commit f21dfedd7f34933987bc2fd4e3ef7c269a79dff1 @prdatur prdatur committed Feb 13, 2013
Showing with 68 additions and 0 deletions.
  1. +9 −0 docs/rapidpush
  2. +35 −0 lib/services/rapidpush.rb
  3. +24 −0 test/rapidpush_test.rb
View
9 docs/rapidpush
@@ -0,0 +1,9 @@
+RapidPush is an easy-to-use push notification service.
+You can receive notifications from third-party applications like nagios, github or flexget directly to your smartphone.
+
+Install Notes
+-------------
+1. Get an account at https://rapidpush.net/signup
+2. Install the RapidPush Android App through the Google Play Store and login to your created account
+3. Generate an API-Key within the user interface under the API-Key tab and provide this key to the GitHub RapidPush service hook
+4. Finished, you can now receive the notifications
View
35 lib/services/rapidpush.rb
@@ -0,0 +1,35 @@
+class Service::RapidPush < Service
+ string :apikey
+ self.title = 'RapidPush'
+ url "http://rapidpush.net"
+ logo_url "http://rapidpush.net/templates/rapidpush/images/logo.png"
+
+ # PrDatur on GitHub is pinged for any bugs with the Hook code.
+ maintained_by :github => 'prdatur'
+
+ # Support channels for user-level Hook problems (service failure,
+ # misconfigured
+ supported_by :web => 'http://rapidpush.net/admin/content/view/9',
+ :email => 'info@rapidpush.net'
+
+ def receive_push
+ return unless payload['commits']
+
+ url = URI.parse('https://rapidpush.net/api')
+ repository = payload['repository']['url'].split("/")
+ title = [repository[-2], repository[-1]].join('/')
+ category = "GitHub"
+ message = "#{payload['commits'].length} commits pushed to #{category} (#{payload['commits'][-1]['id'][0..7]}..#{payload['commits'][0]['id'][0..7]})<br/>
+<br/>
+Latest Commit by #{payload['commits'][-1]['author']['name']}<br/>
+#{payload['commits'][-1]['id'][0..7]} #{payload['commits'][-1]['message']}<br/>
+<br/>
+<a href='#{payload['compare']}'>URL</a>"
+
+ http_post 'https://rapidpush.net/api',
+ :apikey => data['apikey'],
+ :category => category,
+ :title => title,
+ :message => message
+ end
+end
View
24 test/rapidpush_test.rb
@@ -0,0 +1,24 @@
+require File.expand_path('../helper', __FILE__)
+
+class RapidPushTest < Service::TestCase
+ def setup
+ @stubs = Faraday::Adapter::Test::Stubs.new
+ end
+
+ def test_push
+ @stubs.post "/api" do |env|
+ assert_equal 'rapidpush.net', env[:url].host
+ data = Rack::Utils.parse_query(env[:body])
+ assert_equal 'a', data['apikey']
+ [200, {}, '']
+ end
+
+ svc = service({'apikey' => 'a'}, payload)
+ svc.receive_push
+ end
+
+ def service(*args)
+ super Service::RapidPush, *args
+ end
+end
+

0 comments on commit f21dfed

Please sign in to comment.