Class: SalesforceBulkApi::Connection
Constant Summary
collapse
'<?xml version="1.0" encoding="utf-8" ?>'
- @@API_VERSION =
nil
- @@LOGIN_HOST =
'login.salesforce.com'
- @@INSTANCE_HOST =
nil
Instance Method Summary
collapse
#add_throttle, #set_status_throttle, #set_throttle_limit_in_seconds, #throttles
Constructor Details
#initialize(api_version, client) ⇒ Connection
Returns a new instance of Connection.
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/salesforce_bulk_api/connection.rb', line 12
def initialize(api_version,client)
@client=client
@session_id = nil
@server_url = nil
@instance = nil
@@API_VERSION = api_version
@@LOGIN_PATH = "/services/Soap/u/#{@@API_VERSION}"
@@PATH_PREFIX = "/services/async/#{@@API_VERSION}/"
login()
end
|
Instance Method Details
#counters ⇒ Object
86
87
88
89
90
91
|
# File 'lib/salesforce_bulk_api/connection.rb', line 86
def counters
{
get: get_counters[:get],
post: get_counters[:post]
}
end
|
#get_request(host, path, headers) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/salesforce_bulk_api/connection.rb', line 61
def get_request(host, path, )
host = host || @@INSTANCE_HOST
path = "#{@@PATH_PREFIX}#{path}"
if host != @@LOGIN_HOST
['X-SFDC-Session'] = @session_id;
end
count :get
throttle(http_method: :get, path: path)
https(host).get(path, ).body
end
|
#https(host) ⇒ Object
73
74
75
76
77
78
|
# File 'lib/salesforce_bulk_api/connection.rb', line 73
def https(host)
req = Net::HTTP.new(host, 443)
req.use_ssl = true
req.verify_mode = OpenSSL::SSL::VERIFY_NONE
req
end
|
#login ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/salesforce_bulk_api/connection.rb', line 24
def login()
client_type = @client.class.to_s
case client_type
when "Restforce::Data::Client"
@session_id=@client.options[:oauth_token]
@server_url=@client.options[:instance_url]
else
@session_id=@client.oauth_token
@server_url=@client.instance_url
end
@instance = parse_instance()
@@INSTANCE_HOST = "#{@instance}.salesforce.com"
end
|
#parse_instance ⇒ Object
80
81
82
83
84
|
# File 'lib/salesforce_bulk_api/connection.rb', line 80
def parse_instance()
@instance = @server_url.match(/https:\/\/[a-z]{2}[0-9]{1,2}/).to_s.gsub("https://","")
@instance = @server_url.split(".salesforce.com")[0].split("://")[1] if @instance.nil? || @instance.empty?
return @instance
end
|
#post_xml(host, path, xml, headers) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/salesforce_bulk_api/connection.rb', line 38
def post_xml(host, path, xml, )
host = host || @@INSTANCE_HOST
if host != @@LOGIN_HOST
['X-SFDC-Session'] = @session_id
path = "#{@@PATH_PREFIX}#{path}"
end
i = 0
begin
count :post
throttle(http_method: :post, path: path)
https(host).post(path, xml, ).body
rescue
i += 1
if i < 3
puts "Request fail #{i}: Retrying #{path}"
retry
else
puts "FATAL: Request to #{path} failed three times."
raise
end
end
end
|