Class: BusinessInsightApiClient::Helpers::RESTClient
- Inherits:
-
Object
- Object
- BusinessInsightApiClient::Helpers::RESTClient
- Includes:
- HTTPClient::Util
- Defined in:
- lib/business_insight_api_client/helpers/restclient.rb
Overview
RESTClient helper, used as helper to interact with the API endpoints.
Constant Summary collapse
- DEFAULT_OPTIONS =
{ api_url: 'https://api.nedap-bi.com', default_content_type: 'application/json', }
- API_VERSION_PATH =
'/v1'
Instance Attribute Summary collapse
-
#authorization ⇒ Object
readonly
Returns the value of attribute authorization.
-
#base_uri ⇒ URI
readonly
The uri of the api.
-
#content_type ⇒ String
readonly
The content type set.
Instance Method Summary collapse
- #delete(path) ⇒ Object
- #get(path, *args, &block) ⇒ Object
-
#initialize(authorization, options = {}) ⇒ RESTClient
constructor
Creates a new RESTClient helper.
- #post(path, body = '') ⇒ Object
- #put(path, body = '') ⇒ Object
Constructor Details
#initialize(authorization, options = {}) ⇒ RESTClient
Creates a new RESTClient helper
34 35 36 37 38 |
# File 'lib/business_insight_api_client/helpers/restclient.rb', line 34 def initialize(, = {}) @authorization = @base_uri = URI([:api_url] || DEFAULT_OPTIONS[:api_url]) @content_type = [:content_type] || DEFAULT_OPTIONS[:default_content_type] end |
Instance Attribute Details
#authorization ⇒ Object (readonly)
Returns the value of attribute authorization.
19 20 21 |
# File 'lib/business_insight_api_client/helpers/restclient.rb', line 19 def @authorization end |
#base_uri ⇒ URI (readonly)
Returns the uri of the api.
22 23 24 |
# File 'lib/business_insight_api_client/helpers/restclient.rb', line 22 def base_uri @base_uri end |
#content_type ⇒ String (readonly)
Returns the content type set.
25 26 27 |
# File 'lib/business_insight_api_client/helpers/restclient.rb', line 25 def content_type @content_type end |
Instance Method Details
#delete(path) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/business_insight_api_client/helpers/restclient.rb', line 67 def delete(path) build_path(path) response = client.delete(@base_uri.to_s, header: access_token_header) raise_errors(response) response.body end |
#get(path, *args, &block) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/business_insight_api_client/helpers/restclient.rb', line 40 def get(path, *args, &block) build_path(path) begin arguments = argument_to_hash(args,:query, :body, :header, :follow_redirect) || {} arguments[:header] = access_token_header.merge(arguments[:header] || {}) response = client.request(:get, @base_uri.to_s, arguments, &block) rescue HTTPClient::TimeoutError raise ::BusinessInsightApiClient::Errors::RequestTimedOutError end raise_errors(response) response.body end |
#post(path, body = '') ⇒ Object
60 61 62 63 64 65 |
# File 'lib/business_insight_api_client/helpers/restclient.rb', line 60 def post(path, body = '') build_path(path) response = client.post(@base_uri.to_s, body: body, header: { 'Content-Type' => content_type, 'Accept' => content_type}.merge(access_token_header)) raise_errors(response) response.body end |
#put(path, body = '') ⇒ Object
53 54 55 56 57 58 |
# File 'lib/business_insight_api_client/helpers/restclient.rb', line 53 def put(path, body = '') build_path(path) response = client.put(@base_uri.to_s, body: body, header: { 'Content-Type' => content_type, 'Accept' => content_type}.merge(access_token_header)) raise_errors(response) response.body end |