Sha256: 73c36f85129f6b9f505e5acc2b86484c45d463e4abb8a8ff52d369ef4400f3ce

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

module Roqua
  module CoreApi
    module Sessions
      # OrganizationSession represents a session which is scoped to a specific organization
      # in the Core database. It deals with managing dossier groups and dossiers,
      # but only on a anonymous base. It is not allowed to know who these dossiers
      # represent.
      class OrganizationSession
        attr_reader :server_url
        attr_reader :organization_id

        def initialize(organization_id, server_url = ENV["CORE_URL"])
          @server_url = server_url
          @organization_id     = organization_id
        end

        def create_dossier_group(attributes)
          response = post "/dossier_groups", dossier_group: attributes
          fail response.inspect unless response.code == 201
          Models::DossierGroup.new(response)
        end

        def dossier_group_session(dossier_group_id)
          DossierGroupSession.new dossier_group_id, organization_id, server_url
        end

        private

        def get(url, params = {})
          # TODO: Handle authentication here
          HTTParty.get(server_url + base_url + url + ".json", query: params)
        end

        def post(url, params = {})
          # TODO: Handle authentication here
          HTTParty.post(server_url + base_url + url + ".json", body: params)
        end

        def put(url, params = {})
          # TODO: Handle authentication here
          HTTParty.put(server_url + base_url + url + ".json", body: params)
        end

        def base_url
          "/organizations/#{organization_id}"
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
roqua-core-api-0.0.6 lib/roqua/core_api/sessions/organization_session.rb