Class: Pinnacle::AsyncClient

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

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)


161
162
163
164
165
166
167
168
169
170
# File 'lib/rcs.rb', line 161

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
  )
end

Instance Method Details

#check_rcs_capability(phone_number:, request_options: nil) ⇒ Pinnacle::CheckRcsCapabilityResponse

Checks if a phone number is able to receive RCS

Examples:

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

Parameters:

  • phone_number (String)

    Phone number (E.164 format: [+][country code][subscriber number including area code]) to check for RCS capability. Example: +1234567890

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

Returns:



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/rcs.rb', line 185

def check_rcs_capability(phone_number:, 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 || {}), "phone_number": 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)}/check_rcs"
  end
  Pinnacle::CheckRcsCapabilityResponse.from_json(json_object: response.body)
end

#get_account_number(request_options: nil) ⇒ Pinnacle::GetAccountNumberResponse

Retrieve the phone number associated with the account.

Examples:

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

Parameters:

Returns:



244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/rcs.rb', line 244

def (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
    unless request_options.nil? || request_options&.additional_query_parameters.nil?
      req.params = { **(request_options&.additional_query_parameters || {}) }.compact
    end
    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)}/get_account_number"
  end
  Pinnacle::GetAccountNumberResponse.from_json(json_object: response.body)
end

#send(request:, request_options: nil) ⇒ Pinnacle::SendResponse

Send a SMS or RCS message to a phone number

Examples:

api = Pinnacle::Client.new(
  base_url: "https://api.example.com",
  environment: Pinnacle::Environment::DEFAULT,
  api_key: "YOUR_API_KEY"
)
api.send(request: { phone_number: "phone_number", message_type: "card", message: { cards: [{ title: "title" }] } })

Parameters:

Returns:



276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
# File 'lib/rcs.rb', line 276

def send(request:, request_options: nil)
  response = @async_request_client.conn.post 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
    unless request_options.nil? || request_options&.additional_query_parameters.nil?
      req.params = { **(request_options&.additional_query_parameters || {}) }.compact
    end
    req.body = { **(request || {}), **(request_options&.additional_body_parameters || {}) }.compact
    req.url "#{@async_request_client.get_url(request_options: request_options)}/send"
  end
  Pinnacle::SendResponse.from_json(json_object: response.body)
end

#update_settings(webhook_url:, request_options: nil) ⇒ Pinnacle::UpdateSettingsResponse

Initializes settings related to RCS messaging, including webhook registration.

Examples:

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

Parameters:

  • webhook_url (String)

    Webhook URL to receive inbound messages

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

Returns:



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/rcs.rb', line 215

def update_settings(webhook_url:, request_options: nil)
  response = @async_request_client.conn.post 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
    unless request_options.nil? || request_options&.additional_query_parameters.nil?
      req.params = { **(request_options&.additional_query_parameters || {}) }.compact
    end
    req.body = { **(request_options&.additional_body_parameters || {}), webhook_url: webhook_url }.compact
    req.url "#{@async_request_client.get_url(request_options: request_options)}/update_settings"
  end
  Pinnacle::UpdateSettingsResponse.from_json(json_object: response.body)
end