salesforce_http_client 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6c38ff36a429e3f256e1afe166e9a3fb200c21a0
4
- data.tar.gz: 5e6e4e779c1cc7e7d9d105938b9a1f46ee455f89
3
+ metadata.gz: ca610c378d7eab64f6860210db9105cc791524d8
4
+ data.tar.gz: 0a35fb07028a40e27d7ec625f4e19d4b574b483d
5
5
  SHA512:
6
- metadata.gz: 137985ed6c8b5f5f95c741e973a01201dc4a8020cce47d70d4436a17a48c201817b276df545ed9b972f6d4d79d1e48cba96e6e1b2131a3c47c83550b96ed3d34
7
- data.tar.gz: 09827e7788467bf5f7670fa58d0fc9f613f5cc355045919c2b4e713c8861622c1f3546dd5927f62b28c2af9dd18d86f0bcf737ca057164eea53f136c7ef01791
6
+ metadata.gz: e9fa5620a4c8cceaf18fe01e7ec37de1982ad21287f4d678faf1092a457ebf5364010818fc44bf9be3f54852cf662570fc5a2236e101a68459461162004959a2
7
+ data.tar.gz: 7de758e095cd6bc8f4eb16b6fbb0353ba37000d7f1bb5d546c0c89a53a10f4a4bb9934e20a0648aab5dd7411976a9bb6d6e1cae2bbb417b1da504b5ef7985c0a
data/.gitignore CHANGED
@@ -14,7 +14,6 @@ rdoc
14
14
  spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
- tmp
18
17
  *.bundle
19
18
  *.so
20
19
  *.o
data/README.md CHANGED
@@ -3,9 +3,11 @@
3
3
  This gem provides a simple way to download report data from salesforce.com.
4
4
  It works well with any ruby applications, include such as Ruby on Rails.
5
5
 
6
- You can access salesfore.com using only your sales force login id (=email) and password.
6
+ You can access salesfore.com using only your salesforce login id (=email) and password.
7
7
  A security token is no need.
8
8
 
9
+ Data will be saved in CSV format.
10
+
9
11
  [![Gem Version](https://badge.fury.io/rb/salesforce_http_client.svg)](http://badge.fury.io/rb/salesforce_http_client)
10
12
  [![Build Status](https://travis-ci.org/apuruni/salesforce_http_client.svg?branch=master)](https://travis-ci.org/apuruni/salesforce_http_client)
11
13
  [![Coverage Status](https://coveralls.io/repos/apuruni/salesforce_http_client/badge.svg?branch=master)](https://coveralls.io/r/apuruni/salesforce_http_client?branch=master)
@@ -27,11 +29,18 @@ Or install it yourself as:
27
29
  ## Configuring SalesforceHttpClient
28
30
 
29
31
  Add configurations to set your salesforce.com login_id/password.
32
+ You must check your salesforce.com instance to get the right domain for your account.
33
+ For example: https://na12.salesforce.com/000000000000ABC, where 'http://na12.salesforce.com/' is the salesforce.com instance domain.
30
34
 
31
35
  ```ruby
36
+ require 'fileutils'
37
+ require 'httpclient'
38
+
32
39
  SalesforceHttpClient.configure do |config|
33
40
  config.salesforce_login_id = 'my_login_id_or_email'
34
41
  config.salesforce_password = 'my_password'
42
+ # this parameter must be set if you are not using the default (ap.salesforce.com) instance domain of this gem.
43
+ config.salesforce_instance_domain = 'https://na12.salesforce.com'
35
44
  end
36
45
  ```
37
46
 
@@ -15,6 +15,7 @@ module SalesforceHttpClient
15
15
  attr_accessor :salesforce_login_id
16
16
  attr_accessor :salesforce_password
17
17
 
18
+ attr_accessor :salesforce_instance_domain
18
19
  attr_accessor :salesforce_report_url_format
19
20
  attr_accessor :salesforce_report_id_param
20
21
 
@@ -29,10 +30,12 @@ module SalesforceHttpClient
29
30
  end
30
31
 
31
32
  def initialize
33
+ @salesforce_instance_domain = "https://ap.salesforce.com"
34
+
32
35
  @salesforce_login_url = "https://login.salesforce.com/"
33
- @salesforce_logout_url = "https://ap.salesforce.com/secur/logout.jsp"
36
+ @salesforce_logout_url = ->() { @salesforce_instance_domain + "/secur/logout.jsp" }
34
37
 
35
- @salesforce_report_url_format = 'https://ap.salesforce.com/#{report_id}?export=1&enc=UTF-8&xf=csv'
38
+ @salesforce_report_url_format = ->() { @salesforce_instance_domain + '/#{report_id}?export=1&enc=UTF-8&xf=csv' }
36
39
  @salesforce_report_id_param = '#{report_id}'
37
40
 
38
41
  @http_timeout = 5 * 60 * 1000
@@ -42,11 +45,27 @@ module SalesforceHttpClient
42
45
  end
43
46
 
44
47
  def report_url(report_id)
45
- @salesforce_report_url_format.gsub(@salesforce_report_id_param, report_id)
48
+ if @salesforce_report_url_format.is_a? Proc
49
+ url_format = @salesforce_report_url_format.call
50
+ else
51
+ url_format = salesforce_report_url_format
52
+ end
53
+
54
+ url_format.gsub(@salesforce_report_id_param, report_id)
55
+ end
56
+
57
+ def logout_url
58
+ if @salesforce_logout_url.is_a? Proc
59
+ @salesforce_logout_url.call
60
+ else
61
+ @salesforce_logout_url
62
+ end
46
63
  end
47
64
 
48
65
  def cookie_store_file_path
49
- File.join(@tmp_dir, 'cookie_store.dat')
66
+ file_path = File.join(@tmp_dir, 'cookie_store.dat')
67
+ FileUtils.mkdir_p(File.dirname(file_path))
68
+ file_path
50
69
  end
51
70
 
52
71
  private
@@ -52,7 +52,7 @@ module SalesforceHttpClient
52
52
 
53
53
  def salesforce_logout
54
54
  @logger.info "try salesforce logout..."
55
- @http_client.get config.salesforce_logout_url
55
+ @http_client.get config.logout_url
56
56
  @logger.info "salesforce logged out."
57
57
  end
58
58
  end
@@ -1,3 +1,3 @@
1
1
  module SalesforceHttpClient
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -10,21 +10,23 @@ module SalesforceHttpClient
10
10
  end
11
11
 
12
12
  describe '#download_report' do
13
+ let(:sf_domain) { 'https://ap.salesforce.com' }
14
+ let(:report_id) { 'a' }
13
15
  before do
14
16
  stub_request(:get, "https://login.salesforce.com/")
15
17
  .to_return(status: 200, body: "", headers: {})
16
18
 
17
19
  stub_request(:post, "https://login.salesforce.com/")
18
20
  .with(body: { "pw" => "test_password", "un" => "test_login_id" })
19
- .to_return(status: 302, body: "", headers: { 'Location' => 'https://ap.salesforce.com/secur/frontdoor.jsp?sid=00D10000000ZIju%21ARkAQBU5ixFxxAzNvQTreC6rOQ9QSt_cMxFbwmVoVNbWtl.xxHasjFO8v100wa6b0kv.c9Q9RzYuwss9F5TodikF.ELZAHwq&apv=1&cshc=0000001shFs0000000ZIju&display=page' })
21
+ .to_return(status: 302, body: "", headers: { 'Location' => "#{sf_domain}" + '/secur/frontdoor.jsp?sid=00D10000000ZIju%21ARkAQBU5ixFxxAzNvQTreC6rOQ9QSt_cMxFbwmVoVNbWtl.xxHasjFO8v100wa6b0kv.c9Q9RzYuwss9F5TodikF.ELZAHwq&apv=1&cshc=0000001shFs0000000ZIju&display=page' })
20
22
 
21
- stub_request(:get, "https://ap.salesforce.com/secur/frontdoor.jsp?apv=1&cshc=0000001shFs0000000ZIju&display=page&sid=00D10000000ZIju!ARkAQBU5ixFxxAzNvQTreC6rOQ9QSt_cMxFbwmVoVNbWtl.xxHasjFO8v100wa6b0kv.c9Q9RzYuwss9F5TodikF.ELZAHwq")
23
+ stub_request(:get, "#{sf_domain}/secur/frontdoor.jsp?apv=1&cshc=0000001shFs0000000ZIju&display=page&sid=00D10000000ZIju!ARkAQBU5ixFxxAzNvQTreC6rOQ9QSt_cMxFbwmVoVNbWtl.xxHasjFO8v100wa6b0kv.c9Q9RzYuwss9F5TodikF.ELZAHwq")
22
24
  .to_return(status: 200, body: "", headers: {})
23
25
 
24
- stub_request(:get, "https://ap.salesforce.com/a?enc=UTF-8&export=1&xf=csv")
26
+ stub_request(:get, "#{sf_domain}/#{report_id}?enc=UTF-8&export=1&xf=csv")
25
27
  .to_return(status: 200, body: "", headers: {})
26
28
 
27
- stub_request(:get, "https://ap.salesforce.com/secur/logout.jsp")
29
+ stub_request(:get, "#{sf_domain}/secur/logout.jsp")
28
30
  .to_return(status: 200, body: "", headers: {})
29
31
  end
30
32
 
@@ -39,6 +41,29 @@ module SalesforceHttpClient
39
41
 
40
42
  client = SalesforceHttpClient::Client.new
41
43
  client.download_report("a", output_file)
44
+
45
+ expect(File.exist?(output_file)).to be_truthy
46
+ end
47
+
48
+ context 'north american instance' do
49
+ let(:sf_domain) { 'https://na12.salesforce.com' }
50
+ let(:report_id) { 'b' }
51
+
52
+ it 'can download report use customized url format' do
53
+ Configuration.configure do |config|
54
+ config.salesforce_login_id = 'test_login_id'
55
+ config.salesforce_password = 'test_password'
56
+ config.salesforce_instance_domain = 'https://na12.salesforce.com'
57
+ end
58
+
59
+ output_file = "tmp/report_b.csv"
60
+ File.delete(output_file) if File.exist?(output_file)
61
+
62
+ client = SalesforceHttpClient::Client.new
63
+ client.download_report("b", output_file)
64
+
65
+ expect(File.exist?(output_file)).to be_truthy
66
+ end
42
67
  end
43
68
  end
44
69
  end
File without changes
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: salesforce_http_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Apuruni
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-25 00:00:00.000000000 Z
11
+ date: 2015-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient
@@ -209,6 +209,8 @@ files:
209
209
  - spec/salesforce_http_client/version_spec.rb
210
210
  - spec/salesforce_http_client_spec.rb
211
211
  - spec/spec_helper.rb
212
+ - tmp/.gitkeep
213
+ - tmp/cookie_store.dat
212
214
  homepage: https://github.com/apuruni/salesforce_http_client
213
215
  licenses:
214
216
  - MIT