Class: Whatsapp::BusinessPhoneNumber::Profile::Update
- Inherits:
-
Object
- Object
- Whatsapp::BusinessPhoneNumber::Profile::Update
- 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
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
-
#about ⇒ String?
The profile's about text, at most Limits::ABOUT characters.
-
#address ⇒ String?
The business's address, at most Limits::ADDRESS characters.
-
#description ⇒ String?
The business description, at most Limits::DESCRIPTION characters.
-
#email ⇒ String?
The contact email, at most Limits::EMAIL characters.
-
#profile_picture_handle ⇒ String?
A picture handle from Meta's Resumable Upload API.
-
#vertical ⇒ String?
One of Verticals::ALL.
-
#websites ⇒ Array<String>?
At most Limits::WEBSITES URLs.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(about: nil, address: nil, description: nil, email: nil, vertical: nil, websites: nil, profile_picture_handle: nil) ⇒ Update
constructor
A new instance of Update.
-
#serialize ⇒ Hash
The update payload.
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.
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
#about ⇒ String?
Returns The profile's about text, at most Whatsapp::BusinessPhoneNumber::Profile::Update::Limits::ABOUT characters.
38 39 40 |
# File 'lib/ruby/whatsapp/business_phone_number/profile/update.rb', line 38 def about @about end |
#address ⇒ String?
Returns The business's address, at most Whatsapp::BusinessPhoneNumber::Profile::Update::Limits::ADDRESS characters.
42 43 44 |
# File 'lib/ruby/whatsapp/business_phone_number/profile/update.rb', line 42 def address @address end |
#description ⇒ String?
Returns The business description, at most Whatsapp::BusinessPhoneNumber::Profile::Update::Limits::DESCRIPTION characters.
46 47 48 |
# File 'lib/ruby/whatsapp/business_phone_number/profile/update.rb', line 46 def description @description end |
#email ⇒ String?
Returns The contact email, at most Whatsapp::BusinessPhoneNumber::Profile::Update::Limits::EMAIL characters.
50 51 52 |
# File 'lib/ruby/whatsapp/business_phone_number/profile/update.rb', line 50 def email @email end |
#profile_picture_handle ⇒ String?
Returns 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 |
#vertical ⇒ String?
Returns One of Verticals::ALL.
54 55 56 |
# File 'lib/ruby/whatsapp/business_phone_number/profile/update.rb', line 54 def vertical @vertical end |
#websites ⇒ Array<String>?
Returns At most Whatsapp::BusinessPhoneNumber::Profile::Update::Limits::WEBSITES URLs.
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
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
#serialize ⇒ Hash
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.
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 |