Class: ConektaMotion::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/conekta-motion/token.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token_id, error) ⇒ Token



5
6
7
8
# File 'lib/conekta-motion/token.rb', line 5

def initialize(token_id, error)
  @token_id = token_id
  @error = error
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



3
4
5
# File 'lib/conekta-motion/token.rb', line 3

def error
  @error
end

#token_idObject (readonly)

Returns the value of attribute token_id.



3
4
5
# File 'lib/conekta-motion/token.rb', line 3

def token_id
  @token_id
end

Class Method Details

.init_from(response) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/conekta-motion/token.rb', line 15

def init_from(response)
  token_id = nil
  error = nil

  if response
    token_id = response[:id] if response[:object] == 'token'
    error = response[:message_to_purchaser] if response[:object] == 'error'
  end

  Token.new token_id, error
end

Instance Method Details

#valid?Boolean



10
11
12
# File 'lib/conekta-motion/token.rb', line 10

def valid?
  error.nil?
end