Class: AdaptivePayments::AbstractRequest

Inherits:
JsonModel
  • Object
show all
Defined in:
lib/pp-adaptive/abstract_request.rb

Overview

AbstractRequest is a JsonModel that defines some default behaviour for all requests

A request defines the operation it executes and provides a method for building the corresponding response. All requests provide a RequestEnvelope by default. There is no need to re-define it in descendants.

Class Method Summary collapse

Methods included from Aliases

#alias_param, #alias_params

Methods included from JsonModel::Parsing

#from_json, #to_attributes

Methods included from JsonModel::Writing

#to_hash, #to_json

Class Method Details

.build_response(json) ⇒ AbstractResponse

Given a JSON string, return the corresponding response.

Parameters:

  • json (String)

    the raw JSON string as returned by the API

Returns:



49
50
51
52
# File 'lib/pp-adaptive/abstract_request.rb', line 49

def build_response(json)
  klass = AdaptivePayments.const_get(operation.to_s + "Response")
  klass.from_json(json.to_s)
end

.for_operation(name) ⇒ AbstractRequest

Get the request class for the given operation.

Parameters:

  • operation (Symbol)

    the name of the operation

Returns:



38
39
40
# File 'lib/pp-adaptive/abstract_request.rb', line 38

def for_operation(name)
  AdaptivePayments.const_get(name.to_s + "Request")
end

.operation(name = nil) ⇒ Symbol

Set or get the API operation for the request class

Parameters:

  • name (Symbol) (defaults to: nil)

    the name of the operation defined in the Adaptive Payments API, optional

Returns:

  • (Symbol)

    the name of the operation defined in the Adaptive Payments API



26
27
28
29
# File 'lib/pp-adaptive/abstract_request.rb', line 26

def operation(name = nil)
  @operation = name unless name.nil?
  @operation
end