Sha256: 52a7ce6ff1545b03d28ba49b2033c3811943bb3f78a46bc5b7c283b5c3d6b721

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

require 'httparty'

module Roqua
  module CoreApi
    module Sessions
      # AppSession represents a session which is scoped to a specific app
      # in the Core database. It deals with managing organizations and dossiers,
      # but only on a anonymous base. It is not allowed to know who these dossiers
      # represent.
      class AppSession
        include HTTParty
        base_uri ENV["CORE_URL"]

        attr_reader :key

        def initialize(key)
          @key = key
        end

        def create_organization(attributes)
          response = post "/organizations", organization: attributes
          raise response.inspect unless response.code == 201
          Models::Organization.new(response)
        end

        def create_dossier(organization, attributes)
          response = post "/organizations/#{organization.key}/dossiers", dossier: attributes
          raise response.inspect unless response.code == 201
          Models::Dossier.new(response)
        end

        private

        def post(url, params = {})
          # TODO: Handle authentication here
          self.class.post("/apps/#{key}" + url + ".json", body: params)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
roqua-core-api-0.0.1 lib/roqua/core_api/sessions/app_session.rb