class Authy::Response

Attributes

raw_response[R]

Public Class Methods

new(response) click to toggle source
# File lib/authy/response.rb, line 4
def initialize(response)
  @raw_response = response
  @errors = {}
  parse_body
end

Public Instance Methods

body() click to toggle source
# File lib/authy/response.rb, line 19
def body
  @raw_response.body
end
code() click to toggle source
# File lib/authy/response.rb, line 23
def code
  @raw_response.status
end
error_msg() click to toggle source
# File lib/authy/response.rb, line 27
def error_msg
  if ok?
    "No error"
  elsif self.empty?
    self.body
  else
    self["message"] || "No error"
  end
end
errors() click to toggle source
# File lib/authy/response.rb, line 37
def errors
  self["errors"] || @errors
end
id() click to toggle source
# File lib/authy/response.rb, line 10
def id
  self["id"]
end
ok?() click to toggle source
# File lib/authy/response.rb, line 14
def ok?
  @raw_response.status == 200
end
Also aliased as: success?
success?()
Alias for: ok?

Protected Instance Methods

method_missing(name, *args, &block) click to toggle source
Calls superclass method
# File lib/authy/response.rb, line 43
def method_missing(name, *args, &block)
  if self.include?(name.to_s)
    self[name.to_s]
  else
    super(name, *args, &block)
  end
end
parse_body() click to toggle source
# File lib/authy/response.rb, line 51
def parse_body
  body = JSON.parse(@raw_response.body)
  body.each do |k,v|
    self[k] = v
  end
rescue
  self['message'] = 'invalid json'
end