Sha256: fe8c433b73a874094aeafd6efceaff035e1a42585ecdad14ef302a70571809b5

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

module Agcod
  class CreateGiftCard < Agcod::Request
    include Agcod::OptionValidators

    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

    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
      end
    end

    attr_reader :claim_code, :response_id, :value

    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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dpickett-agcod-0.0.0 lib/agcod/create_gift_card.rb