From 55fa7e3fc9cf8202dddd38f2b32d55f6e8b183f9 Mon Sep 17 00:00:00 2001 From: Gabriel Soldani Date: Sun, 20 Jul 2014 07:20:18 -0300 Subject: [PATCH 1/2] Fixes #36 --- src/snapchat.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/snapchat.php b/src/snapchat.php index fe64534..0d7db93 100755 --- a/src/snapchat.php +++ b/src/snapchat.php @@ -230,18 +230,18 @@ public function register($username, $password, $email, $birthday) { * The data returned by the service or FALSE on failure. */ public function getUpdates($force = FALSE) { - if (!$force) { + // Make sure we're logged in and have a valid access token. + if (!$this->auth_token || !$this->username) { + return FALSE; + } + + if (!$force && isset($this->cache)) { $result = $this->cache->get('updates'); if ($result) { return $result; } } - // Make sure we're logged in and have a valid access token. - if (!$this->auth_token || !$this->username) { - return FALSE; - } - $timestamp = parent::timestamp(); $result = parent::post( '/all_updates', @@ -313,18 +313,18 @@ public function getSnaps() { * An array of stories or FALSE on failure. */ function getFriendStories($force = FALSE) { - if (!$force) { + // Make sure we're logged in and have a valid access token. + if (!$this->auth_token || !$this->username) { + return FALSE; + } + + if (!$force && isset($this->cache)) { $result = $this->cache->get('stories'); if ($result) { return $result; } } - // Make sure we're logged in and have a valid access token. - if (!$this->auth_token || !$this->username) { - return FALSE; - } - $timestamp = parent::timestamp(); $result = parent::post( '/all_updates', From 305a0522669f6b0f138d69913698ace7647be824 Mon Sep 17 00:00:00 2001 From: Gabriel Soldani Date: Sun, 20 Jul 2014 07:27:15 -0300 Subject: [PATCH 2/2] More error checking for Snapchat::$cache --- src/snapchat.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/snapchat.php b/src/snapchat.php index 0d7db93..2fa4751 100755 --- a/src/snapchat.php +++ b/src/snapchat.php @@ -257,7 +257,9 @@ public function getUpdates($force = FALSE) { if (!empty($result->updates_response)) { $this->auth_token = $result->updates_response->auth_token; - $this->cache->set('updates', $result->updates_response); + if (isset($this->cache)) { + $this->cache->set('updates', $result->updates_response); + } return $result->updates_response; } @@ -338,7 +340,7 @@ function getFriendStories($force = FALSE) { ) ); - if (!empty($result->stories_response)) { + if (isset($this->cache) && !empty($result->stories_response)) { $this->cache->set('stories', $result->stories_response); } else {