Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscription class not in autoloader #2

Closed
MrOutput opened this issue Jul 16, 2015 · 12 comments
Closed

Subscription class not in autoloader #2

MrOutput opened this issue Jul 16, 2015 · 12 comments

Comments

@MrOutput
Copy link

<?php

require_once('vendor/autoload.php');

// Configuration
define('SANDBOX', 1);
define('BASE_URL', SANDBOX ? 'https://platform.devtest.ringcentral.com' : 'https://platform.ringcentral.com');
define('KEY', 'my_app_key');
define('SECRET', 'my_app_secret');
define('USERNAME', 'my_username'); // Main Phone Number
define('PASSWORD', 'my_password');

$rcsdk = new RC\SDK(KEY, SECRET, BASE_URL);
$rcsdk->getPlatform()->authorize(USERNAME, '', PASSWORD, true);
$rcsdk->getPlatform()->isAuthorized();

function getVoiceMails() {
    if ($rcsdk->getPlatform()->isAuthorized()) {
        try {
            $response = $rcsdk->getPlatform()->get('/account/~/extension/~/message-store?messageType=VoiceMail');
        } catch (RC\http\HttpException $e) {
            print 'Expected HTTP Error: ' . $e->getResponse()->getError() . PHP_EOL;
        }

        return $response->getJson();
    }
}

$rcsdk->getSubscription()
    ->addEvents(array('/restapi/v1.0/account/~/extension/~/presence'))
    ->on(Subscription::EVENT_NOTIFICATION, function (NotificationEvent $e) {

        print_r($e->getPayload());

    })
    ->register();
PHP Fatal error:  Class 'Subscription' not found in /home/rafael/PhpstormProjects/ringcentral-vm/program.php on line 37

Was this done intentionally?

@kirill-konshin
Copy link
Contributor

You have to add

use RC\subscription\Subscription;

statement or refer to the full name of class: RC\subscription\Subscription.

@MrOutput
Copy link
Author

Should it not be included in the autoloader?

@kirill-konshin
Copy link
Contributor

Autoloader only tells php where to locate files, so it's already covered by Autoloader.

In the rest of your code you use full class names and it works, so do the same for subscription. Or have one use statement at the top of your file.

@MrOutput
Copy link
Author

Okay thank you very much. I was confused about autoloading but you cleared it up.

@kirill-konshin
Copy link
Contributor

No problem :)

@MrOutput
Copy link
Author

Receiving this error. I don't want to change protected to public without your advice.

Stack Trace

PHP Fatal error:  Call to protected method RC\subscription\Subscription::notify() from context 'Pubnub\Pubnub' in /home/rafael/PhpstormProjects/ringcentral-vm/vendor/pubnub/pubnub/composer/lib/Pubnub/Pubnub.php on line 468
PHP Stack trace:
PHP   1. {main}() /home/rafael/PhpstormProjects/ringcentral-vm/program.php:0
PHP   2. VMDownloader->startListener() /home/rafael/PhpstormProjects/ringcentral-vm/program.php:62
PHP   3. RC\subscription\Subscription->register($options = *uninitialized*) /home/rafael/PhpstormProjects/ringcentral-vm/program.php:44
PHP   4. RC\subscription\Subscription->subscribe($options = *uninitialized*) /home/rafael/PhpstormProjects/ringcentral-vm/vendor/ringcentral/php-sdk/lib/RC/subscription/Subscription.php:76
PHP   5. RC\subscription\Subscription->subscribeAtPubnub() /home/rafael/PhpstormProjects/ringcentral-vm/vendor/ringcentral/php-sdk/lib/RC/subscription/Subscription.php:119
PHP   6. Pubnub\Pubnub->subscribe($channel = *uninitialized*, $callback = *uninitialized*, $timeToken = *uninitialized*, $presence = *uninitialized*) /home/rafael/PhpstormProjects/ringcentral-vm/vendor/ringcentral/php-sdk/lib/RC/subscription/Subscription.php:241
PHP   7. Pubnub\Pubnub->_subscribe($channel = *uninitialized*, $channelGroup = *uninitialized*, $callback = *uninitialized*, $timeToken = *uninitialized*, $presence = *uninitialized*) /home/rafael/PhpstormProjects/ringcentral-vm/vendor/pubnub/pubnub/composer/lib/Pubnub/Pubnub.php:365

Program.php

<?php

require_once('vendor/autoload.php');

use \RC\SDK;
use \RC\subscription\events\NotificationEvent;
use \RC\subscription\Subscription;

class VMDownloader
{
    // Configuration
    const KEY         = 'my_app_key';
    const SECRET      = 'my_app_secret';
    const SERVER      = 'https://platform.devtest.ringcentral.com';
    const MAIN_NUMBER = 'my_username';
    const PASSWORD    = 'my_password';

    private $sdk;

    function __construct()
    {
        $this->sdk = new SDK(self::KEY, self::SECRET, self::SERVER);
        $this->sdk->getPlatform()->authorize(self::MAIN_NUMBER, '', self::PASSWORD, true);
    }

    public function getVoicemails()
    {
        return $this->sdk->getPlatform()
            ->get('/account/~/extension/~/message-store', ['messageType' => 'VoiceMail'])
            ->getJson();
    }

    /**
     * Listens for new messages
     */
    public function startListener()
    {
        $this->sdk->getSubscription()
            ->addEvents(['/restapi/v1.0/account/~/extension/~/message-store'])
            ->on(Subscription::EVENT_NOTIFICATION, function (NotificationEvent $e) {

                print_r($e->getPayload());

                // TODO: Add curl downloader

            })
            ->register();
    }

    /**
     * @todo finish function definition
     */
    private function download()
    {
    }

    function __destructor()
    {
        print 'Destroyed';
    }
}

$t = new VMDownloader();

$t->startListener();

@kirill-konshin
Copy link
Contributor

What version of PHP do you have?

@MrOutput
Copy link
Author

rafael@rcepeda:~/Downloads/PhpStorm-141.1912/bin$ php -v
PHP 5.6.4-4ubuntu6.2 (cli) (built: Jul  2 2015 15:29:28) 

kirill-konshin added a commit that referenced this issue Jul 17, 2015
@kirill-konshin
Copy link
Contributor

I've pushed a small fix for your case, go ahead and try. The fix is in DEVELOP branch.

@MrOutput
Copy link
Author

Thank you sir.
On Jul 17, 2015 3:28 PM, "Kirill Konshin" notifications@github.com wrote:

I've pushed a small fix for your case, go ahead and try. The fix is in
DEVELOP branch.


Reply to this email directly or view it on GitHub
#2 (comment).

@grokify
Copy link
Contributor

grokify commented Jul 17, 2015

@ralph3991: I replaced the app and user credentials with placeholders in your posts. For security purposes, please don't post your app and user credentials online.

@MrOutput
Copy link
Author

okay, since it was a sandbox, I did not mind it. But I gotcha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants