ringcentral-ruby
Ruby SDK for RingCentral.
Installation
gem install ringcentral-sdk
Documentation
https://developer.ringcentral.com/api-docs/latest/index.html
Usage
require 'ringcentral'
rc = RingCentral.new(ENV['clientId'], ENV['clientSecret'], ENV['server'])
rc.(username: ENV['username'], extension: ENV['extension'], password: ENV['password'])
# get
r = rc.get('/restapi/v1.0/account/~/extension/~')
expect(r).not_to be_nil
expect('101').to eq(JSON.parse(r.body)['extensionNumber'])
Token Refresh
Access token expires. You need to call rc.refresh() before it expores.
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['receiver']}],
from: {phoneNumber: ENV['username']},
text: 'Hello world'
})
Send fax
rc.post('/restapi/v1.0/account/~/extension/~/fax',
payload: { to: [{ phoneNumber: ENV['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['receiver'] }],
from: { phoneNumber: ENV['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 { ||
callback.call()
})
subscription.subscribe()
return subscription
end
createSubscription(lambda { ||
puts
})
For more sample code, please refer to the test cases.
How to test
Create .env file with the following content:
production=false
server=https://platform.devtest.ringcentral.com
clientId=clientId
clientSecret=clientSecret
username=username
extension=extension
password=password
receiver=number-to-receiver-sms
Run rspec
License
MIT
Todo
- Batch requests