Class: Pinnacle::PhoneNumbers::Webhook::Client
- Inherits:
-
Object
- Object
- Pinnacle::PhoneNumbers::Webhook::Client
- Defined in:
- lib/pinnacle/phone_numbers/webhook/client.rb
Instance Method Summary collapse
-
#attach(request_options: {}, **params) ⇒ Pinnacle::Types::ConfiguredWebhook
Connect a webhook to your phone number to receive real-time notifications for incoming messages, delivery status updates, and other communication events.
-
#detach(request_options: {}, **params) ⇒ Pinnacle::Types::DetachedWebhookInfo
Disconnect a webhook from your phone number to stop receiving event notifications for that specific number.
- #initialize(client:) ⇒ void constructor
Constructor Details
#initialize(client:) ⇒ void
10 11 12 |
# File 'lib/pinnacle/phone_numbers/webhook/client.rb', line 10 def initialize(client:) @client = client end |
Instance Method Details
#attach(request_options: {}, **params) ⇒ Pinnacle::Types::ConfiguredWebhook
Connect a webhook to your phone number to receive real-time notifications for incoming messages, delivery status updates, and other communication events.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/pinnacle/phone_numbers/webhook/client.rb', line 27 def attach(request_options: {}, **params) params = Pinnacle::Internal::Types::Utils.normalize_keys(params) request = Pinnacle::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "phone-numbers/#{params[:phone]}/attach-webhook", body: Pinnacle::Types::AttachWebhookParams.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Pinnacle::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Pinnacle::Types::ConfiguredWebhook.load(response.body) else error_class = Pinnacle::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#detach(request_options: {}, **params) ⇒ Pinnacle::Types::DetachedWebhookInfo
Disconnect a webhook from your phone number to stop receiving event notifications for that specific number.
The webhook configuration itself remains intact and available for use with other phone numbers.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/pinnacle/phone_numbers/webhook/client.rb', line 66 def detach(request_options: {}, **params) params = Pinnacle::Internal::Types::Utils.normalize_keys(params) request = Pinnacle::Internal::JSON::Request.new( base_url: [:base_url], method: "DELETE", path: "phone-numbers/#{params[:phone]}/detach-webhook/#{params[:webhook_id]}", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Pinnacle::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Pinnacle::Types::DetachedWebhookInfo.load(response.body) else error_class = Pinnacle::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |