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, content_type, api_version, external_field = nil) ⇒ Object
- .generic_host(prefix) ⇒ 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.
104 105 106 107 108 109 110 |
# File 'lib/executrix/http.rb', line 104 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.
100 101 102 |
# File 'lib/executrix/http.rb', line 100 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
101 102 103 |
# File 'lib/executrix/http.rb', line 101 def headers @headers end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
99 100 101 |
# File 'lib/executrix/http.rb', line 99 def host @host end |
#http_method ⇒ Object (readonly)
Returns the value of attribute http_method.
102 103 104 |
# File 'lib/executrix/http.rb', line 102 def http_method @http_method end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
98 99 100 |
# File 'lib/executrix/http.rb', line 98 def path @path end |
Class Method Details
.add_batch(instance, session_id, job_id, data, api_version) ⇒ Object
175 176 177 178 179 180 181 182 183 |
# File 'lib/executrix/http.rb', line 175 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, generic_host(instance), "/services/async/#{api_version}/job/#{job_id}/batch", data, headers) end |
.close_job(instance, session_id, job_id, api_version) ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/executrix/http.rb', line 158 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, generic_host(instance), "/services/async/#{api_version}/job/#{job_id}", body, headers) end |
.create_job(instance, session_id, operation, sobject, content_type, api_version, external_field = nil) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/executrix/http.rb', line 136 def self.create_job instance, session_id, operation, sobject, content_type, 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>#{content_type}</contentType> </jobInfo> } headers = { 'Content-Type' => 'application/xml; charset=utf-8', 'X-SFDC-Session' => session_id} Http::Request.new( :post, generic_host(instance), "/services/async/#{api_version}/job", body, headers) end |
.generic_host(prefix) ⇒ Object
225 226 227 |
# File 'lib/executrix/http.rb', line 225 def self.generic_host prefix "#{prefix}.salesforce.com" end |
.login(sandbox, username, password, api_version) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/executrix/http.rb', line 112 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' } Http::Request.new( :post, generic_host(sandbox ? 'test' : 'login'), "/services/Soap/u/#{api_version}", body, headers) end |
.query_batch(instance, session_id, job_id, batch_id, api_version) ⇒ Object
185 186 187 188 189 190 191 192 193 |
# File 'lib/executrix/http.rb', line 185 def self.query_batch instance, session_id, job_id, batch_id, api_version headers = {'X-SFDC-Session' => session_id} Http::Request.new( :get, generic_host(instance), "/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
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/executrix/http.rb', line 207 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, generic_host(instance), "/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
195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/executrix/http.rb', line 195 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, generic_host(instance), "/services/async/#{api_version}/job/#{job_id}/batch/#{batch_id}/result", nil, headers) end |