Class: Whatsapp::BusinessPhoneNumber::Account::Update

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: nil, timezone_id: nil) ⇒ Update

Returns a new instance of Update.

Parameters:

  • name (String, nil) (defaults to: nil)

    The account's new name. Meta rejects an empty string, so a blank value fails here rather than at the API.

  • timezone_id (String, nil) (defaults to: nil)

    The account's new timezone identifier. Meta publishes no enum for this field, so only presence is checked.

Raises:

  • (ActiveModel::ValidationError)

    if both are nil, or either is blank.



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

#nameString?

Returns The account's new name.

Returns:

  • (String, nil)

    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_idString?

Returns The account's new timezone identifier.

Returns:

  • (String, nil)

    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

Parameters:

  • client (Whatsapp::Client) (defaults to: Client.new)

    The WhatsApp client instance.

  • name (String, nil) (defaults to: nil)
  • timezone_id (String, nil) (defaults to: nil)

Returns:

Raises:

  • (ActiveModel::ValidationError)

    if no attribute is given, or one is blank.

  • (Error)

    if no WABA ID is configured, or the request fails.



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

#serializeHash

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.

Returns:

  • (Hash)

    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