Sha256: 212c8d23eb4bf6df0f174a26a99b6c4d8f6b123425bac9a22eb7e3e8f7745b08

Contents?: true

Size: 958 Bytes

Versions: 7

Compression:

Stored size: 958 Bytes

Contents

# frozen_string_literal: true

module SolidusBolt
  class BaseService
    def initialize(*)
      @config = SolidusBolt::BoltConfiguration.fetch
    end

    def call
      raise NotImplementedError
    end

    def self.call(*args)
      new(*args).call
    end

    private

    def handle_result(result)
      return result.parsed_response if result.success?

      raise ServerError, error_message(result)
    end

    def error_message(result)
      return result['errors'].map { |e| e['message'] }.join(', ') if result['errors']

      "#{result['error']}: #{result['error_description']}"
    end

    def api_base_url
      @config.environment_url
    end

    def api_version
      'v1'
    end

    def generate_nonce
      SecureRandom.hex
    end

    def authentication_header
      { 'X-API-KEY' => @config.api_key }
    end

    def publishable_key
      @config.publishable_key
    end

    def api_key
      @config.api_key
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
solidus_bolt-0.6.0 app/services/solidus_bolt/base_service.rb
solidus_bolt-0.5.0 app/services/solidus_bolt/base_service.rb
solidus_bolt-0.4.0 app/services/solidus_bolt/base_service.rb
solidus_bolt-0.3.0 app/services/solidus_bolt/base_service.rb
solidus_bolt-0.2.0 app/services/solidus_bolt/base_service.rb
solidus_bolt-0.1.0 app/services/solidus_bolt/base_service.rb
solidus_bolt-0.0.1 app/services/solidus_bolt/base_service.rb