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, #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. For more information, see [GiftCardActivity](developer.squareup.com/docs/gift-cards/using-gi ft-cards-api#giftcardactivity) and [Using activated gift cards](developer.squareup.com/docs/gift-cards/using-gift-cards-api #using-activated-gift-cards). 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



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/square/api/gift_card_activities_api.rb', line 98

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; charset=utf-8'
  }

  # 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. card ID, the endpoint returns activities that belong to the specified gift card. Otherwise, the endpoint returns all gift card activities for the seller. endpoint returns gift card activities of this type. Otherwise, the endpoint returns all types of gift card activities. ID, the endpoint returns gift card activities for that location. Otherwise, the endpoint returns gift card activities for all locations. beginning of the reporting period, in RFC 3339 format. Inclusive. Default: The current time minus one year. the reporting period, in RFC 3339 format. Inclusive. Default: The current time. the endpoint returns the specified number of results (or less) per page. A maximum value is 100. The default value is 50. a previous call to this endpoint. Provide this cursor to retrieve the next set of results for the original query. If you do not provide the cursor, the call returns the first page of the results. 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 you provide a gift

  • type (String) (defaults to: nil)

    Optional parameter: If you provide a type, the

  • location_id (String) (defaults to: nil)

    Optional parameter: If you provide a location

  • 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 you provide a limit value,

  • 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



43
44
45
46
47
48
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
# File 'lib/square/api/gift_card_activities_api.rb', line 43

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