Sha256: c68f8baa4e955b69a37c112ce03a0955cb33338df0118abc4a5d196d09d24b2b

Contents?: true

Size: 870 Bytes

Versions: 3

Compression:

Stored size: 870 Bytes

Contents

# frozen_string_literal: true

module Dhis2
  module Api
    module BulkCreatable
      def self.included(base)
        base.extend(ClassMethods)
      end

      module ClassMethods

        BulkCreationStatusClass = ::Dhis2::Api::ImportSummary

        # args is a hash like: { data_element_groups: [{ name: "foo" }, { name: "bar" }] }
        def bulk_create(client, args, raw_input = false)
          response = client.post(path: "metadata", payload: args, raw_input: raw_input)
          self::BulkCreationStatusClass.new(response).tap do |summary|
            unless summary.bulk_success?
              exception = Dhis2::BulkCreationError.new("Didnt create bulk of data properly.\n Response: #{response.to_json}")
              exception.import_summary = summary
              raise exception
            end
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dhis2-3.0.3 lib/dhis2/api/bulk_creatable.rb
dhis2-3.0.2 lib/dhis2/api/bulk_creatable.rb
dhis2-3.0.0 lib/dhis2/api/bulk_creatable.rb