Module: Dhis2::Api::Creatable::ClassMethods

Defined in:
lib/dhis2/api/creatable.rb

Instance Method Summary collapse

Instance Method Details

#create(client, args, raw_input = false) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dhis2/api/creatable.rb', line 11

def create(client, args, raw_input = false)
  if raw_input
    client.post(path: resource_name, payload: args, raw_input: true).tap do |response|
      validate_instance_creation(response)
    end
  else
    args = creation_args(args)
    with_valid_args(args) do
      response = client.post(path: resource_name, payload: args)
      validate_instance_creation(response)
      new(client, args.merge(id: created_instance_id(response)))
    end
  end
end