metaforce 1.0.6 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Metaforce
2
2
 
3
- [![travis-ci](https://secure.travis-ci.org/ejholmes/metaforce.png)](https://secure.travis-ci.org/ejholmes/metaforce) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/ejholmes/metaforce) [![Dependency Status](https://gemnasium.com/ejholmes/metaforce.png)](https://gemnasium.com/ejholmes/metaforce)
3
+ [![travis-ci](https://secure.travis-ci.org/ejholmes/metaforce.png)](https://secure.travis-ci.org/ejholmes/metaforce) [![Code Climate](https://codeclimate.com/github/ejholmes/metaforce.png)](https://codeclimate.com/github/ejholmes/metaforce) [![Dependency Status](https://gemnasium.com/ejholmes/metaforce.png)](https://gemnasium.com/ejholmes/metaforce)
4
4
 
5
5
  Metaforce is a Ruby gem for interacting with the Salesforce [Metadata](http://www.salesforce.com/us/developer/docs/api_meta/index.htm)
6
6
  and [Services](http://www.salesforce.com/us/developer/docs/api/index.htm) APIs.
@@ -36,17 +36,21 @@ module Metaforce
36
36
  # attempt to reauthenticate by called the reauthentication handler if
37
37
  # present.
38
38
  def request(*args, &block)
39
+ authenticate! unless session_id
40
+ retries = authentication_retries
39
41
  begin
40
- authenticate! unless session_id
41
- _request(*args, &block)
42
+ perform_request(*args, &block)
42
43
  rescue Savon::SOAP::Fault => e
43
- raise e unless e.message =~ /INVALID_SESSION_ID/ && authentication_handler
44
- authenticate!
45
- _request(*args, &block)
44
+ if e.message =~ /INVALID_SESSION_ID/ && authentication_handler && retries > 0
45
+ authenticate!
46
+ retries -= 1
47
+ retry
48
+ end
49
+ raise
46
50
  end
47
51
  end
48
52
 
49
- def _request(*args, &block)
53
+ def perform_request(*args, &block)
50
54
  response = client.request(*args, &block)
51
55
  Hashie::Mash.new(response.body)[:"#{args[0]}_response"].result
52
56
  end
@@ -54,7 +58,9 @@ module Metaforce
54
58
  # Internal Calls the authentication handler, which should set @options to a new
55
59
  # hash.
56
60
  def authenticate!
57
- authentication_handler.call(self, @options)
61
+ options = authentication_handler.call(self, @options)
62
+ @options.merge!(options)
63
+ client.config.soap_header = soap_headers
58
64
  end
59
65
 
60
66
  # A proc object that gets called when the client needs to reauthenticate.
@@ -62,6 +68,10 @@ module Metaforce
62
68
  Metaforce.configuration.authentication_handler
63
69
  end
64
70
 
71
+ def authentication_retries
72
+ 3
73
+ end
74
+
65
75
  # Internal: Soap headers to set for authenticate.
66
76
  def soap_headers
67
77
  { 'ins0:SessionHeader' => { 'ins0:sessionId' => session_id } }
@@ -66,7 +66,7 @@ module Metaforce
66
66
 
67
67
  def authentication_handler
68
68
  @authentication_handler ||= lambda { |client, options|
69
- options.merge!(Metaforce.login(options))
69
+ Metaforce.login(options)
70
70
  }
71
71
  end
72
72
 
@@ -1,3 +1,3 @@
1
1
  module Metaforce
2
- VERSION = '1.0.6'
2
+ VERSION = '1.0.7'
3
3
  end
@@ -19,7 +19,7 @@ shared_examples 'a client' do
19
19
 
20
20
  context 'and an authentication handler is present' do
21
21
  let(:handler) do
22
- proc { |client, options| options = { session_id: 'foo' } }
22
+ proc { |client, options| { :session_id => 'foo' } }
23
23
  end
24
24
 
25
25
  before do
@@ -32,6 +32,7 @@ shared_examples 'a client' do
32
32
  client.send(:client).should_receive(:request).once.and_return(response)
33
33
  handler.should_receive(:call).and_call_original
34
34
  client.send(:request, :foo)
35
+ expect(client.send(:client).config.soap_header).to eq("ins0:SessionHeader"=>{"ins0:sessionId"=>"foo"})
35
36
  end
36
37
  end
37
38
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metaforce
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-02-06 00:00:00.000000000 Z
13
+ date: 2013-04-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: savon
@@ -283,12 +283,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
283
283
  - - ! '>='
284
284
  - !ruby/object:Gem::Version
285
285
  version: '0'
286
+ segments:
287
+ - 0
288
+ hash: -4443080987431715085
286
289
  required_rubygems_version: !ruby/object:Gem::Requirement
287
290
  none: false
288
291
  requirements:
289
292
  - - ! '>='
290
293
  - !ruby/object:Gem::Version
291
294
  version: '0'
295
+ segments:
296
+ - 0
297
+ hash: -4443080987431715085
292
298
  requirements: []
293
299
  rubyforge_project: metaforce
294
300
  rubygems_version: 1.8.23
@@ -332,4 +338,3 @@ test_files:
332
338
  - spec/lib/services/client_spec.rb
333
339
  - spec/spec_helper.rb
334
340
  - spec/support/client.rb
335
- has_rdoc: