class Seiun::Connection
Public Class Methods
new(databasedotcom)
click to toggle source
# File lib/seiun/connection.rb, line 3 def initialize(databasedotcom) @databasedotcom = databasedotcom end
Public Instance Methods
add_batch(data, job_id, callback: nil)
click to toggle source
# File lib/seiun/connection.rb, line 19 def add_batch(data, job_id, callback: nil) connect(:add_batch, data: data, job_id: job_id, callback: callback) end
add_query(soql, job_id, callback: nil)
click to toggle source
# File lib/seiun/connection.rb, line 15 def add_query(soql, job_id, callback: nil) connect(:add_query, data: soql, job_id: job_id, callback: callback) end
close_job(data, job_id, callback: nil)
click to toggle source
# File lib/seiun/connection.rb, line 11 def close_job(data, job_id, callback: nil) connect(:close_job, data: data, job_id: job_id, callback: callback) end
create_job(data, callback: nil)
click to toggle source
# File lib/seiun/connection.rb, line 7 def create_job(data, callback: nil) connect(:create_job, data: data, callback: callback) end
get_batch_details(job_id, callback: nil)
click to toggle source
# File lib/seiun/connection.rb, line 27 def get_batch_details(job_id, callback: nil) connect(:get_batch_details, job_id: job_id, callback: callback) end
get_job_details(job_id, callback: nil)
click to toggle source
# File lib/seiun/connection.rb, line 23 def get_job_details(job_id, callback: nil) connect(:get_job_details, job_id: job_id, callback: callback) end
get_query_result(job_id, batch_id, result_id, callback: nil)
click to toggle source
# File lib/seiun/connection.rb, line 35 def get_query_result(job_id, batch_id, result_id, callback: nil) connect(:get_query_result, job_id: job_id, batch_id: batch_id, result_id: result_id, callback: callback) end
get_result(job_id, batch_id, callback: nil)
click to toggle source
# File lib/seiun/connection.rb, line 31 def get_result(job_id, batch_id, callback: nil) connect(:get_result, job_id: job_id, batch_id: batch_id, callback: callback) end
Private Instance Methods
api_version()
click to toggle source
# File lib/seiun/connection.rb, line 99 def api_version "35.0" end
connect(type, data: nil, job_id: nil, batch_id: nil, result_id: nil, callback: nil)
click to toggle source
# File lib/seiun/connection.rb, line 41 def connect(type, data: nil, job_id: nil, batch_id: nil, result_id: nil, callback: nil) path = request_path(type, job_id, batch_id, result_id) callback.before_request(type, path.dup, data) if callback if callback && mock_body = callback.__send__("mock_response_#{type}") body = mock_body else response = nil raise_over_retry 3 do response = request(type, path, data, job_id, batch_id, result_id, callback: callback) response.value end body = response.body end callback.after_response(type, path, body) if callback body end
headers()
click to toggle source
# File lib/seiun/connection.rb, line 91 def headers { "X-SFDC-Session" => session_id, 'Content-Type' => 'application/xml; charset=UTF-8' } end
instance_host()
click to toggle source
# File lib/seiun/connection.rb, line 85 def instance_host return @instance_host if @instance_host @databasedotcom.instance_url =~ /^https*\:\/\/([^\/]+)/ @instance_host = $1 end
raise_over_retry(times) { || ... }
click to toggle source
# File lib/seiun/connection.rb, line 103 def raise_over_retry(times) count = 0 begin yield rescue => ex count += 1 if count >= times ex.is_a?(Net::HTTPResponse) ? raise(ex, ex.response.body) : raise(ex) end sleep 1 retry end end
request(type, path, data, job_id, batch_id, result_id, callback: nil)
click to toggle source
# File lib/seiun/connection.rb, line 58 def request(type, path, data, job_id, batch_id, result_id, callback: nil) https = Net::HTTP.new(instance_host, 443) https.use_ssl = true https.verify_mode = OpenSSL::SSL::VERIFY_NONE if callback && callback.ssl_verify_none case type when :create_job, :close_job, :add_query, :add_batch https.post(path, data, headers) else https.get(path, headers) end end
request_path(type, job_id, batch_id, result_id)
click to toggle source
# File lib/seiun/connection.rb, line 70 def request_path(type, job_id, batch_id, result_id) case type when :create_job "/services/async/#{api_version}/job" when :close_job, :get_job_details "/services/async/#{api_version}/job/#{job_id}" when :add_query, :add_batch, :get_batch_details "/services/async/#{api_version}/job/#{job_id}/batch" when :get_result "/services/async/#{api_version}/job/#{job_id}/batch/#{batch_id}/result" when :get_query_result "/services/async/#{api_version}/job/#{job_id}/batch/#{batch_id}/result/#{result_id}" end end
session_id()
click to toggle source
# File lib/seiun/connection.rb, line 95 def session_id @session_id ||= @databasedotcom.oauth_token end