Class: OtpWidget::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/otpwidget/otpwidgetclient.rb

Constant Summary collapse

API_URL =
'https://control.msg91.com/api/v5/widget/verifyAccessToken'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(authkey) ⇒ Client

Returns a new instance of Client.



10
11
12
# File 'lib/otpwidget/otpwidgetclient.rb', line 10

def initialize(authkey)
  @authkey = authkey
end

Instance Method Details

#verify_access_token(jwt_token) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/otpwidget/otpwidgetclient.rb', line 14

def verify_access_token(jwt_token)
  uri = URI(API_URL)
  headers = { 'Content-Type': 'application/json' }
  body = {
    authkey: @authkey,
    'access-token': jwt_token
  }.to_json

  response = post_request(uri, headers, body)
  JSON.parse(response.body)
rescue JSON::ParserError => e
  { error: 'Invalid JSON response', message: e.message }
end