Class: Square::GiftCardActivitiesApi

Inherits:
BaseApi
  • Object
show all
Defined in:
lib/square/api/gift_card_activities_api.rb

Overview

GiftCardActivitiesApi

Instance Attribute Summary

Attributes inherited from BaseApi

#config, #http_call_back

Instance Method Summary collapse

Methods inherited from BaseApi

#execute_request, #get_user_agent, #validate_parameters

Constructor Details

#initialize(config, http_call_back: nil) ⇒ GiftCardActivitiesApi

Returns a new instance of GiftCardActivitiesApi.



4
5
6
# File 'lib/square/api/gift_card_activities_api.rb', line 4

def initialize(config, http_call_back: nil)
  super(config, http_call_back: http_call_back)
end

Instance Method Details

#create_gift_card_activity(body:) ⇒ CreateGiftCardActivityResponse Hash

Creates a gift card activity to manage the balance or state of a [gift card]($m/GiftCard). For example, you create an ‘ACTIVATE` activity to activate a gift card with an initial balance before the gift card can be used. containing the fields to POST for the request. See the corresponding object definition for field details.

Parameters:

  • body (CreateGiftCardActivityRequest)

    Required parameter: An object

Returns:

  • (CreateGiftCardActivityResponse Hash)

    response from the API call



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/square/api/gift_card_activities_api.rb', line 103

def create_gift_card_activity(body:)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/gift-cards/activities'
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json',
    'Content-Type' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.post(
    _query_url,
    headers: _headers,
    parameters: body.to_json
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end

#list_gift_card_activities(gift_card_id: nil, type: nil, location_id: nil, begin_time: nil, end_time: nil, limit: nil, cursor: nil, sort_order: nil) ⇒ ListGiftCardActivitiesResponse Hash

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. provided, the endpoint returns activities related to the specified gift card. Otherwise, the endpoint returns all gift card activities for the seller. [type]($m/GiftCardActivityType) is provided, the endpoint returns gift card activities of the specified type. Otherwise, the endpoint returns all types of gift card activities. provided, the endpoint returns gift card activities for the specified location. Otherwise, the endpoint returns gift card activities for all locations. beginning of the reporting period, in RFC 3339 format. This start time is inclusive. The default value is the current time minus one year. the reporting period, in RFC 3339 format. This end time is inclusive. The default value is the current time. endpoint returns the specified number of results (or fewer) per page. The maximum value is 100. The default value is 50. For more information, see [Pagination](developer.squareup.com/docs/working-with-apis/paginat ion). a previous call to this endpoint. Provide this cursor to retrieve the next set of results for the original query. If a cursor is not provided, the endpoint returns the first page of the results. For more information, see [Pagination](developer.squareup.com/docs/working-with-apis/paginat ion). endpoint returns the activities, based on ‘created_at`. - `ASC` - Oldest to newest. - `DESC` - Newest to oldest (default).

Parameters:

  • gift_card_id (String) (defaults to: nil)

    Optional parameter: If a gift card ID is

  • type (String) (defaults to: nil)

    Optional parameter: If a

  • location_id (String) (defaults to: nil)

    Optional parameter: If a location ID is

  • begin_time (String) (defaults to: nil)

    Optional parameter: The timestamp for the

  • end_time (String) (defaults to: nil)

    Optional parameter: The timestamp for the end of

  • limit (Integer) (defaults to: nil)

    Optional parameter: If a limit is provided, the

  • cursor (String) (defaults to: nil)

    Optional parameter: A pagination cursor returned by

  • sort_order (String) (defaults to: nil)

    Optional parameter: The order in which the

Returns:

  • (ListGiftCardActivitiesResponse Hash)

    response from the API call



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/square/api/gift_card_activities_api.rb', line 49

def list_gift_card_activities(gift_card_id: nil,
                              type: nil,
                              location_id: nil,
                              begin_time: nil,
                              end_time: nil,
                              limit: nil,
                              cursor: nil,
                              sort_order: nil)
  # Prepare query url.
  _query_builder = config.get_base_uri
  _query_builder << '/v2/gift-cards/activities'
  _query_builder = APIHelper.append_url_with_query_parameters(
    _query_builder,
    'gift_card_id' => gift_card_id,
    'type' => type,
    'location_id' => location_id,
    'begin_time' => begin_time,
    'end_time' => end_time,
    'limit' => limit,
    'cursor' => cursor,
    'sort_order' => sort_order
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.
  _headers = {
    'accept' => 'application/json'
  }

  # Prepare and execute HttpRequest.
  _request = config.http_client.get(
    _query_url,
    headers: _headers
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)

  # Return appropriate response type.
  decoded = APIHelper.json_deserialize(_response.raw_body)
  _errors = APIHelper.map_response(decoded, ['errors'])
  ApiResponse.new(
    _response, data: decoded, errors: _errors
  )
end