Class: Agcod::CreateGiftCard

Inherits:
Request
  • Object
show all
Includes:
OptionValidators
Defined in:
lib/agcod/create_gift_card.rb

Instance Attribute Summary collapse

Attributes inherited from Request

#action, #errors, #parameters, #request, #request_id, #response, #sent, #status, #timestamp, #xml_response

Instance Method Summary collapse

Methods included from OptionValidators

#validate_timestamp

Methods inherited from Request

#request_url, #sign_string, #submit, #successful?

Constructor Details

#initialize(options = {}) ⇒ CreateGiftCard

Returns a new instance of CreateGiftCard.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/agcod/create_gift_card.rb', line 5

def initialize(options = {})
  @action = "CreateGiftCard"
  super

  validate_greater_than("value", 0)
  validate_length_of("request_id", {"max" => 19, "min" => 1})

  #can't have a nonexistant or 0 value for the gift card
  @parameters["gcValue.amount"] = options["value"]

  @value = options["value"]

  #must have a unique identifier for the request
  @parameters["gcCreationRequestId"]  = Agcod::Configuration.partner_id + options["request_id"].to_s

  @parameters["gcValue.currencyCode"] = options["currency_code"] || "USD" 

end

Instance Attribute Details

#claim_codeObject (readonly)

Returns the value of attribute claim_code.



37
38
39
# File 'lib/agcod/create_gift_card.rb', line 37

def claim_code
  @claim_code
end

#response_idObject (readonly)

Returns the value of attribute response_id.



37
38
39
# File 'lib/agcod/create_gift_card.rb', line 37

def response_id
  @response_id
end

#valueObject (readonly)

Returns the value of attribute value.



37
38
39
# File 'lib/agcod/create_gift_card.rb', line 37

def value
  @value
end

Instance Method Details

#process_responseObject



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/agcod/create_gift_card.rb', line 24

def process_response
  super
  if self.successful?
    @claim_code = self.xml_response.root.elements["gcClaimCode"].text
    @response_id = self.xml_response.root.elements["gcCreationResponseId"].text
  else
    attempt_retry unless @sent_retry
    if @sent_retry
      void_on_resend
    end
  end
end

#to_yaml(name) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/agcod/create_gift_card.rb', line 39

def to_yaml(name)
  {"response_id" => self.response_id, 
    "request_id" => self.request_id, 
    "claim_code" => self.claim_code,
    "value" => self.value,
    "timestamp" => self.timestamp
  }.to_yaml(name)
end