Sha256: 847fd904629e140c34a051236845e5b0841dba3faa17fc5b9c8c8145bea764c8
Contents?: true
Size: 1.73 KB
Versions: 2
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: nil) @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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
roqua-core-api-0.0.15 | lib/roqua/core_api/sessions/auth_session.rb |
roqua-core-api-0.0.14 | lib/roqua/core_api/sessions/auth_session.rb |