Sha256: f2e4607deb74b96f8f404fff0f17dc32e82dab47fbb14cf09a044c4ee119bc8d

Contents?: true

Size: 1.16 KB

Versions: 10

Compression:

Stored size: 1.16 KB

Contents

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

      def execute
        response = session.post "/dossier_groups/#{dossier_group_id}/dossiers",
                                person: attribute_hash(person),
                                dossier: dossier_attributes,
                                credential: attribute_hash(credential)
        if response.code == 422
          errors_to_object(response, person)
          errors_to_object(response, dossier)
          errors_to_object(response, credential)
        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 attribute_hash(obj)
        return {} unless obj
        obj.serializable_hash.keep_if { |_k, v| !v.nil? }
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
roqua-core-api-0.7.0 lib/roqua/core_api/create_dossier.rb
roqua-core-api-0.6.0 lib/roqua/core_api/create_dossier.rb
roqua-core-api-0.5.0 lib/roqua/core_api/create_dossier.rb
roqua-core-api-0.4.0 lib/roqua/core_api/create_dossier.rb
roqua-core-api-0.3.1 lib/roqua/core_api/create_dossier.rb
roqua-core-api-0.3.0 lib/roqua/core_api/create_dossier.rb
roqua-core-api-0.2.4 lib/roqua/core_api/create_dossier.rb
roqua-core-api-0.2.3 lib/roqua/core_api/create_dossier.rb
roqua-core-api-0.2.2 lib/roqua/core_api/create_dossier.rb
roqua-core-api-0.2.1 lib/roqua/core_api/create_dossier.rb