Class: MarbleApiClient::Client

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

Overview

Main class for sending HTTP requests to a URL. Requests are sent using request and response objects crafted for each action. Headers can be provided to the Proxy as default headers for all requests

Instance Method Summary collapse

Constructor Details

#initialize(base_url, headers: {}) ⇒ Client

Returns a new instance of Client.

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
# File 'lib/marble_api_client/client.rb', line 15

def initialize(base_url, headers: {})
  raise ArgumentError, 'Base URL is not valid' unless base_url_valid?(base_url)

  @base_url = base_url
  @headers = { 'Content-Type': 'application/json' }.merge(headers)
  freeze
end

Instance Method Details

#create(path, create_request: Requests::Create.new, headers: {}) ⇒ Object



23
24
25
26
# File 'lib/marble_api_client/client.rb', line 23

def create(path, create_request: Requests::Create.new, headers: {})
  response = send_request(path, Requests::Create.make(create_request), headers, 'create')
  Responses.parse_response(response, Responses::CREATE_ACTION)
end

#index(path, index_request: Requests::Index.new, headers: {}) ⇒ Object



28
29
30
31
# File 'lib/marble_api_client/client.rb', line 28

def index(path, index_request: Requests::Index.new, headers: {})
  response = send_request(path, Requests::Index.make(index_request), headers, 'index')
  Responses.parse_response(response, Responses::INDEX_ACTION)
end