Class: OkComputer::HubspotCheck

Inherits:
HttpCheck
  • Object
show all
Defined in:
lib/ok_computer/checks/hubspot_check.rb

Constant Summary collapse

StatusFailed =
Class.new(StandardError)
STATUS_URL =
"https://api.hubapi.com/integrations/v1/limit/daily"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url: STATUS_URL, api_key: nil, request_timeout: 5) ⇒ HubspotCheck

Returns a new instance of HubspotCheck.



14
15
16
17
18
# File 'lib/ok_computer/checks/hubspot_check.rb', line 14

def initialize(url: STATUS_URL, api_key: nil, request_timeout: 5)
  super(url, request_timeout)

  self.api_key = api_key.presence
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



12
13
14
# File 'lib/ok_computer/checks/hubspot_check.rb', line 12

def api_key
  @api_key
end

Instance Method Details

#checkObject

Public: Return the status of the Rate-Limit check



21
22
23
24
25
26
27
28
29
# File 'lib/ok_computer/checks/hubspot_check.rb', line 21

def check
  status, body = perform_request
  raise(StatusFailed, body) unless status == 200

  mark_message("Rate-Limit check successful")
rescue StandardError => e
  mark_message("Error: '#{e}'")
  mark_failure
end

#perform_requestObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/ok_computer/checks/hubspot_check.rb', line 31

def perform_request
  response = Faraday.get(url, request: { timeout: request_timeout }) do |req|
    req.headers["Content-Type"] = "application/json"
    req.params["hapikey"] = api_key
  end

  [response.status, MultiJson.decode(response.body)]
rescue StandardError => e
  raise(StatusFailed, e)
end