Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Adopt standard PEAR/Zend style PHP coding & naming conventions #1

Open
wants to merge 7 commits into from

2 participants

@ceefour

Make it easier to be integrated with applications and libraries due to familiar coding conventions.

@fasollafsl

I have 2 problem with this code:
1) Take up too much cpu resources 25%
2) Maximum execution time of 30 seconds exceeded in Engine.php on line 538: $html = curl_exec($s);

How can I fix this problem?
Best regards,

@fasollafsl

Note: This is not a support forum.

I think the problem you have is not because of this commit at all. I suspect it's either curl or your Internet connection.

You can report an issue to http://github.com/yahoo/messenger-sdk-php/issues

@fasollafsl

I have 2 problem with this code(http://github.com/ceefour/messenger-sdk-php/):
1) Take up too much cpu resources 25%
2) Maximum execution time of 30 seconds exceeded in Engine.php on line 538: $html = curl_exec($s);

How can I fix this problem?
Best regards,

@ceefour

@fasollafsl ... are you even reading my response ?

Please checkout the original code at http://github.com/yahoo/messenger-sdk-php and see if you still have your problem.

I believe your problem is not caused by my changes to the Yahoo original code because I don't make any changes that could cause your problem. If you experience it, it's more likely that it also happens with the Yahoo code.

@fasollafsl

Thank you for your support.
Regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 67 additions and 39 deletions.
  1. +55 −27 jymengine.class.php → Yahoo/Messenger/Engine.php
  2. +12 −12 client.php
View
82 jymengine.class.php → Yahoo/Messenger/Engine.php
@@ -27,7 +27,7 @@
*
*/
-class JYMEngine
+class Yahoo_Messenger_Engine
{
const URL_OAUTH_DIRECT = 'https://login.yahoo.com/WSLogin/V1/get_auth_token';
const URL_OAUTH_ACCESS_TOKEN = 'https://api.login.yahoo.com/oauth/v2/get_token';
@@ -63,10 +63,10 @@ public function __construct($consumer_key = '', $secret_key = '', $username = ''
$this->_error = null;
}
- public function fetch_request_token()
+ public function fetchRequestToken()
{
//prepare url
- $url = $this::URL_OAUTH_DIRECT;
+ $url = self::URL_OAUTH_DIRECT;
$url .= '?login='. $this->_config['username'];
$url .= '&passwd='. $this->_config['password'];
$url .= '&oauth_consumer_key='. $this->_config['consumer_key'];
@@ -79,10 +79,10 @@ public function fetch_request_token()
return true;
}
- public function fetch_access_token()
+ public function fetchAccessToken()
{
//prepare url
- $url = $this::URL_OAUTH_ACCESS_TOKEN;
+ $url = self::URL_OAUTH_ACCESS_TOKEN;
$url .= '?oauth_consumer_key='. $this->_config['consumer_key'];
$url .= '&oauth_nonce='. uniqid(rand());
$url .= '&oauth_signature='. $this->_config['secret_key']. '%26';
@@ -111,10 +111,10 @@ public function fetch_access_token()
return true;
}
- public function fetch_crumb()
+ public function fetchCrumb()
{
//prepare url
- $url = $this::URL_YM_SESSION;
+ $url = self::URL_YM_SESSION;
$url .= '?oauth_consumer_key='. $this->_config['consumer_key'];
$url .= '&oauth_nonce='. uniqid(rand());
$url .= '&oauth_signature='. $this->_config['secret_key']. '%26'. $this->_token['access']['oauth_token_secret'];
@@ -138,7 +138,7 @@ public function fetch_crumb()
public function signon($status = '', $state = 0)
{
//prepare url
- $url = $this::URL_YM_SESSION;
+ $url = self::URL_YM_SESSION;
$url .= '?oauth_consumer_key='. $this->_config['consumer_key'];
$url .= '&oauth_nonce='. uniqid(rand());
$url .= '&oauth_signature='. $this->_config['secret_key']. '%26'. $this->_token['access']['oauth_token_secret'];
@@ -173,7 +173,7 @@ public function signon($status = '', $state = 0)
public function signoff()
{
//prepare url
- $url = $this::URL_YM_SESSION;
+ $url = self::URL_YM_SESSION;
$url .= '?oauth_consumer_key='. $this->_config['consumer_key'];
$url .= '&oauth_nonce='. uniqid(rand());
$url .= '&oauth_signature='. $this->_config['secret_key']. '%26'. $this->_token['access']['oauth_token_secret'];
@@ -190,10 +190,10 @@ public function signoff()
return true;
}
- public function change_presence($status = '', $state = 0)
+ public function changePresence($status = '', $state = 0)
{
//prepare url
- $url = $this::URL_YM_PRESENCE;
+ $url = self::URL_YM_PRESENCE;
$url .= '?oauth_consumer_key='. $this->_config['consumer_key'];
$url .= '&oauth_nonce='. uniqid(rand());
$url .= '&oauth_signature='. $this->_config['secret_key']. '%26'. $this->_token['access']['oauth_token_secret'];
@@ -211,10 +211,10 @@ public function change_presence($status = '', $state = 0)
return true;
}
- public function send_message($user, $message)
+ public function sendMessage($user, $message)
{
//prepare url
- $url = $this::URL_YM_MESSAGE;
+ $url = self::URL_YM_MESSAGE;
$url .= '?oauth_consumer_key='. $this->_config['consumer_key'];
$url .= '&oauth_nonce='. uniqid(rand());
$url .= '&oauth_signature='. $this->_config['secret_key']. '%26'. $this->_token['access']['oauth_token_secret'];
@@ -234,10 +234,10 @@ public function send_message($user, $message)
return true;
}
- public function fetch_contact_list()
+ public function fetchContactList()
{
//prepare url
- $url = $this::URL_YM_CONTACT;
+ $url = self::URL_YM_CONTACT;
$url .= '?oauth_consumer_key='. $this->_config['consumer_key'];
$url .= '&oauth_nonce='. uniqid(rand());
$url .= '&oauth_signature='. $this->_config['secret_key']. '%26'. $this->_token['access']['oauth_token_secret'];
@@ -260,10 +260,10 @@ public function fetch_contact_list()
return $js['contacts'];
}
- public function add_contact($user, $group = 'Friends', $message = '')
+ public function addContact($user, $group = 'Friends', $message = '')
{
//prepare url
- $url = $this::URL_YM_GROUP;
+ $url = self::URL_YM_GROUP;
$url .= '?oauth_consumer_key='. $this->_config['consumer_key'];
$url .= '&oauth_nonce='. uniqid(rand());
$url .= '&oauth_signature='. $this->_config['secret_key']. '%26'. $this->_token['access']['oauth_token_secret'];
@@ -283,10 +283,10 @@ public function add_contact($user, $group = 'Friends', $message = '')
return true;
}
- public function delete_contact($user, $group = 'Friends')
+ public function deleteContact($user, $group = 'Friends')
{
//prepare url
- $url = $this::URL_YM_GROUP;
+ $url = self::URL_YM_GROUP;
$url .= '?oauth_consumer_key='. $this->_config['consumer_key'];
$url .= '&oauth_nonce='. uniqid(rand());
$url .= '&oauth_signature='. $this->_config['secret_key']. '%26'. $this->_token['access']['oauth_token_secret'];
@@ -305,7 +305,7 @@ public function delete_contact($user, $group = 'Friends')
return true;
}
- public function response_contact($user, $accept = true, $message = '')
+ public function responseContact($user, $accept = true, $message = '')
{
if ($accept)
{
@@ -319,7 +319,7 @@ public function response_contact($user, $accept = true, $message = '')
}
//prepare url
- $url = $this::URL_YM_BUDDYREQUEST;
+ $url = self::URL_YM_BUDDYREQUEST;
$url .= '?oauth_consumer_key='. $this->_config['consumer_key'];
$url .= '&oauth_nonce='. uniqid(rand());
$url .= '&oauth_signature='. $this->_config['secret_key']. '%26'. $this->_token['access']['oauth_token_secret'];
@@ -359,10 +359,10 @@ public function response_contact($user, $accept = true, $message = '')
return true;
}
- public function fetch_notification($seq = 0)
+ public function fetchNotification($seq = 0)
{
//prepare url
- $url = $this::URL_YM_NOTIFICATION;
+ $url = self::URL_YM_NOTIFICATION;
$url .= '?oauth_consumer_key='. $this->_config['consumer_key'];
$url .= '&oauth_nonce='. uniqid(rand());
$url .= '&oauth_signature='. $this->_config['secret_key']. '%26'. $this->_token['access']['oauth_token_secret'];
@@ -393,10 +393,10 @@ public function fetch_notification($seq = 0)
return $js['responses'];
}
- public function fetch_long_notification($seq = 0)
+ public function fetchLongNotification($seq = 0)
{
//prepare url
- $url = $this::URL_YM_NOTIFICATION_LONG;
+ $url = self::URL_YM_NOTIFICATION_LONG;
$url .= '?oauth_consumer_key='. $this->_config['consumer_key'];
$url .= '&oauth_nonce='. uniqid(rand());
$url .= '&oauth_signature='. $this->_config['secret_key']. '%26'. $this->_token['access']['oauth_token_secret'];
@@ -460,8 +460,36 @@ public function fetch_long_notification($seq = 0)
return $js['responses'];
}
+ /**
+ * Sets the request token manually.
+ * @param string $requestToken Request token.
+ */
+ public function setRequestToken($requestToken) {
+ if (stripos($requestToken, 'RequestToken') !== false)
+ $requestToken = trim(str_replace('RequestToken=', '', $requestToken));
+ $this->_token['request'] = $requestToken;
+ }
+ public function getAccessToken() {
+ return $this->_token['access'];
+ }
+ /**
+ * Sets the access token manually.
+ * @param string $accessToken Access token.
+ */
+ public function setAccessToken($accessToken) {
+ $this->_token['access'] = $accessToken;
+ }
+
+ public function getState() {
+ return array('token' => $this->_token, 'ym' => $this->_ym);
+ }
+
+ public function setState($state) {
+ $this->_token = $state['token'];
+ $this->_ym = $state['ym'];
+ }
/*
* fetch url using curl
@@ -508,11 +536,11 @@ private function curl($url, $method = 'get', $header = null, $postdata = null, $
$status = curl_getinfo($s, CURLINFO_HTTP_CODE);
curl_close($s);
-
+
return $html;
}
- public function get_error()
+ public function getError()
{
return $this->_error;
}
View
24 client.php
@@ -31,16 +31,16 @@
define('CONSUMER_KEY', '');
define('SECRET_KEY', '');
-include_once 'jymengine.class.php';
+require_once 'Yahoo/Messenger/Engine.php';
-$engine = new JYMEngine(CONSUMER_KEY, SECRET_KEY, USERNAME, PASSWORD);
+$engine = new Yahoo_Messenger_Engine(CONSUMER_KEY, SECRET_KEY, USERNAME, PASSWORD);
$engine->debug = false;
if ($engine->debug) echo '> Fetching request token'. PHP_EOL;
-if (!$engine->fetch_request_token()) die('Fetching request token failed');
+if (!$engine->fetchRequestToken()) die('Fetching request token failed');
if ($engine->debug) echo '> Fetching access token'. PHP_EOL;
-if (!$engine->fetch_access_token()) die('Fetching access token failed');
+if (!$engine->fetchAccessToken()) die('Fetching access token failed');
if ($engine->debug) echo '> Signon as: '. USERNAME. PHP_EOL;
if (!$engine->signon('I am login from PHP code')) die('Signon failed');
@@ -48,15 +48,15 @@
$seq = -1;
while (true)
{
- $resp = $engine->fetch_long_notification($seq+1);
+ $resp = $engine->fetchLongNotification($seq+1);
if (isset($resp))
{
if ($resp === false)
{
- if ($engine->get_error() != -10)
+ if ($engine->getError() != -10)
{
if ($engine->debug) echo '> Fetching access token'. PHP_EOL;
- if (!$engine->fetch_access_token()) die('Fetching access token failed');
+ if (!$engine->fetchAccessToken()) die('Fetching access token failed');
if ($engine->debug) echo '> Signon as: '. USERNAME. PHP_EOL;
if (!$engine->signon(date('H:i:s'))) die('Signon failed');
@@ -133,7 +133,7 @@
}
else if ($words[0] == 'status')
{
- $engine->change_presence(str_replace('status ', '', strtolower($val['msg'])));
+ $engine->changePresence(str_replace('status ', '', strtolower($val['msg'])));
$out = 'My status is changed';
}
else
@@ -145,17 +145,17 @@
if ($engine->debug) echo '> Sending reply message '. PHP_EOL;
if ($engine->debug) echo ' '. $out. PHP_EOL;
if ($engine->debug) echo '----------'. PHP_EOL;
- $engine->send_message($val['sender'], json_encode($out));
+ $engine->sendMessage($val['sender'], json_encode($out));
}
else if ($key == 'buddyAuthorize') //incoming contact request
{
if ($engine->debug) echo PHP_EOL. 'Accept buddy request from: '. $val['sender']. PHP_EOL;
if ($engine->debug) echo '----------'. PHP_EOL;
- if (!$engine->response_contact($val['sender'], true, 'Welcome to my list'))
+ if (!$engine->responseContact($val['sender'], true, 'Welcome to my list'))
{
- $engine->delete_contact($val['sender']);
- $engine->response_contact($val['sender'], true, 'Welcome to my list');
+ $engine->deleteContact($val['sender']);
+ $engine->responseContact($val['sender'], true, 'Welcome to my list');
}
}
}
Something went wrong with that request. Please try again.