Sha256: e90219bae96b3aaae52c740658a4c9edaf5fdc492eb895e3aa2c34d35e7a0697

Contents?: true

Size: 895 Bytes

Versions: 5

Compression:

Stored size: 895 Bytes

Contents

# frozen_string_literal: true

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

      module ClassMethods

        def bulk_creation_status_class
           ::Dhis2::Api::ImportSummary
        end

        # 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)
          bulk_creation_status_class.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

5 entries across 5 versions & 1 rubygems

Version Path
dhis2-3.3.1 lib/dhis2/api/bulk_creatable.rb
dhis2-3.2.1 lib/dhis2/api/bulk_creatable.rb
dhis2-3.0.7 lib/dhis2/api/bulk_creatable.rb
dhis2-3.0.5 lib/dhis2/api/bulk_creatable.rb
dhis2-3.0.4 lib/dhis2/api/bulk_creatable.rb