Module: Square::APIOperations::Delete

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

Instance Method Summary collapse

Instance Method Details

#delete(id, *args) ⇒ #to_json

Delete a resource.


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

def delete(id, *args)
  if args.count == 2
    parent_id = args[0]
    params = args[1]
  else
    if !nested_under.nil?
      parent_id = args[0]
      params = nil
    else
      parent_id = nil
      params = args[0]
    end
  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: 'DELETE',
    endpoint: self.generate_endpoint_url(id, parent_id),
    payload: params
  )

  Square.parse_response(response)
end