Sha256: 6e15c55ceacb6312436370e3003b43244edc2b3ac9db5fa44dc207429ef78c39

Contents?: true

Size: 964 Bytes

Versions: 2

Compression:

Stored size: 964 Bytes

Contents

module Roqua
  module CoreApi
    # @api private
    class CreateDossier < Base
      model :session, class: Sessions::AuthSession
      string :dossier_group_id
      model :dossier, class: Models::Dossier, default: nil
      model :person, class: Models::Person, default: nil

      def execute
        response = session.post "/dossier_groups/#{dossier_group_id}/dossiers",
                                person: person_attributes, dossier: dossier_attributes
        if response.code == 422
          errors_to_object(response, person)
          errors_to_object(response, dossier)
        end
        Models::Dossier.new(response)
      end

      private

      def dossier_attributes
        return {} unless dossier
        dossier.serializable_hash(except: :people).keep_if { |_k, v| !v.nil? }
      end

      def person_attributes
        return {} unless person
        person.serializable_hash.keep_if { |_k, v| !v.nil? }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
roqua-core-api-0.1.1 lib/roqua/core_api/create_dossier.rb
roqua-core-api-0.1.0 lib/roqua/core_api/create_dossier.rb