Class: AdvancedBilling::WebhooksController

Inherits:
BaseController show all
Defined in:
lib/advanced_billing/controllers/webhooks_controller.rb

Overview

WebhooksController

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_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

#create_endpoint(body: nil) ⇒ EndpointResponse

Creates an endpoint and assigns a list of webhooks subscriptions (events) to it. See the [Webhooks Reference](page:introduction/webhooks/webhooks-reference#events) page for available events. description here

Parameters:

Returns:



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/advanced_billing/controllers/webhooks_controller.rb', line 109

def create_endpoint(body: nil)
  @api_call
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/endpoints.json',
                                 Server::PRODUCTION)
               .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(EndpointResponse.method(:from_hash))
                .local_error_template('422',
                                      'HTTP Response Not OK. Status code: {$statusCode}.'\
                                       ' Response: \'{$response.body}\'.',
                                      ErrorListResponseException))
    .execute
end

#enable_webhooks(body: nil) ⇒ EnableWebhooksResponse

Allows you to enable webhooks for your site description here

Parameters:

Returns:



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/advanced_billing/controllers/webhooks_controller.rb', line 62

def enable_webhooks(body: nil)
  @api_call
    .request(new_request_builder(HttpMethodEnum::PUT,
                                 '/webhooks/settings.json',
                                 Server::PRODUCTION)
               .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(EnableWebhooksResponse.method(:from_hash)))
    .execute
end

#list_endpointsArray[Endpoint]

Returns created endpoints for a site.

Returns:

  • (Array[Endpoint])

    Response from the API call.



131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/advanced_billing/controllers/webhooks_controller.rb', line 131

def list_endpoints
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/endpoints.json',
                                 Server::PRODUCTION)
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(Endpoint.method(:from_hash))
                .is_response_array(true))
    .execute
end

#list_webhooks(options = {}) ⇒ Array[WebhookResponse]

Allows you to view a list of webhooks. You can pass query parameters if you want to filter webhooks. See the [Webhooks](page:introduction/webhooks/webhooks) documentation for more information. status would be returned. Webhooks with the created_at date greater than or equal to the one specified. Webhooks with the created_at date less than or equal to the one specified. 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 20. The maximum allowed values is 200; any per_page value over 200 will be changed to 200. Use in query `per_page=200`. Webhooks are returned. of a subscription you’d like to filter for

Parameters:

  • status (WebhookStatus)

    Optional parameter: Webhooks with matching

  • since_date (String)

    Optional parameter: Format YYYY-MM-DD. Returns

  • until_date (String)

    Optional parameter: Format YYYY-MM-DD. Returns

  • page (Integer)

    Optional parameter: Result records are organized in

  • per_page (Integer)

    Optional parameter: This parameter indicates how

  • order (WebhookOrder)

    Optional parameter: The order in which the

  • subscription (Integer)

    Optional parameter: The Advanced Billing id

Returns:



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/advanced_billing/controllers/webhooks_controller.rb', line 37

def list_webhooks(options = {})
  @api_call
    .request(new_request_builder(HttpMethodEnum::GET,
                                 '/webhooks.json',
                                 Server::PRODUCTION)
               .query_param(new_parameter(options['status'], key: 'status'))
               .query_param(new_parameter(options['since_date'], key: 'since_date'))
               .query_param(new_parameter(options['until_date'], key: 'until_date'))
               .query_param(new_parameter(options['page'], key: 'page'))
               .query_param(new_parameter(options['per_page'], key: 'per_page'))
               .query_param(new_parameter(options['order'], key: 'order'))
               .query_param(new_parameter(options['subscription'], key: 'subscription'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .auth(Single.new('BasicAuth')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(WebhookResponse.method(:from_hash))
                .is_response_array(true))
    .execute
end

#replay_webhooks(body: nil) ⇒ ReplayWebhooksResponse

Replays webhooks. Posting to this endpoint does not immediately resend the webhooks. They are added to a queue and sent as soon as possible, depending on available system resources. You can submit an array of up to 1000 webhook IDs in the replay request. description here

Parameters:

Returns:



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/advanced_billing/controllers/webhooks_controller.rb', line 85

def replay_webhooks(body: nil)
  @api_call
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/webhooks/replay.json',
                                 Server::PRODUCTION)
               .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(ReplayWebhooksResponse.method(:from_hash)))
    .execute
end

#update_endpoint(endpoint_id, body: nil) ⇒ EndpointResponse

Updates an Endpoint. You can change the ‘url` of your endpoint or the list of `webhook_subscriptions` to which you are subscribed. See the [Webhooks Reference](page:introduction/webhooks/webhooks-reference#events) page for available events. Always send a complete list of events to which you want to subscribe. Sending a PUT request for an existing endpoint with an empty list of `webhook_subscriptions` will unsubscribe all events. If you want unsubscribe from a specific event, send a list of `webhook_subscriptions` without the specific event key. for the endpoint that should be updated description here

Parameters:

  • endpoint_id (Integer)

    Required parameter: The Advanced Billing id

  • body (CreateOrUpdateEndpointRequest) (defaults to: nil)

    Optional parameter: TODO: type

Returns:



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

def update_endpoint(endpoint_id,
                    body: nil)
  @api_call
    .request(new_request_builder(HttpMethodEnum::PUT,
                                 '/endpoints/{endpoint_id}.json',
                                 Server::PRODUCTION)
               .template_param(new_parameter(endpoint_id, key: 'endpoint_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(EndpointResponse.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}\'.',
                                      ErrorListResponseException))
    .execute
end