Sha256: 973547055baf36e454af8962ba205b6b5f72707f08abdfca8735c5af8bd9bfb0
Contents?: true
Size: 1.1 KB
Versions: 7
Compression:
Stored size: 1.1 KB
Contents
module QuizApiClient class HttpClient include HTTParty class RequestFailed < StandardError; end attr_reader :jwt, :uri def initialize(uri:, jwt:) @uri = uri @jwt = jwt end def get(path, query = {}) make_request :get, path, options(query: query) end def post(path, body = {}) make_request :post, path, options(body: body) end def patch(path, body = {}) make_request :patch, path, options(body: body) end def put(path, body = {}) make_request :put, path, options(body: body) end def delete(path) make_request :delete, path, options end private def make_request(method, path, options) self.class.send( method, "#{uri}#{path}", options ) rescue HTTParty::Error, Errno::ECONNREFUSED, Net::ReadTimeout => e raise RequestFailed, e.message end def options(opts = {}) { headers: headers }.merge(opts) end def headers { 'Authorization' => jwt, 'AuthType' => 'Signature', 'Accept' => 'application/json' } end end end
Version data entries
7 entries across 7 versions & 1 rubygems