Class: Pinnacle::AsyncClient

Inherits:
Object
  • Object
show all
Defined in:
lib/rcs.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, base_url: nil, environment: Pinnacle::Environment::DEFAULT, max_retries: nil, timeout_in_seconds: nil) ⇒ Pinnacle::AsyncClient

Parameters:

  • base_url (String) (defaults to: nil)
  • environment (Pinnacle::Environment) (defaults to: Pinnacle::Environment::DEFAULT)
  • max_retries (Long) (defaults to: nil)

    The number of times to retry a failed request, defaults to 2.

  • timeout_in_seconds (Long) (defaults to: nil)
  • api_key (String)


81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/rcs.rb', line 81

def initialize(api_key:, base_url: nil, environment: Pinnacle::Environment::DEFAULT, max_retries: nil,
               timeout_in_seconds: nil)
  @async_request_client = Pinnacle::AsyncRequestClient.new(
    base_url: base_url,
    environment: environment,
    max_retries: max_retries,
    timeout_in_seconds: timeout_in_seconds,
    api_key: api_key
  )
  @company = Pinnacle::AsyncCompanyClient.new(request_client: @async_request_client)
  @send = Pinnacle::AsyncSendClient.new(request_client: @async_request_client)
end

Instance Attribute Details

#companyPinnacle::AsyncCompanyClient (readonly)



71
72
73
# File 'lib/rcs.rb', line 71

def company
  @company
end

#sendPinnacle::AsyncSendClient (readonly)



73
74
75
# File 'lib/rcs.rb', line 73

def send
  @send
end

Instance Method Details

#get_rcs_functionality(phone_number: nil, request_options: nil) ⇒ Pinnacle::RcsFunctionalities

Retrieve the RCS functionality of a phone number. For example checks if a phone

number can receive RCS message and if it can receive RCS carousels.

Examples:

api = Pinnacle::Client.new(
  base_url: "https://api.example.com",
  environment: Pinnacle::Environment::DEFAULT,
  api_key: "YOUR_API_KEY"
)
api.get_rcs_functionality

Parameters:

  • phone_number (String) (defaults to: nil)

    The phone number to check for RCS functionality. Should be in E.164 format (i.e. +12345678901).

  • request_options (Pinnacle::RequestOptions) (defaults to: nil)

Returns:



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/rcs.rb', line 108

def get_rcs_functionality(phone_number: nil, request_options: nil)
  response = @async_request_client.conn.get do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["PINNACLE-API-Key"] = request_options.api_key unless request_options&.api_key.nil?
    req.headers = {
  **(req.headers || {}),
  **@async_request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    req.params = { **(request_options&.additional_query_parameters || {}), "phoneNumber": phone_number }.compact
    unless request_options.nil? || request_options&.additional_body_parameters.nil?
      req.body = { **(request_options&.additional_body_parameters || {}) }.compact
    end
    req.url "#{@async_request_client.get_url(request_options: request_options)}/rcs_functionality"
  end
  Pinnacle::RcsFunctionalities.from_json(json_object: response.body)
end