Class: Wirecard::Elastic::Response::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/wirecard/elastic/response/base.rb

Direct Known Subclasses

Refund, Transaction

Constant Summary collapse

SYMBOLS_MAP =

will force symbol conversion for those specific methods calls *method.transaction_state will return a symbol *method.anything will return the raw value from the API

[:request_status, :transaction_type, :transaction_state, :payment_method]
UNDERSCORE_MAP =

‘transaction_type` isn’t here because we don’t want to turn ‘refund-purchase` into `refund_purchase` we use UNDERSCORE_MAP for that

[:request_status, :transaction_state, :payment_method]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(origin, raw) ⇒ Base

Returns a new instance of Base.



23
24
25
26
# File 'lib/wirecard/elastic/response/base.rb', line 23

def initialize(origin, raw)
  @origin = origin
  @raw    = raw
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_symbol, *arguments, &block) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/wirecard/elastic/response/base.rb', line 28

def method_missing(method_symbol, *arguments, &block)
  if map.include?(method_symbol)
    response = cycle(*map[method_symbol])
    if SYMBOLS_MAP.include?(method_symbol)
      if UNDERSCORE_MAP.include?(method_symbol)
        symbolize_data(underscore_data(response))
      else
        symbolize_data(response)
      end
    else
      response
    end
  end
end

Instance Attribute Details

#originObject (readonly)

Returns the value of attribute origin.



21
22
23
# File 'lib/wirecard/elastic/response/base.rb', line 21

def origin
  @origin
end

#rawObject (readonly)

Returns the value of attribute raw.



21
22
23
# File 'lib/wirecard/elastic/response/base.rb', line 21

def raw
  @raw
end

Instance Method Details

#mapObject

general mapping for automatic method recovery when you basically ask for MyResponse.request_id it will go through the hash following the map and return the value at the end of the loop each response class can extend easily the map for its own specific use



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/wirecard/elastic/response/base.rb', line 47

def map
  {
    :request_id                => [:"request-id"],
    :request_status            => [:statuses, :status, 0, :severity],
    :requested_amount          => [:"requested-amount", :value],
    :requested_amount_currency => [:"requested-amount", :currency],
    :transaction_id            => [:"requested-id"],
    :transaction_type          => [:"transaction-type"],
    :transaction_state         => [:"transaction-state"],
    :payment_method            => [:"payment-methods", :"payment-method", 0, :name]
  }
end