Class: Authy::Response
- Inherits:
-
Hash
- Object
- Hash
- Authy::Response
show all
- Defined in:
- lib/authy/response.rb
Direct Known Subclasses
User
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Hash
try_convert
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
4
5
6
7
8
|
# File 'lib/authy/response.rb', line 4
def initialize(response)
@raw_response = response
@errors = {}
parse_body
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/authy/response.rb', line 42
def method_missing(name, *args, &block)
if self.include?(name.to_s)
self[name.to_s]
else
super(name, *args, &block)
end
end
|
Instance Attribute Details
#raw_response ⇒ Object
Returns the value of attribute raw_response.
3
4
5
|
# File 'lib/authy/response.rb', line 3
def raw_response
@raw_response
end
|
Instance Method Details
#body ⇒ Object
19
20
21
|
# File 'lib/authy/response.rb', line 19
def body
@raw_response.body
end
|
#code ⇒ Object
23
24
25
|
# File 'lib/authy/response.rb', line 23
def code
@raw_response.status
end
|
#error_msg ⇒ Object
27
28
29
30
31
32
33
34
35
|
# 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 ⇒ Object
37
38
39
|
# File 'lib/authy/response.rb', line 37
def errors
self["errors"] || @errors
end
|
#id ⇒ Object
10
11
12
|
# File 'lib/authy/response.rb', line 10
def id
self["id"]
end
|
#ok? ⇒ Boolean
Also known as:
success?
14
15
16
|
# File 'lib/authy/response.rb', line 14
def ok?
@raw_response.status == 200
end
|