Permalink
Browse files

update to post all events to a single configurable bucket

  • Loading branch information...
1 parent cda86e5 commit d7b4b35cdc435e43659d8f45f336c9eb7fbed076 @fredrocious fredrocious committed May 3, 2013
Showing with 37 additions and 16 deletions.
  1. +11 −7 docs/simperium
  2. +18 −5 lib/services/simperium.rb
  3. +8 −4 test/simperium_test.rb
View
18 docs/simperium
@@ -1,21 +1,25 @@
-This service creates a Simperium object for hook events in a bucket named
-for the event type.
+This service posts an event object for Github events to a Simperium app.
+A Simperium object is created for each hook event in a bucket you choose.
Supported events are currently:
'push', 'issues', 'issue_comment', 'commit_comment', 'pull_request',
'pull_request_review_comment', 'watch', 'fork', 'fork_apply',
'member', 'public', 'team_add', 'status'
-More details on Github events: http://developer.github.com/v3/repos/hooks/
-
Simperium IDs:
-'push' - Each object ID will be the SHA of the commit (eg. '06f63b43050935962f84fe54473a7c5de7977325')
-all others - Each object ID will be a Unix timestamp (eg. '1367458703')
+Each object ID will be a guid, eg. 'guid-0.3939192'
+
+Data:
+'event' - The github event type, eg. 'push' for commits
+'payload' - The data for the event, varies by event type.
+
+More details on Github events: http://developer.github.com/v3/repos/hooks/
-Instal Notes
+Install Notes
------------
App ID: Your Simperium app id created on https://simperium.com/dashboard
Token: You'll need to generate an access token for a specific user (not an API key)
+Bucket: Name of the bucket you want events posted to
See https://simperium.com/docs/reference/http/#auth for more details on Simperium authentication.
View
23 lib/services/simperium.rb
@@ -1,7 +1,7 @@
class Service::Simperium < Service::HttpPost
- string :app_id, :token
+ string :app_id, :token, :bucket
- white_list :app_id
+ white_list :app_id, :bucket
default_events :push, :issues, :issue_comment, :commit_comment,
:pull_request, :pull_request_review_comment, :watch, :fork,
@@ -20,12 +20,25 @@ class Service::Simperium < Service::HttpPost
def receive_event
appid = required_config_value('app_id')
token = required_config_value('token')
+ bucket = required_config_value('bucket')
- wrap_http_errors do
- url = set_url "https://api.simperium.com/1/#{appid}/#{event.to_s}/i/"
- http.headers['X-Simperium-Token'] = token
+ if appid.match(/^[A-Za-z0-9-]+$/) == nil
+ raise_config_error "Invalid app id"
+ end
+
+ if token.match(/^[A-Za-z0-9]+$/) == nil
+ raise_config_error "Invalid token"
+ end
+ if bucket.match(/^[A-Za-z0-9\-\.@]+$/) == nil
+ raise_config_error "Invalid bucket name"
+ end
+
+ wrap_http_errors do
body = encode_body
+ url = set_url "https://api.simperium.com:443/1/#{appid}/#{bucket}/i/#{delivery_guid}"
+ http.headers['Authorization'] = "Token #{token}"
+
http_post(url, body)
end
end
View
12 test/simperium_test.rb
@@ -6,27 +6,31 @@ class SimperiumTest < Service::TestCase
def test_push
test_app_id = "sample-app-name"
test_token = "0123456789abcde"
+ test_bucket = "github-event"
data = {
'app_id' => test_app_id,
- 'token' => test_token
+ 'token' => test_token,
+ 'bucket' => test_bucket
}
payload = {'commits'=>[{'id'=>'test'}]}
- @stubs.post "/1/#{test_app_id}/push/i" do |env|
+ svc = service(data, payload)
+
+ @stubs.post "/1/#{test_app_id}/#{test_bucket}/i/#{svc.delivery_guid}" do |env|
body = JSON.parse(env[:body])
assert_equal env[:url].host, "api.simperium.com"
- assert_equal env[:request_headers]['X-Simperium-Token'], test_token
+ assert_equal env[:request_headers]['Authorization'], "Token #{test_token}"
assert_equal 'test', body['payload']['commits'][0]['id']
assert_match 'guid-', body['guid']
assert_equal data, body['config']
assert_equal 'push', body['event']
[200, {}, '']
end
- svc = service(data, payload)
svc.receive_event
+ @stubs.verify_stubbed_calls
end
def service_class

0 comments on commit d7b4b35

Please sign in to comment.