Class: SalesforceBulkClient::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/salesforce_bulk_client/connection.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_version, restforce_client) ⇒ Connection

Returns a new instance of Connection.



6
7
8
9
10
11
# File 'lib/salesforce_bulk_client/connection.rb', line 6

def initialize(api_version, restforce_client)
  @restforce_client = restforce_client
  @api_version = api_version
  @path_prefix = "/services/async/#{@api_version}/"
  @restforce_client.authenticate!
end

Instance Method Details

#get_request(path) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/salesforce_bulk_client/connection.rb', line 24

def get_request(path)
  authenticate_results = @restforce_client.authenticate!
  response = @restforce_client.get do |request|
    request.url "#{@path_prefix}#{path}"
    request.headers['Content-Type'] = 'application/json'
    request.headers['X-SFDC-Session'] = authenticate_results.access_token
  end
  response.body
end

#post_request(path, post_data, as_json = true) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/salesforce_bulk_client/connection.rb', line 13

def post_request(path, post_data, as_json = true)
  authenticate_results = @restforce_client.authenticate!
  response = @restforce_client.post do |request|
    request.url [ @path_prefix, path ].join('/')
    request.headers['Content-Type'] = 'application/json'
    request.headers['X-SFDC-Session'] = authenticate_results.access_token
    request.body = as_json ? MultiJson.dump(post_data) : post_data
  end
  response.body
end