Class: SalesforceBulk::Connection
- Inherits:
-
Object
- Object
- SalesforceBulk::Connection
- Defined in:
- lib/salesforce_bulk/connection.rb
Constant Summary collapse
- @@XML_HEADER =
'<?xml version="1.0" encoding="utf-8" ?>'
- @@API_VERSION =
nil
- @@LOGIN_HOST =
'login.salesforce.com'
- @@INSTANCE_HOST =
Gets set in login()
nil
Instance Method Summary collapse
- #get_request(host, path, headers) ⇒ Object
- #https(host) ⇒ Object
-
#initialize(api_version, client) ⇒ Connection
constructor
A new instance of Connection.
-
#login ⇒ Object
private.
- #parse_instance ⇒ Object
- #post_xml(host, path, xml, headers) ⇒ Object
Constructor Details
#initialize(api_version, client) ⇒ Connection
Returns a new instance of Connection.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/salesforce_bulk/connection.rb', line 10 def initialize(api_version,client) #@username = username @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
#get_request(host, path, headers) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/salesforce_bulk/connection.rb', line 44 def get_request(host, path, headers) host = host || @@INSTANCE_HOST path = "#{@@PATH_PREFIX}#{path}" if host != @@LOGIN_HOST # Not login, need to add session id to header headers['X-SFDC-Session'] = @session_id; end https(host).get(path, headers).body end |
#https(host) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/salesforce_bulk/connection.rb', line 55 def https(host) req = Net::HTTP.new(host, 443) req.use_ssl = true req.verify_mode = OpenSSL::SSL::VERIFY_NONE req end |
#login ⇒ Object
private
25 26 27 28 29 30 31 32 33 |
# File 'lib/salesforce_bulk/connection.rb', line 25 def login() @session_id=@client.oauth_token @server_url=@client.instance_url @instance = parse_instance() @@INSTANCE_HOST = "#{@instance}.salesforce.com" end |
#parse_instance ⇒ Object
62 63 64 65 66 |
# File 'lib/salesforce_bulk/connection.rb', line 62 def parse_instance() @instance=@server_url.match(/https:\/\/[a-z]{2}[0-9]{1,2}/).to_s.gsub("https://","") #@server_url =~ /https:\/\/[a-z]{2}[0-9]{1,2}/ #@instance = "ap1" end |
#post_xml(host, path, xml, headers) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/salesforce_bulk/connection.rb', line 35 def post_xml(host, path, xml, headers) host = host || @@INSTANCE_HOST if host != @@LOGIN_HOST # Not login, need to add session id to header headers['X-SFDC-Session'] = @session_id; path = "#{@@PATH_PREFIX}#{path}" end https(host).post(path, xml, headers).body end |