Class: WhatsappSdk::Api::BusinessAccount

Inherits:
Request
  • Object
show all
Defined in:
lib/whatsapp_sdk/api/business_account.rb

Constant Summary collapse

DEFAULT_FIELDS =
%w[id name timezone_id message_template_namespace account_review_status
   business_verification_status country ownership_type primary_business_location]
.join(',')
.freeze

Instance Method Summary collapse

Methods inherited from Request

#download_file, #initialize, #send_request

Constructor Details

This class inherits a constructor from WhatsappSdk::Api::Request

Instance Method Details

#get(business_id, fields: nil) ⇒ Resource::BusinessAccount

Get the details of business account.

Parameters:

  • business_id (Integer)

    Business Account Id.

  • fields (Array<String>) (defaults to: nil)

    Optional list of fields to include in the response. Defaults to 'id,name'.

Returns:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/whatsapp_sdk/api/business_account.rb', line 19

def get(business_id, fields: nil)
  fields = if fields
             fields.join(',')
           else
             DEFAULT_FIELDS
           end

  response = send_request(
    http_method: "get",
    endpoint: "#{business_id}?fields=#{fields}"
  )

  Resource::BusinessAccount.from_hash(response)
end

#update(business_id:, params:) ⇒ Boolean

Update the details of business account.

Parameters:

  • business_id (Integer)

    Business Account Id.

  • params (Hash)

    Params to update. The possible attributes to update are: name, timezone_id.

Returns:

  • (Boolean)

    Whether the update was successful.

Raises:

  • (ArgumentError)


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/whatsapp_sdk/api/business_account.rb', line 39

def update(business_id:, params:)
  raise ArgumentError, "Params must be a hash." unless params.is_a?(Hash)

  # Only name and timezone_id can be updated. If other keys are present, they will be ignored.
  filtered_params = params.transform_keys(&:to_sym).slice(:name, :timezone_id)

  if filtered_params.empty?
    raise ArgumentError, "No valid parameters provided. Only 'name' and 'timezone_id' can be updated."
  end

  response = send_request(
    http_method: "post",
    endpoint: business_id.to_s,
    params: filtered_params
  )

  Api::Responses::SuccessResponse.success_response?(response: response)
end