Class: TryApi::ExampleResponse
- Inherits:
-
Base
- Object
- Base
- TryApi::ExampleResponse
show all
- Defined in:
- app/models/try_api/example_response.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#id, #to_json, typesafe_accessor
Class Method Details
.descriptions ⇒ Object
17
18
19
20
21
22
23
24
|
# File 'app/models/try_api/example_response.rb', line 17
def descriptions
{
200 => :success,
401 => :unauthorized,
422 => :unprocessable_entity,
500 => :internal_server_error,
}
end
|
.parse(hash) ⇒ Object
8
9
10
11
12
13
14
15
|
# File 'app/models/try_api/example_response.rb', line 8
def parse(hash)
return nil if hash.blank?
instance = self.new
instance.code = hash[:code]
instance.response = hash[:response]
instance.type = hash[:type]
instance
end
|
Instance Method Details
#color ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'app/models/try_api/example_response.rb', line 31
def color
case self.code
when 200
'success'
when 200...300
'info'
when 300...400
'warning'
when 400...500
'warning'
when 500
'danger'
else
'default'
end
end
|
#description ⇒ Object
27
28
29
|
# File 'app/models/try_api/example_response.rb', line 27
def description
self.class.descriptions[self.code]
end
|