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:, config:, logging: true, log_level: :info) ⇒ HttpClient

Returns a new instance of HttpClient.



18
19
20
21
22
23
# File 'lib/quiz_api_client/http_client.rb', line 18

def initialize(uri:, jwt:, config:, logging: true, log_level: :info)
  @uri = uri
  @jwt = jwt
  @config = config
  initialize_logger(log_level) if logging
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



16
17
18
# File 'lib/quiz_api_client/http_client.rb', line 16

def config
  @config
end

#jwtObject (readonly)

Returns the value of attribute jwt.



16
17
18
# File 'lib/quiz_api_client/http_client.rb', line 16

def jwt
  @jwt
end

#uriObject (readonly)

Returns the value of attribute uri.



16
17
18
# File 'lib/quiz_api_client/http_client.rb', line 16

def uri
  @uri
end

Instance Method Details

#delete(path) ⇒ Object



49
50
51
# File 'lib/quiz_api_client/http_client.rb', line 49

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

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



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

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: sanitized_query(query, all)
end

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



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

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

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



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

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

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



45
46
47
# File 'lib/quiz_api_client/http_client.rb', line 45

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

#url_for(path) ⇒ Object



25
26
27
28
29
# File 'lib/quiz_api_client/http_client.rb', line 25

def url_for(path)
  url = URI(uri)
  url.path = path
  url.to_s
end