Class: EdmTrain::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/edm_train/client.rb

Overview

Client for the EdmTrain API

Instance Method Summary collapse

Instance Method Details

#get(path, params = {}) ⇒ Hash

Perform a GET request to the EdmTrain API

Parameters:

  • path (String)

    the path to the API endpoint

  • params (Hash) (defaults to: {})

    the query parameters

Returns:

  • (Hash)

    the response from the API

Raises:



46
47
48
49
50
51
52
53
54
# File 'lib/edm_train/client.rb', line 46

def get(path, params = {})
  raise MissingKeyError unless EdmTrain.api_key

  params[:client] = EdmTrain.api_key
  result = JSON.parse(URI.open("https://edmtrain.com/api/#{path}?#{to_query(params)}").read)
  raise APIError, result['message'] unless result['success']

  result['data']
end