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