Class: Remi::DataSource::Salesforce
- Inherits:
-
Remi::DataSubject
- Object
- Remi::DataSubject
- Remi::DataSource::Salesforce
- Defined in:
- lib/remi/cucumber/data_source.rb,
lib/remi/data_subject/salesforce.rb
Overview
Hmmm.… this gets called first because I’m trying to split SF off as a “plugin”
Instance Attribute Summary
Attributes inherited from Remi::DataSubject
Instance Method Summary collapse
-
#extract! ⇒ Object
Public: Called to extract data from the source.
-
#initialize(*args, **kargs, &block) ⇒ Salesforce
constructor
A new instance of Salesforce.
- #sf_bulk ⇒ Object
-
#to_dataframe ⇒ Object
Public: Converts extracted data to a dataframe.
Methods included from Remi::DataSubject::Salesforce
#field_symbolizer, #restforce_client
Methods included from Remi::DataSubject::DataSource
Methods included from DataStub
#empty_stub_df, #stub_df, #stub_row_array, #stub_values
Methods inherited from Remi::DataSubject
Constructor Details
#initialize(*args, **kargs, &block) ⇒ Salesforce
Returns a new instance of Salesforce.
28 29 30 31 |
# File 'lib/remi/data_subject/salesforce.rb', line 28 def initialize(*args, **kargs, &block) super init_salesforce(*args, **kargs, &block) end |
Instance Method Details
#extract! ⇒ Object
Public: Called to extract data from the source.
Returns data in a format that can be used to create a dataframe.
36 37 38 39 40 41 |
# File 'lib/remi/data_subject/salesforce.rb', line 36 def extract! @extract = sf_bulk.query(@sfo, @query, 10000) check_for_errors(@extract) @extract end |
#sf_bulk ⇒ Object
43 44 45 |
# File 'lib/remi/data_subject/salesforce.rb', line 43 def sf_bulk @sf_bulk ||= SalesforceBulkApi::Api.new(restforce_client).tap { |o| o.connection.set_status_throttle(5) } end |
#to_dataframe ⇒ Object
Public: Converts extracted data to a dataframe. Currently only supports Daru DataFrames.
Returns a Remi::DataFrame
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/remi/data_subject/salesforce.rb', line 51 def to_dataframe @logger.info "Converting salesforce query results to a dataframe" hash_array = {} extract['batches'].each do |batch| next unless batch['response'] batch['response'].each do |record| record.each do |field, value| next if ['xsi:type','type'].include? field (hash_array[field.to_sym] ||= []) << case value.first when Hash value.first["xsi:nil"] == "true" ? nil : value.first else value.first end end end # delete raw result at end of processing to free memory batch['response'] = nil end Remi::DataFrame.create(@remi_df_type, hash_array, order: hash_array.keys) end |