Class: Square::GiftCards::Activities::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/square/gift_cards/activities/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Square::GiftCards::Activities::Client



8
9
10
# File 'lib/square/gift_cards/activities/client.rb', line 8

def initialize(client:)
  @client = client
end

Instance Method Details

#create(request_options: {}, **params) ⇒ Square::Types::CreateGiftCardActivityResponse

Creates a gift card activity to manage the balance or state of a [gift card](entity:GiftCard). For example, create an ‘ACTIVATE` activity to activate a gift card with an initial balance before first use.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/square/gift_cards/activities/client.rb', line 50

def create(request_options: {}, **params)
  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "POST",
    path: "v2/gift-cards/activities",
    body: params
  )
  begin
    _response = @client.send(_request)
  rescue Net::HTTPRequestTimeout
    raise Square::Errors::TimeoutError
  end
  code = _response.code.to_i
  if code.between?(200, 299)
    Square::Types::CreateGiftCardActivityResponse.load(_response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(_response.body, code: code)
  end
end

#list(request_options: {}, **params) ⇒ Square::Types::ListGiftCardActivitiesResponse

Lists gift card activities. By default, you get gift card activities for all gift cards in the seller’s account. You can optionally specify query parameters to filter the list. For example, you can get a list of gift card activities for a gift card, for all gift cards in a specific region, or for activities within a time window.



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
43
44
# File 'lib/square/gift_cards/activities/client.rb', line 18

def list(request_options: {}, **params)
  _query_param_names = [
    %w[gift_card_id type location_id begin_time end_time limit cursor sort_order],
    %i[gift_card_id type location_id begin_time end_time limit cursor sort_order]
  ].flatten
  _query = params.slice(*_query_param_names)
  params.except(*_query_param_names)

  _request = Square::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Square::Environment::PRODUCTION,
    method: "GET",
    path: "v2/gift-cards/activities",
    query: _query
  )
  begin
    _response = @client.send(_request)
  rescue Net::HTTPRequestTimeout
    raise Square::Errors::TimeoutError
  end
  code = _response.code.to_i
  if code.between?(200, 299)
    Square::Types::ListGiftCardActivitiesResponse.load(_response.body)
  else
    error_class = Square::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(_response.body, code: code)
  end
end