Class: Pinnacle::Client

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::Client

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)


28
29
30
31
32
33
34
35
36
37
# File 'lib/rcs.rb', line 28

def initialize(api_key:, base_url: nil, environment: Pinnacle::Environment::DEFAULT, max_retries: nil,
               timeout_in_seconds: nil)
  @request_client = Pinnacle::RequestClient.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:



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rcs.rb', line 52

def check_rcs_capability(phone_number:, request_options: nil)
  response = @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 || {}),
  **@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 "#{@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:



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/rcs.rb', line 111

def (request_options: nil)
  response = @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 || {}),
  **@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 "#{@request_client.get_url(request_options: request_options)}/get_account_number"
  end
  Pinnacle::GetAccountNumberResponse.from_json(json_object: response.body)
end

#get_company(company_id: nil, company_name: nil, request_options: nil) ⇒ Array<Pinnacle::Company>

Retrieve the company’s information (i.e. approval status, company name, etc.).

Search by company ID or company name.

Examples:

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

Parameters:

  • company_id (Integer) (defaults to: nil)

    The unique identifier for the company

  • company_name (String) (defaults to: nil)

    The name of the company

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

Returns:



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/rcs.rb', line 175

def get_company(company_id: nil, company_name: nil, request_options: nil)
  response = @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 || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    req.params = {
      **(request_options&.additional_query_parameters || {}),
      "companyId": company_id,
      "companyName": company_name
    }.compact
    unless request_options.nil? || request_options&.additional_body_parameters.nil?
      req.body = { **(request_options&.additional_body_parameters || {}) }.compact
    end
    req.url "#{@request_client.get_url(request_options: request_options)}/company"
  end
  parsed_json = JSON.parse(response.body)
  parsed_json&.map do |item|
    item = item.to_json
    Pinnacle::Company.from_json(json_object: item)
  end
end

#register_company(company:, company_contact:, point_of_contact:, optionals: nil, request_options: nil) ⇒ Pinnacle::RegisterCompanyResponse

Register a company for RCS with the Pinnacle platform

Examples:

api = Pinnacle::Client.new(
  base_url: "https://api.example.com",
  environment: Pinnacle::Environment::DEFAULT,
  api_key: "YOUR_API_KEY"
)
api.register_company(
  company: { name: "name", address: "address", ein: "ein", description: "description", brand_color: "brandColor", logo_url: "logoUrl", hero_url: "heroUrl" },
  company_contact: { primary_website_url: "primaryWebsiteUrl", primary_website_label: "primaryWebsiteLabel", primary_phone: "primaryPhone", primary_phone_label: "primaryPhoneLabel", primary_email: "primaryEmail", primary_email_label: "primaryEmailLabel", privacy_policy_url: "privacyPolicyUrl", tos_url: "tosUrl" },
  point_of_contact: { poc_name: "pocName", poc_title: "pocTitle", poc_email: "pocEmail" }
)

Parameters:

  • company (Hash)

    Request of type Pinnacle::CompanyDetails, as a Hash

    • :name (String)

    • :address (String)

    • :ein (String)

    • :description (String)

    • :brand_color (String)

    • :logo_url (String)

    • :hero_url (String)

  • company_contact (Hash)

    Request of type Pinnacle::CompanyContact, as a Hash

    • :primary_website_url (String)

    • :primary_website_label (String)

    • :primary_phone (String)

    • :primary_phone_label (String)

    • :primary_email (String)

    • :primary_email_label (String)

    • :privacy_policy_url (String)

    • :tos_url (String)

  • point_of_contact (Hash)

    Request of type Pinnacle::PointOfContact, as a Hash

    • :poc_name (String)

    • :poc_title (String)

    • :poc_email (String)

  • optionals (Hash) (defaults to: nil)

    Request of type Pinnacle::Optionals, as a Hash

    • :additional_websites (Array<Pinnacle::AdditionalWebsite>)

    • :additional_phone_numbers (Array<Pinnacle::AdditionalPhoneNumber>)

    • :additional_emails (Array<Pinnacle::AdditionalEmail>)

    • :test_numbers (Array<String>)

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

Returns:



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

def register_company(company:, company_contact:, point_of_contact:, optionals: nil, request_options: nil)
  response = @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 || {}),
  **@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 || {}),
      company: company,
      companyContact: company_contact,
      pointOfContact: point_of_contact,
      optionals: optionals
    }.compact
    req.url "#{@request_client.get_url(request_options: request_options)}/company/register"
  end
  Pinnacle::RegisterCompanyResponse.from_json(json_object: response.body)
end

#send_message(request:, request_options: nil) ⇒ Pinnacle::SendMessageResponse

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_message(request: { phone_number: "phone_number", message_type: "card", message: { cards: [{ title: "title" }] } })

Parameters:

Returns:



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/rcs.rb', line 143

def send_message(request:, request_options: nil)
  response = @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 || {}),
  **@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 "#{@request_client.get_url(request_options: request_options)}/send"
  end
  Pinnacle::SendMessageResponse.from_json(json_object: response.body)
end

#update_company(company_id:, company: nil, company_contact: nil, point_of_contact: nil, optionals: nil, request_options: nil) ⇒ Pinnacle::UpdateCompanyResponse

Update a company on the Pinnacle platform

Examples:

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

Parameters:

  • company_id (String)
  • company (Hash) (defaults to: nil)

    Request of type Pinnacle::Company, as a Hash

    • :id (Integer)

    • :created_at (DateTime)

    • :name (String)

    • :address (String)

    • :ein (String)

    • :description (String)

    • :brand_color (String)

    • :logo_url (String)

    • :hero_url (String)

    • :primary_website_url (String)

    • :primary_website_label (String)

    • :primary_phone (String)

    • :primary_phone_label (String)

    • :primary_email (String)

    • :primary_email_label (String)

    • :privacy_policy_url (String)

    • :tos_url (String)

    • :poc_name (String)

    • :poc_title (String)

    • :poc_email (String)

    • :test_numbers (Array<String>)

    • :status (String)

    • :additional_websites (Array<Pinnacle::CompanyAdditionalWebsitesItem>)

    • :additional_emails (Array<Pinnacle::CompanyAdditionalEmailsItem>)

    • :additional_phone_numbers (Array<Pinnacle::CompanyAdditionalPhoneNumbersItem>)

  • company_contact (Hash) (defaults to: nil)

    Request of type Pinnacle::CompanyContact, as a Hash

    • :primary_website_url (String)

    • :primary_website_label (String)

    • :primary_phone (String)

    • :primary_phone_label (String)

    • :primary_email (String)

    • :primary_email_label (String)

    • :privacy_policy_url (String)

    • :tos_url (String)

  • point_of_contact (Hash) (defaults to: nil)

    Request of type Pinnacle::PointOfContact, as a Hash

    • :poc_name (String)

    • :poc_title (String)

    • :poc_email (String)

  • optionals (Hash) (defaults to: nil)

    Request of type Pinnacle::Optionals, as a Hash

    • :additional_websites (Array<Pinnacle::AdditionalWebsite>)

    • :additional_phone_numbers (Array<Pinnacle::AdditionalPhoneNumber>)

    • :additional_emails (Array<Pinnacle::AdditionalEmail>)

    • :test_numbers (Array<String>)

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

Returns:



322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
# File 'lib/rcs.rb', line 322

def update_company(company_id:, company: nil, company_contact: nil, point_of_contact: nil, optionals: nil,
                   request_options: nil)
  response = @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 || {}),
  **@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 || {}),
      companyId: company_id,
      company: company,
      companyContact: company_contact,
      pointOfContact: point_of_contact,
      optionals: optionals
    }.compact
    req.url "#{@request_client.get_url(request_options: request_options)}/company/update"
  end
  Pinnacle::UpdateCompanyResponse.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:



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/rcs.rb', line 82

def update_settings(webhook_url:, request_options: nil)
  response = @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 || {}),
  **@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 "#{@request_client.get_url(request_options: request_options)}/update_settings"
  end
  Pinnacle::UpdateSettingsResponse.from_json(json_object: response.body)
end