Class: TheCompaniesAPI::HttpClient
- Inherits:
-
Object
- Object
- TheCompaniesAPI::HttpClient
- Defined in:
- lib/thecompaniesapi/http_client.rb
Direct Known Subclasses
Defined Under Namespace
Classes: QuerySerializer
Constant Summary collapse
- DEFAULT_API_URL =
'https://api.thecompaniesapi.com'- DEFAULT_TIMEOUT =
300
Instance Attribute Summary collapse
-
#api_token ⇒ Object
readonly
Returns the value of attribute api_token.
-
#api_url ⇒ Object
readonly
Returns the value of attribute api_url.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#visitor_id ⇒ Object
readonly
Returns the value of attribute visitor_id.
Instance Method Summary collapse
- #delete(path, params: {}) ⇒ Object
-
#get(path, params: {}) ⇒ Object
HTTP method helpers.
-
#initialize(api_token: nil, api_url: nil, visitor_id: nil) ⇒ HttpClient
constructor
A new instance of HttpClient.
- #patch(path, body: {}) ⇒ Object
- #post(path, body: {}) ⇒ Object
- #put(path, body: {}) ⇒ Object
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_token ⇒ Object (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_url ⇒ Object (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 |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
14 15 16 |
# File 'lib/thecompaniesapi/http_client.rb', line 14 def connection @connection end |
#visitor_id ⇒ Object (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 |