Sha256: 1715575709f429252a28cb3fc93cf8914906be1011bcc51f741814bc3b2b2f04

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

module OMCMS
  class Client
    attr_reader :client

    def initialize(opts)
      configure_credentials(opts)
      @client = configure_client
    end

    def configure_client
      @configure_client ||= Faraday.new do |f|
        f.request :authorization, :basic, @username, @password
        f.options[:open_timeout] = @open_timeout
        f.options[:timeout] = @timeout
        f.request :omcms_set_header
        f.response :omcms_parse_response
        f.response :json, content_type: /\bjson$/
        f.adapter :httpclient
      end
    end

    def offerings
      OMCMS::Offering.new(@client, @host, @response)
    end

    private

    def configure_credentials(opts)
      raise ArgumentError, "Public Key is missing for the OMCMS client" if opts[:public_key].to_s.empty?
      raise ArgumentError, "Private Key is missing for the OMCMS client" if opts[:private_key].to_s.empty?
      raise ArgumentError, "Host is missing for the OMCMS client" if opts[:host].to_s.empty?

      @username = opts[:public_key]
      @password = opts[:private_key]
      @host = opts[:host]
      @open_timeout = opts[:open_timeout] || 10
      @timeout = opts[:timeout] || 20
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
omcms-ruby-client-1.3.0 lib/omcms/client.rb