Module: Square::APIOperations::Update

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

Instance Method Summary collapse

Instance Method Details

#update(id, *args) ⇒ Square::DataType

Update 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
38
39
40
41
42
# File 'lib/square/api_operations/update.rb', line 11

def update(id, *args)
  if args.count == 2
    if !nested_under.nil?
      parent_id = args[0]
      params = args[1]
    else
      parent_id = nil
      params = args[0]
    end
  else
    if !nested_under.nil?
      parent_id = args[0]
      params = args[1]
    else
      parent_id = nil
      params = args[0]
    end
  end

  if params.nil?
    raise ArgumentError.new("`params` is a required argument.")
  end

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

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