Class: Executrix::Http::Request
- Inherits:
-
Object
- Object
- Executrix::Http::Request
- Defined in:
- lib/executrix/http.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#http_method ⇒ Object
readonly
Returns the value of attribute http_method.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
- .add_batch(instance, session_id, job_id, data, api_version) ⇒ Object
- .close_job(instance, session_id, job_id, api_version) ⇒ Object
- .create_job(instance, session_id, operation, sobject, api_version, external_field = nil) ⇒ Object
- .login(sandbox, username, password, api_version) ⇒ Object
- .query_batch(instance, session_id, job_id, batch_id, api_version) ⇒ Object
- .query_batch_result_data(instance, session_id, job_id, batch_id, result_id, api_version) ⇒ Object
- .query_batch_result_id(instance, session_id, job_id, batch_id, api_version) ⇒ Object
Instance Method Summary collapse
-
#initialize(http_method, host, path, body, headers) ⇒ Request
constructor
A new instance of Request.
Constructor Details
#initialize(http_method, host, path, body, headers) ⇒ Request
Returns a new instance of Request.
91 92 93 94 95 96 97 |
# File 'lib/executrix/http.rb', line 91 def initialize http_method, host, path, body, headers @http_method = http_method @host = host @path = path @body = body @headers = headers end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
87 88 89 |
# File 'lib/executrix/http.rb', line 87 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
88 89 90 |
# File 'lib/executrix/http.rb', line 88 def headers @headers end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
86 87 88 |
# File 'lib/executrix/http.rb', line 86 def host @host end |
#http_method ⇒ Object (readonly)
Returns the value of attribute http_method.
89 90 91 |
# File 'lib/executrix/http.rb', line 89 def http_method @http_method end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
85 86 87 |
# File 'lib/executrix/http.rb', line 85 def path @path end |
Class Method Details
.add_batch(instance, session_id, job_id, data, api_version) ⇒ Object
163 164 165 166 167 168 169 170 171 |
# File 'lib/executrix/http.rb', line 163 def self.add_batch instance, session_id, job_id, data, api_version headers = {'Content-Type' => 'text/csv; charset=UTF-8', 'X-SFDC-Session' => session_id} Http::Request.new( :post, "#{instance}.salesforce.com", "/services/async/#{api_version}/job/#{job_id}/batch", data, headers) end |
.close_job(instance, session_id, job_id, api_version) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/executrix/http.rb', line 146 def self.close_job instance, session_id, job_id, api_version body = %Q{<?xml version="1.0" encoding="utf-8" ?> <jobInfo xmlns="http://www.force.com/2009/06/asyncapi/dataload"> <state>Closed</state> </jobInfo> } headers = { 'Content-Type' => 'application/xml; charset=utf-8', 'X-SFDC-Session' => session_id} Http::Request.new( :post, "#{instance}.salesforce.com", "/services/async/#{api_version}/job/#{job_id}", body, headers) end |
.create_job(instance, session_id, operation, sobject, api_version, external_field = nil) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/executrix/http.rb', line 124 def self.create_job instance, session_id, operation, sobject, api_version, external_field = nil external_field_line = external_field ? "<externalIdFieldName>#{external_field}</externalIdFieldName>" : nil body = %Q{<?xml version="1.0" encoding="utf-8" ?> <jobInfo xmlns="http://www.force.com/2009/06/asyncapi/dataload"> <operation>#{operation}</operation> <object>#{sobject}</object> #{external_field_line} <contentType>CSV</contentType> </jobInfo> } headers = { 'Content-Type' => 'application/xml; charset=utf-8', 'X-SFDC-Session' => session_id} Http::Request.new( :post, "#{instance}.salesforce.com", "/services/async/#{api_version}/job", body, headers) end |
.login(sandbox, username, password, api_version) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/executrix/http.rb', line 99 def self.login sandbox, username, password, api_version body = %Q{<?xml version="1.0" encoding="utf-8" ?> <env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"> <env:Body> <n1:login xmlns:n1="urn:partner.soap.sforce.com"> <n1:username>#{username}</n1:username> <n1:password>#{password}</n1:password> </n1:login> </env:Body> </env:Envelope>} headers = { 'Content-Type' => 'text/xml; charset=utf-8', 'SOAPAction' => 'login' } host = sandbox ? 'test.salesforce.com' : 'login.salesforce.com' Http::Request.new( :post, host, "/services/Soap/u/#{api_version}", body, headers) end |
.query_batch(instance, session_id, job_id, batch_id, api_version) ⇒ Object
173 174 175 176 177 178 179 180 181 |
# File 'lib/executrix/http.rb', line 173 def self.query_batch instance, session_id, job_id, batch_id, api_version headers = {'X-SFDC-Session' => session_id} Http::Request.new( :get, "#{instance}.salesforce.com", "/services/async/#{api_version}/job/#{job_id}/batch/#{batch_id}", nil, headers) end |
.query_batch_result_data(instance, session_id, job_id, batch_id, result_id, api_version) ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/executrix/http.rb', line 195 def self.query_batch_result_data(instance, session_id, job_id, batch_id, result_id, api_version) headers = { 'Content-Type' => 'text/csv; charset=UTF-8', 'X-SFDC-Session' => session_id} Http::Request.new( :get, "#{instance}.salesforce.com", "/services/async/#{api_version}" \ "/job/#{job_id}/batch/#{batch_id}/result/#{result_id}", nil, headers) end |
.query_batch_result_id(instance, session_id, job_id, batch_id, api_version) ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/executrix/http.rb', line 183 def self.query_batch_result_id instance, session_id, job_id, batch_id, api_version headers = { 'Content-Type' => 'application/xml; charset=utf-8', 'X-SFDC-Session' => session_id} Http::Request.new( :get, "#{instance}.salesforce.com", "/services/async/#{api_version}/job/#{job_id}/batch/#{batch_id}/result", nil, headers) end |