Class: Voltaria::Webhooks::Client
- Inherits:
-
Object
- Object
- Voltaria::Webhooks::Client
- Defined in:
- lib/voltaria/webhooks/client.rb
Instance Method Summary collapse
-
#create_webhook_subscription(request_options: {}, **params) ⇒ Voltaria::Types::WebhookSubscriptionResponse
Create a new webhook subscription for a specific event type.
-
#delete_webhook_subscription(request_options: {}, **params) ⇒ Hash[String, Object]
Delete a specific webhook subscription.
-
#get_webhook_subscription(request_options: {}, **params) ⇒ Voltaria::Types::WebhookSubscriptionResponse
Retrieve details for a specific webhook subscription with its webhook ID.
- #initialize(client:) ⇒ void constructor
-
#list_webhook_logs(request_options: {}, **params) ⇒ Voltaria::Types::PaginatedResponseWebhookLogResponse
Retrieve all webhook logs linked to your partner account.
-
#list_webhook_subscriptions(request_options: {}, **params) ⇒ Voltaria::Types::PaginatedResponseWebhookSubscriptionResponse
List all webhook subscriptions for your partner account.
-
#update_webhook_subscription(request_options: {}, **params) ⇒ Voltaria::Types::WebhookSubscriptionResponse
Update a webhook subscription with its specific webhook ID.
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/voltaria/webhooks/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#create_webhook_subscription(request_options: {}, **params) ⇒ Voltaria::Types::WebhookSubscriptionResponse
Create a new webhook subscription for a specific event type.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/voltaria/webhooks/client.rb', line 68 def create_webhook_subscription(request_options: {}, **params) params = Voltaria::Internal::Types::Utils.normalize_keys(params) request = Voltaria::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v2/webhooks/subscriptions", body: Voltaria::Webhooks::Types::WebhookCreatePayload.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Voltaria::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Voltaria::Types::WebhookSubscriptionResponse.load(response.body) else error_class = Voltaria::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#delete_webhook_subscription(request_options: {}, **params) ⇒ Hash[String, Object]
Delete a specific webhook subscription.
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/voltaria/webhooks/client.rb', line 176 def delete_webhook_subscription(request_options: {}, **params) params = Voltaria::Internal::Types::Utils.normalize_keys(params) request = Voltaria::Internal::JSON::Request.new( base_url: [:base_url], method: "DELETE", path: "v2/webhooks/subscriptions/#{URI.encode_uri_component(params[:webhook_id].to_s)}", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Voltaria::Errors::TimeoutError end code = response.code.to_i return if code.between?(200, 299) error_class = Voltaria::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end |
#get_webhook_subscription(request_options: {}, **params) ⇒ Voltaria::Types::WebhookSubscriptionResponse
Retrieve details for a specific webhook subscription with its webhook ID.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/voltaria/webhooks/client.rb', line 103 def get_webhook_subscription(request_options: {}, **params) params = Voltaria::Internal::Types::Utils.normalize_keys(params) request = Voltaria::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v2/webhooks/subscriptions/#{URI.encode_uri_component(params[:webhook_id].to_s)}", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Voltaria::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Voltaria::Types::WebhookSubscriptionResponse.load(response.body) else error_class = Voltaria::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#list_webhook_logs(request_options: {}, **params) ⇒ Voltaria::Types::PaginatedResponseWebhookLogResponse
Retrieve all webhook logs linked to your partner account.
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 235 236 237 238 |
# File 'lib/voltaria/webhooks/client.rb', line 210 def list_webhook_logs(request_options: {}, **params) params = Voltaria::Internal::Types::Utils.normalize_keys(params) query_param_names = %i[webhook_id page page_size] query_params = {} query_params["webhook_id"] = params[:webhook_id] if params.key?(:webhook_id) query_params["page"] = params[:page] if params.key?(:page) query_params["page_size"] = params[:page_size] if params.key?(:page_size) params.except(*query_param_names) request = Voltaria::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v2/webhooks/logs", query: query_params, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Voltaria::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Voltaria::Types::PaginatedResponseWebhookLogResponse.load(response.body) else error_class = Voltaria::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#list_webhook_subscriptions(request_options: {}, **params) ⇒ Voltaria::Types::PaginatedResponseWebhookSubscriptionResponse
List all webhook subscriptions for your partner account.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/voltaria/webhooks/client.rb', line 27 def list_webhook_subscriptions(request_options: {}, **params) params = Voltaria::Internal::Types::Utils.normalize_keys(params) query_param_names = %i[page page_size event_type] query_params = {} query_params["page"] = params[:page] if params.key?(:page) query_params["page_size"] = params[:page_size] if params.key?(:page_size) query_params["event_type"] = params[:event_type] if params.key?(:event_type) params.except(*query_param_names) request = Voltaria::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v2/webhooks/subscriptions", query: query_params, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Voltaria::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Voltaria::Types::PaginatedResponseWebhookSubscriptionResponse.load(response.body) else error_class = Voltaria::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#update_webhook_subscription(request_options: {}, **params) ⇒ Voltaria::Types::WebhookSubscriptionResponse
Update a webhook subscription with its specific webhook ID.
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/voltaria/webhooks/client.rb', line 137 def update_webhook_subscription(request_options: {}, **params) params = Voltaria::Internal::Types::Utils.normalize_keys(params) request_data = Voltaria::Webhooks::Types::WebhookUpdatePayload.new(params).to_h non_body_param_names = ["webhook_id"] body = request_data.except(*non_body_param_names) request = Voltaria::Internal::JSON::Request.new( base_url: [:base_url], method: "PUT", path: "v2/webhooks/subscriptions/#{URI.encode_uri_component(params[:webhook_id].to_s)}", body: body, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Voltaria::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Voltaria::Types::WebhookSubscriptionResponse.load(response.body) else error_class = Voltaria::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |