Module: Square::APIOperations::Create

Included in:
Category, Discount, Fee, Item, Refund, Variation
Defined in:
lib/square/api_operations/create.rb

Instance Method Summary collapse

Instance Method Details

#create(*args) ⇒ DataType

Create resource.


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/square/api_operations/create.rb', line 10

def create(*args)
  if args.count == 1
    parent_id = nil
    params = args[0]
  elsif args.count == 2
    parent_id = args[0]
    params = args[1]
  end

  # If this item is nested_under something, the parent_id is required.
  if !nested_under.nil? && parent_id.nil?
    raise ArgumentError.new("parent_id is required because this resource is nested under: #{nested_under}.")
  end

  response = Square.make_request(
    method: 'POST',
    endpoint: self.generate_endpoint_url(nil, parent_id),
    payload: params
  )

  response = Square.parse_response(response)
  @data_type.new(response)
end