Class: TryApi::ExampleResponse
- Defined in:
- app/models/try_api/example_response.rb
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Base
Class Method Details
.descriptions ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'app/models/try_api/example_response.rb', line 19 def descriptions { 200 => :success, 401 => :unauthorized, 422 => :unprocessable_entity, 500 => :internal_server_error, } end |
.parse(hash:, project:) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'app/models/try_api/example_response.rb', line 9 def parse(hash:, project:) return nil if hash.blank? instance = self.new instance.code = hash[:code] instance.project = project instance.response = hash[:response] instance.type = hash[:type] instance end |
Instance Method Details
#color ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/models/try_api/example_response.rb', line 33 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
29 30 31 |
# File 'app/models/try_api/example_response.rb', line 29 def description self.class.descriptions[self.code].to_s.humanize end |
#response=(input) ⇒ Object
54 55 56 57 58 59 60 |
# File 'app/models/try_api/example_response.rb', line 54 def response=(input) if input['var:'] @response = self.project.variables[input.gsub('var:', '')] else @response = input end end |
#to_json ⇒ Object
50 51 52 |
# File 'app/models/try_api/example_response.rb', line 50 def to_json super.merge color: color, description: description, isCollapsed: true end |