Class: TheCompaniesAPI::HttpClient

Inherits:
Object
  • Object
show all
Defined in:
lib/thecompaniesapi/http_client.rb

Direct Known Subclasses

Client

Defined Under Namespace

Classes: QuerySerializer

Constant Summary collapse

DEFAULT_API_URL =
'https://api.thecompaniesapi.com'
DEFAULT_TIMEOUT =
300

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_token: nil, api_url: nil, visitor_id: nil) ⇒ HttpClient

Returns a new instance of HttpClient.



16
17
18
19
20
21
22
# File 'lib/thecompaniesapi/http_client.rb', line 16

def initialize(api_token: nil, api_url: nil, visitor_id: nil)
  @api_token = api_token
  @api_url = api_url || DEFAULT_API_URL
  @visitor_id = visitor_id
  
  @connection = build_connection
end

Instance Attribute Details

#api_tokenObject (readonly)

Returns the value of attribute api_token.



14
15
16
# File 'lib/thecompaniesapi/http_client.rb', line 14

def api_token
  @api_token
end

#api_urlObject (readonly)

Returns the value of attribute api_url.



14
15
16
# File 'lib/thecompaniesapi/http_client.rb', line 14

def api_url
  @api_url
end

#connectionObject (readonly)

Returns the value of attribute connection.



14
15
16
# File 'lib/thecompaniesapi/http_client.rb', line 14

def connection
  @connection
end

#visitor_idObject (readonly)

Returns the value of attribute visitor_id.



14
15
16
# File 'lib/thecompaniesapi/http_client.rb', line 14

def visitor_id
  @visitor_id
end

Instance Method Details

#delete(path, params: {}) ⇒ Object



49
50
51
52
53
# File 'lib/thecompaniesapi/http_client.rb', line 49

def delete(path, params: {})
  handle_response do
    connection.delete(path, params)
  end
end

#get(path, params: {}) ⇒ Object

HTTP method helpers



25
26
27
28
29
# File 'lib/thecompaniesapi/http_client.rb', line 25

def get(path, params: {})
  handle_response do
    connection.get(path, params)
  end
end

#patch(path, body: {}) ⇒ Object



43
44
45
46
47
# File 'lib/thecompaniesapi/http_client.rb', line 43

def patch(path, body: {})
  handle_response do
    connection.patch(path, body)
  end
end

#post(path, body: {}) ⇒ Object



31
32
33
34
35
# File 'lib/thecompaniesapi/http_client.rb', line 31

def post(path, body: {})
  handle_response do
    connection.post(path, body)
  end
end

#put(path, body: {}) ⇒ Object



37
38
39
40
41
# File 'lib/thecompaniesapi/http_client.rb', line 37

def put(path, body: {})
  handle_response do
    connection.put(path, body)
  end
end