Sha256: 39c6fca7ba52ce9691817388700a39f5d6b92a4e7d883ce78d266463adee6888

Contents?: true

Size: 919 Bytes

Versions: 2

Compression:

Stored size: 919 Bytes

Contents

# frozen_string_literal: true

module SolidusDrip
  class Base
    include Spree::Core::Engine.routes.url_helpers

    attr_accessor :client

    def initialize(*_args)
      @client = ::Drip::Client.new do |c|
        c.api_key = ENV['DRIP_API_KEY']
        c.account_id = ENV['DRIP_ACCOUNT_ID']
      end
    end

    private

    ##
    # When a response is not successful this method should be called
    # to handle it appropriately. Currently it logs the bad request and does
    # not stop the execution flow. A failed response from Drip shouldn't affect
    # the user experience with the site.
    #
    def handle_error_response(response)
      # Some errors come back under the `message` key while others are nested
      # under `error`
      error_message = response.body.dig('message') || response.body.dig('error', 'message')
      Rails.logger.error("SOLIDUS DRIP | #{error_message}")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
solidus_drip-0.1.0 lib/solidus_drip/base.rb
solidus_drip-0.0.1 lib/solidus_drip/base.rb