Class: MoesifApi::BaseController

Inherits:
Object
  • Object
show all
Defined in:
lib/moesif_api/controllers/base_controller.rb

Direct Known Subclasses

ApiController, HealthController

Constant Summary collapse

@@http_client =
UnirestClient.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_client: nil, http_call_back: nil) ⇒ BaseController

Returns a new instance of BaseController.



9
10
11
12
# File 'lib/moesif_api/controllers/base_controller.rb', line 9

def initialize(http_client: nil, http_call_back: nil)
  @http_client = http_client ||= @@http_client
  @http_call_back = http_call_back
end

Instance Attribute Details

#http_call_backObject

Returns the value of attribute http_call_back.



5
6
7
# File 'lib/moesif_api/controllers/base_controller.rb', line 5

def http_call_back
  @http_call_back
end

#http_clientObject

Returns the value of attribute http_client.



5
6
7
# File 'lib/moesif_api/controllers/base_controller.rb', line 5

def http_client
  @http_client
end

Instance Method Details

#validate_response(context) ⇒ Object



14
15
16
17
18
# File 'lib/moesif_api/controllers/base_controller.rb', line 14

def validate_response(context)      
  if !context.response.status_code.between?(200, 208) #[200,208] = HTTP OK
    raise APIException.new 'HTTP Response Not OK', context
  end
end