Coder Social home page Coder Social logo

grokify / ringcentral-sdk-ruby Goto Github PK

View Code? Open in Web Editor NEW
13.0 4.0 13.0 892 KB

RingCentral SDK in Ruby (https://developers.ringcentral.com)

Home Page: http://ringcentral-sdk-ruby.readthedocs.org/

License: MIT License

Ruby 97.06% HTML 1.75% Handlebars 1.18%
ringcentral ringcentral-ruby sms mms fax

ringcentral-sdk-ruby's Introduction

RingCentral SDK for Ruby

Gem Version Build Status Coverage Status Code Climate Scrutinizer Code Quality Docs Docs License

Stack Overflow Chat

Table of contents

  1. Overview
  2. Documentation
  3. Installation
  4. Usage
  5. Synopsis
  6. API Requests 1. Generic HTTP Requests 2. SMS and MMS Examples 3. Fax Examples
  7. Advanced Use Cases
  8. Supported Ruby Versions
  9. Releases
  10. Versioning
  11. Change Log
  12. Links
  13. Contributions
  14. License

Overview

A Ruby SDK for the RingCentral REST API.

Important Notes

Version 2.0.0 introduces the following backward breaking changes:

  • SDK instantiation by moving to a block-based configuration
  • Removal of RingCentralSdk::REST::Config class
  • Removal of RingCentralSdk::REST::Client.authorize_user method

Documentation

Full documentation and resources are available at:

  1. Ruby SDK Developer Guide - Read the Docs
  2. Ruby SDK Reference Guide - RubyDoc.info

For API information, see the official RingCentral resources:

  1. API Developer and Reference Guide
  2. API Explorer
  3. CTI Tutorial

Installation

Via Bundler

Add 'ringcentral_sdk' to Gemfile and then run bundle:

$ echo "gem 'ringcentral_sdk'" >> Gemfile
$ bundle

Via RubyGems

$ gem install ringcentral_sdk

Usage

Synopsis

require 'ringcentral_sdk'

client = RingCentralSdk::REST::Client.new do |config|
  # App info (mandatory)
  config.client_id = 'myAppClientID'
  config.client_secret = 'myAppClientSecret'
  config.server_url = RingCentralSdk::RC_SERVER_SANDBOX

  # User info for password grant (optional)
  config.username = 'myUsername'
  config.extension = 'myExtension'
  config.password = 'myPassword'

  # Set a custom logger (optional)
  config.logger = Logger.new(STDOUT)

  # Enable HTTP retries for 429, 503, and 504 errors
  # Set custom codes and retry after using retry_options
  config.retry = true
end

# Send SMS
res = client.messages.sms.create(
  from: '+16505551212',
  to: '+14155551212',
  text: 'Hi there!'
)

More information on the authorization code flow:

  1. Full documentation
  2. Sinatra example

API Requests

API requests can be made via the included Faraday client or RingCentralSdk::Helpers::Request subclasses. These are described below.

Generic HTTP Requests

To make generic API requests, use included Faraday client which can be accessed via client.http. The client automatically adds the correct access token to the HTTP request and handles OAuth token refresh using the OAuth gem.

This is useful to access many API endpoints which do not have custom wrappers and for debugging purposes.

http = client.http

SMS and MMS Examples

SMS:

client.messages.sms.create(
  from: '+16505551212',
  to: '+14155551212',
  text: 'Hi there!'
)

MMS with media file:

client.messages.sms.create(
  from: '+16505551212',
  to: '+14155551212',
  text: 'Hi there!',
  media: '/filepath/to/file.ext'
)

Fax Examples

Fax files:

client.messages.fax.create(
  to: '+14155551212',
  coverPageText: 'Hi there!',
  files: ['/path/to/myfile.pdf']
)

Fax text:

client.messages.fax.create(
  to: '+14155551212',
  coverPageText: 'Hi there!',
  text: 'Hi there!'
)

Subscription Example

To make subscriptions with RingCentral, use the SDK object to create subscription Observer object and then add observers to it.

# Create an observer object
class MyObserver
  def update(message)
    puts 'Subscription Message Received'
    puts JSON.dump(message)
  end
end

# Create an observable subscription and add your observer
sub = client.create_subscription
sub.add_observer MyObserver.new

# Subscribe to an arbitrary number of event filters
sub.subscribe ['/restapi/v1.0/account/~/extension/~/presence']

# End the subscription
sub.destroy

Advanced Use Cases

  1. Subscribing to All Extensions
  2. Managing Call Queue Member Status

Supported Ruby Versions

This library is tested against this list of Ruby implementations.

Releases

Releases with release notes are availabe on GitHub releases. Release notes include a high level description of the release as well as lists of non-breaking and breaking changes.

Versioning

  • Versions 1.0.0 and above follow semantic versioning. Breaking changes will be indicated by a change in major version.
  • Versions below 1.0.0 are in active development. During initial development (Version 0.x.x), minor version changes will indicate either substantial feature inclusion or breaking changes.

Change Log

See CHANGELOG.md

Links

Project Repo

RingCentral API Docs

RingCentral API Explorer

RingCentral Official SDKs

Contributing

  1. Fork it ( http://github.com/grokify/ringcentral-sdk-ruby/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

RingCentral SDK is available under an MIT-style license. See LICENSE.md for details.

RingCentral SDK © 2015-2023 by John Wang

ringcentral-sdk-ruby's People

Contributors

brutalbeard avatar grokify avatar mnort9 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ringcentral-sdk-ruby's Issues

Use block based config

Move from arguments to block based configuration, e.g.

client = RingCentralSdk.new do |config|
  # Mandatory
  config.app_key = "your app key"
  config.app_secret = "your app secret"

  # Server URL - defaults to sandbox
  config.server_url = RingCentralSdk::RC_SERVER_PRODUCTION

  # Password Grant
  config.username = "your RingCentral username"
  config.extension = "your RingCentral extension"
  config.password = "your RingCentral password"

  # Authorization Code Grant
  config.redirect_url = "your OAuth redirect URI"

  # Access Token
  config.token = { "access_token" => "my_token" }

  # Retry uses middleware to notify the user
  # when hitting the rate limit, sleep automatically,
  # then retry the request.
  config.retry = true

  # Logger prints to STDERR by default, to e.g. print to stdout:
  require 'logger'
  config.logger = Logger.new(STDOUT)
end

Retry after 429/503 is always enabled

It appears that auto-retry of throttling is always enabled regardless of config.retry setting in v2.2.1.

Will investigate to allow disabling of this setting as intended.

Support async requests

Support async requests, likely using Celluoid, with testing on JRuby and possibly Rubinus.

Requests that fail aren't propagating errors

I was working with a subscription and the response came back with an error. Nothing checked for the error, so when a value was nil that shouldn't have been, my call returned a runtime error. That was difficult to track down. Perhaps this isn't different enough from #8 to warrant a new issue, but it's related. This is the line that is liberally catching the errors.

Subscriptions are not received with pubnub 4.0.7

PubNub's Ruby SDK was updated from 3.x to 4.x to use Celluloid in lieu of EventMachine. While the API remains the same and events are executed, something is preventing the subscription callbacks from being executed. This code is in the RingCentralSdk::REST::Subscription class.

Examined two approaches so far:

  1. Pubnub#subscribe now returns a Celluloid::Future object. Did some initial tests such as saving the Celluloid::Future as an object property so it doesn't go out of scope but that didn't solve the issue.
  2. Changed the .subscribe call from using the callback: parameter to the tutorial style, but that also didn't address the issue:
pubnub.subscribe(
  channel: 'my_channel'
) do |envelope| 
  puts envelope.message
end

Will do more testing later.

For now, this can be an issue when using RingCentral 1.3.0 and 1.2.3 which use the latest PubNub, e.g. 4.0.7.

RingCentral 1.3.1 handles this by locking to PubNub 3.8 for now.

Unable to authorize request

I will have to research this further myself at a different time, but when I follow the instructions to authorize my application with the password grant method and I call client.authorize_password('myUsername', 'myExtension', 'myPassword') it returns this error:

NoMethodError: undefined method +' for nil:NilClass
from /Users/myusernamehere/.rbenv/versions/2.2.3/lib/ruby/2.2.0/net/http.rb:1532:in addr_port'

I might have a gem out of date or something similar but any direction you can give me would be helpful. Thanks in advance!

Add access_token_ttl param option to README

The README doesn't mention this, but I figured out via reading through the code that I can pass a custom param access_token_ttl=x to Client#authorize_code(code, access_token_ttl: 600) to set a custom ttl. It would be helpful to point this out in the README for other developers.

Deprecated farady dependencies

This library depends on pre-1.0 faraday and faraday middleware libraries that are deprecated. This is causing dependency conflicts with other libraries that are depending on newer versions of faraday.

[question] Refresh Token Flow

I'm building an application to hook into users' CRM and send automated text messages throughout their sales campaigns. I'm a bit confused regarding the best way to generate a new token using the refresh token flow - I'm able to obtain a token using the Authorization Flow and cache the token for future use. I'm able to use the cached token with a new Rest Client (client.set_token(token)) and the refresh performs automatically if the token's 'expires_at' time has passed, however I can't get access to the refresh token object after the refresh has been performed. Will I be able to reuse the original token object indefinitely so long as it's refreshed within a week of when the previous refresh was performed? I was under the impression that the refresh token would cease to work one week (or however long the 'refresh_token_expires_in' is set to) after the original token was issued.

Essentially, I'm wondering whether users will need to log in at least once a week and obtain a new OAuth token, or if we're able to retrieve a new token via a background process/worker via Refresh Token Flow.

I posted this question on the developer forum as well - https://devcommunity.ringcentral.com/ringcentraldev/topics/text-automation#reply-comment-list-18391351

Thanks in advance for your help! Hope you're having a nice day.

::REST Uninitialized Constant

Hello, this issue is purely a bug review/help request.

I have just read through your docs and decided that this gem would make RC's API fairly easy to work with.

So I went ahead and added ringcentral_sdk to my Gemfile, ran bundle install and tried to play around with the API.

I tried to load a test file with a basic http GET request and it error'd out giving me an Uninitialize Constant error for ::REST

Any thoughts?

Message retrieval leads to retries and failure

We have a production app which has Call Log and Read Messages permissions. For many messages, we are able to retrieve the message details. For some, however, we get a retry followed by a failure.

Such as this message: https://platform.ringcentral.com/restapi/v1.0/account/346124008/extension/346247008/message-store/748682490016

      message_uri = "https://platform.ringcentral.com/restapi/v1.0/account/346124008/extension/346247008/message-store/748682490016"
      response = client.http.get do |req|
        req.url lead.message_uri
      end

Then, I get the following perplexing series of messages:

W, [2017-06-12T09:48:34.397029 #25438]  WARN -- : You have been rate limited. Retrying in 60 seconds...
W, [2017-06-12T09:48:35.397205 #25438]  WARN -- : 60...
W, [2017-06-12T09:48:40.398032 #25438]  WARN -- : 55...
W, [2017-06-12T09:48:45.398863 #25438]  WARN -- : 50...
W, [2017-06-12T09:48:50.399689 #25438]  WARN -- : 45...
W, [2017-06-12T09:48:55.400518 #25438]  WARN -- : 40...
W, [2017-06-12T09:49:00.401316 #25438]  WARN -- : 35...
W, [2017-06-12T09:49:05.402063 #25438]  WARN -- : 30...
W, [2017-06-12T09:49:10.402881 #25438]  WARN -- : 25...
W, [2017-06-12T09:49:15.403729 #25438]  WARN -- : 20...
W, [2017-06-12T09:49:20.404500 #25438]  WARN -- : 15...
W, [2017-06-12T09:49:25.405330 #25438]  WARN -- : 10...
W, [2017-06-12T09:49:30.406249 #25438]  WARN -- : 5...
W, [2017-06-12T09:49:34.407022 #25438]  WARN -- : Retrying...
 => #<Faraday::Response:0x007f1ef4b29a48 @on_complete_callbacks=[], @env=#<Faraday::Env @method=:get @body={"errorCode"=>"CMN-301", "message"=>"Request rate exceeded", "errors"=>[{"errorCode"=>"CMN-301", "message"=>"Request rate exceeded"}]} @url=#<URI::HTTPS https://platform.ringcentral.com/restapi/v1.0/account/346124008/extension/346247008/message-store/748682490016> @request=#<Faraday::RequestOptions (empty)> @request_headers={"User-Agent"=>"ringcentral-sdk-ruby/2.1.0 ruby/2.3.1 x86_64-linux", "RC-User-Agent"=>"ringcentral-sdk-ruby/2.1.0 ruby/2.3.1 x86_64-linux", "SDK-User-Agent"=>"ringcentral-sdk-ruby/2.1.0 ruby/2.3.1 x86_64-linux", "Authorization"=>"Bearer U0pDMDFQMDdQQVMwMHxBQUNVT1lPZGVaaFZ1ek1yNWp4YkdrTmhiWVRlR3kxbDVtTTh2TWJWTUNkelRKdHhRVjE2VWNzRnpNVGlBN1RfdUhaNF9QWWRPMEVYNEhPV3FzbEwwTUtuMFBGMUVfcGdXQ3pFSkNZMWxXNnVxamVYbXlNT1RibFU2R21FWE1EcVBPd3dEY3NJUXNrNHFvLWlCTnp2aVZCdjVRRVlGOGg0VWRyekVBVlhXSWkzV2h4THVQZW9wZmFieG9oT28yUDdGY3N8SkRpS0dBfE9GNFlRX1dwZE1SNHoyVno2UXZ0WFE"} @ssl=#<Faraday::SSLOptions verify=true> @response=#<Faraday::Response:0x007f1ef4b29a48 ...> @response_headers={"server"=>"nginx/1.10.2", "date"=>"Mon, 12 Jun 2017 09:49:56 GMT", "content-type"=>"application/json", "content-length"=>"161", "connection"=>"close", "x-rate-limit-group"=>"light", "x-rate-limit-limit"=>"50", "x-rate-limit-remaining"=>"50", "x-rate-limit-window"=>"60", "retry-after"=>"60", "www-authenticate"=>"Bearer realm=\"RingCentral REST API\", error=\"CMN-301\", error_description=\"Request rate exceeded\"", "content-language"=>"en", "routingkey"=>"SJC01P07", "rcrequestid"=>"7db9fc62-4f54-11e7-94f2-005056af6d4e"} @status=429 @reason_phrase="Too Many Requests">>

How have we possibly been "rate limited" or submitted "Too Many Requests", when we have x-rate-limit-remaining of 50?

RubyGems `certificate has expired` has error

Retrying download gem from https://rubygems.org/ due to error (2/4): Gem::RemoteFetcher::FetchError SSL_connect returned=1 errno=0 state=error: certificate verify failed (certificate has expired)

Resolved using the following. Kept here for posterity.

Homebrew/legacy-homebrew#32251

$ sudo security delete-certificate -Z 2F173F7DE99667AFA57AF80AA2D1B12FAC830338 /System/Library/Keychains/SystemRootCertificates.keychain
$ brew postinstall openssl

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.