GithubHelp home page GithubHelp logo

ringcentral-ruby's Introduction

RingCentral SDK for Ruby

Ruby Twitter

RingCentral Developers is a cloud communications platform which can be accessed via more than 70 APIs. The platform's main capabilities include technologies that enable: Voice, SMS/MMS, Fax, Glip Team Messaging, Data and Configurations.

API Reference and APIs Explorer.

Getting help and support

If you are having difficulty using this SDK, or working with the RingCentral API, please visit our developer community forums for help and to get quick answers to your questions. If you wish to contact the RingCentral Developer Support team directly, please submit a help ticket from our developer website.

Installation

gem install ringcentral-sdk

Name collision with ringcentral gem

The ringcentral gem is using RingCentral's legacy API which was End-of-Lifed in 2018. Everyone is recommended to move to the REST API.

If you have both the ringcentral and ringcentral-sdk gems installed, you will run into a collision error when attempting to initialize the ringcentral-sdk RingCentral SDK.

The solution is gem uninstall ringcentral

Documentation

https://developer.ringcentral.com/api-docs/latest/index.html

Usage

require 'ringcentral'

rc = RingCentral.new('clientID', 'clientSecret', 'serverURL')
rc.authorize(username: 'username', extension: 'extension', password: 'password')

# get
r = rc.get('/restapi/v1.0/account/~/extension/~')
expect(r).not_to be_nil
expect('101').to eq(r.body['extensionNumber'])

How to specify query parameters

for get & delete

rc.get('/restapi/v1.0/account/~/extension', { hello: 'world' })

for post, put & patch

rc.post('/restapi/v1.0/account/~/extension/~/sms', payload: body, params: { hello: 'world' })

multi-value query parameter

rc.get('/restapi/v1.0/account/~/extension', { hello: ['world1', 'world2'] })

Above will be translated to /restapi/v1.0/account/~/extension?hello=world1&hello=world2.

Token Refresh

Access token expires. You need to call rc.refresh() before it expires. If you want the SDK to do auto refresh please rc.auto_refresh = true before authorization.

Load preexisting token

Let's say you already have a token. Then you can load it like this: rc.token = your_token_object.

The benifits of loading a preexisting token is you don't need to go through any authorization flow.

If what you have is a JSON string instead of a Ruby object, you need to convert it first: JSON.parse(your_token_string).

If you only have a string for the access token instead of for the whole object, you can set it like this:

rc.token = { access_token: 'the token string' }

Send SMS

r = rc.post('/restapi/v1.0/account/~/extension/~/sms', payload: {
    to: [{phoneNumber: ENV['RINGCENTRAL_RECEIVER']}],
    from: {phoneNumber: ENV['RINGCENTRAL_USERNAME']},
    text: 'Hello world'
})

Send fax

rc.post('/restapi/v1.0/account/~/extension/~/fax',
payload: { to: [{ phoneNumber: ENV['RINGCENTRAL_RECEIVER'] }] },
    files: [
        ['spec/test.txt', 'text/plain'],
        ['spec/test.png', 'image/png']
    ]
)

Send MMS

r = rc.post('/restapi/v1.0/account/~/extension/~/sms',
    payload: {
        to: [{ phoneNumber: ENV['RINGCENTRAL_RECEIVER'] }],
        from: { phoneNumber: ENV['RINGCENTRAL_USERNAME'] },
        text: 'hello world'
    },
    files: [
        ['spec/test.png', 'image/png']
    ]
)

PubNub subscription

def createSubscription(callback)
    events = [
        '/restapi/v1.0/account/~/extension/~/message-store',
    ]
    subscription = PubNub.new(rc, events, lambda { |message|
        callback.call(message)
    })
    subscription.subscribe()
    return subscription
end

createSubscription(lambda { |message|
    puts message
})

For more sample code, please refer to the test cases.

How to test

bundle install --path vendor/bundle

Create .env file with the following content:

RINGCENTRAL_SERVER_URL=https://platform.devtest.ringcentral.com
RINGCENTRAL_CLIENT_ID=
RINGCENTRAL_CLIENT_SECRET=
RINGCENTRAL_USERNAME=
RINGCENTRAL_EXTENSION=
RINGCENTRAL_PASSWORD=
RINGCENTRAL_RECEIVER=

RINGCENTRAL_RECEIVER is a phone number to receive SMS, Fax..etc.

Run bundle exec rspec

License

MIT

Todo

  • Batch requests

ringcentral-ruby's People

Contributors

byrnereese avatar grokify avatar pacovu avatar tylerlong avatar

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.