Class: Multiwoven::Integrations::Source::SalesforceConsumerGoodsCloud::Client
- Inherits:
-
SourceConnector
- Object
- SourceConnector
- Multiwoven::Integrations::Source::SalesforceConsumerGoodsCloud::Client
- Includes:
- Core::RateLimiter
- Defined in:
- lib/multiwoven/integrations/source/salesforce_consumer_goods_cloud/client.rb
Overview
rubocop:disable Metrics/ClassLength
Instance Method Summary collapse
- #check_connection(connection_config) ⇒ Object
- #discover(connection_config) ⇒ Object
- #read(sync_config) ⇒ Object
Methods included from Core::RateLimiter
Instance Method Details
#check_connection(connection_config) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/multiwoven/integrations/source/salesforce_consumer_goods_cloud/client.rb', line 16 def check_connection(connection_config) connection_config = connection_config.with_indifferent_access initialize_client(connection_config) authenticate_client success_status rescue StandardError => e failure_status(e) end |
#discover(connection_config) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/multiwoven/integrations/source/salesforce_consumer_goods_cloud/client.rb', line 25 def discover(connection_config) connection_config = connection_config.with_indifferent_access initialize_client(connection_config) catalog = build_catalog(load_catalog.with_indifferent_access) streams = catalog[:streams] SALESFORCE_OBJECTS.each do |object| object_description = @client.describe(object) streams << JSON.parse(create_json_schema_for_object(object_description).to_json) end catalog. rescue StandardError => e handle_exception("SALESFORCE:CRM:DISCOVER:EXCEPTION", "error", e) end |
#read(sync_config) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/multiwoven/integrations/source/salesforce_consumer_goods_cloud/client.rb', line 39 def read(sync_config) connection_config = sync_config.source.connection_specification.with_indifferent_access initialize_client(connection_config) return [] if sync_config.offset&.> 2000 # TODO: Salesforce imposes a limit on the use of OFFSET in SOQL queries, where you cannot skip(offset) more than 2000 records. # This limitation can hinder the retrieval of large datasets in a single query. # To overcome this, we need a cursor-based pagination strategy instead of relying on OFFSET. # query = batched_query(query, sync_config.limit, sync_config.offset) unless sync_config.limit.nil? && sync_config.offset.nil? query = sync_config.model.query exclude_keys = ["attributes"] queried_data = @client.query(query) results = queried_data.map do |record| record.reject { |key, _| exclude_keys.include?(key) } end results.map do |row| RecordMessage.new(data: row, emitted_at: Time.now.to_i). end rescue StandardError => e handle_exception("SALESFORCE:CRM:WRITE:EXCEPTION", "error", e) end |