Sha256: 0a7557ecabf33b0a9f8e7ddcc51cfa61ac520700199dfff3c2f2f1afe9225322

Contents?: true

Size: 1.3 KB

Versions: 39

Compression:

Stored size: 1.3 KB

Contents

module Remi
  module DataTarget
    class Salesforce
      include DataTarget

      def initialize(object:, operation:, credentials:, api: :bulk, logger: Remi::Settings.logger)
        @sfo = object
        @operation = operation
        @credentials = credentials
        @api = api
        @logger = logger
      end

      def field_symbolizer
        Remi::FieldSymbolizers[:salesforce]
      end

      def load
        return true if @loaded || df.size == 0

        @logger.info "Performing Salesforce #{@operation} on object #{@sfo}"

        if @operation == :update
          Remi::SfBulkHelper::SfBulkUpdate.update(restforce_client, @sfo, df_as_array_of_hashes, logger: @logger)
        elsif @operation == :create
          Remi::SfBulkHelper::SfBulkCreate.create(restforce_client, @sfo, df_as_array_of_hashes, logger: @logger)
        end

        @loaded = true
      end

      def restforce_client
        @restforce_client ||= begin
          client = Restforce.new(@credentials)

          #run a dummy query to initiate a connection. Workaround for Bulk API problem
          # https://github.com/yatish27/salesforce_bulk_api/issues/33
          client.query('SELECT Id FROM Contact LIMIT 1')
          client
        end
      end

      def df_as_array_of_hashes
        df.to_a[0]
      end

    end
  end
end

Version data entries

39 entries across 25 versions & 1 rubygems

Version Path
remi-0.2.26 lib/remi/data_target/salesforce.rb
remi-0.2.25 lib/remi/data_target/salesforce.rb
remi-0.2.24 lib/remi/data_target/salesforce.rb
remi-0.2.23 lib/remi/data_target/salesforce.rb
remi-0.2.22 lib/remi/data_target/salesforce.rb
remi-0.2.21 lib/remi/data_target/salesforce.rb
remi-0.2.20 lib/remi/data_target/salesforce.rb
remi-0.2.19 lib/remi/data_target/salesforce.rb
remi-0.2.18 lib/remi/data_target/salesforce.rb
remi-0.2.17 lib/remi/data_target/salesforce.rb
remi-0.2.16 lib/remi/data_target/salesforce.rb
remi-0.2.15 lib/remi/data_target/salesforce.rb
remi-0.2.15 lib/remi/data_target/csv_file.rb
remi-0.2.14 lib/remi/data_target/salesforce.rb
remi-0.2.14 lib/remi/data_target/csv_file.rb
remi-0.2.13 lib/remi/data_target/salesforce.rb
remi-0.2.13 lib/remi/data_target/csv_file.rb
remi-0.2.12 lib/remi/data_target/salesforce.rb
remi-0.2.12 lib/remi/data_target/csv_file.rb
remi-0.2.11 lib/remi/data_target/salesforce.rb