Class: Square::GiftCards::Activities::Client
- Inherits:
-
Object
- Object
- Square::GiftCards::Activities::Client
- Defined in:
- lib/square/gift_cards/activities/client.rb
Instance Method Summary collapse
-
#create(request_options: {}, **params) ⇒ Square::Types::CreateGiftCardActivityResponse
Creates a gift card activity to manage the balance or state of a [gift card](entity:GiftCard).
- #initialize(client:) ⇒ void constructor
-
#list(request_options: {}, **params) ⇒ Square::Types::ListGiftCardActivitiesResponse
Lists gift card activities.
Constructor Details
#initialize(client:) ⇒ void
10 11 12 |
# File 'lib/square/gift_cards/activities/client.rb', line 10 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.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/square/gift_cards/activities/client.rb', line 90 def create(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/gift-cards/activities", body: Square::GiftCards::Activities::Types::CreateGiftCardActivityRequest.new(params).to_h, request_options: ) 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.
36 37 38 39 40 41 42 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 |
# File 'lib/square/gift_cards/activities/client.rb', line 36 def list(request_options: {}, **params) params = Square::Internal::Types::Utils.normalize_keys(params) query_param_names = %i[gift_card_id type location_id begin_time end_time limit cursor sort_order] query_params = {} query_params["gift_card_id"] = params[:gift_card_id] if params.key?(:gift_card_id) query_params["type"] = params[:type] if params.key?(:type) query_params["location_id"] = params[:location_id] if params.key?(:location_id) query_params["begin_time"] = params[:begin_time] if params.key?(:begin_time) query_params["end_time"] = params[:end_time] if params.key?(:end_time) query_params["limit"] = params[:limit] if params.key?(:limit) query_params["cursor"] = params[:cursor] if params.key?(:cursor) query_params["sort_order"] = params[:sort_order] if params.key?(:sort_order) params.except(*query_param_names) Square::Internal::CursorItemIterator.new( cursor_field: :cursor, item_field: :gift_card_activities, initial_cursor: query_params[:cursor] ) do |next_cursor| query_params[:cursor] = next_cursor request = Square::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v2/gift-cards/activities", query: query_params, request_options: ) 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 end |