Class: ProcessOut::CardUpdateRequest

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Initializes the CardUpdateRequest object Params:

client

ProcessOut client instance

data

data that can be used to fill the object



23
24
25
26
27
28
# File 'lib/processout/card_update_request.rb', line 23

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

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

Instance Attribute Details

#preferred_schemeObject

Returns the value of attribute preferred_scheme.



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

def preferred_scheme
  @preferred_scheme
end

Instance Method Details

#fill_with_data(data) ⇒ Object

Fills the object with data coming from the API Params:

data

Hash of data coming from the API



45
46
47
48
49
50
51
52
53
54
# File 'lib/processout/card_update_request.rb', line 45

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

#new(data = {}) ⇒ Object

Create a new CardUpdateRequest using the current client



31
32
33
# File 'lib/processout/card_update_request.rb', line 31

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

#prefill(data) ⇒ Object

Prefills the object with the data passed as parameters Params:

data

Hash of data



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

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

#to_json(options) ⇒ Object

Overrides the JSON marshaller to only send the fields we want



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

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

#update(card_id, options = {}) ⇒ Object

Update a card by its ID. Params:

card_id

ID of the card

options

Hash of options



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/processout/card_update_request.rb', line 72

def update(card_id, options = {})
  self.prefill(options)

  request = Request.new(@client)
  path    = "/cards/" + CGI.escape(card_id) + ""
  data    = {
    "preferred_scheme" => @preferred_scheme
  }

  response = Response.new(request.put(path, data, options))
  return_values = Array.new
  
  body = response.body
  body = body["card"]
  
  
  return_values.push(self.fill_with_data(body))
  

  
  return_values[0]
end