Class: Whatsapp::BusinessPhoneNumber::Account::Update
- Inherits:
-
Object
- Object
- Whatsapp::BusinessPhoneNumber::Account::Update
- Extended by:
- Transport, ResponseHandling
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/ruby/whatsapp/business_phone_number/account/update.rb
Overview
Updates a WhatsApp Business Account's name or timezone.
A validated instance rather than a bare class method (unlike Get, which has
nothing to check): Meta documents name as a non-empty string, and since both
fields are optional an all-nil call would spend a request to change nothing.
Source: https://developers.facebook.com/documentation/business-messaging/whatsapp/reference/whatsapp-business-account/whatsapp-business-account-api
Constant Summary
Constants included from ResponseHandling
ResponseHandling::MAX_ERROR_BODY
Instance Attribute Summary collapse
-
#name ⇒ String?
The account's new name.
-
#timezone_id ⇒ String?
The account's new timezone identifier.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name: nil, timezone_id: nil) ⇒ Update
constructor
A new instance of Update.
-
#serialize ⇒ Hash
The update payload.
Constructor Details
#initialize(name: nil, timezone_id: nil) ⇒ Update
Returns a new instance of Update.
34 35 36 37 38 39 |
# File 'lib/ruby/whatsapp/business_phone_number/account/update.rb', line 34 def initialize(name: nil, timezone_id: nil) @name = name @timezone_id = timezone_id validate! end |
Instance Attribute Details
#name ⇒ String?
Returns The account's new name.
19 20 21 |
# File 'lib/ruby/whatsapp/business_phone_number/account/update.rb', line 19 def name @name end |
#timezone_id ⇒ String?
Returns The account's new timezone identifier.
23 24 25 |
# File 'lib/ruby/whatsapp/business_phone_number/account/update.rb', line 23 def timezone_id @timezone_id end |
Class Method Details
.call(client: Client.new, name: nil, timezone_id: nil) ⇒ BusinessPhoneNumber::Response
55 56 57 58 59 60 61 62 |
# File 'lib/ruby/whatsapp/business_phone_number/account/update.rb', line 55 def call(client: Client.new, name: nil, timezone_id: nil) body = new(name:, timezone_id:).serialize response = client.connection.post(node_path(client), json: body) BusinessPhoneNumber::Response.deserialize( parse_json(handle_response!(response, error_class: Error, action: "update business account")) ) end |
Instance Method Details
#serialize ⇒ Hash
Returns The update payload. Both fields are optional, so an omitted one is compacted away rather than sent as null — which Meta would read as an instruction to blank it.
44 45 46 |
# File 'lib/ruby/whatsapp/business_phone_number/account/update.rb', line 44 def serialize { name:, timezone_id: }.compact end |