Permalink
Browse files

Trajectory and test

  • Loading branch information...
1 parent 825d6a5 commit de0445ee91f8ddf75f7a7ad92edd6b4e640ad558 @KensoDev KensoDev committed Jan 1, 2012
Showing with 34 additions and 0 deletions.
  1. +13 −0 services/trajectory.rb
  2. +21 −0 test/trajectory_test.rb
View
@@ -0,0 +1,13 @@
+class Service::Trajectory < Service
+ string :api_key
+
+ def receive_push
+ raise_config_error "Missing 'api_key'" if data['api_key'].to_s == ''
+
+ res = http_post "https://www.apptrajectory.com/api/payloads?api_key=#{data['api_key'].to_s}", JSON.generate(payload)
+
+ if res.status < 200 || res.status > 299
+ raise_config_error
+ end
+ end
+end
View
@@ -0,0 +1,21 @@
+require File.expand_path('../helper', __FILE__)
+
+class TrajectoryTest < Service::TestCase
+ def setup
+ @stubs = Faraday::Adapter::Test::Stubs.new
+ end
+
+ def test_push
+ @stubs.post '/api/payloads?api_key=test_api_key' do |env|
+ assert_equal 'application/json', env[:request_headers]['Content-Type']
+ [200, {}, '']
+ end
+
+ svc = service({'api_key' => 'test_api_key'})
+ svc.receive_push
+ end
+
+ def service(*args)
+ super Service::Trajectory, *args
+ end
+end

0 comments on commit de0445e

Please sign in to comment.