import time
from rcsdk import RCSDK
from threading import Thread
from time import sleep
from rcsdk.subscription import EVENTS

#Instantiating the SDK
RC_SERVER_PRODUCTION = 'https://platform.ringcentral.com'
RC_SERVER_SANDBOX = 'https://platform.devtest.ringcentral.com'
YOUR_APPKEY = ''
YOUR_APPSECRET = ''
YOUR_PHONENUMBER= ''
YOUR_EXTENSION=''
YOUR_PASSWORD= ''
sdk = RCSDK(YOUR_APPKEY, YOUR_APPSECRET , RC_SERVER_SANDBOX)


#Getting the Platform Singleton
platform = sdk.get_platform()

#Login
platform.authorize(YOUR_PHONENUMBER, YOUR_EXTENSION, YOUR_PASSWORD)

#Determining Authn Status
platform.is_authorized()

#Manual Access Token Refresh
platform.refresh()

#Account and Extension Information
Пример #2
0
def main():
    cache = get_file_cache()

    # Create SDK instance
    sdk = RCSDK(APP_KEY, APP_SECRET, SERVER)
    platform = sdk.get_platform()

    # Set cached authentication data
    # platform.set_auth_data(cache)

    # Check authentication
    try:
        platform.is_authorized()
        print('Authorized already by cached data')
    except Exception as e:
        platform.authorize(USERNAME, EXTENSION, PASSWORD)
        print('Authorized by credentials')

    # Perform refresh by force
    platform.refresh()
    print('Refreshed')

    # Simple GET
    response = platform.get('/account/~/extension/~')
    user = response.get_json(True)
    user_id = str(user.id)
    print('User loaded ' + user.name + ' (' + user_id + ')')
    print('Headers ' + str(response.get_headers()))

    # Multipart response
    try:
        multipart_response = platform.get('/account/~/extension/' + user_id + ',' + user_id + '/presence').get_responses()
        print 'Multipart 1\n' + str(multipart_response[0].get_json())
        print 'Multipart 2\n' + str(multipart_response[1].get_json())
    except HttpException as e:
        print 'Cannot load multipart'
        print 'URL ' + e.get_request().get_url()
        print 'Response' + str(e.get_response().get_json())

    # Pubnub notifications example
    def on_message(msg):
        print(msg)

    def pubnub():
        try:
            s = sdk.get_subscription()
            s.add_events(['/account/~/extension/~/message-store'])
            s.on(EVENTS['notification'], on_message)
            s.register()
            while True:
                sleep(0.1)
        except KeyboardInterrupt:
            print("Pubnub listener stopped...")

    p = Process(target=pubnub)
    try:
        p.start()
    except KeyboardInterrupt:
        p.terminate()
        print("Stopped by User")

    set_file_cache(platform.get_auth_data())
    print("Authentication data has been cached")

    print("Wait for notification...")