Class: ActiveForce::Bulk::Job
- Inherits:
-
Object
- Object
- ActiveForce::Bulk::Job
- Defined in:
- lib/active_force/bulk/job.rb
Constant Summary collapse
- STATES =
{ Open: 'Open', UploadComplete: 'UploadComplete', InProgress: 'InProgress', JobComplete: 'JobComplete', Failed: 'Failed', Aborted: 'Aborted', Deleted: 'Deleted' }.freeze
- OPERATIONS =
%i[insert delete hardDelete update upsert]
Instance Attribute Summary collapse
-
#content_url ⇒ Object
readonly
Returns the value of attribute content_url.
-
#id ⇒ Object
Returns the value of attribute id.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#operation ⇒ Object
readonly
Returns the value of attribute operation.
-
#records ⇒ Object
readonly
Returns the value of attribute records.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Class Method Summary collapse
Instance Method Summary collapse
- #abort ⇒ Object
- #create ⇒ Object
- #delete ⇒ Object
- #failed_results ⇒ Object
- #finished? ⇒ Boolean
- #info ⇒ Object
-
#initialize(operation:, object:, id: nil, records: nil) ⇒ Job
constructor
A new instance of Job.
- #result ⇒ Object
- #run ⇒ Object
- #successful_results ⇒ Object
- #upload ⇒ Object
Constructor Details
#initialize(operation:, object:, id: nil, records: nil) ⇒ Job
Returns a new instance of Job.
21 22 23 24 25 26 27 28 29 |
# File 'lib/active_force/bulk/job.rb', line 21 def initialize(operation:, object:, id: nil, records: nil) @operation = operation.to_sym @object = object @id = id @records = records @state = nil @content_url = nil initialize_state_methods end |
Instance Attribute Details
#content_url ⇒ Object
Returns the value of attribute content_url.
6 7 8 |
# File 'lib/active_force/bulk/job.rb', line 6 def content_url @content_url end |
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'lib/active_force/bulk/job.rb', line 7 def id @id end |
#object ⇒ Object
Returns the value of attribute object.
6 7 8 |
# File 'lib/active_force/bulk/job.rb', line 6 def object @object end |
#operation ⇒ Object
Returns the value of attribute operation.
6 7 8 |
# File 'lib/active_force/bulk/job.rb', line 6 def operation @operation end |
#records ⇒ Object (readonly)
Returns the value of attribute records.
6 7 8 |
# File 'lib/active_force/bulk/job.rb', line 6 def records @records end |
#state ⇒ Object
Returns the value of attribute state.
6 7 8 |
# File 'lib/active_force/bulk/job.rb', line 6 def state @state end |
Class Method Details
.run ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/active_force/bulk/job.rb', line 48 def self.run(...) job = new(...) job.create job.upload job.run job end |
Instance Method Details
#abort ⇒ Object
74 75 76 |
# File 'lib/active_force/bulk/job.rb', line 74 def abort change_state(STATES[:Aborted]) end |
#create ⇒ Object
31 32 33 34 35 36 |
# File 'lib/active_force/bulk/job.rb', line 31 def create request_body = .merge(operation: operation, object: object) response = client.post("#{ingest_path}/", request_body) update_attributes_from(response) response end |
#delete ⇒ Object
78 79 80 81 |
# File 'lib/active_force/bulk/job.rb', line 78 def delete response = client.delete("#{ingest_path}/#{id}") response end |
#failed_results ⇒ Object
56 57 58 |
# File 'lib/active_force/bulk/job.rb', line 56 def failed_results client.get("#{ingest_path}/#{id}/failedResults/") end |
#finished? ⇒ Boolean
83 84 85 |
# File 'lib/active_force/bulk/job.rb', line 83 def finished? job_complete? || failed? || aborted? end |
#info ⇒ Object
64 65 66 67 68 |
# File 'lib/active_force/bulk/job.rb', line 64 def info response = client.get("#{ingest_path}/#{id}") update_attributes_from(response) response end |
#result ⇒ Object
44 45 46 |
# File 'lib/active_force/bulk/job.rb', line 44 def result ActiveForce::Bulk::JobResult.new(job: self) end |
#run ⇒ Object
70 71 72 |
# File 'lib/active_force/bulk/job.rb', line 70 def run change_state(STATES[:UploadComplete]) end |
#successful_results ⇒ Object
60 61 62 |
# File 'lib/active_force/bulk/job.rb', line 60 def successful_results client.get("#{ingest_path}/#{id}/successfulResults/") end |
#upload ⇒ Object
38 39 40 41 42 |
# File 'lib/active_force/bulk/job.rb', line 38 def upload headers = {"Content-Type": 'text/csv'} response = client.put(content_url, records.to_csv, headers) response end |