Added Agile Bench to the list of service hooks #272

Merged
merged 5 commits into from Apr 11, 2012
View
21 docs/agile_bench
@@ -0,0 +1,21 @@
+Agile Bench
+===========
+
+[Agile Bench](http://agilebench.com/) is planning software for agile teams with backlog management and story walls.
+
+Install Notes
+-------------
+ 1. **token** - is a user's API token. Get it from your Agile Bench's user settings page.
+
+ 2. **project_id** - can be found in your Agile Bench project URL. i.e. if the URL is http://agilebench.com/projects/3000-my-project, then the project id will be 3000.
+
+Git Commit example: `$ git commit -am "[Fixes #5 #6] Added even more documentation"` - will add _"Added even more documentation"_ to stories #5 and #6 and move stories #5 & #6 into the last (the fixed!) workflow state.
+
+Developer Notes
+---------------
+data
+ - token
+ - project_id
+
+payload
+ - refer to docs/github_payload
View
46 services/agile_bench.rb
@@ -0,0 +1,46 @@
+class Service::AgileBench < Service
+ string :token, :project_id
+
+ def receive_push
+ ensure_required_data
+ post_to_agile_bench
+ verify_response
+ end
+
+ protected
+ def ensure_required_data
+ raise_config_error "Token is required" if !token.present?
+ raise_config_error "Project ID is required" if !project_id.present?
+ end
+
+ def post_to_agile_bench
+ @response = http_post "http://agilebench.com/services/v1/github" do |req|
+ req.headers['Content-Type'] = 'application/json'
+ req.body = JSON.generate({
+ :payload => payload,
+ :data => {
+ :project_id => project_id,
+ :token => token
+ }
+ })
+ end
+ end
+
+ def token
+ @token ||= data['token'].to_s.strip
+ end
+
+ def project_id
+ @project_id ||= data['project_id'].to_s.strip
+ end
+
+ def verify_response
+ case @response.status
+ when 200..299
+ when 403, 401, 422 then raise_config_error("Invalid Credentials")
+ when 404, 301, 302 then raise_config_error("Invalid URL")
+ else raise_config_error("HTTP: #{@response.status}")
+ end
+ end
+end
+
View
43 test/agile_bench_test.rb
@@ -0,0 +1,43 @@
+require File.expand_path('../helper', __FILE__)
+
+class AgileBenchTest < Service::TestCase
+ def setup
+ @stubs = Faraday::Adapter::Test::Stubs.new
+ end
+
+ def test_push
+ @stubs.post "/services/v1/github" do |env|
+ assert_equal 'agilebench.com', env[:url].host
+ assert_equal 'application/json',
+ env[:request_headers]['Content-type']
+ [200, {}, '']
+ end
+
+ svc = service({'token' => 'test_token', 'project_id' => '123'},
+ payload)
+ svc.receive_push
+ end
+
+ def test_missing_token
+ @stubs.post "/services/v1/github"
+ svc = service({'token' => '', 'project_id' => '123'},
+ payload)
+ assert_raise Service::ConfigurationError do
+ svc.receive_push
+ end
+ end
+
+ def test_missing_project_id
+ @stubs.post "/services/v1/github"
+ svc = service({'token' => 'test_token', 'project_id' => ''},
+ payload)
+ assert_raise Service::ConfigurationError do
+ svc.receive_push
+ end
+ end
+
+ def service(*args)
+ super Service::AgileBench, *args
+ end
+end
+