Class: QuizApiClient::HttpClient

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/quiz_api_client/http_client.rb

Defined Under Namespace

Classes: RequestFailed

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#jwtObject (readonly)

Returns the value of attribute jwt.



9
10
11
# File 'lib/quiz_api_client/http_client.rb', line 9

def jwt
  @jwt
end

#uriObject (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



41
42
43
# File 'lib/quiz_api_client/http_client.rb', line 41

def delete(path)
  make_request :delete, url_for(path)
end

#get(path, all: false, query: {}) ⇒ Object



24
25
26
27
# 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



33
34
35
# File 'lib/quiz_api_client/http_client.rb', line 33

def patch(path, body = {})
  make_request :patch, url_for(path), body: body.to_json
end

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



29
30
31
# File 'lib/quiz_api_client/http_client.rb', line 29

def post(path, body = {})
  make_request :post, url_for(path), body: body.to_json
end

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



37
38
39
# File 'lib/quiz_api_client/http_client.rb', line 37

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