PureCloud Ruby Gem

Gem Version


gem install PureCloud


Start be setting the access token in the configuration

PureCloud.configure do |config|
  config.access_token = '7oSpBrJ1w2mIf2kDVNJxR3BLzdxsD3hC7hTdG4A8cR50tpcSuxh74SuL4rk_WNqtwkRt2f004eVgXMCVFo84VQ'
  config.host = 'api.mypurecloud.com'

Specifying the host is optional, it will default to api.mypurecloud.com. This gem contains a number of Api classes e.g. UsersApi, ConfigurationApi. Create an instance of the API you want to use and then you can make calls into the API

user_api = PureCloud::UsersApi.new
me = user_api.users_me_get

Full Example Using Client Credentials Auth

require_relative 'lib/purecloud'

require 'rest_client'
require 'json'
require "base64"

secret = ENV['purecloud_secret']
id = ENV['purecloud_client_id']

PureCloud.authenticate_with_client_credentials id, secret, "mypurecloud.com"

auth_api = PureCloud::AuthorizationApi.new
roles = auth_api.get_roles
puts roles.to_body

Creating an OAuth client

oauth_api = PureCloud::OAuthApi.new
opts = {
    #pass a hash into the constructor, these are the same properties that you can find in the rest documentation, not the properties on the OAuthClient object. 

            :name => 'Demo Client',
            :description => "",
            :authorizedGrantTypes => ["CLIENT-CREDENTIALS"],
            :roleIds =>["02983623-600c-4779-a0ce-17f79e50e285"]

client = oauth_api.create_clients opts

For more examples, see the tests in the /tests directory