Class: QuizApiClient::HttpClient
- Inherits:
-
Object
- Object
- QuizApiClient::HttpClient
- Includes:
- HTTParty
- Defined in:
- lib/quiz_api_client/http_client.rb
Defined Under Namespace
Classes: RequestFailed
Instance Attribute Summary collapse
-
#jwt ⇒ Object
readonly
Returns the value of attribute jwt.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #delete(path) ⇒ Object
- #get(path, all: false, query: {}) ⇒ Object
-
#initialize(uri:, jwt:, consumer_request_id: nil, logging: true, log_level: :info) ⇒ HttpClient
constructor
A new instance of HttpClient.
- #patch(path, body = {}) ⇒ Object
- #post(path, body = {}) ⇒ Object
- #put(path, body = {}) ⇒ Object
- #url_for(path) ⇒ Object
Constructor Details
#initialize(uri:, jwt:, consumer_request_id: nil, logging: true, log_level: :info) ⇒ HttpClient
Returns a new instance of HttpClient.
11 12 13 14 15 16 |
# File 'lib/quiz_api_client/http_client.rb', line 11 def initialize(uri:, jwt:, consumer_request_id: nil, logging: true, log_level: :info) @uri = uri @jwt = jwt @consumer_request_id = consumer_request_id initialize_logger(log_level) if logging end |
Instance Attribute Details
#jwt ⇒ Object (readonly)
Returns the value of attribute jwt.
9 10 11 |
# File 'lib/quiz_api_client/http_client.rb', line 9 def jwt @jwt end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
9 10 11 |
# File 'lib/quiz_api_client/http_client.rb', line 9 def uri @uri end |
Instance Method Details
#delete(path) ⇒ Object
42 43 44 |
# File 'lib/quiz_api_client/http_client.rb', line 42 def delete(path) make_request :delete, url_for(path) end |
#get(path, all: false, query: {}) ⇒ Object
24 25 26 27 28 |
# File 'lib/quiz_api_client/http_client.rb', line 24 def get(path, all: false, query: {}) return make_request :get, url_for(path), query: query unless all make_paginated_request :get, url_for(path), query: query end |
#patch(path, body = {}) ⇒ Object
34 35 36 |
# File 'lib/quiz_api_client/http_client.rb', line 34 def patch(path, body = {}) make_request :patch, url_for(path), body: body.to_json end |
#post(path, body = {}) ⇒ Object
30 31 32 |
# File 'lib/quiz_api_client/http_client.rb', line 30 def post(path, body = {}) make_request :post, url_for(path), body: body.to_json end |
#put(path, body = {}) ⇒ Object
38 39 40 |
# File 'lib/quiz_api_client/http_client.rb', line 38 def put(path, body = {}) make_request :put, url_for(path), body: body.to_json end |
#url_for(path) ⇒ Object
18 19 20 21 22 |
# File 'lib/quiz_api_client/http_client.rb', line 18 def url_for(path) url = URI(uri) url.path = path url.to_s end |