Class: Whatsapp::BusinessPhoneNumber::Profile::Update

Inherits:
Object
  • Object
show all
Extended by:
Transport, ResponseHandling
Includes:
ActiveModel::Validations
Defined in:
lib/ruby/whatsapp/business_phone_number/profile/update.rb

Overview

Updates a business profile: its about text, description, contact details, websites, industry vertical, and profile picture.

A validated instance rather than a bare class method (unlike Get, which has nothing to check): Meta documents a closed vertical enum and per-field character limits, and since every field is optional an all-nil call would spend a request to change nothing. Source: https://developers.facebook.com/documentation/business-messaging/whatsapp/reference/whatsapp-business-phone-number/whatsapp-business-profile-api

Defined Under Namespace

Modules: Defaults, Limits

Constant Summary collapse

ATTRIBUTES =

Every updatable field, in payload order. Drives both the "change something" guard and its message, so the two cannot drift apart.

%i[about address description email vertical websites profile_picture_handle].freeze

Constants included from ResponseHandling

ResponseHandling::MAX_ERROR_BODY

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(about: nil, address: nil, description: nil, email: nil, vertical: nil, websites: nil, profile_picture_handle: nil) ⇒ Update

Returns a new instance of Update.

Parameters:

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

    See #about.

  • address (String, nil) (defaults to: nil)
  • description (String, nil) (defaults to: nil)
  • email (String, nil) (defaults to: nil)

    Length only — Meta validates the address itself server-side, and a format check here would reject valid exotic addresses.

  • vertical (String, Symbol, nil) (defaults to: nil)

    One of Verticals::ALL, either casing.

  • websites (Array<String>, nil) (defaults to: nil)

    At most Whatsapp::BusinessPhoneNumber::Profile::Update::Limits::WEBSITES URLs. An empty array is a deliberate instruction to clear the list, not an omission.

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

    Opaque to this gem; presence only.

Raises:

  • (ActiveModel::ValidationError)

    if every field is nil, or one breaks a documented limit.



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/ruby/whatsapp/business_phone_number/profile/update.rb', line 84

def initialize(about: nil, address: nil, description: nil, email: nil, vertical: nil,
  websites: nil, profile_picture_handle: nil)
  @about = about
  @address = address
  @description = description
  @email = email
  @vertical = Verticals.normalize(vertical)
  @websites = websites
  @profile_picture_handle = profile_picture_handle

  validate!
end

Instance Attribute Details

#aboutString?

Returns The profile's about text, at most Whatsapp::BusinessPhoneNumber::Profile::Update::Limits::ABOUT characters.

Returns:



38
39
40
# File 'lib/ruby/whatsapp/business_phone_number/profile/update.rb', line 38

def about
  @about
end

#addressString?

Returns The business's address, at most Whatsapp::BusinessPhoneNumber::Profile::Update::Limits::ADDRESS characters.

Returns:



42
43
44
# File 'lib/ruby/whatsapp/business_phone_number/profile/update.rb', line 42

def address
  @address
end

#descriptionString?

Returns The business description, at most Whatsapp::BusinessPhoneNumber::Profile::Update::Limits::DESCRIPTION characters.

Returns:



46
47
48
# File 'lib/ruby/whatsapp/business_phone_number/profile/update.rb', line 46

def description
  @description
end

#emailString?

Returns The contact email, at most Whatsapp::BusinessPhoneNumber::Profile::Update::Limits::EMAIL characters.

Returns:



50
51
52
# File 'lib/ruby/whatsapp/business_phone_number/profile/update.rb', line 50

def email
  @email
end

#profile_picture_handleString?

Returns A picture handle from Meta's Resumable Upload API.

Returns:

  • (String, nil)

    A picture handle from Meta's Resumable Upload API.



62
63
64
# File 'lib/ruby/whatsapp/business_phone_number/profile/update.rb', line 62

def profile_picture_handle
  @profile_picture_handle
end

#verticalString?

Returns One of Verticals::ALL.

Returns:



54
55
56
# File 'lib/ruby/whatsapp/business_phone_number/profile/update.rb', line 54

def vertical
  @vertical
end

#websitesArray<String>?

Returns:



58
59
60
# File 'lib/ruby/whatsapp/business_phone_number/profile/update.rb', line 58

def websites
  @websites
end

Class Method Details

.call(client: Client.new, about: nil, address: nil, description: nil, email: nil, vertical: nil, websites: nil, profile_picture_handle: nil) ⇒ BusinessPhoneNumber::Response

Parameters:

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

    The WhatsApp client instance.

  • about (String, nil) (defaults to: nil)
  • address (String, nil) (defaults to: nil)
  • description (String, nil) (defaults to: nil)
  • email (String, nil) (defaults to: nil)
  • vertical (String, Symbol, nil) (defaults to: nil)
  • websites (Array<String>, nil) (defaults to: nil)
  • profile_picture_handle (String, nil) (defaults to: nil)

Returns:

Raises:

  • (ActiveModel::ValidationError)

    if no field is given, or one is invalid.

  • (Error)

    if no phone number ID is configured, or the request fails.



118
119
120
121
122
123
124
125
126
127
# File 'lib/ruby/whatsapp/business_phone_number/profile/update.rb', line 118

def call(client: Client.new, about: nil, address: nil, description: nil, email: nil,
  vertical: nil, websites: nil, profile_picture_handle: nil)
  body = new(about:, address:, description:, email:, vertical:, websites:,
    profile_picture_handle:).serialize
  response = client.connection.post(edge_path(client, Defaults::EDGE), json: body)

  BusinessPhoneNumber::Response.deserialize(
    parse_json(handle_response!(response, error_class: Error, action: "update business profile"))
  )
end

Instance Method Details

#serializeHash

Returns The update payload. messaging_product is documented required so it is always sent; every other field is optional and an omitted one is compacted away rather than sent as null, which Meta would read as an instruction to blank it. An empty websites array survives compaction on purpose — that is the clear.

Returns:

  • (Hash)

    The update payload. messaging_product is documented required so it is always sent; every other field is optional and an omitted one is compacted away rather than sent as null, which Meta would read as an instruction to blank it. An empty websites array survives compaction on purpose — that is the clear.



101
102
103
104
# File 'lib/ruby/whatsapp/business_phone_number/profile/update.rb', line 101

def serialize
  { messaging_product: Defaults::MESSAGING_PRODUCT, about:, address:, description:,
    email:, vertical:, websites:, profile_picture_handle:, }.compact
end