How to install and use the RingCentral Ruby SDK
RVM + Gemset + RingCentral Ruby SDK
Ruby is a powerful object-oriented programming language that allows you to build a variety of solutions including websites, web apps, desktop apps, and more. With the RingCentral Ruby SDK you can easily bring message, video, phone capabilities into your application with just a few lines of code.
In this quick tutorial we’ll show you how to install the RingCentral Ruby gem and setup a ruby script that returns your RingCentral extension information.
Install RVM
curl -L https://get.rvm.io | bash -s stable - autolibs=enabled
Open a new terminal and run
rvm --version
If everything goes well, you should see something like this:
➜ ~ rvm --version
rvm 1.29.12 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
Your RVM version may be different than mine.
Install Ruby
rvm install ruby
Check your installed ruby version
ruby --version
If everything goes well, you should see something like this:
➜ ~ ruby --version
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin20]
Your Ruby version may be different than mine.
Setup Gemset
rvm gemset create dev
We just created a gemset with name dev
. List all gemsets:
rvm gemset list
If everything goes well, you should see something like this:
➜ ~ rvm gemset listgemsets for ruby-3.0.0 (found in /Users/tyler.liu/.rvm/gems/ruby-3.0.0)
=> (default)
dev
global
Your output may differ since you may have a different ruby version and gemsets.
We can see that the gemset named dev
is in the list, but it is not the default one.
rvm use 3.0.0@dev --default
Above we use Ruby 3.0.0 and gemset dev
and we set them as the default. Your Ruby version may be different, it depends on which version you installed in the “Install Ruby” step.
Let’s double check everything works as expected:
➜ ~ rvm gemset listgemsets for ruby-3.0.0 (found in /Users/tyler.liu/.rvm/gems/ruby-3.0.0)
(default)
=> dev
global
Make sure that you have used the expected Ruby and gemset before going to the next step.
Install RingCentral Ruby SDK
gem install ringcentral-sdk
If everything goes well, you should see something like this:
➜ ~ gem install ringcentral-sdk
Fetching concurrent-ruby-1.1.9.gem
Fetching dry-core-0.7.1.gem
Fetching dry-logic-1.2.0.gem
Fetching dry-inflector-0.2.1.gem
Fetching dry-configurable-0.13.0.gem
Fetching timers-4.3.3.gem
Fetching httpclient-2.8.3.gem
Fetching dry-container-0.9.0.gem
Fetching dry-types-1.5.1.gem
Fetching dry-initializer-3.0.4.gem
Fetching dry-schema-1.8.0.gem
Fetching dry-validation-1.7.0.gem
Fetching concurrent-ruby-edge-0.5.0.gem
Fetching public_suffix-4.0.6.gem
Fetching addressable-2.8.0.gem
Fetching pubnub-4.6.2.gem
Fetching ringcentral-sdk-0.9.4.gem
Fetching multipart-post-2.1.1.gem
Fetching faraday-0.17.4.gem
Fetching faraday_middleware-0.14.0.gem
Successfully installed timers-4.3.3
Successfully installed httpclient-2.8.3
Successfully installed concurrent-ruby-1.1.9
Successfully installed dry-core-0.7.1
Successfully installed dry-logic-1.2.0
Successfully installed dry-inflector-0.2.1
Successfully installed dry-configurable-0.13.0
Successfully installed dry-container-0.9.0
Successfully installed dry-types-1.5.1
Successfully installed dry-initializer-3.0.4
Successfully installed dry-schema-1.8.0
Successfully installed dry-validation-1.7.0
Successfully installed concurrent-ruby-edge-0.5.0
Successfully installed public_suffix-4.0.6
Successfully installed addressable-2.8.0
Successfully installed pubnub-4.6.2
Successfully installed multipart-post-2.1.1
Successfully installed faraday-0.17.4
Successfully installed faraday_middleware-0.14.0
Successfully installed ringcentral-sdk-0.9.4
Parsing documentation for timers-4.3.3
Installing ri documentation for timers-4.3.3
Parsing documentation for httpclient-2.8.3
Installing ri documentation for httpclient-2.8.3
Parsing documentation for concurrent-ruby-1.1.9
Installing ri documentation for concurrent-ruby-1.1.9
Parsing documentation for dry-core-0.7.1
Installing ri documentation for dry-core-0.7.1
Parsing documentation for dry-logic-1.2.0
Installing ri documentation for dry-logic-1.2.0
Parsing documentation for dry-inflector-0.2.1
Installing ri documentation for dry-inflector-0.2.1
Parsing documentation for dry-configurable-0.13.0
Installing ri documentation for dry-configurable-0.13.0
Parsing documentation for dry-container-0.9.0
Installing ri documentation for dry-container-0.9.0
Parsing documentation for dry-types-1.5.1
Installing ri documentation for dry-types-1.5.1
Parsing documentation for dry-initializer-3.0.4
Installing ri documentation for dry-initializer-3.0.4
Parsing documentation for dry-schema-1.8.0
Installing ri documentation for dry-schema-1.8.0
Parsing documentation for dry-validation-1.7.0
Installing ri documentation for dry-validation-1.7.0
Parsing documentation for concurrent-ruby-edge-0.5.0
Installing ri documentation for concurrent-ruby-edge-0.5.0
Parsing documentation for public_suffix-4.0.6
Installing ri documentation for public_suffix-4.0.6
Parsing documentation for addressable-2.8.0
Installing ri documentation for addressable-2.8.0
Parsing documentation for pubnub-4.6.2
Installing ri documentation for pubnub-4.6.2
Parsing documentation for multipart-post-2.1.1
Installing ri documentation for multipart-post-2.1.1
Parsing documentation for faraday-0.17.4
Installing ri documentation for faraday-0.17.4
Parsing documentation for faraday_middleware-0.14.0
Installing ri documentation for faraday_middleware-0.14.0
Parsing documentation for ringcentral-sdk-0.9.4
Installing ri documentation for ringcentral-sdk-0.9.4
Done installing documentation for timers, httpclient, concurrent-ruby, dry-core, dry-logic, dry-inflector, dry-configurable, dry-container, dry-types, dry-initializer, dry-schema, dry-validation, concurrent-ruby-edge, public_suffix, addressable, pubnub, multipart-post, faraday, faraday_middleware, ringcentral-sdk after 10 seconds
20 gems installed
Write a simple ruby script
require 'ringcentral'rc = RingCentral.new(ENV['RINGCENTRAL_CLIENT_ID'], ENV['RINGCENTRAL_CLIENT_SECRET'], ENV['RINGCENTRAL_SERVER_URL'])
rc.authorize(username: ENV['RINGCENTRAL_USERNAME'], extension: ENV['RINGCENTRAL_EXTENSION'], password: ENV['RINGCENTRAL_PASSWORD'])r = rc.get('/restapi/v1.0/account/~/extension/~')
puts r.body['extensionNumber']
Make sure that you have the following environment variables specifying proper credentials:
- RINGCENTRAL_SERVER_URL
- RINGCENTRAL_CLIENT_ID
- RINGCENTRAL_CLIENT_SECRET
- RINGCENTRAL_USERNAME
- RINGCENTRAL_EXTENSION
- RINGCENTRAL_PASSWORD
If you don’t want to set those environment variables, you may hard code the credentials in your code as well. It is just an experiment, anyway. Just remember to keep credentials safely.
Save the ruby script as a file ruby.rb
, then execute it:
ruby test.rb
If everything goes well, you should see something like this:
ruby test.rb
101
In the output above, we can see that extension number is 101
. You may see different extension number depending on whose credentials you specified in the script.
Summary
In this article, I mainly covered the fundamentals to setup a Ruby development environment. It’s always a good idea to start with a solid development environment before coding. Thanks for reading and enjoy your Ruby journey!
Please let us know what you think by leaving your questions and comments below. To learn even more about other features we have make sure to visit our developer site and if you’re ever stuck make sure to go to our developer forum.
Want to stay up to date and in the know about new APIs and features? Join our Game Changer Program and earn great rewards for building your skills and learning more about RingCentral!