Class: Sendly::Verification

Inherits:
Object
  • Object
show all
Defined in:
lib/sendly/verify.rb

Constant Summary collapse

STATUSES =
%w[pending verified expired failed].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Verification

Returns a new instance of Verification.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/sendly/verify.rb', line 11

def initialize(data)
  @id = data["id"]
  @status = data["status"]
  @phone = data["phone"]
  @delivery_status = data["delivery_status"]
  @attempts = data["attempts"] || 0
  @max_attempts = data["max_attempts"] || 3
  @expires_at = parse_time(data["expires_at"])
  @verified_at = parse_time(data["verified_at"])
  @created_at = parse_time(data["created_at"])
  @sandbox = data["sandbox"] || false
  @app_name = data["app_name"]
  @template_id = data["template_id"]
  @profile_id = data["profile_id"]
end

Instance Attribute Details

#app_nameObject (readonly)

Returns the value of attribute app_name.



5
6
7
# File 'lib/sendly/verify.rb', line 5

def app_name
  @app_name
end

#attemptsObject (readonly)

Returns the value of attribute attempts.



5
6
7
# File 'lib/sendly/verify.rb', line 5

def attempts
  @attempts
end

#created_atObject (readonly)

Returns the value of attribute created_at.



5
6
7
# File 'lib/sendly/verify.rb', line 5

def created_at
  @created_at
end

#delivery_statusObject (readonly)

Returns the value of attribute delivery_status.



5
6
7
# File 'lib/sendly/verify.rb', line 5

def delivery_status
  @delivery_status
end

#expires_atObject (readonly)

Returns the value of attribute expires_at.



5
6
7
# File 'lib/sendly/verify.rb', line 5

def expires_at
  @expires_at
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/sendly/verify.rb', line 5

def id
  @id
end

#max_attemptsObject (readonly)

Returns the value of attribute max_attempts.



5
6
7
# File 'lib/sendly/verify.rb', line 5

def max_attempts
  @max_attempts
end

#phoneObject (readonly)

Returns the value of attribute phone.



5
6
7
# File 'lib/sendly/verify.rb', line 5

def phone
  @phone
end

#profile_idObject (readonly)

Returns the value of attribute profile_id.



5
6
7
# File 'lib/sendly/verify.rb', line 5

def profile_id
  @profile_id
end

#sandboxObject (readonly)

Returns the value of attribute sandbox.



5
6
7
# File 'lib/sendly/verify.rb', line 5

def sandbox
  @sandbox
end

#statusObject (readonly)

Returns the value of attribute status.



5
6
7
# File 'lib/sendly/verify.rb', line 5

def status
  @status
end

#template_idObject (readonly)

Returns the value of attribute template_id.



5
6
7
# File 'lib/sendly/verify.rb', line 5

def template_id
  @template_id
end

#verified_atObject (readonly)

Returns the value of attribute verified_at.



5
6
7
# File 'lib/sendly/verify.rb', line 5

def verified_at
  @verified_at
end

Instance Method Details

#expired?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/sendly/verify.rb', line 35

def expired?
  status == "expired"
end

#failed?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/sendly/verify.rb', line 39

def failed?
  status == "failed"
end

#pending?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/sendly/verify.rb', line 27

def pending?
  status == "pending"
end

#to_hObject



43
44
45
46
47
48
49
50
51
# File 'lib/sendly/verify.rb', line 43

def to_h
  {
    id: id, status: status, phone: phone, delivery_status: delivery_status,
    attempts: attempts, max_attempts: max_attempts,
    expires_at: expires_at&.iso8601, verified_at: verified_at&.iso8601,
    created_at: created_at&.iso8601, sandbox: sandbox, app_name: app_name,
    template_id: template_id, profile_id: profile_id
  }.compact
end

#verified?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/sendly/verify.rb', line 31

def verified?
  status == "verified"
end