Permalink
Browse files

Create a Service Hook for Jeapie

  • Loading branch information...
1 parent a2d0abf commit 39300b62dd2d0cd48c5f431eb653ed184352ad84 test committed Aug 1, 2013
Showing with 84 additions and 0 deletions.
  1. +18 −0 docs/jeapie
  2. +37 −0 lib/services/jeapie.rb
  3. +29 −0 test/jeapie_test.rb
View
@@ -0,0 +1,18 @@
+Jeapie
+========
+
+Jeapie is a platform for building mobile notifications subscription. We provide Jeapie mobile apps to receive and store push notifications from many services including GitHub. Also you can create you own providers. [Jeapie site](http://jeapie.com/).
+
+Install Notes
+-------------
+
+1. Sign up in [Dashboard](http://dashboard.jeapie.com) and create your notification provider. Copy the provider token. You can invite team-members to subscribe on this provider.
+
+2. Install the [iOS client](http://jeapie.com/en/site/start) from the App Store, or the [Android client](http://jeapie.com/en/site/start) from the Google Play.
+
+3. Login to Jeapie app using your Dashboard login and password.
+
+3. Add your provider token in the field above. After that all of the subscribers including you will get notified about every commit in the repository.
+
+
+Get your productivity on the next level!
View
@@ -0,0 +1,37 @@
+class Service::Jeapie < Service
+ string :token
+
+ def receive_push
+ if !payload["commits"].any?
+ return
+ end
+
+ if !data["token"]
+ raise_config_error "Invalid Jeapie token."
+ end
+
+ url = URI.parse("https://api.jeapie.com/v1/broadcast/send/message.json")
+
+ commits = payload["commits"].length
+ repo = payload["repository"]["url"].split("/")[-2 .. -1].join("/")
+ latest_message = payload["commits"].last["message"].split("\n").first
+ if latest_message.length > 300
+ latest_message = latest_message[0 ... 296] + "[..]"
+ end
+ latest_url = shorten_url(payload["commits"].last["url"])
+
+ if commits == 1
+ title = "#{payload["pusher"]["name"]} pushed to #{repo}"
+ message = latest_message
+ else
+ title = "#{payload["pusher"]["name"]} pushed #{commits} " +
+ "commit#{commits == 1 ? '' : 's'} to #{repo}"
+ message = "Latest: #{latest_message}"
+ end
+
+ http_post url.to_s,
+ :token => data["token"],
+ :title => title,
+ :message => message,
+ end
+end
View
@@ -0,0 +1,29 @@
+require File.expand_path('../helper', __FILE__)
+
+class JeapieTest < Service::TestCase
+ def setup
+ @stubs = Faraday::Adapter::Test::Stubs.new
+ end
+
+ def test_push
+ svc = service({"token" => "a"}, payload)
+
+ def svc.shorten_url(*args)
+ "short"
+ end
+
+ @stubs.post "/v1/broadcast/send/message.json" do |env|
+ assert_equal "api.jeapie.com", env[:url].host
+ data = Faraday::Utils.parse_query(env[:body])
+ assert_equal "a", data["token"]
+ [200, {}, '']
+ end
+
+ svc.receive_push
+ end
+
+ def service(*args)
+ super Service::Jeapie, *args
+ end
+end
+

0 comments on commit 39300b6

Please sign in to comment.