ringcentral-ruby

Build Status Coverage Status

Ruby SDK for RingCentral.

Installation

gem install ringcentral-sdk

Name collision with ringcentral gem

The ringcentral gem is using RingCentral's legacy API, 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.

Solution is gem uninstall ringcentral

Documentation

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

Usage

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'])

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

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.

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

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 rspec

License

MIT

Todo

  • Batch requests