Class: TryApi::ExampleResponse

Inherits:
Base
  • Object
show all
Defined in:
app/models/try_api/example_response.rb

Instance Attribute Summary

Attributes inherited from Base

#id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize, #load_inclusion, load_inclusion, #project, typesafe_accessor

Constructor Details

This class inherits a constructor from TryApi::Base

Class Method Details

.descriptionsObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/models/try_api/example_response.rb', line 18

def descriptions
  {
      200 => :success,
      201 => :created,
      204 => :no_content,
      304 => :not_modified,
      400 => :bad_request,
      401 => :unauthorized,
      403 => :forbidden,
      404 => :not_found,
      408 => :request_timeout,
      422 => :unprocessable_entity,
      500 => :internal_server_error,
      502 => :bad_gateway,
      503 => :service_unavailable,
      504 => :gateway_timeout
  }
end

.parse(hash:, project:) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'app/models/try_api/example_response.rb', line 8

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

#colorObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/models/try_api/example_response.rb', line 42

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

#descriptionObject



38
39
40
# File 'app/models/try_api/example_response.rb', line 38

def description
  self.class.descriptions[self.code].to_s.humanize
end

#to_json(id) ⇒ Object



59
60
61
# File 'app/models/try_api/example_response.rb', line 59

def to_json(id)
  super(id).merge color: color, description: description, isCollapsed: true
end