Sha256: 9722a0d71baeed73eedaa3e9eb4b06724afff4ee81db8a218e55f5419aab45ba

Contents?: true

Size: 1.38 KB

Versions: 2

Compression:

Stored size: 1.38 KB

Contents

module Roqua
  module CoreApi
    module Sessions
      class AuthSession
        attr_reader :core_host

        def initialize(core_host: ENV['ROQUA_CORE_HOST'])
          @core_host = core_host
        end

        def get(path, params = {})
          perform_request_or_fail do
            HTTParty.get(full_url_for(path), headers: headers, query: params, basic_auth: basic_auth)
          end
        end

        def post(path, params = {})
          perform_request_or_fail do
            HTTParty.post(full_url_for(path), headers: headers, body: params, basic_auth: basic_auth)
          end
        end

        def patch(path, params = {})
          perform_request_or_fail do
            HTTParty.patch(full_url_for(path), headers: headers, body: params, basic_auth: basic_auth)
          end
        end

        def delete(path, params = {})
          HTTParty.delete(full_url_for(path), headers: headers, query: params, basic_auth: basic_auth)
        end

        private

        def perform_request_or_fail(&block)
          response = yield
          fail response.parsed_response unless (200..299).include? 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.11 lib/roqua/core_api/sessions/auth_session.rb
roqua-core-api-0.0.10 lib/roqua/core_api/sessions/auth_session.rb