Class: SalesforceBulkApi::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/salesforce_bulk_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, salesforce_api_version = "46.0") ⇒ Api

Returns a new instance of Api.


16
17
18
19
20
# File 'lib/salesforce_bulk_api.rb', line 16

def initialize(client, salesforce_api_version = "46.0")
  @connection = SalesforceBulkApi::Connection.new(salesforce_api_version, client)
  @listeners = {job_created: []}
  @counters = Hash.new(0)
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.


14
15
16
# File 'lib/salesforce_bulk_api.rb', line 14

def connection
  @connection
end

Instance Method Details

#countersObject


32
33
34
35
36
37
38
39
40
41
42
# File 'lib/salesforce_bulk_api.rb', line 32

def counters
  {
    http_get: @connection.counters[:get],
    http_post: @connection.counters[:post],
    upsert: @counters[:upsert],
    update: @counters[:update],
    create: @counters[:create],
    delete: @counters[:delete],
    query: @counters[:query]
  }
end

#job_from_id(job_id) ⇒ Object


53
54
55
# File 'lib/salesforce_bulk_api.rb', line 53

def job_from_id(job_id)
  SalesforceBulkApi::Job.new(job_id: job_id, connection: @connection)
end

#on_job_created(&block) ⇒ Object

Allows you to attach a listener that accepts the created job (which has a useful #job_id field). This is useful for recording a job ID persistently before you begin batch work (i.e. start modifying the salesforce database), so if the load process you are writing needs to recover, it can be aware of previous jobs it started and wait for them to finish.


49
50
51
# File 'lib/salesforce_bulk_api.rb', line 49

def on_job_created(&block)
  @listeners[:job_created] << block
end

#query(sobject, query) ⇒ Object


28
29
30
# File 'lib/salesforce_bulk_api.rb', line 28

def query(sobject, query, **)
  do_operation("query", sobject, query, nil, get_response: true, **)
end