Sha256: d6760bdcea6cdef2f4bd33be288fb1e0de1853936547f26f4858cfb2c7af445f
Contents?: true
Size: 1.73 KB
Versions: 1
Compression:
Stored size: 1.73 KB
Contents
module Roqua module CoreApi module Sessions class AuthSession attr_reader :core_host attr_reader :default_timeout # timeout for requests in seconds def initialize(core_host: ENV['CORE_HOST'], timeout: 5) @core_host = core_host @default_timeout = timeout end def get(path, timeout: default_timeout, **params) perform_request_or_fail do HTTParty.get(full_url_for(path), headers: headers, query: params, basic_auth: basic_auth, timeout: timeout) end end def post(path, timeout: default_timeout, **params) perform_request_or_fail do HTTParty.post(full_url_for(path), headers: headers, body: params, basic_auth: basic_auth, timeout: timeout) end end def patch(path, timeout: default_timeout, **params) perform_request_or_fail do HTTParty.patch(full_url_for(path), headers: headers, body: params, basic_auth: basic_auth, timeout: timeout) end end def delete(path, timeout: default_timeout, **params) HTTParty.delete(full_url_for(path), headers: headers, query: params, basic_auth: basic_auth, timeout: timeout) end private def perform_request_or_fail(&block) response = yield fail response.parsed_response unless (200..299).include?(response.code) || 422 == response.code response end def full_url_for(path) core_host + api_base + path + '.json' end def api_base '/api/v1' end def headers end def basic_auth end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
roqua-core-api-0.0.13 | lib/roqua/core_api/sessions/auth_session.rb |