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 # auth = { username: '..', password: '..' } def initialize(organization_id, server_url = ENV["CORE_URL"], auth:nil) @server_url = server_url @organization_id = organization_id @basic_auth = auth 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 # send_email_to(dossier_group.id, dossier.id, person.id, # subject: '..', # body: 'Hello %firstname%, ..', # bcc: 'bcc@test.com', # content_type: 'text/html', # mail_type: 'daily_recap') # Possible variables in the body are: # %firstname%, # %lastname%, # %initials% def send_email_to(dossier_group_id, dossier_id, person_id, attributes) response = post "/dossier_groups/#{dossier_group_id}/dossiers/#{dossier_id}/people/#{person_id}/emails", email: attributes fail response.inspect unless response.code == 201 response end private def get(url, params = {}) # TODO: Handle authentication here HTTParty.get(server_url + base_url + url + ".json", query: params, basic_auth: @basic_auth) end def post(url, params = {}) # TODO: Handle authentication here HTTParty.post(server_url + base_url + url + ".json", body: params, basic_auth: @basic_auth) end def put(url, params = {}) # TODO: Handle authentication here HTTParty.put(server_url + base_url + url + ".json", body: params, basic_auth: @basic_auth) end def base_url "/api/v1/organizations/#{organization_id}" end end end end end