def main():
    cache = get_file_cache()

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

    # Set cached authentication data
    platform.auth().set_data(cache)

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

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

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

    # Multipart response
    try:
        multipart_response = platform.get('/account/~/extension/' + user_id + ',' + user_id + '/presence').multipart()
        print 'Multipart 1\n' + str(multipart_response[0].json_dict())
        print 'Multipart 2\n' + str(multipart_response[1].json_dict())
    except ApiException as e:
        print 'Cannot load multipart'
        print 'URL ' + e.api_response().request().url
        print 'Response' + str(e.api_response().json())

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

    def pubnub():
        try:
            s = sdk.create_subscription()
            s.add_events(['/account/~/extension/~/message-store'])
            s.on(Events.notification, on_message)
            s.register()

            while True:
                sleep(0.1)

        except __HOLE__:
            print("Pubnub listener stopped...")

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

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

    print("Wait for notification...")
dataset/ETHPy150Open ringcentral/ringcentral-python/demo.py/main