Class: Rescuetime::Requester

Inherits:
Object
  • Object
show all
Defined in:
lib/rescuetime/requester.rb

Overview

The Rescuetime::Requestable module contains client methods relating to sending HTTP requests

Since:

  • v0.2.0

Constant Summary collapse

INVALID =

Contains bodies of error responses recieved from rescuetime.com. If one of these responses is recieved, an error will be raised.

Since:

  • v0.2.0

{
  key_not_found: '"error":"# key not found","messages":"key not found"',
  query: '"error": "# query error",'\
  '"messages": "Error: Likely a badly formatted or missing parameter"'
}.freeze

Class Method Summary collapse

Class Method Details

.get(host, params) ⇒ String

Performs the GET request to the specified host. Before making the request, it checks for API key presence and raises an exception if it is not present. All other exceptions require the request to go through.

Parameters:

  • host (String)

    request host

  • params (Hash)

    request parameters

Returns:

  • (String)

Raises:

See Also:

Since:

  • v0.2.0



37
38
39
40
41
42
43
44
45
46
# File 'lib/rescuetime/requester.rb', line 37

def get(host, params)
  # guard clause: fail if no API key is present
  key = CoreExtensions::String.new params[:key].to_s # adds #present?
  key.present? || raise(Errors::MissingCredentialsError)

  uri = set_uri host, params
  response = Net::HTTP.get_response uri

  fail_or_return_body response
end