Class: Prove::Verification

Inherits:
Object
  • Object
show all
Defined in:
lib/prove/verification.rb

Constant Summary collapse

ACCESSORS =
[:id, :tel, :text, :call, :verified]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attr_hash = {}) ⇒ Verification

Returns a new instance of Verification.



6
7
8
9
10
# File 'lib/prove/verification.rb', line 6

def initialize(attr_hash={})
  attr_hash.each do |key, val|
    self.instance_variable_set("@#{key}", val)
  end
end

Class Method Details

.create(*args) ⇒ Object



12
13
14
15
16
# File 'lib/prove/verification.rb', line 12

def self.create(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  tel = args[0] || options[:tel]
  from_json Prove.client.post('/api/v1/verify', {tel: tel}).body
end

.from_json(verification_hash) ⇒ Object



54
55
56
# File 'lib/prove/verification.rb', line 54

def self.from_json(verification_hash)
  return Verification.new(verification_hash)
end

.from_json_array(verifications) ⇒ Object



58
59
60
# File 'lib/prove/verification.rb', line 58

def self.from_json_array(verifications)
  return verifications.map{|attr_hash| Verification.new(attr_hash)}
end

.listObject



18
19
20
# File 'lib/prove/verification.rb', line 18

def self.list
  from_json_array Prove.client.get('/api/v1/verify').body
end

.retrieve(*args) ⇒ Object



30
31
32
33
34
# File 'lib/prove/verification.rb', line 30

def self.retrieve(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  id = args[0] || options[:id]
  from_json Prove.client.get('/api/v1/verify/' + id).body
end

.verify(*args) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/prove/verification.rb', line 22

def self.verify(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  id = args[0] || options[:id]
  pin = args[1] || options[:pin]

  from_json Prove.client.post('/api/v1/verify/' + id + '/pin', {pin: pin}).body
end

Instance Method Details

#retrieveObject



42
43
44
# File 'lib/prove/verification.rb', line 42

def retrieve
  self.class.retrieve(self.id)
end

#to_jsonObject



46
47
48
49
50
51
52
# File 'lib/prove/verification.rb', line 46

def to_json
  return {id: self.id, 
    tel: self.tel,
    text: self.text, 
    call: self.call, 
    verified: self.verified}.to_json
end

#verify(*args) ⇒ Object



36
37
38
39
40
# File 'lib/prove/verification.rb', line 36

def verify(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  pin = args[0] || options[:pin]
  self.class.verify(self.id, pin)
end