Class: AdvancedBilling::WebhooksController
- Inherits:
-
BaseController
- Object
- BaseController
- AdvancedBilling::WebhooksController
- Defined in:
- lib/advanced_billing/controllers/webhooks_controller.rb
Overview
WebhooksController
Constant Summary
Constants inherited from BaseController
Instance Attribute Summary
Attributes inherited from BaseController
Instance Method Summary collapse
-
#create_endpoint(body: nil) ⇒ EndpointResponse
The Chargify API allows you to create an endpoint and assign a list of webhooks subscriptions (events) to it.
-
#enable_webhooks(body: nil) ⇒ EnableWebhooksResponse
This method allows you to enable webhooks via API for your site.
-
#list_endpoints ⇒ Array[Endpoint]
This method returns created endpoints for site.
-
#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.
-
#replay_webhooks(body: nil) ⇒ ReplayWebhooksResponse
Posting to the replay endpoint does not immediately resend the webhooks.
-
#update_endpoint(endpoint_id, body: nil) ⇒ EndpointResponse
You can update an Endpoint via the API with a PUT request to the resource endpoint.
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
#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)
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/advanced_billing/controllers/webhooks_controller.rb', line 128 def create_endpoint(body: nil) new_api_call_builder .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
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/advanced_billing/controllers/webhooks_controller.rb', line 81 def enable_webhooks(body: nil) new_api_call_builder .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_endpoints ⇒ Array[Endpoint]
This method returns created endpoints for site.
150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/advanced_billing/controllers/webhooks_controller.rb', line 150 def list_endpoints new_api_call_builder .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
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( = {}) new_api_call_builder .request(new_request_builder(HttpMethodEnum::GET, '/webhooks.json', Server::PRODUCTION) .query_param(new_parameter(['status'], key: 'status')) .query_param(new_parameter(['since_date'], key: 'since_date')) .query_param(new_parameter(['until_date'], key: 'until_date')) .query_param(new_parameter(['page'], key: 'page')) .query_param(new_parameter(['per_page'], key: 'per_page')) .query_param(new_parameter(['order'], key: 'order')) .query_param(new_parameter(['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.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/advanced_billing/controllers/webhooks_controller.rb', line 104 def replay_webhooks(body: nil) new_api_call_builder .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
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/advanced_billing/controllers/webhooks_controller.rb', line 180 def update_endpoint(endpoint_id, body: nil) new_api_call_builder .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 |