Class: Kount::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/kount/request.rb

Overview

This class acts as an abstract class for each type of request.

Direct Known Subclasses

Inquiry, Update

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(initial_params = {}) ⇒ Request

Initialize a Request object

Example usage

Not used directly. Use Inquiry or Update instead.

Parameters:

  • initial_params (Hash) (defaults to: {})

    Initial params for request



14
15
16
17
18
# File 'lib/kount/request.rb', line 14

def initialize(initial_params = {})
  fail "Cannot directly instantiate a #{self.class}." if
    self.class == Request
  @params = initial_params
end

Instance Attribute Details

#paramsObject

Returns the value of attribute params.



6
7
8
# File 'lib/kount/request.rb', line 6

def params
  @params
end

Instance Method Details

#add_params(hash) ⇒ Object

Add params to the current request object

Parameters:

  • hash (Hash)

    Hash of values to be added



22
23
24
# File 'lib/kount/request.rb', line 22

def add_params(hash)
  @params.merge!(hash)
end

#prepare_params(version, merchant_id, response_format, _ksalt = '') ⇒ Object

This method creates the final state of the params collection such that it can be sent to RIS. Items that are specific to either the Inquiry or Update calls are delegated to the prepare_params method in each respective class.

Parameters:

  • version (String)

    RIS version

  • merchant_id (String)

    Merchant ID

  • response_format (String)

    Response format (JSON)

  • _ksalt (String) (defaults to: '')

    Kount supplied secret salt for KHASH



35
36
37
38
39
# File 'lib/kount/request.rb', line 35

def prepare_params(version, merchant_id, response_format, _ksalt = '')
  # The KSALT is not used here, however, it is used in the corresponding
  # subclass prepare_params methods.
  params.merge!(VERS: version, MERC: merchant_id, FRMT: response_format)
end