Class: ProcessOut::ErrorCodes

Inherits:
Object
  • Object
show all
Defined in:
lib/processout/error_codes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, data = {}) ⇒ ErrorCodes

Initializes the ErrorCodes object Params:

client

ProcessOut client instance

data

data that can be used to fill the object



35
36
37
38
39
40
# File 'lib/processout/error_codes.rb', line 35

def initialize(client, data = {})
  @client = client

  self.gateway = data.fetch(:gateway, nil)
  
end

Instance Attribute Details

#gatewayObject

Returns the value of attribute gateway.



11
12
13
# File 'lib/processout/error_codes.rb', line 11

def gateway
  @gateway
end

Instance Method Details

#all(options = {}) ⇒ Object

Get all error codes. Params:

options

Hash of options



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/processout/error_codes.rb', line 83

def all(options = {})
  self.prefill(options)

  request = Request.new(@client)
  path    = "/error-codes"
  data    = {

  }

  response = Response.new(request.get(path, data, options))
  return_values = Array.new
  
  body = response.body
  
  obj = ErrorCodes.new(@client)
  return_values.push(obj.fill_with_data(body))
  

  
  return_values[0]
end

#fill_with_data(data) ⇒ Object

Fills the object with data coming from the API Params:

data

Hash of data coming from the API



57
58
59
60
61
62
63
64
65
66
# File 'lib/processout/error_codes.rb', line 57

def fill_with_data(data)
  if data.nil?
    return self
  end
  if data.include? "gateway"
    self.gateway = data["gateway"]
  end
  
  self
end

#new(data = {}) ⇒ Object

Create a new ErrorCodes using the current client



43
44
45
# File 'lib/processout/error_codes.rb', line 43

def new(data = {})
  ErrorCodes.new(@client, data)
end

#prefill(data) ⇒ Object

Prefills the object with the data passed as parameters Params:

data

Hash of data



71
72
73
74
75
76
77
78
# File 'lib/processout/error_codes.rb', line 71

def prefill(data)
  if data.nil?
    return self
  end
  self.gateway = data.fetch(:gateway, self.gateway)
  
  self
end

#to_json(options) ⇒ Object

Overrides the JSON marshaller to only send the fields we want



48
49
50
51
52
# File 'lib/processout/error_codes.rb', line 48

def to_json(options)
  {
      "gateway": self.gateway,
  }.to_json
end