Class: Shipay::Client

Inherits:
Object show all
Defined in:
lib/shipay/authenticator.rb

Overview

Class to hold client authetication data

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Client

Initialize Client instance

Parameters:

  • **options (Hash)

    Options required



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/shipay/authenticator.rb', line 25

def initialize(**options)
  begin
    @secret_key = options.fetch(:secret_key, Shipay.secret_key)
    @access_key = options.fetch(:access_key, Shipay.access_key)
    @client_id = options.fetch(:client_id)
    @key = Shipay::Util.to_sym(options.fetch(:key, Shipay.default_client_key ))
    @default = options.fetch(:default, true)
    @type = options.fetch(:type, :pdv)
    raise ParamError.new("Incorrect client type, must be one of #{CLIENT_TYPES}", :type, "Symbol") unless CLIENT_TYPES.include? @type
  rescue KeyError => e
    raise ParamError.new("Missing data for credentials: #{e.key}, (#{e.message})", "Credentials", "Symbol or String") unless CLIENT_TYPES.include? @type
  end
end

Instance Attribute Details

#access_keyObject (readonly)

Returns the value of attribute access_key.



11
12
13
# File 'lib/shipay/authenticator.rb', line 11

def access_key
  @access_key
end

#client_idObject (readonly)

Returns the value of attribute client_id.



11
12
13
# File 'lib/shipay/authenticator.rb', line 11

def client_id
  @client_id
end

#defaultObject

Returns the value of attribute default.



12
13
14
# File 'lib/shipay/authenticator.rb', line 12

def default
  @default
end

#keyObject (readonly)

Returns the value of attribute key.



11
12
13
# File 'lib/shipay/authenticator.rb', line 11

def key
  @key
end

#secret_keyObject (readonly)

Returns the value of attribute secret_key.



11
12
13
# File 'lib/shipay/authenticator.rb', line 11

def secret_key
  @secret_key
end

#typeObject (readonly)

Returns the value of attribute type.



11
12
13
# File 'lib/shipay/authenticator.rb', line 11

def type
  @type
end

Instance Method Details

#to_hHash

Convert Client instance to hash

Returns:

  • (Hash)

    Return Client in hash form



44
45
46
47
48
49
50
51
# File 'lib/shipay/authenticator.rb', line 44

def to_h
  {
    secret_key: @secret_key,
    access_key: @access_key,
    client_id: @client_id,
    key: @key
  }
end