Class: ApiReference::CouponApi

Inherits:
BaseApi
  • Object
show all
Defined in:
lib/api_reference/apis/coupon_api.rb

Overview

CouponApi

Constant Summary

Constants inherited from BaseApi

BaseApi::GLOBAL_ERRORS

Instance Attribute Summary

Attributes inherited from BaseApi

#config, #http_call_back

Instance Method Summary collapse

Methods inherited from BaseApi

#initialize, #new_parameter, #new_request_builder, #new_response_handler, user_agent, user_agent_parameters

Constructor Details

This class inherits a constructor from ApiReference::BaseApi

Instance Method Details

#archive_coupon(coupon_id) ⇒ ApiResponse

This endpoint allows a coupon to be archived. Archived coupons can no longer be redeemed, and will be hidden from lists of active coupons. Additionally, once a coupon is archived, its redemption code can be reused for a different coupon. here

Parameters:

  • coupon_id (String)

    Required parameter: TODO: type description

Returns:

  • (ApiResponse)

    Complete http response with raw body and status code.



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/api_reference/apis/coupon_api.rb', line 159

def archive_coupon(coupon_id)
  @api_call
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/coupons/{coupon_id}/archive',
                                 Server::DEFAULT)
               .template_param(new_parameter(coupon_id, key: 'coupon_id')
                                .is_required(true)
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('APIKeyAuth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(Coupon.method(:from_hash))
                .is_api_response(true)
                .local_error('400',
                             'Bad Request',
                             APIException)
                .local_error('401',
                             'Unauthorized',
                             AuthorizationErrorException)
                .local_error('404',
                             'Not Found',
                             APIException)
                .local_error('409',
                             'Conflict',
                             IdempotencyRequestMismatchException)
                .local_error('413',
                             'Content Too Large',
                             APIException)
                .local_error('429',
                             'Too Many Requests',
                             TooManyRequestsException)
                .local_error('500',
                             'Internal Server Error',
                             ServerErrorException))
    .execute
end

#create_coupon(body) ⇒ ApiResponse

This endpoint allows the creation of coupons, which can then be redeemed at subscription creation or plan change.

Parameters:

  • body (NewCoupon)

    Required parameter: TODO: type description here

Returns:

  • (ApiResponse)

    Complete http response with raw body and status code.



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
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/api_reference/apis/coupon_api.rb', line 68

def create_coupon(body)
  @api_call
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/coupons',
                                 Server::DEFAULT)
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body)
                            .is_required(true))
               .header_param(new_parameter('application/json', key: 'accept'))
               .body_serializer(proc do |param| param.to_json unless param.nil? end)
               .auth(Single.new('APIKeyAuth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(Coupon.method(:from_hash))
                .is_api_response(true)
                .local_error('400',
                             'Bad Request',
                             APIException)
                .local_error('401',
                             'Unauthorized',
                             AuthorizationErrorException)
                .local_error('404',
                             'Not Found',
                             APIException)
                .local_error('409',
                             'Conflict',
                             IdempotencyRequestMismatchException)
                .local_error('413',
                             'Content Too Large',
                             APIException)
                .local_error('429',
                             'Too Many Requests',
                             TooManyRequestsException)
                .local_error('500',
                             'Internal Server Error',
                             ServerErrorException))
    .execute
end

#fetch_coupon(coupon_id) ⇒ ApiResponse

This endpoint retrieves a coupon by its ID. To fetch coupons by their redemption code, use the List coupons endpoint with the redemption_code parameter. here

Parameters:

  • coupon_id (String)

    Required parameter: TODO: type description

Returns:

  • (ApiResponse)

    Complete http response with raw body and status code.



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/api_reference/apis/coupon_api.rb', line 113

def fetch_coupon(coupon_id)
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/coupons/{coupon_id}',
                                 Server::DEFAULT)
               .template_param(new_parameter(coupon_id, key: 'coupon_id')
                                .is_required(true)
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('APIKeyAuth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(Coupon.method(:from_hash))
                .is_api_response(true)
                .local_error('400',
                             'Bad Request',
                             APIException)
                .local_error('401',
                             'Unauthorized',
                             AuthorizationErrorException)
                .local_error('404',
                             'Not Found',
                             APIException)
                .local_error('409',
                             'Conflict',
                             IdempotencyRequestMismatchException)
                .local_error('413',
                             'Content Too Large',
                             APIException)
                .local_error('429',
                             'Too Many Requests',
                             TooManyRequestsException)
                .local_error('500',
                             'Internal Server Error',
                             ServerErrorException))
    .execute
end

#list_coupon_subscriptions(coupon_id, limit: 20, cursor: nil) ⇒ ApiResponse

This endpoint returns a list of all subscriptions that have redeemed a given coupon as a paginated list, ordered starting from the most recently created subscription. For a full discussion of the subscription resource, see Subscription. here

Parameters:

  • coupon_id (String)

    Required parameter: TODO: type description

  • limit (Integer) (defaults to: 20)

    Optional parameter: Example:20

  • cursor (String) (defaults to: nil)

    Optional parameter: TODO: type description here

Returns:

  • (ApiResponse)

    Complete http response with raw body and status code.



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'lib/api_reference/apis/coupon_api.rb', line 208

def list_coupon_subscriptions(coupon_id,
                              limit: 20,
                              cursor: nil)
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/coupons/{coupon_id}/subscriptions',
                                 Server::DEFAULT)
               .template_param(new_parameter(coupon_id, key: 'coupon_id')
                                .is_required(true)
                                .should_encode(true))
               .query_param(new_parameter(limit, key: 'limit'))
               .query_param(new_parameter(cursor, key: 'cursor'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('APIKeyAuth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(Subscriptions.method(:from_hash))
                .is_api_response(true)
                .local_error('400',
                             'Bad Request',
                             APIException)
                .local_error('401',
                             'Unauthorized',
                             AuthorizationErrorException)
                .local_error('404',
                             'Not Found',
                             APIException)
                .local_error('409',
                             'Conflict',
                             IdempotencyRequestMismatchException)
                .local_error('413',
                             'Content Too Large',
                             APIException)
                .local_error('429',
                             'Too Many Requests',
                             TooManyRequestsException)
                .local_error('500',
                             'Internal Server Error',
                             ServerErrorException))
    .execute
end

#list_coupons(limit: 20, cursor: nil, show_archived: nil, redemption_code: nil) ⇒ ApiResponse

This endpoint returns a list of all coupons for an account in a list format. The list of coupons is ordered starting from the most recently created coupon. The response also includes pagination_metadata, which lets the caller retrieve the next page of results if they exist. type description here here

Parameters:

  • limit (Integer) (defaults to: 20)

    Optional parameter: Example:20

  • cursor (String) (defaults to: nil)

    Optional parameter: TODO: type description here

  • show_archived (TrueClass | FalseClass) (defaults to: nil)

    Optional parameter: TODO:

  • redemption_code (String) (defaults to: nil)

    Optional parameter: TODO: type description

Returns:

  • (ApiResponse)

    Complete http response with raw body and status code.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
# File 'lib/api_reference/apis/coupon_api.rb', line 22

def list_coupons(limit: 20,
                 cursor: nil,
                 show_archived: nil,
                 redemption_code: nil)
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/coupons',
                                 Server::DEFAULT)
               .query_param(new_parameter(limit, key: 'limit'))
               .query_param(new_parameter(cursor, key: 'cursor'))
               .query_param(new_parameter(show_archived, key: 'show_archived'))
               .query_param(new_parameter(redemption_code, key: 'redemption_code'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('APIKeyAuth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(Coupons.method(:from_hash))
                .is_api_response(true)
                .local_error('400',
                             'Bad Request',
                             APIException)
                .local_error('401',
                             'Unauthorized',
                             AuthorizationErrorException)
                .local_error('404',
                             'Not Found',
                             APIException)
                .local_error('409',
                             'Conflict',
                             IdempotencyRequestMismatchException)
                .local_error('413',
                             'Content Too Large',
                             APIException)
                .local_error('429',
                             'Too Many Requests',
                             TooManyRequestsException)
                .local_error('500',
                             'Internal Server Error',
                             ServerErrorException))
    .execute
end