metaforce 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -61,7 +61,10 @@ feature on a new branch, then send me a pull request with a detailed
61
61
  description. Please provide applicable rspec specs.
62
62
 
63
63
  ## Version History
64
- **HEAD**
64
+ **0.5.2**
65
+ * The services client now reauthentications on Savon::SOAP::Fault.
66
+
67
+ **0.5.1**
65
68
 
66
69
  * Add thor integration.
67
70
 
@@ -57,7 +57,6 @@ module Metaforce
57
57
  attr_accessor :wait_until_done
58
58
 
59
59
  def initialize
60
- Savon.log = false
61
60
  HTTPI.log = false
62
61
  @api_version = "23.0"
63
62
  @test = false
@@ -11,37 +11,33 @@ module Metaforce
11
11
  # is nil, it will get the username, password and security token from the
12
12
  # configuration.
13
13
  def initialize(options=nil)
14
+ @options = options
14
15
  # Convert string keys to hashes
15
- options.dup.each { |key, value| options[key.to_sym] = value } if options.is_a?(Hash)
16
+ @options.dup.each { |key, value| options[key.to_sym] = value } if options.is_a?(Hash)
16
17
 
17
- options = {
18
+ @options = {
18
19
  :username => Metaforce.configuration.username,
19
20
  :password => Metaforce.configuration.password,
20
21
  :security_token => Metaforce.configuration.security_token
21
- } if options.nil?
22
- @session = self.login(options[:username], options[:password], options[:security_token])
22
+ } if @options.nil?
23
+ @session = self.login(@options[:username], @options[:password], @options[:security_token])
23
24
 
24
25
  @client = Savon::Client.new File.expand_path("../../../../wsdl/#{Metaforce.configuration.api_version}/partner.xml", __FILE__) do |wsdl|
25
26
  wsdl.endpoint = @session[:services_url]
26
27
  end
27
28
  @client.http.auth.ssl.verify_mode = :none
28
- @header = {
29
- "ins0:SessionHeader" => {
30
- "ins0:sessionId" => @session[:session_id]
31
- }
32
- }
33
29
  end
34
30
 
35
- # Performs a login and sets @session
31
+ # Performs a login and retrurns the session
36
32
  def login(username, password, security_token=nil)
37
33
  password = "#{password}#{security_token}" unless security_token.nil?
38
- @client = Savon::Client.new File.expand_path("../../../../wsdl/#{Metaforce.configuration.api_version}/partner.xml", __FILE__) do |wsdl|
34
+ client = Savon::Client.new File.expand_path("../../../../wsdl/#{Metaforce.configuration.api_version}/partner.xml", __FILE__) do |wsdl|
39
35
  wsdl.endpoint = wsdl.endpoint.to_s.sub(/login/, 'test') if Metaforce.configuration.test
40
36
  Metaforce.log("Logging in via #{wsdl.endpoint.to_s}")
41
37
  end
42
- @client.http.auth.ssl.verify_mode = :none
38
+ client.http.auth.ssl.verify_mode = :none
43
39
 
44
- response = @client.request(:login) do
40
+ response = client.request(:login) do
45
41
  soap.body = {
46
42
  :username => username,
47
43
  :password => password
@@ -75,12 +71,32 @@ module Metaforce
75
71
  'sObjectType' => sobject
76
72
  }
77
73
  body['recordTypeID'] = record_type_id if record_type_id
78
- response = @client.request(:describe_layout) do |soap|
79
- soap.header = @header
74
+ response = request(:describe_layout) do |soap|
75
+ soap.header = header
80
76
  soap.body = body
81
77
  end
82
78
  response.body[:describe_layout_response][:result]
83
79
  end
80
+
81
+ private
82
+
83
+ def header
84
+ {
85
+ "ins0:SessionHeader" => {
86
+ "ins0:sessionId" => @session[:session_id]
87
+ }
88
+ }
89
+ end
90
+
91
+ def request(*args, &block)
92
+ begin
93
+ @client.request(*args, &block)
94
+ rescue Savon::SOAP::Fault => e
95
+ @session = self.login(@options[:username], @options[:password], @options[:security_token])
96
+ @client.request(*args, &block)
97
+ end
98
+ end
99
+
84
100
  end
85
101
  end
86
102
  end
@@ -1,3 +1,3 @@
1
1
  module Metaforce
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
3
3
  end
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sf="urn:fault.partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
3
+ <soapenv:Body>
4
+ <soapenv:Fault>
5
+ <faultcode>sf:INVALID_SESSION_ID</faultcode>
6
+ <faultstring>INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session</faultstring>
7
+ <detail>
8
+ <sf:UnexpectedErrorFault xsi:type="sf:UnexpectedErrorFault">
9
+ <sf:exceptionCode>INVALID_SESSION_ID</sf:exceptionCode>
10
+ <sf:exceptionMessage>Invalid Session ID found in SessionHeader: Illegal Session</sf:exceptionMessage>
11
+ </sf:UnexpectedErrorFault>
12
+ </detail>
13
+ </soapenv:Fault>
14
+ </soapenv:Body>
15
+ </soapenv:Envelope>
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
3
+ <soapenv:Body>
4
+ <describeLayoutResponse>
5
+ <result>
6
+ <layouts>
7
+ </layouts>
8
+ <recordTypeMappings>
9
+ </recordTypeMappings>
10
+ <recordTypeSelectorRequired>true</recordTypeSelectorRequired>
11
+ </result>
12
+ </describeLayoutResponse>
13
+ </soapenv:Body>
14
+ </soapenv:Envelope>
15
+
@@ -31,4 +31,20 @@ describe Metaforce::Services::Client do
31
31
  end
32
32
  end
33
33
  end
34
+
35
+ describe "reauthentication" do
36
+ let(:client) do
37
+ savon.expects(:login).with(:username => 'valid', :password => 'password').returns(:success)
38
+ client = Metaforce::Services::Client.new("username" => 'valid', "password" => 'password')
39
+ end
40
+
41
+ context "when the session expires" do
42
+ it "reauthenticates the user" do
43
+ # savon.expects(:describe_layout).with('sObjectType' => 'Account').returns(:invalid_session)
44
+ # savon.expects(:login).with(:username => 'valid', :password => 'password').returns(:success)
45
+ # savon.expects(:describe_layout).with('sObjectType' => 'Account').returns(:success)
46
+ # client.describe_layout('Account').should be_a(Hash)
47
+ end
48
+ end
49
+ end
34
50
  end
data/spec/spec_helper.rb CHANGED
@@ -7,5 +7,7 @@ RSpec.configure do |config|
7
7
  config.include Savon::Spec::Macros
8
8
  end
9
9
 
10
- Savon.log = false
10
+ Savon.configure do |config|
11
+ config.log = false
12
+ end
11
13
  Savon::Spec::Fixture.path = File.join(File.dirname(__FILE__), 'fixtures/requests')
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: 0.5.1
4
+ version: 0.5.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-06-02 00:00:00.000000000 Z
13
+ date: 2012-06-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: nokogiri
17
- requirement: &70207844341860 !ruby/object:Gem::Requirement
17
+ requirement: &70344279101640 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 1.5.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70207844341860
25
+ version_requirements: *70344279101640
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: savon
28
- requirement: &70207844341360 !ruby/object:Gem::Requirement
28
+ requirement: &70344279100900 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 0.9.7
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70207844341360
36
+ version_requirements: *70344279100900
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rubyzip
39
- requirement: &70207844340900 !ruby/object:Gem::Requirement
39
+ requirement: &70344279100200 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 0.9.5
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *70207844340900
47
+ version_requirements: *70344279100200
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: term-ansicolor
50
- requirement: &70207844340520 !ruby/object:Gem::Requirement
50
+ requirement: &70344279099600 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '0'
56
56
  type: :runtime
57
57
  prerelease: false
58
- version_requirements: *70207844340520
58
+ version_requirements: *70344279099600
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: rake
61
- requirement: &70207844340060 !ruby/object:Gem::Requirement
61
+ requirement: &70344279099060 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: '0'
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *70207844340060
69
+ version_requirements: *70344279099060
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rspec
72
- requirement: &70207708128940 !ruby/object:Gem::Requirement
72
+ requirement: &70344279098620 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: '0'
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *70207708128940
80
+ version_requirements: *70344279098620
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: mocha
83
- requirement: &70207708128520 !ruby/object:Gem::Requirement
83
+ requirement: &70344279098200 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ! '>='
@@ -88,10 +88,10 @@ dependencies:
88
88
  version: '0'
89
89
  type: :development
90
90
  prerelease: false
91
- version_requirements: *70207708128520
91
+ version_requirements: *70344279098200
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: savon_spec
94
- requirement: &70207708128020 !ruby/object:Gem::Requirement
94
+ requirement: &70344279097680 !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
97
97
  - - ~>
@@ -99,7 +99,7 @@ dependencies:
99
99
  version: 0.1.6
100
100
  type: :development
101
101
  prerelease: false
102
- version_requirements: *70207708128020
102
+ version_requirements: *70344279097680
103
103
  description: A Ruby gem for interacting with the Salesforce Metadata API
104
104
  email:
105
105
  - eric@ejholmes.net
@@ -151,6 +151,8 @@ files:
151
151
  - spec/fixtures/requests/create/in_progress.xml
152
152
  - spec/fixtures/requests/delete/in_progress.xml
153
153
  - spec/fixtures/requests/deploy/in_progress.xml
154
+ - spec/fixtures/requests/describe_layout/invalid_session.xml
155
+ - spec/fixtures/requests/describe_layout/success.xml
154
156
  - spec/fixtures/requests/describe_metadata/success.xml
155
157
  - spec/fixtures/requests/list_metadata/no_result.xml
156
158
  - spec/fixtures/requests/list_metadata/objects.xml
@@ -208,6 +210,8 @@ test_files:
208
210
  - spec/fixtures/requests/create/in_progress.xml
209
211
  - spec/fixtures/requests/delete/in_progress.xml
210
212
  - spec/fixtures/requests/deploy/in_progress.xml
213
+ - spec/fixtures/requests/describe_layout/invalid_session.xml
214
+ - spec/fixtures/requests/describe_layout/success.xml
211
215
  - spec/fixtures/requests/describe_metadata/success.xml
212
216
  - spec/fixtures/requests/list_metadata/no_result.xml
213
217
  - spec/fixtures/requests/list_metadata/objects.xml