Permalink
Browse files

Fix Pushalot service to accept untouched payload

  • Loading branch information...
1 parent e2d782f commit 4fd2c95ee9496b537aa06fbf642195fb64a4b4cf Maciej Olesiński committed Mar 23, 2013
Showing with 40 additions and 44 deletions.
  1. +3 −3 docs/pushalot
  2. +14 −30 lib/services/pushalot.rb
  3. +23 −11 test/pushalot_test.rb
View
@@ -1,14 +1,14 @@
Pushalot
========
-Pushalot is a platform for receiving custom push notifications to connected devices running Windows Phone or Windows 8. Custom means that those push notifications can be sent from virtually any source, as long as that source can interact with our open [REST API](http://pushalot.com/api).
+Pushalot is a platform for receiving custom push notifications to connected devices running Windows Phone or Windows 8. Custom means that those push notifications can be sent from virtually any source, as long as that source can interact with our open [REST API](https://pushalot.com/api).
Install Notes
-------------
-1. Install the [Windows 8 app](http://pushalot.com/apps) from the Windows Store, or the [Windows Phone app](http://pushalot.com/apps) from the Windows Phone Apps+Games Store.
+1. Install the [Windows 8 app](https://pushalot.com/apps) from the Windows Store, or the [Windows Phone app](https://pushalot.com/apps) from the Windows Phone Apps+Games Store.
-2. Sign in to [Pushalot](http://pushalot.com/) and copy your authorization token.
+2. Sign in to [Pushalot](https://pushalot.com/) and copy your authorization token.
3. Add your authorization token in the field above.
View
@@ -1,39 +1,23 @@
class Service::Pushalot < Service
string :authorization_token
- def receive_push
- if !payload["commits"].any?
- return
- end
-
- if !data["authorization_token"] or data["authorization_token"].length != 32
- raise_config_error "Invalid Pushalot authorization token."
- end
-
- url = URI.parse("https://pushalot.com/api/sendmessage")
+ url "https://pushalot.com"
+ logo_url "https://pushalot.com/content/images/favicon.png"
+ maintained_by :github => 'molesinski'
+ supported_by :web => 'https://pushalot.com/support'
- 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 > 1000
- latest_message = latest_message[0 ... 997] + "..."
- end
- latest_url = shorten_url(payload["commits"].last["url"])
+ def receive_push
+ res = http_post "https://pushalot.com/api/githubhook",
+ :authorizationToken => authorization_token,
+ :payload => payload.to_json
- 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}"
+ if res.status != 200
+ raise_config_error
end
+ end
- http_post url.to_s,
- :AuthorizationToken => data["authorization_token"],
- :Title => title,
- :Body => message,
- :Link => latest_url,
- :LinkTitle => "View commit on GitHub"
+ def authorization_token
+ data["authorization_token"].to_s.strip
end
end
+
View
@@ -3,27 +3,39 @@
class PushalotTest < Service::TestCase
def setup
@stubs = Faraday::Adapter::Test::Stubs.new
+ @svc = service(data, payload)
end
- def test_push
- svc = service({"authorization_token" => "be82304d88d74eb884e384a98a282b8a"}, payload)
+ def test_reads_token_from_data
+ assert_equal "be82304d88d74eb884e384a98a282b8a", @svc.authorization_token
+ end
- def svc.shorten_url(*args)
- "short"
- end
+ def test_strips_whitespace_from_token
+ svc = service({'authorization_token' => 'be82304d88d74eb884e384a98a282b8a '}, payload)
+ assert_equal 'be82304d88d74eb884e384a98a282b8a', svc.authorization_token
+ end
- @stubs.post "/api/sendmessage" do |env|
- assert_equal "pushalot.com", env[:url].host
+ def test_posts_payload
+ @stubs.post '/api/githubhook' do |env|
+ assert_equal 'https', env[:url].scheme
+ assert_equal 'pushalot.com', env[:url].host
data = Rack::Utils.parse_query(env[:body])
- assert_equal "be82304d88d74eb884e384a98a282b8a", data["AuthorizationToken"]
- [200, {}, '']
+ assert_equal "be82304d88d74eb884e384a98a282b8a", data["authorizationToken"]
+ assert_equal payload, JSON.parse(data['payload'])
end
- svc.receive_push
+ @svc.receive_push
end
+private
+
def service(*args)
super Service::Pushalot, *args
end
-end
+
+ def data
+ { 'authorization_token' => 'be82304d88d74eb884e384a98a282b8a' }
+ end
+
+end

0 comments on commit 4fd2c95

Please sign in to comment.