Class: Kasabi::BaseClient
- Inherits:
-
Object
- Object
- Kasabi::BaseClient
- Defined in:
- lib/kasabi/api/base_client.rb
Overview
Base class for API clients
Direct Known Subclasses
Attribution, Augment::Client, Dataset, Jobs::Client, Lookup::Client, Reconcile::Client, Search::Client, Sparql::Client, Status, Storage::Client
Instance Attribute Summary collapse
-
#apikey ⇒ Object
readonly
Returns the value of attribute apikey.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
Instance Method Summary collapse
- #client_options ⇒ Object
- #get(uri, query = nil, headers = {}) ⇒ Object
-
#initialize(endpoint, options = {}) ⇒ BaseClient
constructor
Initialize the client to work with a specific endpoint.
- #post(uri, body = "", headers = {}) ⇒ Object
- #validate_response(response) ⇒ Object
Constructor Details
#initialize(endpoint, options = {}) ⇒ BaseClient
Initialize the client to work with a specific endpoint
The options hash can contain the following values:
-
:apikey: required. apikey authorized to use the API
-
:client: HTTPClient object instance
15 16 17 18 19 |
# File 'lib/kasabi/api/base_client.rb', line 15 def initialize(endpoint, ={}) @endpoint = endpoint @client = [:client] || HTTPClient.new() @apikey = [:apikey] || nil end |
Instance Attribute Details
#apikey ⇒ Object (readonly)
Returns the value of attribute apikey.
8 9 10 |
# File 'lib/kasabi/api/base_client.rb', line 8 def apikey @apikey end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
7 8 9 |
# File 'lib/kasabi/api/base_client.rb', line 7 def client @client end |
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
6 7 8 |
# File 'lib/kasabi/api/base_client.rb', line 6 def endpoint @endpoint end |
Instance Method Details
#client_options ⇒ Object
21 22 23 |
# File 'lib/kasabi/api/base_client.rb', line 21 def {:apikey => @apikey, :client => @client} end |
#get(uri, query = nil, headers = {}) ⇒ Object
25 26 27 28 |
# File 'lib/kasabi/api/base_client.rb', line 25 def get(uri, query=nil, headers={}) headers["X_KASABI_APIKEY"] = @apikey return @client.get(uri, query, headers) end |
#post(uri, body = "", headers = {}) ⇒ Object
30 31 32 33 |
# File 'lib/kasabi/api/base_client.rb', line 30 def post(uri, body="", headers={}) headers["X_KASABI_APIKEY"] = @apikey return @client.post(uri, body, headers) end |
#validate_response(response) ⇒ Object
35 36 37 38 39 |
# File 'lib/kasabi/api/base_client.rb', line 35 def validate_response(response) if response.status != 200 raise "Unable to perform request. Status: #{response.status}. Message: #{response.content}" end end |