Class: Bulkforce::Http::Request
- Inherits:
-
Object
- Object
- Bulkforce::Http::Request
- Defined in:
- lib/bulkforce/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
- .instance_host(instance) ⇒ Object
- .login(host, username, password, api_version) ⇒ Object
- .oauth_login(host, client_id, client_secret, refresh_token) ⇒ 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.
128 129 130 131 132 133 134 |
# File 'lib/bulkforce/http.rb', line 128 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.
124 125 126 |
# File 'lib/bulkforce/http.rb', line 124 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
125 126 127 |
# File 'lib/bulkforce/http.rb', line 125 def headers @headers end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
123 124 125 |
# File 'lib/bulkforce/http.rb', line 123 def host @host end |
#http_method ⇒ Object (readonly)
Returns the value of attribute http_method.
126 127 128 |
# File 'lib/bulkforce/http.rb', line 126 def http_method @http_method end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
122 123 124 |
# File 'lib/bulkforce/http.rb', line 122 def path @path end |
Class Method Details
.add_batch(instance, session_id, job_id, data, api_version) ⇒ Object
222 223 224 225 226 227 228 229 230 |
# File 'lib/bulkforce/http.rb', line 222 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_host(instance), "/services/async/#{api_version}/job/#{job_id}/batch", data, headers) end |
.close_job(instance, session_id, job_id, api_version) ⇒ Object
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/bulkforce/http.rb', line 205 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_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
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/bulkforce/http.rb', line 183 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, instance_host(instance), "/services/async/#{api_version}/job", body, headers) end |
.instance_host(instance) ⇒ Object
272 273 274 |
# File 'lib/bulkforce/http.rb', line 272 def self.instance_host instance "#{instance}.salesforce.com" end |
.login(host, username, password, api_version) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/bulkforce/http.rb', line 136 def self.login host, 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, host, "/services/Soap/u/#{api_version}", body, headers) end |
.oauth_login(host, client_id, client_secret, refresh_token) ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/bulkforce/http.rb', line 160 def self.oauth_login(host, client_id, client_secret, refresh_token) headers = { "Content-Type" => "application/x-www-form-urlencoded", "Accept" => "application/xml", } body = { grant_type: "refresh_token", client_id: client_id, client_secret: client_secret, refresh_token: refresh_token }.inject("") do |string, (k,v)| string += "#{k}=#{v}&" end Http::Request.new( :post, host, "/services/oauth2/token", body, headers) end |
.query_batch(instance, session_id, job_id, batch_id, api_version) ⇒ Object
232 233 234 235 236 237 238 239 240 |
# File 'lib/bulkforce/http.rb', line 232 def self.query_batch instance, session_id, job_id, batch_id, api_version headers = {"X-SFDC-Session" => session_id} Http::Request.new( :get, instance_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
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/bulkforce/http.rb', line 254 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_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
242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/bulkforce/http.rb', line 242 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_host(instance), "/services/async/#{api_version}/job/#{job_id}/batch/#{batch_id}/result", nil, headers) end |