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-chargify.zendesk.com/hc/en-us/articles/5405357509645-W ebhooks-Reference#example-payloads)
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/advanced_billing/controllers/webhooks_controller.rb', line 147 def create_endpoint(body: nil) new_api_call_builder .request(new_request_builder(HttpMethodEnum::POST, '/endpoints.json', Server::DEFAULT) .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 .is_nullify404(true) .deserializer(APIHelper.method(:custom_type_deserializer)) .deserialize_into(EndpointResponse.method(:from_hash)) .local_error('422', 'Unprocessable Entity (WebDAV)', ErrorListResponseException)) .execute end |
#enable_webhooks(body: nil) ⇒ EnableWebhooksResponse
This method allows you to enable webhooks via API for your site
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/advanced_billing/controllers/webhooks_controller.rb', line 122 def enable_webhooks(body: nil) new_api_call_builder .request(new_request_builder(HttpMethodEnum::PUT, '/webhooks/settings.json', Server::DEFAULT) .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 .is_nullify404(true) .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.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/advanced_billing/controllers/webhooks_controller.rb', line 35 def list_endpoints new_api_call_builder .request(new_request_builder(HttpMethodEnum::GET, '/endpoints.json', Server::DEFAULT) .header_param(new_parameter('application/json', key: 'accept')) .auth(Single.new('BasicAuth'))) .response(new_response_handler .is_nullify404(true) .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 Chargify’s webhook documentation located in our help site. The following resources will help guide you on how to use webhooks in Chargify, in addition to these webhook endpoints: + [Adding/editing new webhooks](maxio-chargify.zendesk.com/hc/en-us/articles/54044484503 17#configure-webhook-url) + [Webhooks introduction and delivery information](maxio-chargify.zendesk.com/hc/en-us/articles/54055680 68365#webhooks-introduction-0-0) + [Main webhook overview](maxio-chargify.zendesk.com/hc/en-us/articles/54053575096 45-Webhooks-Reference#webhooks-reference-0-0) + [Available webhooks and payloads](maxio-chargify.zendesk.com/hc/en-us/articles/54053575096 45-Webhooks-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. subscription you’d like to filter for
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/advanced_billing/controllers/webhooks_controller.rb', line 97 def list_webhooks( = {}) new_api_call_builder .request(new_request_builder(HttpMethodEnum::GET, '/webhooks.json', Server::DEFAULT) .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 .is_nullify404(true) .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.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/advanced_billing/controllers/webhooks_controller.rb', line 16 def replay_webhooks(body: nil) new_api_call_builder .request(new_request_builder(HttpMethodEnum::POST, '/webhooks/replay.json', Server::DEFAULT) .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 .is_nullify404(true) .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-chargify.zendesk.com/hc/en-us/articles/5404448450317-W ebhooks#configure-webhook-url). 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. endpoint that should be updated
183 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 |
# File 'lib/advanced_billing/controllers/webhooks_controller.rb', line 183 def update_endpoint(endpoint_id, body: nil) new_api_call_builder .request(new_request_builder(HttpMethodEnum::PUT, '/endpoints/{endpoint_id}.json', Server::DEFAULT) .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 .is_nullify404(true) .deserializer(APIHelper.method(:custom_type_deserializer)) .deserialize_into(EndpointResponse.method(:from_hash)) .local_error('404', 'Not Found', APIException) .local_error('422', 'Unprocessable Entity (WebDAV)', ErrorListResponseException)) .execute end |