Skip to content
This repository was archived by the owner on Jun 6, 2018. It is now read-only.

Commit 73a15eb

Browse files
committed
Merge pull request #8 from leifg/custom_instance_name
Need support for custom salesforce instance names
2 parents 33f966f + dbb48de commit 73a15eb

4 files changed

Lines changed: 36 additions & 3 deletions

File tree

lib/executrix/helper.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,10 @@ def records_to_csv records
3232
end
3333
file_mock.string
3434
end
35+
36+
def fetch_instance_from_server_url server_url
37+
before_sf = server_url[/^https?:\/\/(.+)\.salesforce\.com/, 1]
38+
before_sf.gsub(/-api$/,'')
39+
end
3540
end
3641
end

lib/executrix/http.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def process_soap_response res
7777
raise raw_result[:fault][:faultstring] if raw_result[:fault]
7878

7979
login_result = raw_result[:login_response][:result]
80-
instance = login_result[:server_url][/^https?:\/\/(\w+)(-api)?/, 1]
80+
instance = Helper.fetch_instance_from_server_url(login_result[:server_url])
8181
login_result.merge(instance: instance)
8282
end
8383

@@ -112,7 +112,6 @@ def self.login sandbox, username, password, api_version
112112
'Content-Type' => 'text/xml; charset=utf-8',
113113
'SOAPAction' => 'login'
114114
}
115-
host = sandbox ? 'test.salesforce.com' : 'login.salesforce.com'
116115
Http::Request.new(
117116
:post,
118117
generic_host(sandbox ? 'test' : 'login'),

lib/executrix/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Executrix
2-
VERSION = '1.1.1'
2+
VERSION = '1.1.2'
33
end

spec/lib/executrix/helper_spec.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,33 @@
6161
expect(described_class.records_to_csv(input)).to eq(expected_csv)
6262
end
6363
end
64+
65+
describe '.fetch_instance_from_server_url' do
66+
let(:basic_api_server_url) {
67+
'https://cs7-api.salesforce.com/services/Soap/u/28.0/00CS00000095Y5b'
68+
}
69+
70+
let(:basic_server_url) {
71+
'https://eu1.salesforce.com/services/Soap/u/28.0/00EU00000096Y8c'
72+
}
73+
74+
let(:named_server_url) {
75+
'https://supercustomname.my.salesforce.com/services/Soap/u/28.0/00EH0000001jNQu'
76+
}
77+
78+
it 'should return correct instance for regular salesforce server url' do
79+
expect(described_class.fetch_instance_from_server_url(basic_server_url))
80+
.to eq('eu1')
81+
end
82+
83+
it 'should return correct instance for api salesforce server url' do
84+
expect(described_class.fetch_instance_from_server_url(basic_api_server_url))
85+
.to eq('cs7')
86+
end
87+
88+
it 'should return correct instance for named salesforce server url' do
89+
expect(described_class.fetch_instance_from_server_url(named_server_url))
90+
.to eq('supercustomname.my')
91+
end
92+
end
6493
end

0 commit comments

Comments
 (0)