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

The Chargify API allows you to create an endpoint and assign a list of webhooks subscriptions (events) to it. You can check available events here. [Event keys](maxio.zendesk.com/hc/en-us/articles/24266136649869-Webhooks- Reference#events) description here

Parameters:

Returns:



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

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

This method allows you to enable webhooks via API for your site description here

Parameters:

Returns:



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

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]

This method returns created endpoints for site.

Returns:

  • (Array[Endpoint])

    Response from the API call.



153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/advanced_billing/controllers/webhooks_controller.rb', line 153

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]

## Webhooks Intro The Webhooks API allows you to view a list of all webhooks and to selectively resend individual or groups of webhooks. Webhooks will be sent on endpoints specified by you. Endpoints can be added via API or Web UI. There is also an option to enable / disable webhooks via API request. We recommend that you review Advanced Billing’s webhook documentation located in our help site. The following resources will help guide you on how to use webhooks in Advanced Billing, in addition to these webhook endpoints: + [Adding/editing new webhooks](maxio.zendesk.com/hc/en-us/articles/24286723085197-Webho oks#configure-webhook-url) + [Webhooks introduction and delivery information](maxio.zendesk.com/hc/en-us/articles/24266143173901-We bhooks-Overview) + [Main webhook reference](maxio.zendesk.com/hc/en-us/articles/24266136649869-Webh ooks-Reference) + [Available webhooks and payloads](maxio.zendesk.com/hc/en-us/articles/24266136649869-Webho oks-Reference#events) ## List Webhooks for a Site This method allows you to fetch data about webhooks. You can pass query parameters if you want to filter webhooks. 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:



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

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

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

Parameters:

Returns:



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/advanced_billing/controllers/webhooks_controller.rb', line 106

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

You can update an Endpoint via the API with a PUT request to the resource endpoint. You can change the ‘url` of your endpoint which consumes webhooks or list of `webhook_subscriptions`. Check available [Event keys](maxio.zendesk.com/hc/en-us/articles/24266136649869-Webhooks- Reference#events). Always send a complete list of events which you want subscribe/watch. Sending an PUT request for existing endpoint with empty list of `webhook_subscriptions` will end with unsubscribe from all events. If you want unsubscribe from specific event, just 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:



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/advanced_billing/controllers/webhooks_controller.rb', line 184

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