From 03705a83c6fd4ff6bea69bd319801ef6a6f19a9d Mon Sep 17 00:00:00 2001 From: Joe Gillotti Date: Thu, 19 Feb 2015 03:52:38 +0000 Subject: [PATCH] Check for login before pulling from cache, resolving fatal errors Currently, if login fails and you try getSnaps() or any of the other get functions, it will call getUpdates() which calls $this->cache->get() before checking for a valid login. As $this->cache is not populated until a valid login, this will cause this sort of error: Fatal error: Call to a member function get() on a non-object in /homepages/15/d419114431/htdocs/bobink/snapchat/src/snapchat.php on line 234 This change modifies the code to perform the login check before pulling from cache, solving the fatal errors. --- src/snapchat.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/snapchat.php b/src/snapchat.php index fe64534..4ec50c3 100755 --- a/src/snapchat.php +++ b/src/snapchat.php @@ -230,6 +230,12 @@ public function register($username, $password, $email, $birthday) { * The data returned by the service or FALSE on failure. */ public function getUpdates($force = FALSE) { + + // Make sure we're logged in and have a valid access token. + if (!$this->auth_token || !$this->username) { + return FALSE; + } + if (!$force) { $result = $this->cache->get('updates'); if ($result) { @@ -237,11 +243,6 @@ public function getUpdates($force = FALSE) { } } - // 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', @@ -312,7 +313,13 @@ public function getSnaps() { * @return mixed * An array of stories or FALSE on failure. */ - function getFriendStories($force = FALSE) { + public function getFriendStories($force = FALSE) { + + // Make sure we're logged in and have a valid access token. + if (!$this->auth_token || !$this->username) { + return FALSE; + } + if (!$force) { $result = $this->cache->get('stories'); if ($result) { @@ -320,11 +327,6 @@ function getFriendStories($force = FALSE) { } } - // 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',