Class: AdvancedBilling::EventsBasedBillingSegmentsController

Inherits:
BaseController
  • Object
show all
Defined in:
lib/advanced_billing/controllers/events_based_billing_segments_controller.rb

Overview

EventsBasedBillingSegmentsController

Constant Summary

Constants inherited from BaseController

BaseController::GLOBAL_ERRORS

Instance Attribute Summary

Attributes inherited from BaseController

#config, #http_call_back

Instance Method Summary collapse

Methods inherited from BaseController

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

Constructor Details

This class inherits a constructor from AdvancedBilling::BaseController

Instance Method Details

#bulk_create_segments(component_id, price_point_id, body: nil) ⇒ ListSegmentsResponse

This endpoint allows you to create multiple segments in one request. The array of segments can contain up to ‘2000` records. If any of the records contain an error the whole request would fail and none of the requested segments get created. The error response contains a message for only the one segment that failed validation, with the corresponding index in the array. You may specify component and/or price point by using either the numeric ID or the `handle:gold` syntax. Component Price Point belonging to the Component

Parameters:

  • component_id (String)

    Required parameter: ID or Handle for the

  • price_point_id (String)

    Required parameter: ID or Handle for the

  • body (BulkCreateSegments) (defaults to: nil)

    Optional parameter: Example:

Returns:



205
206
207
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
# File 'lib/advanced_billing/controllers/events_based_billing_segments_controller.rb', line 205

def bulk_create_segments(component_id,
                         price_point_id,
                         body: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/components/{component_id}/price_points/{price_point_id}/segments/bulk.json',
                                 Server::DEFAULT)
               .template_param(new_parameter(component_id, key: 'component_id')
                                .is_required(true)
                                .should_encode(true))
               .template_param(new_parameter(price_point_id, key: 'price_point_id')
                                .is_required(true)
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body))
               .header_param(new_parameter('application/json', key: 'accept'))
               .body_serializer(proc do |param| param.to_json unless param.nil? end)
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(ListSegmentsResponse.method(:from_hash))
                .local_error_template('404',
                                      'Not Found:\'{$response.body}\'',
                                      APIException)
                .local_error_template('422',
                                      'HTTP Response Not OK. Status code: {$statusCode}.'\
                                       ' Response: \'{$response.body}\'.',
                                      EventBasedBillingSegmentException))
    .execute
end

#bulk_update_segments(component_id, price_point_id, body: nil) ⇒ ListSegmentsResponse

This endpoint allows you to update multiple segments in one request. The array of segments can contain up to ‘1000` records. If any of the records contain an error the whole request would fail and none of the requested segments get updated. The error response contains a message for only the one segment that failed validation, with the corresponding index in the array. You may specify component and/or price point by using either the numeric ID or the `handle:gold` syntax. Component Price Point belonging to the Component

Parameters:

  • component_id (String)

    Required parameter: ID or Handle for the

  • price_point_id (String)

    Required parameter: ID or Handle for the

  • body (BulkUpdateSegments) (defaults to: nil)

    Optional parameter: Example:

Returns:



250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/advanced_billing/controllers/events_based_billing_segments_controller.rb', line 250

def bulk_update_segments(component_id,
                         price_point_id,
                         body: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::PUT,
                                 '/components/{component_id}/price_points/{price_point_id}/segments/bulk.json',
                                 Server::DEFAULT)
               .template_param(new_parameter(component_id, key: 'component_id')
                                .is_required(true)
                                .should_encode(true))
               .template_param(new_parameter(price_point_id, key: 'price_point_id')
                                .is_required(true)
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body))
               .header_param(new_parameter('application/json', key: 'accept'))
               .body_serializer(proc do |param| param.to_json unless param.nil? end)
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(ListSegmentsResponse.method(:from_hash))
                .local_error_template('404',
                                      'Not Found:\'{$response.body}\'',
                                      APIException)
                .local_error_template('422',
                                      'HTTP Response Not OK. Status code: {$statusCode}.'\
                                       ' Response: \'{$response.body}\'.',
                                      EventBasedBillingSegmentException))
    .execute
end

#create_segment(component_id, price_point_id, body: nil) ⇒ SegmentResponse

This endpoint creates a new Segment for a Component with segmented Metric. It allows you to specify properties to bill upon and prices for each Segment. You can only pass as many “property_values” as the related Metric has segmenting properties defined. You may specify component and/or price point by using either the numeric ID or the ‘handle:gold` syntax. Component Price Point belonging to the Component

Parameters:

  • component_id (String)

    Required parameter: ID or Handle for the

  • price_point_id (String)

    Required parameter: ID or Handle for the

  • body (CreateSegmentRequest) (defaults to: nil)

    Optional parameter: Example:

Returns:



21
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
# File 'lib/advanced_billing/controllers/events_based_billing_segments_controller.rb', line 21

def create_segment(component_id,
                   price_point_id,
                   body: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/components/{component_id}/price_points/{price_point_id}/segments.json',
                                 Server::DEFAULT)
               .template_param(new_parameter(component_id, key: 'component_id')
                                .is_required(true)
                                .should_encode(true))
               .template_param(new_parameter(price_point_id, key: 'price_point_id')
                                .is_required(true)
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body))
               .header_param(new_parameter('application/json', key: 'accept'))
               .body_serializer(proc do |param| param.to_json unless param.nil? end)
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(SegmentResponse.method(:from_hash))
                .local_error_template('404',
                                      'Not Found:\'{$response.body}\'',
                                      APIException)
                .local_error_template('422',
                                      'HTTP Response Not OK. Status code: {$statusCode}.'\
                                       ' Response: \'{$response.body}\'.',
                                      EventBasedBillingSegmentErrorsException))
    .execute
end

#delete_segment(component_id, price_point_id, id) ⇒ void

This method returns an undefined value.

This endpoint allows you to delete a Segment with specified ID. You may specify component and/or price point by using either the numeric ID or the ‘handle:gold` syntax. Component Price Point belonging to the Component

Parameters:

  • component_id (String)

    Required parameter: ID or Handle of the

  • price_point_id (String)

    Required parameter: ID or Handle of the

  • id (Float)

    Required parameter: The ID of the Segment



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
# File 'lib/advanced_billing/controllers/events_based_billing_segments_controller.rb', line 162

def delete_segment(component_id,
                   price_point_id,
                   id)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::DELETE,
                                 '/components/{component_id}/price_points/{price_point_id}/segments/{id}.json',
                                 Server::DEFAULT)
               .template_param(new_parameter(component_id, key: 'component_id')
                                .is_required(true)
                                .should_encode(true))
               .template_param(new_parameter(price_point_id, key: 'price_point_id')
                                .is_required(true)
                                .should_encode(true))
               .template_param(new_parameter(id, key: 'id')
                                .is_required(true)
                                .should_encode(true))
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .is_response_void(true)
                .local_error_template('404',
                                      'Not Found:\'{$response.body}\'',
                                      APIException)
                .local_error_template('422',
                                      'HTTP Response Not OK. Status code: {$statusCode}.'\
                                       ' Response: \'{$response.body}\'.',
                                      APIException))
    .execute
end

#list_segments_for_price_point(options = {}) ⇒ ListSegmentsResponse

This endpoint allows you to fetch Segments created for a given Price Point. They will be returned in the order of creation. You can pass ‘page` and `per_page` parameters in order to access all of the segments. By default it will return `30` records. You can set `per_page` to `200` at most. You may specify component and/or price point by using either the numeric ID or the `handle:gold` syntax. Component Price Point belonging to the Component pages. By default, the first page of results is displayed. The page parameter specifies a page number of results to fetch. You can start navigating through the pages to consume the results. You do this by passing in a page parameter. Retrieve the next page by adding ?page=2 to the query string. If there are no results to return, then an empty result set will be returned. Use in query `page=1`. many records to fetch in each request. Default value is 30. The maximum allowed values is 200; any per_page value over 200 will be changed to 200. Use in query `per_page=200`. List Segments for a Price Point operation

Parameters:

  • component_id (String)

    Required parameter: ID or Handle for the

  • price_point_id (String)

    Required parameter: ID or Handle for the

  • page (Integer)

    Optional parameter: Result records are organized in

  • per_page (Integer)

    Optional parameter: This parameter indicates how

  • filter (ListSegmentsFilter)

    Optional parameter: Filter to use for

Returns:



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/advanced_billing/controllers/events_based_billing_segments_controller.rb', line 77

def list_segments_for_price_point(options = {})
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/components/{component_id}/price_points/{price_point_id}/segments.json',
                                 Server::DEFAULT)
               .template_param(new_parameter(options['component_id'], key: 'component_id')
                                .is_required(true)
                                .should_encode(true))
               .template_param(new_parameter(options['price_point_id'], key: 'price_point_id')
                                .is_required(true)
                                .should_encode(true))
               .query_param(new_parameter(options['page'], key: 'page'))
               .query_param(new_parameter(options['per_page'], key: 'per_page'))
               .query_param(new_parameter(options['filter'], key: 'filter'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('BasicAuth'))
               .array_serialization_format(ArraySerializationFormat::CSV))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(ListSegmentsResponse.method(:from_hash))
                .local_error_template('404',
                                      'Not Found:\'{$response.body}\'',
                                      APIException)
                .local_error_template('422',
                                      'HTTP Response Not OK. Status code: {$statusCode}.'\
                                       ' Response: \'{$response.body}\'.',
                                      EventBasedBillingListSegmentsErrorsException))
    .execute
end

#update_segment(component_id, price_point_id, id, body: nil) ⇒ SegmentResponse

This endpoint updates a single Segment for a Component with a segmented Metric. It allows you to update the pricing for the segment. You may specify component and/or price point by using either the numeric ID or the ‘handle:gold` syntax. Component Price Point belonging to the Component

Parameters:

  • component_id (String)

    Required parameter: ID or Handle of the

  • price_point_id (String)

    Required parameter: ID or Handle of the

  • id (Float)

    Required parameter: The ID of the Segment

  • body (UpdateSegmentRequest) (defaults to: nil)

    Optional parameter: Example:

Returns:



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
150
151
# File 'lib/advanced_billing/controllers/events_based_billing_segments_controller.rb', line 118

def update_segment(component_id,
                   price_point_id,
                   id,
                   body: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::PUT,
                                 '/components/{component_id}/price_points/{price_point_id}/segments/{id}.json',
                                 Server::DEFAULT)
               .template_param(new_parameter(component_id, key: 'component_id')
                                .is_required(true)
                                .should_encode(true))
               .template_param(new_parameter(price_point_id, key: 'price_point_id')
                                .is_required(true)
                                .should_encode(true))
               .template_param(new_parameter(id, key: 'id')
                                .is_required(true)
                                .should_encode(true))
               .header_param(new_parameter('application/json', key: 'Content-Type'))
               .body_param(new_parameter(body))
               .header_param(new_parameter('application/json', key: 'accept'))
               .body_serializer(proc do |param| param.to_json unless param.nil? end)
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(SegmentResponse.method(:from_hash))
                .local_error_template('404',
                                      'Not Found:\'{$response.body}\'',
                                      APIException)
                .local_error_template('422',
                                      'HTTP Response Not OK. Status code: {$statusCode}.'\
                                       ' Response: \'{$response.body}\'.',
                                      EventBasedBillingSegmentErrorsException))
    .execute
end