heracles-wrapper 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -28,9 +28,9 @@ Once installed in your application use rails generate:
28
28
 
29
29
  Heracles::Wrapper.service(
30
30
  :create_job,
31
- :workflow_name => 'RabbitWarren',
31
+ :workflow_name => <WORKFLOW_NAME>,
32
32
  :parameters => {
33
- :callback_url => 'http://google.com'
33
+ :notification_url => 'http://google.com'
34
34
  }
35
35
  )
36
36
 
@@ -43,9 +43,9 @@ Once installed in your application use rails generate:
43
43
  let(:service) {
44
44
  Heracles::Wrapper.service(
45
45
  :create_job,
46
- :workflow_name => 'RabbitWarren',
46
+ :workflow_name => <WORKFLOW_NAME>,
47
47
  :parameters => {
48
- :callback_url => 'http://google.com'
48
+ :notification_url => 'http://google.com'
49
49
  }
50
50
  )
51
51
  }
@@ -1,3 +1,4 @@
1
+ require 'active_support/core_ext/hash/indifferent_access'
1
2
  require 'method_decorators'
2
3
  require 'method_decorators/decorators/precondition'
3
4
 
@@ -19,8 +20,9 @@ class Heracles::Wrapper::NotificationResponse
19
20
  params[:job_status] &&
20
21
  params[:notification_payload].respond_to?(:to_hash)
21
22
  }
22
- def initialize(params)
23
- @notification_payload = params.fetch(:notification_payload).to_hash
23
+ def initialize(raw_params)
24
+ params = HashWithIndifferentAccess.new(raw_params)
25
+ @notification_payload = HashWithIndifferentAccess.new(params.fetch(:notification_payload))
24
26
  @job_id = params.fetch(:job_id).to_i
25
27
  @job_status = params.fetch(:job_status).to_sym
26
28
  @one_time_notification_key = params.fetch(:one_time_notification_key, nil)
@@ -44,22 +44,25 @@ class Heracles::Wrapper::Request::CreateJob
44
44
  # Hits a given URL
45
45
  # Syncrhonously waits for response.
46
46
  def call
47
- decorate_response(
48
- RestClient.post(
49
- url.to_s,
50
- as_json,
51
- {
52
- :content_type => :json,
53
- :accept => :json,
54
- :verify_ssl => OpenSSL::SSL::VERIFY_NONE
55
- }
56
- )
57
- )
47
+ request_decorator.call(make_request)
58
48
  rescue RestClient::Exception => e
59
49
  raise Heracles::Wrapper::RequestFailure.new(e.response)
60
50
  end
61
51
  protected
62
- def decorate_response(response)
63
- Heracles::Wrapper::RequestSuccess.new(response)
52
+
53
+ def make_request
54
+ RestClient.post(
55
+ url.to_s,
56
+ as_json,
57
+ {
58
+ :content_type => :json,
59
+ :accept => :json,
60
+ :verify_ssl => OpenSSL::SSL::VERIFY_NONE
61
+ }
62
+ )
63
+ end
64
+
65
+ def request_decorator
66
+ Heracles::Wrapper::RequestSuccess.method(:new)
64
67
  end
65
68
  end
@@ -1,5 +1,5 @@
1
1
  module Heracles
2
2
  module Wrapper
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -10,8 +10,7 @@ class <%= class_name %> < DelegateClass(Heracles::Wrapper::NotificationResponse)
10
10
  # The following two lines are logically equivalent
11
11
  # @pid = fetch(:pid)
12
12
  # @pid = params.fetch(:notification_payload).fetch(:pid)
13
- #
14
- # You may also want to define, at the class level the following:
15
- # attr_reader :pid
16
13
  end
14
+ # You may also want to define, at the class level the following:
15
+ # attr_reader :pid
17
16
  end
@@ -25,7 +25,9 @@ describe <%= class_name %> do
25
25
  end
26
26
  it 'should behave as a the :notification_payload hash' do
27
27
  subject[:hello].should == params[:notification_payload][:hello]
28
+ subject['hello'].should == params[:notification_payload][:hello]
28
29
  subject.fetch(:hello).should == params[:notification_payload][:hello]
30
+ subject.fetch('hello').should == params[:notification_payload][:hello]
29
31
  end
30
32
  end
31
33
  end
@@ -8,10 +8,12 @@ describe Heracles::Wrapper::NotificationResponse do
8
8
  describe 'well formed response' do
9
9
  let(:expected_job_status) { 'ok'}
10
10
  let(:expected_job_id) { '1234' }
11
+ let(:expected_one_time_notification_key) { '1234' }
11
12
  let(:params) {
12
13
  {
13
14
  :job_id => expected_job_id,
14
15
  :job_status => expected_job_status,
16
+ :one_time_notification_key => expected_one_time_notification_key,
15
17
  :notification_payload => {
16
18
  :hello => { :world => [{:foo => 1},{:foo => 2},{:bar => 3}]}
17
19
  }
@@ -20,8 +22,11 @@ describe Heracles::Wrapper::NotificationResponse do
20
22
 
21
23
  it 'should extract methods based on keys' do
22
24
  subject.must_respond_to :fetch
25
+ subject.fetch('hello').must_equal(subject.fetch(:hello))
23
26
  subject.fetch(:hello).must_equal(
24
- params.fetch(:notification_payload).fetch(:hello)
27
+ HashWithIndifferentAccess.new(
28
+ params.fetch(:notification_payload).fetch(:hello)
29
+ )
25
30
  )
26
31
  end
27
32
 
@@ -32,7 +37,7 @@ describe Heracles::Wrapper::NotificationResponse do
32
37
  subject.job_id.must_equal expected_job_id.to_i
33
38
  end
34
39
 
35
- it 'should have #one_time_key' do
40
+ it 'should have #one_time_notification_key' do
36
41
  subject.must_respond_to :one_time_notification_key
37
42
  end
38
43
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heracles-wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-09 00:00:00.000000000 Z
12
+ date: 2012-11-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -193,7 +193,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
193
193
  version: '0'
194
194
  segments:
195
195
  - 0
196
- hash: 3196260337063136150
196
+ hash: -1695767987685687120
197
197
  required_rubygems_version: !ruby/object:Gem::Requirement
198
198
  none: false
199
199
  requirements:
@@ -202,7 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
202
  version: '0'
203
203
  segments:
204
204
  - 0
205
- hash: 3196260337063136150
205
+ hash: -1695767987685687120
206
206
  requirements: []
207
207
  rubyforge_project:
208
208
  rubygems_version: 1.8.24