Class: CuentaDigital::Coupon
- Inherits:
-
Object
- Object
- CuentaDigital::Coupon
- Defined in:
- lib/cuenta_digital/coupon.rb
Constant Summary collapse
- ATTRIBUTES_PRECENSE =
i[id price first_due_date code concept currency].freeze
Instance Attribute Summary collapse
-
#code ⇒ Object
Su numero de CuentaDigital.
-
#concept ⇒ Object
Su numero de CuentaDigital.
-
#currency ⇒ Object
Su numero de CuentaDigital.
-
#email_from ⇒ Object
Su numero de CuentaDigital.
-
#email_to ⇒ Object
Su numero de CuentaDigital.
-
#errors ⇒ Object
Su numero de CuentaDigital.
-
#first_due_date ⇒ Object
Su numero de CuentaDigital.
-
#hash ⇒ Object
Su numero de CuentaDigital.
-
#id ⇒ Object
Su numero de CuentaDigital.
-
#m0 ⇒ Object
Su numero de CuentaDigital.
-
#m2 ⇒ Object
Su numero de CuentaDigital.
-
#m4 ⇒ Object
Su numero de CuentaDigital.
-
#price ⇒ Object
Su numero de CuentaDigital.
-
#price_second_due_date ⇒ Object
Su numero de CuentaDigital.
-
#response_body ⇒ Object
Su numero de CuentaDigital.
-
#response_code ⇒ Object
Su numero de CuentaDigital.
-
#second_due_date ⇒ Object
Su numero de CuentaDigital.
-
#site ⇒ Object
Su numero de CuentaDigital.
Instance Method Summary collapse
- #error? ⇒ Boolean
- #generate(xml: true, wget: false) ⇒ Object
- #generated? ⇒ Boolean
-
#initialize(params = {}) ⇒ Coupon
constructor
A new instance of Coupon.
- #params ⇒ Object
- #response ⇒ Object
- #uri(xml: true) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(params = {}) ⇒ Coupon
Returns a new instance of Coupon.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/cuenta_digital/coupon.rb', line 26 def initialize(params = {}) @id = params[:id] @price = params[:price] @site = params[:site] @first_due_date = params[:first_due_date] @code = params[:code] @email_from = params[:email_from].nil? || params[:email_from].empty? ? nil : params[:email_from] @email_to = params[:email_to].nil? || params[:email_to].empty? ? nil : params[:email_to] @concept = params[:concept] @currency = params[:currency] ? params[:currency].to_sym : nil @hash = Digest::MD5.hexdigest(params[:key_hash]) if params[:key_hash] @price_second_due_date = params[:price_second_due_date] @second_due_date = params[:second_due_date] @m0 = params[:m0] || 0 @m2 = params[:m2] || 0 @m4 = params[:m4] || 1 @errors = {} end |
Instance Attribute Details
#code ⇒ Object
Su numero de CuentaDigital
7 8 9 |
# File 'lib/cuenta_digital/coupon.rb', line 7 def code @code end |
#concept ⇒ Object
Su numero de CuentaDigital
7 8 9 |
# File 'lib/cuenta_digital/coupon.rb', line 7 def concept @concept end |
#currency ⇒ Object
Su numero de CuentaDigital
7 8 9 |
# File 'lib/cuenta_digital/coupon.rb', line 7 def currency @currency end |
#email_from ⇒ Object
Su numero de CuentaDigital
7 8 9 |
# File 'lib/cuenta_digital/coupon.rb', line 7 def email_from @email_from end |
#email_to ⇒ Object
Su numero de CuentaDigital
7 8 9 |
# File 'lib/cuenta_digital/coupon.rb', line 7 def email_to @email_to end |
#errors ⇒ Object
Su numero de CuentaDigital
7 8 9 |
# File 'lib/cuenta_digital/coupon.rb', line 7 def errors @errors end |
#first_due_date ⇒ Object
Su numero de CuentaDigital
7 8 9 |
# File 'lib/cuenta_digital/coupon.rb', line 7 def first_due_date @first_due_date end |
#hash ⇒ Object
Su numero de CuentaDigital
7 8 9 |
# File 'lib/cuenta_digital/coupon.rb', line 7 def hash @hash end |
#id ⇒ Object
Su numero de CuentaDigital
7 8 9 |
# File 'lib/cuenta_digital/coupon.rb', line 7 def id @id end |
#m0 ⇒ Object
Su numero de CuentaDigital
7 8 9 |
# File 'lib/cuenta_digital/coupon.rb', line 7 def m0 @m0 end |
#m2 ⇒ Object
Su numero de CuentaDigital
7 8 9 |
# File 'lib/cuenta_digital/coupon.rb', line 7 def m2 @m2 end |
#m4 ⇒ Object
Su numero de CuentaDigital
7 8 9 |
# File 'lib/cuenta_digital/coupon.rb', line 7 def m4 @m4 end |
#price ⇒ Object
Su numero de CuentaDigital
7 8 9 |
# File 'lib/cuenta_digital/coupon.rb', line 7 def price @price end |
#price_second_due_date ⇒ Object
Su numero de CuentaDigital
7 8 9 |
# File 'lib/cuenta_digital/coupon.rb', line 7 def price_second_due_date @price_second_due_date end |
#response_body ⇒ Object
Su numero de CuentaDigital
7 8 9 |
# File 'lib/cuenta_digital/coupon.rb', line 7 def response_body @response_body end |
#response_code ⇒ Object
Su numero de CuentaDigital
7 8 9 |
# File 'lib/cuenta_digital/coupon.rb', line 7 def response_code @response_code end |
#second_due_date ⇒ Object
Su numero de CuentaDigital
7 8 9 |
# File 'lib/cuenta_digital/coupon.rb', line 7 def second_due_date @second_due_date end |
#site ⇒ Object
Su numero de CuentaDigital
7 8 9 |
# File 'lib/cuenta_digital/coupon.rb', line 7 def site @site end |
Instance Method Details
#error? ⇒ Boolean
107 108 109 |
# File 'lib/cuenta_digital/coupon.rb', line 107 def error? response.error? end |
#generate(xml: true, wget: false) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/cuenta_digital/coupon.rb', line 76 def generate(xml: true, wget: false) return false unless valid? retries = 0 begin if wget @response_code = '200' @response_body = `wget -O- "#{uri(xml: xml).to_s}"` else partial_response = Net::HTTP.get_response(uri(xml: xml)) @response_code = partial_response.code @response_body = partial_response.body end response rescue => e if retries < 3 retries += 1 retry end raise e end end |
#generated? ⇒ Boolean
103 104 105 |
# File 'lib/cuenta_digital/coupon.rb', line 103 def generated? response.invoice_generated? end |
#params ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/cuenta_digital/coupon.rb', line 45 def params attr_params = { id: @id, precio: @price, site: @site, venc: @first_due_date, codigo: @code, concepto: @concept.to_sym, moneda: CuentaDigital::CURRENCIES[@currency], m0: @m0, m2: @m2, m4: @m4, desde: @email_from, hacia: @email_to, precio2: @price_second_due_date, vence2: @second_due_date, hash: @hash } attr_params.delete_if { |k, v| v.nil? } end |
#response ⇒ Object
99 100 101 |
# File 'lib/cuenta_digital/coupon.rb', line 99 def response @response = CuentaDigital::Response.new(@response_body) end |
#uri(xml: true) ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/cuenta_digital/coupon.rb', line 65 def uri(xml: true) uri_params = params uri_params[:xml] = 1 if xml uri_request = CuentaDigital.uri_coupon_generation uri_request.query = URI.encode_www_form(uri_params.to_a) uri_request end |
#valid? ⇒ Boolean
111 112 113 114 |
# File 'lib/cuenta_digital/coupon.rb', line 111 def valid? validate! errors.empty? end |