From 3fc65d85c0f984a65c1a43b3e9325eea960434c3 Mon Sep 17 00:00:00 2001 From: Nicolas Widart Date: Fri, 27 Nov 2015 10:30:08 +0100 Subject: [PATCH 01/85] Adding method to get the me followers --- src/Pinterest/Endpoints/Users.php | 42 ++++++++++++------- tests/Pinterest/Endpoints/UsersTest.php | 10 ++++- .../UsersTest/testGetMeFollowers.json | 20 +++++++++ 3 files changed, 57 insertions(+), 15 deletions(-) create mode 100644 tests/Pinterest/responses/UsersTest/testGetMeFollowers.json diff --git a/src/Pinterest/Endpoints/Users.php b/src/Pinterest/Endpoints/Users.php index 1c06db2..e685844 100644 --- a/src/Pinterest/Endpoints/Users.php +++ b/src/Pinterest/Endpoints/Users.php @@ -1,9 +1,9 @@ - - * + * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ @@ -14,10 +14,10 @@ use DirkGroenen\Pinterest\Models\Collection; class Users extends Endpoint { - + /** * Get the current user - * + * * @access public * @param array $data * @throws Exceptions/PinterestExceptions @@ -31,7 +31,7 @@ public function me( array $data = [] ) /** * Get the provided user - * + * * @access public * @param string $username * @param array $data @@ -46,7 +46,7 @@ public function find( $username, array $data = [] ) /** * Get the authenticated user's pins - * + * * @access public * @param array $data * @throws Exceptions/PinterestExceptions @@ -60,7 +60,7 @@ public function getMePins( array $data = [] ) /** * Search in the user's pins - * + * * @param string $query * @param array $data * @throws Exceptions/PinterestExceptions @@ -70,12 +70,12 @@ public function searchMePins( $query, array $data = [] ) { $data["query"] = $query; $response = $this->request->get( "me/search/pins", $data ); - return new Collection( $this->master, $response, "Pin" ); + return new Collection( $this->master, $response, "Pin" ); } /** * Search in the user's boards - * + * * @param string $query * @param array $data * @throws Exceptions/PinterestExceptions @@ -86,12 +86,12 @@ public function searchMeBoards( $query, array $data = [] ) $data["query"] = $query; $response = $this->request->get( "me/search/boards", $data ); - return new Collection( $this->master, $response, "Board" ); + return new Collection( $this->master, $response, "Board" ); } /** * Get the authenticated user's boards - * + * * @access public * @param array $data * @throws Exceptions/PinterestExceptions @@ -105,7 +105,7 @@ public function getMeBoards( array $data = [] ) /** * Get the authenticated user's likes - * + * * @access public * @param array $data * @throws Exceptions/PinterestExceptions @@ -117,4 +117,18 @@ public function getMeLikes( array $data = [] ) return new Collection( $this->master, $response, "Pin" ); } -} \ No newline at end of file + /** + * Get the authenticated user's followers + * + * @access public + * @param array $data + * @throws \DirkGroenen\Pinterest\Exceptions\PinterestException + * @return Collection + */ + public function getMeFollowers(array $data = []) + { + $response = $this->request->get( "me/followers", $data ); + return new Collection( $this->master, $response, "Pin" ); + } + +} diff --git a/tests/Pinterest/Endpoints/UsersTest.php b/tests/Pinterest/Endpoints/UsersTest.php index 8e5ff53..f8044d3 100644 --- a/tests/Pinterest/Endpoints/UsersTest.php +++ b/tests/Pinterest/Endpoints/UsersTest.php @@ -115,4 +115,12 @@ public function testGetMeLikes() $this->assertInstanceOf( "DirkGroenen\Pinterest\Models\Pin", $response->get(0) ); } -} \ No newline at end of file + public function testGetMeFollowers() + { + $response = $this->pinterest->users->getMeFollowers(); + + $this->assertInstanceOf( "DirkGroenen\Pinterest\Models\Collection", $response ); + $this->assertInstanceOf( "DirkGroenen\Pinterest\Models\Pin", $response->get(0) ); + } + +} diff --git a/tests/Pinterest/responses/UsersTest/testGetMeFollowers.json b/tests/Pinterest/responses/UsersTest/testGetMeFollowers.json new file mode 100644 index 0000000..7743616 --- /dev/null +++ b/tests/Pinterest/responses/UsersTest/testGetMeFollowers.json @@ -0,0 +1,20 @@ +{ + "data": [ + { + "url": "https:\/\/www.pinterest.com\/ben\/", + "first_name": "Ben", + "last_name": "Silbermann", + "id": "123456" + }, + { + "url": "https:\/\/www.pinterest.com\/evan\/", + "first_name": "Evan", + "last_name": "Sharp", + "id": "234567" + } + ], + "page": { + "cursor": "PyEyNXxmMGVmZDA5mOTAw", + "next": "https:\/\/api.pinterest.com\/v1\/me\/followers\/?access_token=&cursor=PyEyNXxmMGVmZDA5YmOTAw" + } +} From ac346743d26aa124dc4e9df913d4c543780425a6 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Sat, 28 Nov 2015 13:38:52 +0100 Subject: [PATCH 02/85] Add correct model and readme info --- README.md | 9 +++++++++ src/Pinterest/Endpoints/Users.php | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 61e3b09..111b4dc 100644 --- a/README.md +++ b/README.md @@ -262,6 +262,15 @@ $pinterest->users->getMeLikes(); Returns: `Collection` +### Get user's followers +`getMeLikes( array $data );` + +```php +$pinterest->users->getMeFollowers(); +``` + +Returns: `Collection` + ## Boards The methods below are available through `$pinterest->boards`. diff --git a/src/Pinterest/Endpoints/Users.php b/src/Pinterest/Endpoints/Users.php index e685844..500956b 100644 --- a/src/Pinterest/Endpoints/Users.php +++ b/src/Pinterest/Endpoints/Users.php @@ -122,13 +122,13 @@ public function getMeLikes( array $data = [] ) * * @access public * @param array $data - * @throws \DirkGroenen\Pinterest\Exceptions\PinterestException + * @throws Exceptions\PinterestException * @return Collection */ public function getMeFollowers(array $data = []) { $response = $this->request->get( "me/followers", $data ); - return new Collection( $this->master, $response, "Pin" ); + return new Collection( $this->master, $response, "User" ); } } From 7bdcf1ada3cb99ba221d51ded0a444d0ed03587d Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Sat, 28 Nov 2015 13:42:47 +0100 Subject: [PATCH 03/85] Fix test fails --- tests/Pinterest/Endpoints/UsersTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Pinterest/Endpoints/UsersTest.php b/tests/Pinterest/Endpoints/UsersTest.php index f8044d3..9b9bcc0 100644 --- a/tests/Pinterest/Endpoints/UsersTest.php +++ b/tests/Pinterest/Endpoints/UsersTest.php @@ -120,7 +120,7 @@ public function testGetMeFollowers() $response = $this->pinterest->users->getMeFollowers(); $this->assertInstanceOf( "DirkGroenen\Pinterest\Models\Collection", $response ); - $this->assertInstanceOf( "DirkGroenen\Pinterest\Models\Pin", $response->get(0) ); + $this->assertInstanceOf( "DirkGroenen\Pinterest\Models\User", $response->get(0) ); } } From 0ad77477b6f1ede358b3334b54e3283bfac8e778 Mon Sep 17 00:00:00 2001 From: Nicolas Widart Date: Thu, 3 Dec 2015 10:03:04 +0100 Subject: [PATCH 04/85] Adding @properties on Pinterest class to enable auto completion in IDEs --- src/Pinterest/Pinterest.php | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/Pinterest/Pinterest.php b/src/Pinterest/Pinterest.php index fe3eb1d..8b9f494 100644 --- a/src/Pinterest/Pinterest.php +++ b/src/Pinterest/Pinterest.php @@ -1,9 +1,9 @@ - - * + * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ @@ -15,33 +15,39 @@ use DirkGroenen\Pinterest\Transport\Request; use DirkGroenen\Pinterest\Exceptions\InvalidEndpointException; +/** + * @property \DirkGroenen\Pinterest\Endpoints\Boards boards + * @property \DirkGroenen\Pinterest\Endpoints\Following following + * @property \DirkGroenen\Pinterest\Endpoints\Pins pins + * @property \DirkGroenen\Pinterest\Endpoints\Users users + */ class Pinterest { - + /** * Reference to authentication class instance - * + * * @var Auth\PinterestOAuth */ public $auth; /** * A reference to the request class which travels - * through the application - * + * through the application + * * @var Transport\Request */ public $request; /** * A array containing the cached endpoints - * + * * @var array */ private $cachedEndpoints = []; /** * Constructor - * + * * @param string $client_id * @param string $client_secret * @param CurlBuilder $curlbuilder @@ -64,28 +70,28 @@ public function __construct($client_id, $client_secret, $curlbuilder = null) * * @access public * @param string $endpoint - * @return mixed + * @return mixed * @throws Exceptions\InvalidEndpointException */ public function __get($endpoint) { $endpoint = strtolower($endpoint); $class = "\\DirkGroenen\\Pinterest\\Endpoints\\" . ucfirst($endpoint); - + // Check if an instance has already been initiated if(!isset($this->cachedEndpoints[$endpoint])){ // Check endpoint existence if(!class_exists($class)) throw new InvalidEndpointException; - // Create a reflection of the called class and initialize it + // Create a reflection of the called class and initialize it // with a reference to the request class $ref = new \ReflectionClass($class); - $obj = $ref->newInstanceArgs([ $this->request, $this ]); + $obj = $ref->newInstanceArgs([ $this->request, $this ]); $this->cachedEndpoints[$endpoint] = $obj; } return $this->cachedEndpoints[$endpoint]; } -} \ No newline at end of file +} From fe6159477d3f907ebc69dd8890cf7deee8412ccf Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Thu, 3 Dec 2015 11:12:02 +0100 Subject: [PATCH 05/85] Update README.md --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 111b4dc..cc80618 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,6 @@ A PHP wrapper for the official [Pinterest API](https://dev.pinterest.com). -**Still a work in progress, but all documented methods are working.** - # Requirements - PHP 5.4 or higher - cURL From acd84d08da7e25b162f2b4b4fd07524be85ad59d Mon Sep 17 00:00:00 2001 From: Chan Shing Fai Date: Fri, 11 Dec 2015 17:29:46 +0800 Subject: [PATCH 06/85] Fix the pagination object of collection is always empty --- src/Pinterest/Models/Collection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Pinterest/Models/Collection.php b/src/Pinterest/Models/Collection.php index 603b633..2357c07 100644 --- a/src/Pinterest/Models/Collection.php +++ b/src/Pinterest/Models/Collection.php @@ -87,7 +87,7 @@ public function __construct( Pinterest $master, $items, $model ){ $this->items = $this->buildCollectionModels($this->items); // Add pagination object - if( isset($this->response->page) ){ + if( isset($this->response->page['next']) ){ $this->pagination = $this->response->page; } else{ From fed77628398d7eab705cc3c4be827c2e4c4abb7e Mon Sep 17 00:00:00 2001 From: Chan Shing Fai Date: Fri, 11 Dec 2015 18:21:08 +0800 Subject: [PATCH 07/85] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 708f646..6e0c1ce 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "dirkgroenen/pinterest-api-php", + "name": "sfai05/pinterest-api-php", "description": "PHP Wrapper for the official Pinterest API", "authors": [ { From 479d46e65b637da58ff448aec4abfffe65167420 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Fri, 11 Dec 2015 11:33:33 +0100 Subject: [PATCH 08/85] disable image upload test --- tests/Pinterest/Endpoints/ImageUploadTest.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tests/Pinterest/Endpoints/ImageUploadTest.php b/tests/Pinterest/Endpoints/ImageUploadTest.php index 8e12125..38d19c6 100644 --- a/tests/Pinterest/Endpoints/ImageUploadTest.php +++ b/tests/Pinterest/Endpoints/ImageUploadTest.php @@ -1,9 +1,9 @@ - * + * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ @@ -17,7 +17,7 @@ class ImageUploadTest extends \PHPUnit_Framework_TestCase{ /** * The Pinterest instance - * + * * @var Pinterest */ private $pinterest; @@ -28,12 +28,17 @@ class ImageUploadTest extends \PHPUnit_Framework_TestCase{ * @return void */ public function setUp() - { + { // Setup Pinterest without the curlbuilder mock (since we wan't to test real interaction) $this->pinterest = new Pinterest(CLIENT_ID, CLIENT_SECRET); $this->pinterest->auth->setOAuthToken(ACCESS_TOKEN); } + /* + * This test is returning a 401 when someone else made a change. For now + * I've disabled it, but somewhere in the future I need to come up with + * a good fix for this. + * public function testCreatePinWithRealFileUpload() { $response = $this->pinterest->pins->create(array( @@ -44,9 +49,10 @@ public function testCreatePinWithRealFileUpload() // Check if we got a pin back $this->assertInstanceOf( "DirkGroenen\Pinterest\Models\Pin", $response ); - + // Delete pin $this->pinterest->pins->delete($response->id); } + */ } \ No newline at end of file From 52b2559ac430e5e51c50f89a79e0a0783d132745 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Fri, 11 Dec 2015 11:36:41 +0100 Subject: [PATCH 09/85] add double check --- src/Pinterest/Models/Collection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Pinterest/Models/Collection.php b/src/Pinterest/Models/Collection.php index 2357c07..c1946db 100644 --- a/src/Pinterest/Models/Collection.php +++ b/src/Pinterest/Models/Collection.php @@ -87,7 +87,7 @@ public function __construct( Pinterest $master, $items, $model ){ $this->items = $this->buildCollectionModels($this->items); // Add pagination object - if( isset($this->response->page['next']) ){ + if( isset($this->response->page) && !empty($this->response->page['next']) ){ $this->pagination = $this->response->page; } else{ From 87ab025fee21093280602d811a71b5177a23adff Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Fri, 11 Dec 2015 11:40:06 +0100 Subject: [PATCH 10/85] Mark test as incomplete --- tests/Pinterest/Endpoints/ImageUploadTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/Pinterest/Endpoints/ImageUploadTest.php b/tests/Pinterest/Endpoints/ImageUploadTest.php index 38d19c6..1a2eaa2 100644 --- a/tests/Pinterest/Endpoints/ImageUploadTest.php +++ b/tests/Pinterest/Endpoints/ImageUploadTest.php @@ -34,13 +34,9 @@ public function setUp() $this->pinterest->auth->setOAuthToken(ACCESS_TOKEN); } - /* - * This test is returning a 401 when someone else made a change. For now - * I've disabled it, but somewhere in the future I need to come up with - * a good fix for this. - * public function testCreatePinWithRealFileUpload() { + /* $response = $this->pinterest->pins->create(array( "note" => "Test pin from API wrapper. phpversion(" . phpversion() . ")", "image" => __DIR__ . '/../testimage.jpg', @@ -52,7 +48,11 @@ public function testCreatePinWithRealFileUpload() // Delete pin $this->pinterest->pins->delete($response->id); + */ + + $this->markTestIncomplete( + "This test has not been implemented yet." + ); } - */ } \ No newline at end of file From 98cb022728664799070d2e10840b56cb4953aeb6 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Mon, 14 Dec 2015 10:38:19 +0100 Subject: [PATCH 11/85] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6e0c1ce..708f646 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "sfai05/pinterest-api-php", + "name": "dirkgroenen/pinterest-api-php", "description": "PHP Wrapper for the official Pinterest API", "authors": [ { From 820d72e98f07d7201763a7b80c5afdd95356b69f Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Mon, 14 Dec 2015 10:41:19 +0100 Subject: [PATCH 12/85] Changed isset to is_array, fixed #13 --- src/Pinterest/Models/Collection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Pinterest/Models/Collection.php b/src/Pinterest/Models/Collection.php index c1946db..4a8b54e 100644 --- a/src/Pinterest/Models/Collection.php +++ b/src/Pinterest/Models/Collection.php @@ -87,7 +87,7 @@ public function __construct( Pinterest $master, $items, $model ){ $this->items = $this->buildCollectionModels($this->items); // Add pagination object - if( isset($this->response->page) && !empty($this->response->page['next']) ){ + if( is_array($this->response->page) && !empty($this->response->page['next']) ){ $this->pagination = $this->response->page; } else{ From 917a6cb635b3231b9eb86b7ee1ef1c8cb513757e Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Mon, 14 Dec 2015 11:05:42 +0100 Subject: [PATCH 13/85] Fixed checking existance of pagination --- src/Pinterest/Models/Collection.php | 2 +- src/Pinterest/Transport/Response.php | 30 +++++++++++++++++-------- tests/Pinterest/Endpoints/UsersTest.php | 2 ++ 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/Pinterest/Models/Collection.php b/src/Pinterest/Models/Collection.php index 4a8b54e..c1946db 100644 --- a/src/Pinterest/Models/Collection.php +++ b/src/Pinterest/Models/Collection.php @@ -87,7 +87,7 @@ public function __construct( Pinterest $master, $items, $model ){ $this->items = $this->buildCollectionModels($this->items); // Add pagination object - if( is_array($this->response->page) && !empty($this->response->page['next']) ){ + if( isset($this->response->page) && !empty($this->response->page['next']) ){ $this->pagination = $this->response->page; } else{ diff --git a/src/Pinterest/Transport/Response.php b/src/Pinterest/Transport/Response.php index a45497d..d2bcd06 100644 --- a/src/Pinterest/Transport/Response.php +++ b/src/Pinterest/Transport/Response.php @@ -1,9 +1,9 @@ - - * + * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ @@ -14,7 +14,7 @@ use DirkGroenen\Pinterest\Exceptions\PinterestException; class Response { - + /** * Contains the raw response * @@ -24,14 +24,14 @@ class Response { /** * Used curl instance - * + * * @var curl */ private $curl; /** * Constructor - * + * * @param array $response * @param CurlBuilder $curl * @param curl $curl @@ -48,7 +48,7 @@ public function __construct( $response, CurlBuilder $curl ) /** * Decode the string to an array - * + * * @access private * @param string $response * @return array @@ -60,7 +60,7 @@ private function decodeString( $response ) /** * Return the requested key data - * + * * @access public * @param string $key * @return array @@ -70,9 +70,21 @@ public function __get($key) return $this->response[$key]; } + /** + * Return if the key is set + * + * @access public + * @param string $key + * @return array + */ + public function __isset($key) + { + return isset($this->response[$key]); + } + /** * Get the response code from the request - * + * * @access public * @return int */ diff --git a/tests/Pinterest/Endpoints/UsersTest.php b/tests/Pinterest/Endpoints/UsersTest.php index 9b9bcc0..c5ff6ed 100644 --- a/tests/Pinterest/Endpoints/UsersTest.php +++ b/tests/Pinterest/Endpoints/UsersTest.php @@ -113,6 +113,7 @@ public function testGetMeLikes() $this->assertInstanceOf( "DirkGroenen\Pinterest\Models\Collection", $response ); $this->assertInstanceOf( "DirkGroenen\Pinterest\Models\Pin", $response->get(0) ); + $this->assertFalse( $response->pagination ); } public function testGetMeFollowers() @@ -121,6 +122,7 @@ public function testGetMeFollowers() $this->assertInstanceOf( "DirkGroenen\Pinterest\Models\Collection", $response ); $this->assertInstanceOf( "DirkGroenen\Pinterest\Models\User", $response->get(0) ); + $this->assertNotFalse( $response->pagination ); } } From b448c0affdea6c0b8734add488d70f81450b2f45 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Fri, 18 Dec 2015 00:42:09 +0100 Subject: [PATCH 14/85] Fix curl follow location error #2 --- src/Pinterest/Transport/Request.php | 53 ++++++++------- src/Pinterest/Transport/Response.php | 30 ++++++--- src/Pinterest/Utils/CurlBuilder.php | 96 ++++++++++++++++++++++++---- 3 files changed, 129 insertions(+), 50 deletions(-) diff --git a/src/Pinterest/Transport/Request.php b/src/Pinterest/Transport/Request.php index ec28002..ff467eb 100644 --- a/src/Pinterest/Transport/Request.php +++ b/src/Pinterest/Transport/Request.php @@ -1,9 +1,9 @@ - - * + * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ @@ -14,7 +14,7 @@ use DirkGroenen\Pinterest\Exceptions\PinterestException; class Request { - + /** * Host to make the calls to * @@ -24,21 +24,21 @@ class Request { /** * Access token - * + * * @var string */ protected $access_token = null; /** * Instance of the CurlBuilder class - * + * * @var CurlBuilder */ private $curlbuilder; /** * Constructor - * + * * @param CurlBuilder $curlbuilder */ public function __construct( CurlBuilder $curlbuilder ) @@ -48,7 +48,7 @@ public function __construct( CurlBuilder $curlbuilder ) /** * Set the access token - * + * * @access public * @param string $token */ @@ -59,9 +59,9 @@ public function setAccessToken( $token ) /** * Make a get request to the given endpoint - * + * * @access public - * @param string $endpoint + * @param string $endpoint * @param array $parameters * @return [type] */ @@ -79,9 +79,9 @@ public function get( $endpoint, array $parameters = array() ) /** * Make a post request to the given endpoint - * + * * @access public - * @param string $endpoint + * @param string $endpoint * @param array $parameters * @return [type] */ @@ -92,9 +92,9 @@ public function post( $path, array $parameters = array() ) /** * Make a delete request to the given endpoint - * + * * @access public - * @param string $endpoint + * @param string $endpoint * @param array $parameters * @return [type] */ @@ -105,9 +105,9 @@ public function delete( $path, array $parameters = array() ) /** * Make an update request to the given endpoint - * + * * @access public - * @param string $endpoint + * @param string $endpoint * @param array $parameters * @return [type] */ @@ -118,17 +118,17 @@ public function update( $path, array $parameters = array() ) /** * Execute the http request - * + * * @access public - * @param string $method - * @param string $apiCall - * @param array $parameters - * @param array $headers + * @param string $method + * @param string $apiCall + * @param array $parameters + * @param array $headers * @return mixed */ public function execute( $method, $apiCall, array $parameters = array(), $headers = array() ) - { - // Check if the access token needs to be added + { + // Check if the access token needs to be added if($this->access_token != null){ $headers = array_merge($headers, array( "Authorization: Bearer " . $this->access_token, @@ -149,8 +149,7 @@ public function execute( $method, $apiCall, array $parameters = array(), $header CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_HEADER => false, - CURLINFO_HEADER_OUT => true, - CURLOPT_FOLLOWLOCATION => true + CURLINFO_HEADER_OUT => true ) ); switch ($method) { @@ -176,7 +175,7 @@ public function execute( $method, $apiCall, array $parameters = array(), $header break; } - + // Execute request and catch response $response_data = $ch->execute(); @@ -195,7 +194,7 @@ public function execute( $method, $apiCall, array $parameters = array(), $header // Close curl resource $ch->close(); - + // Return the response return $response; } diff --git a/src/Pinterest/Transport/Response.php b/src/Pinterest/Transport/Response.php index a45497d..d2bcd06 100644 --- a/src/Pinterest/Transport/Response.php +++ b/src/Pinterest/Transport/Response.php @@ -1,9 +1,9 @@ - - * + * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ @@ -14,7 +14,7 @@ use DirkGroenen\Pinterest\Exceptions\PinterestException; class Response { - + /** * Contains the raw response * @@ -24,14 +24,14 @@ class Response { /** * Used curl instance - * + * * @var curl */ private $curl; /** * Constructor - * + * * @param array $response * @param CurlBuilder $curl * @param curl $curl @@ -48,7 +48,7 @@ public function __construct( $response, CurlBuilder $curl ) /** * Decode the string to an array - * + * * @access private * @param string $response * @return array @@ -60,7 +60,7 @@ private function decodeString( $response ) /** * Return the requested key data - * + * * @access public * @param string $key * @return array @@ -70,9 +70,21 @@ public function __get($key) return $this->response[$key]; } + /** + * Return if the key is set + * + * @access public + * @param string $key + * @return array + */ + public function __isset($key) + { + return isset($this->response[$key]); + } + /** * Get the response code from the request - * + * * @access public * @return int */ diff --git a/src/Pinterest/Utils/CurlBuilder.php b/src/Pinterest/Utils/CurlBuilder.php index dd7687a..6481371 100644 --- a/src/Pinterest/Utils/CurlBuilder.php +++ b/src/Pinterest/Utils/CurlBuilder.php @@ -1,9 +1,9 @@ - - * + * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ @@ -13,7 +13,7 @@ use DirkGroenen\Pinterest\Exceptions\PinterestException; class CurlBuilder { - + /** * Contains the curl instance * @@ -31,7 +31,7 @@ public function __construct() /** * Return a new instance of the CurlBuilder - * + * * @access public * @return CurlBuilder */ @@ -42,7 +42,7 @@ public function create() /** * Sets an option in the curl instance - * + * * @access public * @param string $option * @param string $value @@ -57,7 +57,7 @@ public function setOption( $option, $value ) /** * Sets multiple options at the same time - * + * * @access public * @param array $options * @return $this @@ -71,18 +71,18 @@ public function setOptions( array $options = [] ) /** * Execute the curl request - * + * * @access public * @return mixed */ public function execute() { - return curl_exec($this->curl); + return $this->execFollow(); } /** * Check if the curl request ended up with errors - * + * * @access public * @return boolean */ @@ -93,7 +93,7 @@ public function hasErrors() /** * Get curl errors - * + * * @access public * @return string */ @@ -104,7 +104,7 @@ public function getErrors() /** * Get curl info key - * + * * @access public * @param string $key * @return string @@ -115,8 +115,8 @@ public function getInfo($key) } /** - * Close the curl resource - * + * Close the curl resource + * * @access public * @return void */ @@ -124,4 +124,72 @@ public function close() { curl_close($this->curl); } + + /** + * Function which acts as a replacement for curl's default + * FOLLOW_LOCATION option, since that gives errors when + * combining it with open basedir. + * + * @see http://slopjong.de/2012/03/31/curl-follow-locations-with-safe_mode-enabled-or-open_basedir-set/ + * @access private + * @return mixed + */ + private function execFollow() { + $mr = 5; + + if(ini_get("open_basedir") == "" && ini_get("safe_mode" == "Off")){ + curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, $mr > 0); + curl_setopt($this->curl, CURLOPT_MAXREDIRS, $mr); + } + else{ + $this->setOption(CURLOPT_FOLLOWLOCATION, false); + + if($mr > 0){ + $original_url = $this->getInfo(CURLINFO_EFFECTIVE_URL); + $newurl = $original_url; + + $rch = curl_copy_handle($this->curl); + + curl_setopt($rch, CURLOPT_HEADER, true); + curl_setopt($rch, CURLOPT_NOBODY, true); + curl_setopt($rch, CURLOPT_FORBID_REUSE, false); + + do{ + curl_setopt($rch, CURLOPT_URL, $newurl); + $header = curl_exec($rch); + + if(curl_errno($rch)){ + $code = 0; + } + else{ + $code = curl_getinfo($rch, CURLINFO_HTTP_CODE); + + if ($code == 301 || $code == 302) { + preg_match('/Location:(.*?)\n/i', $header, $matches); + $newurl = trim(array_pop($matches)); + } + else{ + $code = 0; + } + } + } while($code && --$mr); + + curl_close($rch); + + if(!$mr){ + if ($maxredirect === null){ + trigger_error('Too many redirects.', E_USER_WARNING); + } + else{ + $maxredirect = 0; + } + + return false; + } + $this->setOption(CURLOPT_URL, $newurl); + } + } + + return curl_exec($this->curl); + } } \ No newline at end of file From adc88644f0f7436a16205cc14a80c674e9e3bfda Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Fri, 18 Dec 2015 00:55:30 +0100 Subject: [PATCH 15/85] Use oath code by default, fixes #14 #7 #4 --- src/Pinterest/Auth/PinterestOAuth.php | 37 ++++++++++++++------------- src/Pinterest/Transport/Request.php | 2 +- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/Pinterest/Auth/PinterestOAuth.php b/src/Pinterest/Auth/PinterestOAuth.php index 76bcbcc..fe2a611 100644 --- a/src/Pinterest/Auth/PinterestOAuth.php +++ b/src/Pinterest/Auth/PinterestOAuth.php @@ -1,9 +1,9 @@ - - * + * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ @@ -14,32 +14,32 @@ use DirkGroenen\Pinterest\Exceptions\PinterestException; class PinterestOAuth { - + /** * The application ID - * + * * @var string */ private $client_id; /** * The app secret - * + * * @var string */ private $client_secret; /** - * Random string indicating the state + * Random string indicating the state * to prevent spoofing - * + * * @var void */ private $state; /** * A reference to the request instance - * + * * @var Transport\Request */ private $request; @@ -51,7 +51,7 @@ class PinterestOAuth { /** * Construct - * + * * @param string $client_id * @param string $client_secret */ @@ -69,16 +69,16 @@ public function __construct( $client_id, $client_secret, $request ) /** * Returns the login url - * + * * @access public * @param array $scopes * @param string $redirect_uri * @return string */ - public function getLoginUrl( $redirect_uri, $scopes = array("read_public") ) + public function getLoginUrl( $redirect_uri, $scopes = array("read_public"), $response_type = "code" ) { $queryparams = array( - "response_type" => "token", + "response_type" => $response_type, "redirect_uri" => $redirect_uri, "client_id" => $this->client_id, "client_secret" => $this->client_secret, @@ -92,7 +92,7 @@ public function getLoginUrl( $redirect_uri, $scopes = array("read_public") ) /** * Generates a random string and returns is - * + * * @access private * @return string random string */ @@ -103,9 +103,9 @@ private function generateState() /** * Change the code for an access_token - * - * @param string $code - * @return array + * + * @param string $code + * @return array */ public function getOAuthToken( $code ) { @@ -113,6 +113,7 @@ public function getOAuthToken( $code ) $data = array( "grant_type" => "authorization_code", "client_id" => $this->client_id, + "client_secret" => $this->client_secret, "code" => $code ); @@ -124,7 +125,7 @@ public function getOAuthToken( $code ) /** * Set the access_token for further requests - * + * * @access public * @param string $access_token * @return void diff --git a/src/Pinterest/Transport/Request.php b/src/Pinterest/Transport/Request.php index ff467eb..c0d43e2 100644 --- a/src/Pinterest/Transport/Request.php +++ b/src/Pinterest/Transport/Request.php @@ -87,7 +87,7 @@ public function get( $endpoint, array $parameters = array() ) */ public function post( $path, array $parameters = array() ) { - return $this->execute("POST", sprintf("%s%s", $this->host, $path) . "/", $parameters ); + return $this->execute("POST", sprintf("%s%s", $this->host, $path), $parameters ); } /** From 8e7a6b22cc0c7b2636c7bab66d1da714801e045b Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Fri, 18 Dec 2015 01:00:14 +0100 Subject: [PATCH 16/85] changed readme text --- README.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cc80618..9911304 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,15 @@ echo 'Authorize Pinterest'; Check the [Pinterest documentation](https://dev.pinterest.com/docs/api/overview/#scopes) for the available scopes. +After your user has used the login link to authorize he will be send back to the given `CALLBACK_URL`. The URL will contain the `code` which can be exchanged into an `access_token`. To exchange the code for an `access_token` and set it you can use the following code: + +```php +if(isset($_GET["code"])){ + $token = $pinterest->auth->getOAuthToken($_GET["code"]); + $pinterest->auth->setOAuthToken($token->access_token); +} +``` + ## Get the user's profile To get the profile of the current logged in user you can use the `Users::me();` method. @@ -167,7 +176,7 @@ Returns: `Boolean` The methods below are available through `$pinterest->auth`. ### Get login URL -`getLoginUrl(string $redirect_uri, array $scopes);` +`getLoginUrl(string $redirect_uri, array $scopes, string $response_type = "code");` ```php $pinterest->auth->getLoginUrl("https://pinterest.dev/callback.php", array("read_public")); @@ -175,7 +184,7 @@ $pinterest->auth->getLoginUrl("https://pinterest.dev/callback.php", array("read_ Check the [Pinterest documentation](https://dev.pinterest.com/docs/api/overview/#scopes) for the available scopes. -> At this moment the Pinterest API returns the user's `access_token` in the query string on the callback page. The documentation states that this should be a code, so the next method has been writing assuming this will be changed somewhere in the future +**Note: since 0.2.0 the default authentication method has changed to `code` instead of `token`. This means you have to exchange the returned code for an access_token.** ### Get access_token `getOAuthToken(string $code );` From 81848d994f65d54a259727bed883dd539dd65799 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Fri, 18 Dec 2015 01:02:11 +0100 Subject: [PATCH 17/85] Add readme --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..ceb200e --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +### 0.2.0 (18-12-2015) + +- Changed default authentication response_type to `code` ( #4 / #7 / #14 ) +- Fixed `getAccessToken()` path +- Added fallback for servers using open_basedir ( #9 ) \ No newline at end of file From 89a5df6e81f2a6dade6c655e71812c15c4d6eb0d Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Mon, 21 Dec 2015 00:26:46 +0100 Subject: [PATCH 18/85] Add link to packagist --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9911304..6ea5776 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![](http://i.imgur.com/cacgQlq.png) Pinterest API - PHP [![](https://travis-ci.org/dirkgroenen/Pinterest-API-PHP.svg)](https://travis-ci.org/dirkgroenen/Pinterest-API-PHP) ![](https://img.shields.io/packagist/v/dirkgroenen/pinterest-api-php.svg) +![](http://i.imgur.com/cacgQlq.png) Pinterest API - PHP [![](https://travis-ci.org/dirkgroenen/Pinterest-API-PHP.svg)](https://travis-ci.org/dirkgroenen/Pinterest-API-PHP) ![https://packagist.org/packages/dirkgroenen/pinterest-api-php](https://img.shields.io/packagist/v/dirkgroenen/pinterest-api-php.svg) ------------------- A PHP wrapper for the official [Pinterest API](https://dev.pinterest.com). From 9dbbd1a55b7911669735b10e8e11e3506a2fba00 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Mon, 21 Dec 2015 00:34:35 +0100 Subject: [PATCH 19/85] Changd badges --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6ea5776..96d0203 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![](http://i.imgur.com/cacgQlq.png) Pinterest API - PHP [![](https://travis-ci.org/dirkgroenen/Pinterest-API-PHP.svg)](https://travis-ci.org/dirkgroenen/Pinterest-API-PHP) ![https://packagist.org/packages/dirkgroenen/pinterest-api-php](https://img.shields.io/packagist/v/dirkgroenen/pinterest-api-php.svg) +![](http://i.imgur.com/cacgQlq.png) Pinterest API - PHP [![](https://travis-ci.org/dirkgroenen/Pinterest-API-PHP.svg)](https://travis-ci.org/dirkgroenen/Pinterest-API-PHP) [![Packagist](https://img.shields.io/packagist/v/dirkgroenen/pinterest-api-php.svg)](https://packagist.org/packages/dirkgroenen/pinterest-api-php) [![Support me with some coffee](https://img.shields.io/badge/donate-paypal-orange.svg)](https://www.paypal.me/dirkgroenen) ------------------- A PHP wrapper for the official [Pinterest API](https://dev.pinterest.com). @@ -483,4 +483,4 @@ Returns: `True|PinterestException` # Examples -Please check [https://bitlabs.nl/pinterest](https://bitlabs.nl/pinterest) for an example project. +There are no examples available yet. Let me know if you have an (example) project using the this library. \ No newline at end of file From 7c071a8d56a88694f070b8f11a999f762c9a2e15 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Wed, 23 Dec 2015 21:18:07 +0100 Subject: [PATCH 20/85] add support for setting and retrieving the state, #15 --- src/Pinterest/Auth/PinterestOAuth.php | 21 ++++++++ tests/Pinterest/Endpoints/AuthTest.php | 59 +++++++++++++++++++++++ tests/Pinterest/PinterestTest.php | 45 ----------------- tests/Pinterest/Utils/CurlBuilderMock.php | 23 +++++---- 4 files changed, 94 insertions(+), 54 deletions(-) create mode 100644 tests/Pinterest/Endpoints/AuthTest.php delete mode 100644 tests/Pinterest/PinterestTest.php diff --git a/src/Pinterest/Auth/PinterestOAuth.php b/src/Pinterest/Auth/PinterestOAuth.php index fe2a611..7caa7b6 100644 --- a/src/Pinterest/Auth/PinterestOAuth.php +++ b/src/Pinterest/Auth/PinterestOAuth.php @@ -101,6 +101,27 @@ private function generateState() return substr( md5( rand() ), 0, 7 ); } + /** + * Get the generated state + * + * @return string + */ + public function getState() + { + return $this->state; + } + + /** + * Set a state manually + * + * @param string state + * @return void + */ + public function setState($state) + { + $this->state = $state; + } + /** * Change the code for an access_token * diff --git a/tests/Pinterest/Endpoints/AuthTest.php b/tests/Pinterest/Endpoints/AuthTest.php new file mode 100644 index 0000000..3abbb3b --- /dev/null +++ b/tests/Pinterest/Endpoints/AuthTest.php @@ -0,0 +1,59 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace DirkGroenen\Pinterest\Tests\Endpoints; + +use \DirkGroenen\Pinterest\Pinterest; +use \DirkGroenen\Pinterest\Tests\Utils\CurlBuilderMock; + +class AuthTest extends \PHPUnit_Framework_TestCase{ + + /** + * The Pinterest instance + * + * @var Pinterest + */ + private $pinterest; + + /** + * Setup a new instance of the Pinterest class + * + * @return void + */ + public function setUp() + { + $curlbuilder = CurlBuilderMock::create( $this ); + + // Setup Pinterest + $this->pinterest = new Pinterest("0", "0", $curlbuilder); + $this->pinterest->auth->setOAuthToken( "0" ); + } + + /** + * @skipmock true + */ + public function testRandomStateIsSet() + { + $state = $this->pinterest->auth->getState(); + + $this->assertNotEmpty( $state ); + } + + /** + * @skipmock true + */ + public function testSetState() + { + $state = substr( md5( rand() ), 0, 7 ); + $this->pinterest->auth->setState($state); + + $this->assertEquals( $this->pinterest->auth->getState(), $state ); + } +} diff --git a/tests/Pinterest/PinterestTest.php b/tests/Pinterest/PinterestTest.php deleted file mode 100644 index 1f2467b..0000000 --- a/tests/Pinterest/PinterestTest.php +++ /dev/null @@ -1,45 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace DirkGroenen\Pinterest\Tests; - -use DirkGroenen\Pinterest\Pinterest; - -class PinterestTest extends \PHPUnit_Framework_TestCase{ - - /** - * Instance of Pinterest class - * - * @var Pinterest - */ - protected $pinterest; - - /** - * Setup a new instance of the Pinterest class - * - * @return void - */ - protected function setUp() - { - $this->pinterest = new Pinterest( CLIENT_ID, CLIENT_SECRET ); - } - - public function testAuthInstance() - { - //$this->assertInstanceOf( 'DirkGroenen\Pinterest\Auth\PinterestOAuth', $this->pinterest->auth ); - } - - public function testLoginUrlCreator() - { - //$this->assertTrue( is_string( $this->pinterest->auth->getLoginUrl( CALLBACK_URL ) ) ); - //$this->assertContains( urlencode( CALLBACK_URL ), $this->pinterest->auth->getLoginUrl( CALLBACK_URL ) ); - } - -} \ No newline at end of file diff --git a/tests/Pinterest/Utils/CurlBuilderMock.php b/tests/Pinterest/Utils/CurlBuilderMock.php index 160d101..d0540c3 100644 --- a/tests/Pinterest/Utils/CurlBuilderMock.php +++ b/tests/Pinterest/Utils/CurlBuilderMock.php @@ -1,9 +1,9 @@ - * + * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ @@ -13,21 +13,26 @@ class CurlBuilderMock { /** - * Create a new mock of the curlbuilder and return + * Create a new mock of the curlbuilder and return * the given filename as content - * + * * @access public * @param PHPUnit_Framework_TestCase $instance * @return mock */ public static function create( $instance ) - { + { $reflection = new \ReflectionMethod( $instance, $instance->getName() ); $doc_block = $reflection->getDocComment(); $responsefile = self::parseDocBlock( $doc_block, '@responsefile' ); $responsecode = self::parseDocBlock( $doc_block, '@responsecode' ); + $skipmock = self::parseDocBlock( $doc_block, '@skipmock' ); + + if(isset($skipmock[0])) + return false; + if(empty($responsecode)) $responsecode = [201]; @@ -56,11 +61,11 @@ public static function create( $instance ) /** * Parse the methods docblock and search for the * requested tag's value - * + * * @access private - * @param string $doc_block - * @param string $tag - * @return array + * @param string $doc_block + * @param string $tag + * @return array */ private static function parseDocBlock( $doc_block, $tag ) { From 802f616d9dd047e43f3cf2bb6b98019bd5189361 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Wed, 23 Dec 2015 21:21:19 +0100 Subject: [PATCH 21/85] Add proper doc --- README.md | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 96d0203..da85a0d 100644 --- a/README.md +++ b/README.md @@ -187,19 +187,36 @@ Check the [Pinterest documentation](https://dev.pinterest.com/docs/api/overview/ **Note: since 0.2.0 the default authentication method has changed to `code` instead of `token`. This means you have to exchange the returned code for an access_token.** ### Get access_token -`getOAuthToken(string $code );` +`getOAuthToken( string $code );` ```php $pinterest->auth->getOAuthToken($code); ``` ### Set access_token -`setOAuthToken(string $access_token );` +`setOAuthToken( string $access_token );` ```php $pinterest->auth->setOAuthToken($access_token); ``` +### Get state +`getState();` + +```php +$pinterest->auth->getState(); +``` + +### Set state +`setState( string $state );` + +This method can be used to set a state manually, but this isn't required since the API will automatically generate a random state on initialize. + +```php +$pinterest->auth->setState($state); +``` + + ## Users The methods below are available through `$pinterest->users`. From 74f03306ca9a0a9264e4a872a4c92cebe6d4b387 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Wed, 23 Dec 2015 21:22:49 +0100 Subject: [PATCH 22/85] Add changes --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ceb200e..779a09a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### 0.2.1 (23-12-2015) + +- Add `setState` and `getState` methods ( [#15](https://github.com/dirkgroenen/Pinterest-API-PHP/issues/15) ) + ### 0.2.0 (18-12-2015) - Changed default authentication response_type to `code` ( #4 / #7 / #14 ) From 5f7610360e3f9e2764f4cb5517a8d9e1d915104e Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Wed, 23 Dec 2015 21:23:55 +0100 Subject: [PATCH 23/85] Add return value --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index da85a0d..ce640fd 100644 --- a/README.md +++ b/README.md @@ -207,6 +207,8 @@ $pinterest->auth->setOAuthToken($access_token); $pinterest->auth->getState(); ``` +Returns: `string` + ### Set state `setState( string $state );` From e6461e844158d2fd9554156f15c3a57120ba5dc5 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Thu, 31 Dec 2015 11:34:52 +0100 Subject: [PATCH 24/85] add error numbers, #17 --- src/Pinterest/Transport/Request.php | 4 ++-- src/Pinterest/Utils/CurlBuilder.php | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Pinterest/Transport/Request.php b/src/Pinterest/Transport/Request.php index c0d43e2..a0621d1 100644 --- a/src/Pinterest/Transport/Request.php +++ b/src/Pinterest/Transport/Request.php @@ -181,7 +181,7 @@ public function execute( $method, $apiCall, array $parameters = array(), $header // Check if we have a valid response if ( !$response_data || $ch->hasErrors() ) { - throw new PinterestException( 'Error: execute() - cURL error: ' . $ch->getErrors() ); + throw new PinterestException( 'Error: execute() - cURL error: ' . $ch->getErrors(), $ch->getErrorNumber() ); } // Initiate the response @@ -189,7 +189,7 @@ public function execute( $method, $apiCall, array $parameters = array(), $header // Check the response code if ( $response->getResponseCode() >= 400 ) { - throw new PinterestException( 'Pinterest error (code: ' . $response->getResponseCode() . ') with message: ' . $response->message ); + throw new PinterestException( 'Pinterest error (code: ' . $response->getResponseCode() . ') with message: ' . $response->message, $response->getResponseCode() ); } // Close curl resource diff --git a/src/Pinterest/Utils/CurlBuilder.php b/src/Pinterest/Utils/CurlBuilder.php index 6481371..43b9418 100644 --- a/src/Pinterest/Utils/CurlBuilder.php +++ b/src/Pinterest/Utils/CurlBuilder.php @@ -102,6 +102,18 @@ public function getErrors() return curl_error($this->curl); } + /** + * Get last curl error number + * + * @access public + * @return int + */ + public function getErrorNumber() + { + return curl_errno($this->curl); + } + + /** * Get curl info key * From 302127ac31cd2351fcd3717f44b0207c31b1c804 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Thu, 31 Dec 2015 11:36:21 +0100 Subject: [PATCH 25/85] Changelog updated --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 779a09a..f049f55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### 0.2.2 (31-12-2015) + +- Add error codes to PinterestException ( [#17](https://github.com/dirkgroenen/Pinterest-API-PHP/issues/17) ) + ### 0.2.1 (23-12-2015) - Add `setState` and `getState` methods ( [#15](https://github.com/dirkgroenen/Pinterest-API-PHP/issues/15) ) From 519e22bfcf91b8cbc2cba0cb913a9ac09571c5bb Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Sun, 3 Jan 2016 15:14:43 +0100 Subject: [PATCH 26/85] Remove whoops as dep --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index 708f646..ddef230 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,6 @@ "pinterest" ], "require": { - "filp/whoops": "^1.1", "php": ">=5.4" }, "require-dev": { From 86b1556ed65d65338211d2dd76de5dcbb669fc30 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Sun, 3 Jan 2016 15:17:10 +0100 Subject: [PATCH 27/85] add changes to changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f049f55..4018771 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +### 0.2.3 (03-01-2016) + +- Add error codes to PinterestException ( [#17](https://github.com/dirkgroenen/Pinterest-API-PHP/issues/17) ) +- Remove `whoops` as dependency + ### 0.2.2 (31-12-2015) - Add error codes to PinterestException ( [#17](https://github.com/dirkgroenen/Pinterest-API-PHP/issues/17) ) From 1cd96c666f339b8d6d05fea5e6f277d88d6847a6 Mon Sep 17 00:00:00 2001 From: Ziga Berce Date: Wed, 6 Jan 2016 00:53:38 +0100 Subject: [PATCH 28/85] Get rate limit and remaining from headers Optimize curl to make only one request to API --- src/Pinterest/Pinterest.php | 24 ++++++++++++ src/Pinterest/Transport/Request.php | 21 +++++++++++ src/Pinterest/Utils/CurlBuilder.php | 58 ++++++++++++++++++++++++++--- 3 files changed, 98 insertions(+), 5 deletions(-) diff --git a/src/Pinterest/Pinterest.php b/src/Pinterest/Pinterest.php index 8b9f494..811f726 100644 --- a/src/Pinterest/Pinterest.php +++ b/src/Pinterest/Pinterest.php @@ -94,4 +94,28 @@ public function __get($endpoint) return $this->cachedEndpoints[$endpoint]; } + + + + /** + * Get rate limit from the headers + * + * @return integer + */ + public function getLimit() + { + $header = $this->request->getHeaders(); + return (isset($header['X-Ratelimit-Limit']) ? $header['X-Ratelimit-Limit'] : 200); //docs say 1000 but praktice shows 200/h + } + + /** + * Get rate limit remaining from the headers + * + * @return integer + */ + public function getRemaining() + { + $header = $this->request->getHeaders(); + return (isset($header['X-Ratelimit-Remaining']) ? $header['X-Ratelimit-Remaining'] : 'unknown'); + } } diff --git a/src/Pinterest/Transport/Request.php b/src/Pinterest/Transport/Request.php index a0621d1..97c99a6 100644 --- a/src/Pinterest/Transport/Request.php +++ b/src/Pinterest/Transport/Request.php @@ -35,6 +35,14 @@ class Request { * @var CurlBuilder */ private $curlbuilder; + + /** + * Instance of the CurlBuilder class + * + * @var CurlBuilder + */ + private $headers; + /** * Constructor @@ -115,6 +123,18 @@ public function update( $path, array $parameters = array() ) { return $this->execute("PATCH", sprintf("%s%s", $this->host, $path) . "/", $parameters ); } + + /** + * Create a new model instance + * + * @param Transport\Request $request + * @param Pinterest $master + * @return void + */ + public function getHeaders() + { + return $this->headers; + } /** * Execute the http request @@ -191,6 +211,7 @@ public function execute( $method, $apiCall, array $parameters = array(), $header if ( $response->getResponseCode() >= 400 ) { throw new PinterestException( 'Pinterest error (code: ' . $response->getResponseCode() . ') with message: ' . $response->message, $response->getResponseCode() ); } + $this->headers = $ch->getHeaders(); // Close curl resource $ch->close(); diff --git a/src/Pinterest/Utils/CurlBuilder.php b/src/Pinterest/Utils/CurlBuilder.php index 43b9418..1b967bb 100644 --- a/src/Pinterest/Utils/CurlBuilder.php +++ b/src/Pinterest/Utils/CurlBuilder.php @@ -20,6 +20,7 @@ class CurlBuilder { * @var resource */ private $curl; + private $headers; /** * Constructor @@ -126,6 +127,17 @@ public function getInfo($key) return curl_getinfo($this->curl, $key); } + /** + * Get headers + * + * @access public + * @return string + */ + public function getHeaders() + { + return $this->headers; + } + /** * Close the curl resource * @@ -136,6 +148,24 @@ public function close() { curl_close($this->curl); } + + /** + * Parse string headers into array + * + * @access private + * @param array $headers + * @return array + */ + private function parseHeaders($headers) { + $result = array(); + foreach(explode("\n",$headers) as $row) + { + $header = explode(':', $row,2); + if (count($header) == 2) $result[$header[0]] = $header[1]; + else $result[] = $header[0]; + } + return $result; + } /** * Function which acts as a replacement for curl's default @@ -148,7 +178,8 @@ public function close() */ private function execFollow() { $mr = 5; - + $body = null; + if(ini_get("open_basedir") == "" && ini_get("safe_mode" == "Off")){ curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, $mr > 0); curl_setopt($this->curl, CURLOPT_MAXREDIRS, $mr); @@ -163,13 +194,17 @@ private function execFollow() { $rch = curl_copy_handle($this->curl); curl_setopt($rch, CURLOPT_HEADER, true); - curl_setopt($rch, CURLOPT_NOBODY, true); + //curl_setopt($rch, CURLOPT_NOBODY, true); curl_setopt($rch, CURLOPT_FORBID_REUSE, false); do{ curl_setopt($rch, CURLOPT_URL, $newurl); - $header = curl_exec($rch); - + $response = curl_exec($rch); + + $header_size = curl_getinfo($rch, CURLINFO_HEADER_SIZE); + $header = substr($response, 0, $header_size); + $body = substr($response, $header_size); + if(curl_errno($rch)){ $code = 0; } @@ -199,9 +234,22 @@ private function execFollow() { return false; } $this->setOption(CURLOPT_URL, $newurl); + + $this->headers = $this->parseHeaders($header); + } } - return curl_exec($this->curl); + if (!$body){ + curl_setopt($this->curl, CURLOPT_HEADER, true); + $response = curl_exec($this->curl); + + $header_size = curl_getinfo($rch, CURLINFO_HEADER_SIZE); + $header = substr($response, 0, $header_size); + $body = substr($response, $header_size); + + $this->headers = $this->parseHeaders($header); + } + return $body; } } \ No newline at end of file From 96588f224b9b94824518cdeabbde3637c2eb9f42 Mon Sep 17 00:00:00 2001 From: Ziga Berce Date: Wed, 6 Jan 2016 00:53:48 +0100 Subject: [PATCH 29/85] Returns empty array on no response --- src/Pinterest/Transport/Response.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Pinterest/Transport/Response.php b/src/Pinterest/Transport/Response.php index d2bcd06..9296a39 100644 --- a/src/Pinterest/Transport/Response.php +++ b/src/Pinterest/Transport/Response.php @@ -67,7 +67,7 @@ private function decodeString( $response ) */ public function __get($key) { - return $this->response[$key]; + return isset($this->response[$key]) ? $this->response[$key] : []; } /** From f0e2e72e3667a0975f13b50ec32bc87a50bdce16 Mon Sep 17 00:00:00 2001 From: Ziga Berce Date: Wed, 6 Jan 2016 08:23:30 +0100 Subject: [PATCH 30/85] Trim header value --- src/Pinterest/Utils/CurlBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Pinterest/Utils/CurlBuilder.php b/src/Pinterest/Utils/CurlBuilder.php index 1b967bb..6614b1f 100644 --- a/src/Pinterest/Utils/CurlBuilder.php +++ b/src/Pinterest/Utils/CurlBuilder.php @@ -161,7 +161,7 @@ private function parseHeaders($headers) { foreach(explode("\n",$headers) as $row) { $header = explode(':', $row,2); - if (count($header) == 2) $result[$header[0]] = $header[1]; + if (count($header) == 2) $result[$header[0]] = trim($header[1]); else $result[] = $header[0]; } return $result; From 19dc22cd80e849a2768cf71811a86a6c8110fe9e Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Wed, 6 Jan 2016 21:59:36 +0100 Subject: [PATCH 31/85] Some updates to new code and tests --- README.md | 23 +++++++++++ src/Pinterest/Pinterest.php | 16 ++++---- src/Pinterest/Utils/CurlBuilder.php | 40 ++++++++++-------- tests/Pinterest/Endpoints/AuthTest.php | 6 --- tests/Pinterest/PinterestTest.php | 50 +++++++++++++++++++++++ tests/Pinterest/Utils/CurlBuilderMock.php | 22 ++++++---- 6 files changed, 119 insertions(+), 38 deletions(-) create mode 100644 tests/Pinterest/PinterestTest.php diff --git a/README.md b/README.md index ce640fd..315dc69 100644 --- a/README.md +++ b/README.md @@ -218,6 +218,29 @@ This method can be used to set a state manually, but this isn't required since t $pinterest->auth->setState($state); ``` +## Rate limit + +### Get limit +`getRateLimit();` + +This method can be used to get the maximum number of requests. + +```php +$pinterest->getRateLimit(); +``` + +Returns: `int` + +### Get remaining +`getRateLimitRemaining();` + +This method can be used to get the remaining number of calls. + +```php +$pinterest->getRateLimitRemaining(); +``` + +Returns: `int` ## Users diff --git a/src/Pinterest/Pinterest.php b/src/Pinterest/Pinterest.php index 811f726..ffe0a9b 100644 --- a/src/Pinterest/Pinterest.php +++ b/src/Pinterest/Pinterest.php @@ -94,28 +94,28 @@ public function __get($endpoint) return $this->cachedEndpoints[$endpoint]; } - - - + /** * Get rate limit from the headers * + * @access public * @return integer */ - public function getLimit() + public function getRateLimit() { $header = $this->request->getHeaders(); - return (isset($header['X-Ratelimit-Limit']) ? $header['X-Ratelimit-Limit'] : 200); //docs say 1000 but praktice shows 200/h + return (isset($header['X-Ratelimit-Limit']) ? $header['X-Ratelimit-Limit'] : 1000); } /** * Get rate limit remaining from the headers * - * @return integer + * @access public + * @return mixed */ - public function getRemaining() + public function getRateLimitRemaining() { $header = $this->request->getHeaders(); return (isset($header['X-Ratelimit-Remaining']) ? $header['X-Ratelimit-Remaining'] : 'unknown'); - } + } } diff --git a/src/Pinterest/Utils/CurlBuilder.php b/src/Pinterest/Utils/CurlBuilder.php index 6614b1f..7b9b1e2 100644 --- a/src/Pinterest/Utils/CurlBuilder.php +++ b/src/Pinterest/Utils/CurlBuilder.php @@ -20,6 +20,12 @@ class CurlBuilder { * @var resource */ private $curl; + + /** + * Array containing headers from last performed request + * + * @var array + */ private $headers; /** @@ -114,7 +120,6 @@ public function getErrorNumber() return curl_errno($this->curl); } - /** * Get curl info key * @@ -136,8 +141,8 @@ public function getInfo($key) public function getHeaders() { return $this->headers; - } - + } + /** * Close the curl resource * @@ -148,21 +153,22 @@ public function close() { curl_close($this->curl); } - + /** * Parse string headers into array - * + * * @access private * @param array $headers * @return array */ private function parseHeaders($headers) { $result = array(); - foreach(explode("\n",$headers) as $row) - { - $header = explode(':', $row,2); - if (count($header) == 2) $result[$header[0]] = trim($header[1]); - else $result[] = $header[0]; + foreach(explode("\n", $headers) as $row){ + $header = explode(':', $row, 2); + if (count($header) == 2) + $result[$header[0]] = trim($header[1]); + else + $result[] = $header[0]; } return $result; } @@ -179,7 +185,7 @@ private function parseHeaders($headers) { private function execFollow() { $mr = 5; $body = null; - + if(ini_get("open_basedir") == "" && ini_get("safe_mode" == "Off")){ curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, $mr > 0); curl_setopt($this->curl, CURLOPT_MAXREDIRS, $mr); @@ -200,11 +206,11 @@ private function execFollow() { do{ curl_setopt($rch, CURLOPT_URL, $newurl); $response = curl_exec($rch); - + $header_size = curl_getinfo($rch, CURLINFO_HEADER_SIZE); $header = substr($response, 0, $header_size); $body = substr($response, $header_size); - + if(curl_errno($rch)){ $code = 0; } @@ -234,22 +240,22 @@ private function execFollow() { return false; } $this->setOption(CURLOPT_URL, $newurl); - + $this->headers = $this->parseHeaders($header); - } } if (!$body){ curl_setopt($this->curl, CURLOPT_HEADER, true); $response = curl_exec($this->curl); - + $header_size = curl_getinfo($rch, CURLINFO_HEADER_SIZE); $header = substr($response, 0, $header_size); $body = substr($response, $header_size); - + $this->headers = $this->parseHeaders($header); } + return $body; } } \ No newline at end of file diff --git a/tests/Pinterest/Endpoints/AuthTest.php b/tests/Pinterest/Endpoints/AuthTest.php index 3abbb3b..d263974 100644 --- a/tests/Pinterest/Endpoints/AuthTest.php +++ b/tests/Pinterest/Endpoints/AuthTest.php @@ -36,9 +36,6 @@ public function setUp() $this->pinterest->auth->setOAuthToken( "0" ); } - /** - * @skipmock true - */ public function testRandomStateIsSet() { $state = $this->pinterest->auth->getState(); @@ -46,9 +43,6 @@ public function testRandomStateIsSet() $this->assertNotEmpty( $state ); } - /** - * @skipmock true - */ public function testSetState() { $state = substr( md5( rand() ), 0, 7 ); diff --git a/tests/Pinterest/PinterestTest.php b/tests/Pinterest/PinterestTest.php new file mode 100644 index 0000000..223062a --- /dev/null +++ b/tests/Pinterest/PinterestTest.php @@ -0,0 +1,50 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace DirkGroenen\Pinterest\Tests; + +use \DirkGroenen\Pinterest\Pinterest; +use \DirkGroenen\Pinterest\Tests\Utils\CurlBuilderMock; + +class PinterestTest extends \PHPUnit_Framework_TestCase{ + + /** + * The Pinterest instance + * + * @var Pinterest + */ + private $pinterest; + + /** + * Setup a new instance of the Pinterest class + * + * @return void + */ + public function setUp() + { + $curlbuilder = CurlBuilderMock::create( $this ); + + // Setup Pinterest + $this->pinterest = new Pinterest("0", "0", $curlbuilder); + $this->pinterest->auth->setOAuthToken( "0" ); + } + + public function testGetRateLimit() + { + $ratelimit = $this->pinterest->getRateLimit(); + $this->assertEquals( $ratelimit, 1000 ); + } + + public function testGetRateLimitRemaining() + { + $ratelimit = $this->pinterest->getRateLimitRemaining(); + $this->assertEquals( $ratelimit, 'unknown' ); + } +} diff --git a/tests/Pinterest/Utils/CurlBuilderMock.php b/tests/Pinterest/Utils/CurlBuilderMock.php index d0540c3..c8afd82 100644 --- a/tests/Pinterest/Utils/CurlBuilderMock.php +++ b/tests/Pinterest/Utils/CurlBuilderMock.php @@ -28,10 +28,13 @@ public static function create( $instance ) $responsefile = self::parseDocBlock( $doc_block, '@responsefile' ); $responsecode = self::parseDocBlock( $doc_block, '@responsecode' ); - $skipmock = self::parseDocBlock( $doc_block, '@skipmock' ); + $defaultheaders = array( + "X-Ratelimit-Limit" => "1000", + "X-Ratelimit-Remaining" => "998", + "X-Varnish" => "4059929980" + ); - if(isset($skipmock[0])) - return false; + $skipmock = self::parseDocBlock( $doc_block, '@skipmock' ); if(empty($responsecode)) $responsecode = [201]; @@ -43,13 +46,18 @@ public static function create( $instance ) $curlbuilder = $instance->getMockBuilder("\\DirkGroenen\\Pinterest\\Utils\\CurlBuilder") ->getMock(); - $curlbuilder->expects($instance->once()) + $curlbuilder->expects($instance->any()) ->method('create') ->will($instance->returnSelf()); - $curlbuilder->expects($instance->once()) - ->method('execute') - ->will( $instance->returnValue( file_get_contents( __DIR__ . '/../responses/' . (new \ReflectionClass($instance))->getShortName() . '/' . $responsefile[0] . ".json" ) ) ); + // Build response file path + $responseFilePath = __DIR__ . '/../responses/' . (new \ReflectionClass($instance))->getShortName() . '/' . $responsefile[0] . ".json"; + + if(file_exists($responseFilePath)){ + $curlbuilder->expects($instance->once()) + ->method('execute') + ->will( $instance->returnValue( file_get_contents( $responseFilePath ) ) ); + } $curlbuilder->expects($instance->any()) ->method('getInfo') From d929dd571129288988ba375d14e848de3fa0f2ec Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Sat, 9 Jan 2016 15:56:46 +0100 Subject: [PATCH 32/85] Add php 7 to tests --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7927540..fe7b4c9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,11 +3,12 @@ php: - 5.6 - 5.5 - 5.4 + - 7.0 - hhvm before_script: - composer self-update - composer install --prefer-source --no-interaction -script: +script: - phpunit branches: From 11a2986a2d6c353ed432885511f1c848ea04d5fe Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Sat, 9 Jan 2016 15:58:31 +0100 Subject: [PATCH 33/85] Only disable safe_upload when required --- src/Pinterest/Transport/Request.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Pinterest/Transport/Request.php b/src/Pinterest/Transport/Request.php index 97c99a6..3976349 100644 --- a/src/Pinterest/Transport/Request.php +++ b/src/Pinterest/Transport/Request.php @@ -35,14 +35,14 @@ class Request { * @var CurlBuilder */ private $curlbuilder; - + /** * Instance of the CurlBuilder class * * @var CurlBuilder */ private $headers; - + /** * Constructor @@ -123,7 +123,7 @@ public function update( $path, array $parameters = array() ) { return $this->execute("PATCH", sprintf("%s%s", $this->host, $path) . "/", $parameters ); } - + /** * Create a new model instance * @@ -180,7 +180,7 @@ public function execute( $method, $apiCall, array $parameters = array(), $header CURLOPT_POSTFIELDS => $parameters ) ); - if(defined('CURLOPT_SAFE_UPLOAD')) + if(!class_exists("\CURLFile") && defined('CURLOPT_SAFE_UPLOAD')) $ch->setOption( CURLOPT_SAFE_UPLOAD, false ); break; From b39ad303c39d6082df3226e279a8afbb05ed2b2a Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Sat, 9 Jan 2016 16:00:00 +0100 Subject: [PATCH 34/85] Add development branch to travis --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index fe7b4c9..a9d177a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,4 +13,5 @@ script: branches: only: - - master \ No newline at end of file + - master + - development \ No newline at end of file From 91806d501a6a164ecee5f9720c6344e1858d812c Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Sat, 9 Jan 2016 16:07:19 +0100 Subject: [PATCH 35/85] ADd changes --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4018771..19accc6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### 0.2.4 (09-01-2016) + +- Fixed disabling CURL safe_mode issue in PHP 7.0 [#21](https://github.com/dirkgroenen/Pinterest-API-PHP/issues/21) + ### 0.2.3 (03-01-2016) - Add error codes to PinterestException ( [#17](https://github.com/dirkgroenen/Pinterest-API-PHP/issues/17) ) From 39e40448a415471b390d61ab546c23cf1f54fb0e Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Sat, 9 Jan 2016 16:07:54 +0100 Subject: [PATCH 36/85] Correct version ref --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19accc6..c164946 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -### 0.2.4 (09-01-2016) +### 0.2.5 (09-01-2016) - Fixed disabling CURL safe_mode issue in PHP 7.0 [#21](https://github.com/dirkgroenen/Pinterest-API-PHP/issues/21) From 6be65b0b1b4da36cfdac802dfe8de0c2da0714d5 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Sat, 9 Jan 2016 16:15:53 +0100 Subject: [PATCH 37/85] add scrutinizer config --- .scrutinizer.yml | 15 ++ README.md | 7 +- coverage-report | 582 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 603 insertions(+), 1 deletion(-) create mode 100644 .scrutinizer.yml create mode 100644 coverage-report diff --git a/.scrutinizer.yml b/.scrutinizer.yml new file mode 100644 index 0000000..0bc8876 --- /dev/null +++ b/.scrutinizer.yml @@ -0,0 +1,15 @@ +filter: + excluded_paths: + - 'tests/*' +checks: + php: true +coding_style: + php: { } +build: + tests: + override: + - + command: 'phpunit --coverage-clover=.coverage-report.xml' + coverage: + file: '.coverage-report.xml' + format: 'php-clover' \ No newline at end of file diff --git a/README.md b/README.md index 315dc69..2678928 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,9 @@ -![](http://i.imgur.com/cacgQlq.png) Pinterest API - PHP [![](https://travis-ci.org/dirkgroenen/Pinterest-API-PHP.svg)](https://travis-ci.org/dirkgroenen/Pinterest-API-PHP) [![Packagist](https://img.shields.io/packagist/v/dirkgroenen/pinterest-api-php.svg)](https://packagist.org/packages/dirkgroenen/pinterest-api-php) [![Support me with some coffee](https://img.shields.io/badge/donate-paypal-orange.svg)](https://www.paypal.me/dirkgroenen) +![](http://i.imgur.com/cacgQlq.png) Pinterest API - PHP + +[![](https://travis-ci.org/dirkgroenen/Pinterest-API-PHP.svg)](https://travis-ci.org/dirkgroenen/Pinterest-API-PHP) +[![](https://scrutinizer-ci.com/g/dirkgroenen/Pinterest-API-PHP/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/dirkgroenen/Pinterest-API-PHP/?branch=master) +[![Packagist](https://img.shields.io/packagist/v/dirkgroenen/pinterest-api-php.svg)](https://packagist.org/packages/dirkgroenen/pinterest-api-php) +[![Support me with some coffee](https://img.shields.io/badge/donate-paypal-orange.svg)](https://www.paypal.me/dirkgroenen) ------------------- A PHP wrapper for the official [Pinterest API](https://dev.pinterest.com). diff --git a/coverage-report b/coverage-report new file mode 100644 index 0000000..ac193f4 --- /dev/null +++ b/coverage-report @@ -0,0 +1,582 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From a4de1df7330752b4df46a62d5a1c991e2d042c43 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Sat, 9 Jan 2016 16:19:12 +0100 Subject: [PATCH 38/85] Add shield badges --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2678928..db9df11 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ ![](http://i.imgur.com/cacgQlq.png) Pinterest API - PHP [![](https://travis-ci.org/dirkgroenen/Pinterest-API-PHP.svg)](https://travis-ci.org/dirkgroenen/Pinterest-API-PHP) -[![](https://scrutinizer-ci.com/g/dirkgroenen/Pinterest-API-PHP/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/dirkgroenen/Pinterest-API-PHP/?branch=master) +[![](https://img.shields.io/scrutinizer/g/dirkgroenen/Pinterest-API-PHP.svg)](https://scrutinizer-ci.com/g/dirkgroenen/Pinterest-API-PHP/?branch=master) +[![](https://img.shields.io/scrutinizer/g/dirkgroenen/Pinterest-API-PHP.svg)](https://scrutinizer-ci.com/g/dirkgroenen/Pinterest-API-PHP/?branch=master) +[![](https://img.shields.io/scrutinizer/coverage/g/dirkgroenen/Pinterest-API-PHP.svg)](https://scrutinizer-ci.com/g/dirkgroenen/Pinterest-API-PHP/?branch=master) [![Packagist](https://img.shields.io/packagist/v/dirkgroenen/pinterest-api-php.svg)](https://packagist.org/packages/dirkgroenen/pinterest-api-php) [![Support me with some coffee](https://img.shields.io/badge/donate-paypal-orange.svg)](https://www.paypal.me/dirkgroenen) ------------------- From a02838155dcb72eb5f7ab6f58014a49c22fe295f Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Sat, 9 Jan 2016 16:21:30 +0100 Subject: [PATCH 39/85] Update markdown looks --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index db9df11..ec3f783 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ -![](http://i.imgur.com/cacgQlq.png) Pinterest API - PHP +-> +#Pinterest API - PHP +![](http://i.imgur.com/cacgQlq.png) [![](https://travis-ci.org/dirkgroenen/Pinterest-API-PHP.svg)](https://travis-ci.org/dirkgroenen/Pinterest-API-PHP) [![](https://img.shields.io/scrutinizer/g/dirkgroenen/Pinterest-API-PHP.svg)](https://scrutinizer-ci.com/g/dirkgroenen/Pinterest-API-PHP/?branch=master) @@ -6,6 +8,7 @@ [![](https://img.shields.io/scrutinizer/coverage/g/dirkgroenen/Pinterest-API-PHP.svg)](https://scrutinizer-ci.com/g/dirkgroenen/Pinterest-API-PHP/?branch=master) [![Packagist](https://img.shields.io/packagist/v/dirkgroenen/pinterest-api-php.svg)](https://packagist.org/packages/dirkgroenen/pinterest-api-php) [![Support me with some coffee](https://img.shields.io/badge/donate-paypal-orange.svg)](https://www.paypal.me/dirkgroenen) +<- ------------------- A PHP wrapper for the official [Pinterest API](https://dev.pinterest.com). From 1745401a223b82bf0842ae6f2650230467cfd083 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Sat, 9 Jan 2016 16:23:14 +0100 Subject: [PATCH 40/85] Update markdown --- .gitignore | 1 + README.md | 6 ++---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 40e4398..c28e66f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +README.html /demo/ /vendor/ /tests/Pinterest/env diff --git a/README.md b/README.md index ec3f783..ba18549 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ --> -#Pinterest API - PHP -![](http://i.imgur.com/cacgQlq.png) +## ![](http://i.imgur.com/cacgQlq.png) Pinterest API - PHP + [![](https://travis-ci.org/dirkgroenen/Pinterest-API-PHP.svg)](https://travis-ci.org/dirkgroenen/Pinterest-API-PHP) [![](https://img.shields.io/scrutinizer/g/dirkgroenen/Pinterest-API-PHP.svg)](https://scrutinizer-ci.com/g/dirkgroenen/Pinterest-API-PHP/?branch=master) @@ -8,7 +7,6 @@ [![](https://img.shields.io/scrutinizer/coverage/g/dirkgroenen/Pinterest-API-PHP.svg)](https://scrutinizer-ci.com/g/dirkgroenen/Pinterest-API-PHP/?branch=master) [![Packagist](https://img.shields.io/packagist/v/dirkgroenen/pinterest-api-php.svg)](https://packagist.org/packages/dirkgroenen/pinterest-api-php) [![Support me with some coffee](https://img.shields.io/badge/donate-paypal-orange.svg)](https://www.paypal.me/dirkgroenen) -<- ------------------- A PHP wrapper for the official [Pinterest API](https://dev.pinterest.com). From f7e59c5b0e2c2d48fe3a1998789163aea0d1fd2d Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Sat, 9 Jan 2016 16:44:14 +0100 Subject: [PATCH 41/85] Fix serveral code quaility issues --- src/Pinterest/Endpoints/Boards.php | 10 ++++---- src/Pinterest/Endpoints/Endpoint.php | 15 ++++++----- src/Pinterest/Endpoints/Following.php | 28 ++++++++++----------- src/Pinterest/Endpoints/Pins.php | 16 ++++++------ src/Pinterest/Models/Collection.php | 4 +-- src/Pinterest/Models/Model.php | 29 +++++++++++---------- src/Pinterest/Pinterest.php | 1 - src/Pinterest/Transport/Request.php | 36 +++++++++++++-------------- src/Pinterest/Transport/Response.php | 5 ++++ src/Pinterest/Utils/CurlBuilder.php | 7 +++--- 10 files changed, 75 insertions(+), 76 deletions(-) diff --git a/src/Pinterest/Endpoints/Boards.php b/src/Pinterest/Endpoints/Boards.php index e5f1188..ff456ce 100644 --- a/src/Pinterest/Endpoints/Boards.php +++ b/src/Pinterest/Endpoints/Boards.php @@ -1,9 +1,9 @@ - - * + * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ @@ -17,7 +17,7 @@ class Boards extends Endpoint { /** * Find the provided board - * + * * @access public * @param string $board_id * @param array $data @@ -54,7 +54,7 @@ public function create( array $data ) */ public function delete( $board_id ) { - $response = $this->request->delete( sprintf("boards/%s", $board_id) ); + $this->request->delete( sprintf("boards/%s", $board_id) ); return true; } } \ No newline at end of file diff --git a/src/Pinterest/Endpoints/Endpoint.php b/src/Pinterest/Endpoints/Endpoint.php index c8ae138..5cda9aa 100644 --- a/src/Pinterest/Endpoints/Endpoint.php +++ b/src/Pinterest/Endpoints/Endpoint.php @@ -1,9 +1,9 @@ - - * + * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ @@ -18,14 +18,14 @@ class Endpoint { /** * Instance of the request class - * - * @var Transport\Request + * + * @var Request */ protected $request; /** * Instance of the master class - * + * * @var Pinterest */ protected $master; @@ -33,9 +33,8 @@ class Endpoint { /** * Create a new model instance * - * @param Transport\Request $request + * @param Request $request * @param Pinterest $master - * @return void */ public function __construct( Request $request, Pinterest $master ) { diff --git a/src/Pinterest/Endpoints/Following.php b/src/Pinterest/Endpoints/Following.php index cfc5b3b..13c5313 100644 --- a/src/Pinterest/Endpoints/Following.php +++ b/src/Pinterest/Endpoints/Following.php @@ -1,9 +1,9 @@ - - * + * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ @@ -14,11 +14,11 @@ use DirkGroenen\Pinterest\Models\Collection; class Following extends Endpoint { - - + + /** * Get the authenticated user's following users - * + * * @access public * @param array $data * @throws Exceptions/PinterestExceptions @@ -32,7 +32,7 @@ public function users( array $data = [] ) /** * Get the authenticated user's following boards - * + * * @access public * @param array $data * @throws Exceptions/PinterestExceptions @@ -46,7 +46,7 @@ public function boards( array $data = [] ) /** * Get the authenticated user's following interest - * + * * @access public * @param array $data * @throws Exceptions/PinterestExceptions @@ -68,7 +68,7 @@ public function interests( array $data = [] ) */ public function followUser( $user ) { - $user = $this->request->post( "me/following/users", array( + $this->request->post( "me/following/users", array( "user" => $user ) ); return true; @@ -84,7 +84,7 @@ public function followUser( $user ) */ public function unfollowUser( $user ) { - $user = $this->request->delete( sprintf("me/following/users/%s", $user) ); + $this->request->delete( sprintf("me/following/users/%s", $user) ); return true; } @@ -98,7 +98,7 @@ public function unfollowUser( $user ) */ public function followBoard( $board ) { - $user = $this->request->post( "me/following/boards", array( + $this->request->post( "me/following/boards", array( "board" => $board ) ); return true; @@ -114,7 +114,7 @@ public function followBoard( $board ) */ public function unfollowBoard( $board_id ) { - $user = $this->request->delete( sprintf("me/following/boards/%s", $board_id) ); + $this->request->delete( sprintf("me/following/boards/%s", $board_id) ); return true; } @@ -128,7 +128,7 @@ public function unfollowBoard( $board_id ) */ public function followInterest( $interest ) { - $user = $this->request->post( "me/following/interests", array( + $this->request->post( "me/following/interests", array( "interest" => $interest ) ); return true; @@ -144,7 +144,7 @@ public function followInterest( $interest ) */ public function unfollowInterest( $interest_id ) { - $user = $this->request->delete( sprintf("me/following/interests/%s", $interest_id) ); + $this->request->delete( sprintf("me/following/interests/%s", $interest_id) ); return true; } } \ No newline at end of file diff --git a/src/Pinterest/Endpoints/Pins.php b/src/Pinterest/Endpoints/Pins.php index 3589481..6a3dda9 100644 --- a/src/Pinterest/Endpoints/Pins.php +++ b/src/Pinterest/Endpoints/Pins.php @@ -1,9 +1,9 @@ - - * + * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ @@ -14,10 +14,10 @@ use DirkGroenen\Pinterest\Models\Collection; class Pins extends Endpoint { - + /** * Get a pin object - * + * * @access public * @param string $pin_id * @param array $data @@ -32,7 +32,7 @@ public function get( $pin_id, array $data = [] ) /** * Get all pins from the given board - * + * * @access public * @param string $board_id * @param array $data @@ -60,7 +60,7 @@ public function create( array $data ) $data["image"] = new \CURLFile($data['image']); } else{ - $data["image"] = '@' . $data['image']; + $data["image"] = '@' . $data['image']; } } @@ -93,7 +93,7 @@ public function update( $pin_id, array $data ) */ public function delete( $pin_id ) { - $response = $this->request->delete( sprintf("pins/%s", $pin_id) ); + $this->request->delete( sprintf("pins/%s", $pin_id) ); return true; } } \ No newline at end of file diff --git a/src/Pinterest/Models/Collection.php b/src/Pinterest/Models/Collection.php index c1946db..a1546c3 100644 --- a/src/Pinterest/Models/Collection.php +++ b/src/Pinterest/Models/Collection.php @@ -27,14 +27,14 @@ class Collection implements \JsonSerializable, \ArrayAccess, \IteratorAggregate{ /** * The model of each collection item * - * @var Model + * @var string */ private $model; /** * Stores the pagination object * - * @var array + * @var array|boolean */ public $pagination; diff --git a/src/Pinterest/Models/Model.php b/src/Pinterest/Models/Model.php index abe3427..09fd7bf 100644 --- a/src/Pinterest/Models/Model.php +++ b/src/Pinterest/Models/Model.php @@ -1,9 +1,9 @@ - - * + * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ @@ -25,14 +25,14 @@ class Model implements \JsonSerializable { /** * The available object keys - * + * * @var array */ protected $fillable = []; /** * Instance of the master Pinterest class - * + * * @var Pinterest */ protected $master; @@ -42,10 +42,9 @@ class Model implements \JsonSerializable { * * @param Pinterest $master * @param array|Transport\Response $modeldata - * @return void */ public function __construct( Pinterest $master, $modeldata = null ) - { + { $this->master = $master; // Fill the model @@ -53,13 +52,13 @@ public function __construct( Pinterest $master, $modeldata = null ) $this->fill($modeldata); } else if( $modeldata instanceof \DirkGroenen\Pinterest\Transport\Response ){ - $this->fill($modeldata->data); + $this->fill($modeldata->data); } } /** * Get the model's attribute - * + * * @access public * @param string $key * @return mixed @@ -71,7 +70,7 @@ public function __get($key) /** * Set the model's attribute - * + * * @access public * @param string $key * @param mixed $value @@ -117,10 +116,10 @@ private function fill(array $attributes) /** * Check if the key is fillable - * + * * @access public * @param string $key - * @return boolean + * @return boolean */ public function isFillable($key) { @@ -136,7 +135,7 @@ public function isFillable($key) public function toArray() { $array = array(); - + foreach($this->fillable as $key){ $array[$key] = $this->{$key}; } @@ -146,7 +145,7 @@ public function toArray() /** * Convert the model instance to JSON - * + * * @access public * @return string */ @@ -168,7 +167,7 @@ public function jsonSerialize() /** * Convert the model to its string representation - * + * * @access public * @return string */ diff --git a/src/Pinterest/Pinterest.php b/src/Pinterest/Pinterest.php index ffe0a9b..c99c0ea 100644 --- a/src/Pinterest/Pinterest.php +++ b/src/Pinterest/Pinterest.php @@ -51,7 +51,6 @@ class Pinterest { * @param string $client_id * @param string $client_secret * @param CurlBuilder $curlbuilder - * @param string $redirect_uri */ public function __construct($client_id, $client_secret, $curlbuilder = null) { diff --git a/src/Pinterest/Transport/Request.php b/src/Pinterest/Transport/Request.php index 3976349..322c47e 100644 --- a/src/Pinterest/Transport/Request.php +++ b/src/Pinterest/Transport/Request.php @@ -37,13 +37,12 @@ class Request { private $curlbuilder; /** - * Instance of the CurlBuilder class + * Array with the headers from the last request * - * @var CurlBuilder + * @var array */ private $headers; - /** * Constructor * @@ -59,6 +58,7 @@ public function __construct( CurlBuilder $curlbuilder ) * * @access public * @param string $token + * @return void */ public function setAccessToken( $token ) { @@ -71,7 +71,7 @@ public function setAccessToken( $token ) * @access public * @param string $endpoint * @param array $parameters - * @return [type] + * @return Response */ public function get( $endpoint, array $parameters = array() ) { @@ -89,13 +89,13 @@ public function get( $endpoint, array $parameters = array() ) * Make a post request to the given endpoint * * @access public - * @param string $endpoint + * @param string $path * @param array $parameters - * @return [type] + * @return Response */ - public function post( $path, array $parameters = array() ) + public function post( $endpoint, array $parameters = array() ) { - return $this->execute("POST", sprintf("%s%s", $this->host, $path), $parameters ); + return $this->execute("POST", sprintf("%s%s", $this->host, $endpoint), $parameters ); } /** @@ -104,11 +104,11 @@ public function post( $path, array $parameters = array() ) * @access public * @param string $endpoint * @param array $parameters - * @return [type] + * @return Response */ - public function delete( $path, array $parameters = array() ) + public function delete( $endpoint, array $parameters = array() ) { - return $this->execute("DELETE", sprintf("%s%s", $this->host, $path) . "/", $parameters ); + return $this->execute("DELETE", sprintf("%s%s", $this->host, $endpoint) . "/", $parameters ); } /** @@ -117,19 +117,17 @@ public function delete( $path, array $parameters = array() ) * @access public * @param string $endpoint * @param array $parameters - * @return [type] + * @return Response */ - public function update( $path, array $parameters = array() ) + public function update( $endpoint, array $parameters = array() ) { - return $this->execute("PATCH", sprintf("%s%s", $this->host, $path) . "/", $parameters ); + return $this->execute("PATCH", sprintf("%s%s", $this->host, $endpoint) . "/", $parameters ); } /** - * Create a new model instance + * Return the headers from the last request * - * @param Transport\Request $request - * @param Pinterest $master - * @return void + * @return array */ public function getHeaders() { @@ -144,7 +142,7 @@ public function getHeaders() * @param string $apiCall * @param array $parameters * @param array $headers - * @return mixed + * @return Response */ public function execute( $method, $apiCall, array $parameters = array(), $headers = array() ) { diff --git a/src/Pinterest/Transport/Response.php b/src/Pinterest/Transport/Response.php index 9296a39..5c2799a 100644 --- a/src/Pinterest/Transport/Response.php +++ b/src/Pinterest/Transport/Response.php @@ -13,6 +13,11 @@ use DirkGroenen\Pinterest\Utils\CurlBuilder; use DirkGroenen\Pinterest\Exceptions\PinterestException; + /** + * @property array $page + * @property array $data + * @property string $message + */ class Response { /** diff --git a/src/Pinterest/Utils/CurlBuilder.php b/src/Pinterest/Utils/CurlBuilder.php index 7b9b1e2..ab46a22 100644 --- a/src/Pinterest/Utils/CurlBuilder.php +++ b/src/Pinterest/Utils/CurlBuilder.php @@ -52,7 +52,7 @@ public function create() * * @access public * @param string $option - * @param string $value + * @param mixed $value * @return $this */ public function setOption( $option, $value ) @@ -200,7 +200,6 @@ private function execFollow() { $rch = curl_copy_handle($this->curl); curl_setopt($rch, CURLOPT_HEADER, true); - //curl_setopt($rch, CURLOPT_NOBODY, true); curl_setopt($rch, CURLOPT_FORBID_REUSE, false); do{ @@ -230,11 +229,11 @@ private function execFollow() { curl_close($rch); if(!$mr){ - if ($maxredirect === null){ + if ($mr === null){ trigger_error('Too many redirects.', E_USER_WARNING); } else{ - $maxredirect = 0; + $mr = 0; } return false; From 69061f55cb741701b808e59ac03729e49741c33c Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Sat, 9 Jan 2016 16:49:06 +0100 Subject: [PATCH 42/85] Remove unused --- src/Pinterest/Utils/CurlBuilder.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Pinterest/Utils/CurlBuilder.php b/src/Pinterest/Utils/CurlBuilder.php index ab46a22..c57693d 100644 --- a/src/Pinterest/Utils/CurlBuilder.php +++ b/src/Pinterest/Utils/CurlBuilder.php @@ -193,7 +193,7 @@ private function execFollow() { else{ $this->setOption(CURLOPT_FOLLOWLOCATION, false); - if($mr > 0){ + if($CURLOPT_MAXREDIRS > 0){ $original_url = $this->getInfo(CURLINFO_EFFECTIVE_URL); $newurl = $original_url; @@ -232,9 +232,6 @@ private function execFollow() { if ($mr === null){ trigger_error('Too many redirects.', E_USER_WARNING); } - else{ - $mr = 0; - } return false; } From f932e8323a43dfaa827068c59c0da5a3a1f19704 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Sat, 9 Jan 2016 16:50:23 +0100 Subject: [PATCH 43/85] Fix issue --- src/Pinterest/Models/Model.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Pinterest/Models/Model.php b/src/Pinterest/Models/Model.php index 09fd7bf..d367cfa 100644 --- a/src/Pinterest/Models/Model.php +++ b/src/Pinterest/Models/Model.php @@ -40,8 +40,8 @@ class Model implements \JsonSerializable { /** * Create a new model instance * - * @param Pinterest $master - * @param array|Transport\Response $modeldata + * @param Pinterest $master + * @param array|Response $modeldata */ public function __construct( Pinterest $master, $modeldata = null ) { From 02f18bde8274a9dbaa6f470e4c3d6b30bd1e3050 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Sat, 9 Jan 2016 16:51:10 +0100 Subject: [PATCH 44/85] Fix parameter name --- src/Pinterest/Transport/Request.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Pinterest/Transport/Request.php b/src/Pinterest/Transport/Request.php index 322c47e..9c3fb07 100644 --- a/src/Pinterest/Transport/Request.php +++ b/src/Pinterest/Transport/Request.php @@ -89,7 +89,7 @@ public function get( $endpoint, array $parameters = array() ) * Make a post request to the given endpoint * * @access public - * @param string $path + * @param string $endpoint * @param array $parameters * @return Response */ From 3f6f3b8c8a62bae87f44e14e0bcad459faf62b83 Mon Sep 17 00:00:00 2001 From: Scrutinizer Auto-Fixer Date: Sat, 9 Jan 2016 15:55:56 +0000 Subject: [PATCH 45/85] Scrutinizer Auto-Fixes This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com --- src/Pinterest/Auth/PinterestOAuth.php | 13 +++---- src/Pinterest/Endpoints/Boards.php | 23 ++++++------ src/Pinterest/Endpoints/Endpoint.php | 2 +- src/Pinterest/Endpoints/Following.php | 48 ++++++++++++------------- src/Pinterest/Endpoints/Pins.php | 42 +++++++++++----------- src/Pinterest/Endpoints/Users.php | 50 +++++++++++++-------------- src/Pinterest/Models/Collection.php | 26 +++++++------- src/Pinterest/Pinterest.php | 10 +++--- src/Pinterest/Transport/Request.php | 42 +++++++++++----------- src/Pinterest/Transport/Response.php | 20 +++++------ src/Pinterest/Utils/CurlBuilder.php | 42 ++++++++++------------ 11 files changed, 157 insertions(+), 161 deletions(-) diff --git a/src/Pinterest/Auth/PinterestOAuth.php b/src/Pinterest/Auth/PinterestOAuth.php index 7caa7b6..daf32ae 100644 --- a/src/Pinterest/Auth/PinterestOAuth.php +++ b/src/Pinterest/Auth/PinterestOAuth.php @@ -54,8 +54,9 @@ class PinterestOAuth { * * @param string $client_id * @param string $client_secret + * @param Request $request */ - public function __construct( $client_id, $client_secret, $request ) + public function __construct($client_id, $client_secret, $request) { $this->client_id = $client_id; $this->client_secret = $client_secret; @@ -75,7 +76,7 @@ public function __construct( $client_id, $client_secret, $request ) * @param string $redirect_uri * @return string */ - public function getLoginUrl( $redirect_uri, $scopes = array("read_public"), $response_type = "code" ) + public function getLoginUrl($redirect_uri, $scopes = array("read_public"), $response_type = "code") { $queryparams = array( "response_type" => $response_type, @@ -87,7 +88,7 @@ public function getLoginUrl( $redirect_uri, $scopes = array("read_public"), $res ); // Build url and return it - return sprintf( "%s?%s", self::AUTH_HOST, http_build_query($queryparams) ); + return sprintf("%s?%s", self::AUTH_HOST, http_build_query($queryparams)); } /** @@ -98,7 +99,7 @@ public function getLoginUrl( $redirect_uri, $scopes = array("read_public"), $res */ private function generateState() { - return substr( md5( rand() ), 0, 7 ); + return substr(md5(rand()), 0, 7); } /** @@ -128,7 +129,7 @@ public function setState($state) * @param string $code * @return array */ - public function getOAuthToken( $code ) + public function getOAuthToken($code) { // Build data array $data = array( @@ -151,7 +152,7 @@ public function getOAuthToken( $code ) * @param string $access_token * @return void */ - public function setOAuthToken( $access_token ) + public function setOAuthToken($access_token) { $this->request->setAccessToken($access_token); } diff --git a/src/Pinterest/Endpoints/Boards.php b/src/Pinterest/Endpoints/Boards.php index ff456ce..a2d526f 100644 --- a/src/Pinterest/Endpoints/Boards.php +++ b/src/Pinterest/Endpoints/Boards.php @@ -11,7 +11,6 @@ namespace DirkGroenen\Pinterest\Endpoints; use DirkGroenen\Pinterest\Models\Board; -use DirkGroenen\Pinterest\Models\Collection; class Boards extends Endpoint { @@ -22,12 +21,12 @@ class Boards extends Endpoint { * @param string $board_id * @param array $data * @throws Exceptions/PinterestExceptions - * @return Models\Board + * @return Board */ - public function get( $board_id, array $data = [] ) + public function get($board_id, array $data = []) { - $response = $this->request->get( sprintf("boards/%s", $board_id), $data ); - return new Board( $this->master, $response ); + $response = $this->request->get(sprintf("boards/%s", $board_id), $data); + return new Board($this->master, $response); } /** @@ -36,12 +35,12 @@ public function get( $board_id, array $data = [] ) * @access public * @param array $data * @throws Exceptions/PinterestExceptions - * @return Models\Board + * @return Board */ - public function create( array $data ) + public function create(array $data) { - $response = $this->request->post( "boards", $data ); - return new Board( $this->master, $response ); + $response = $this->request->post("boards", $data); + return new Board($this->master, $response); } /** @@ -50,11 +49,11 @@ public function create( array $data ) * @access public * @param string $board_id * @throws Exceptions/PinterestExceptions - * @return Models\Board + * @return boolean */ - public function delete( $board_id ) + public function delete($board_id) { - $this->request->delete( sprintf("boards/%s", $board_id) ); + $this->request->delete(sprintf("boards/%s", $board_id)); return true; } } \ No newline at end of file diff --git a/src/Pinterest/Endpoints/Endpoint.php b/src/Pinterest/Endpoints/Endpoint.php index 5cda9aa..b9ae0cc 100644 --- a/src/Pinterest/Endpoints/Endpoint.php +++ b/src/Pinterest/Endpoints/Endpoint.php @@ -36,7 +36,7 @@ class Endpoint { * @param Request $request * @param Pinterest $master */ - public function __construct( Request $request, Pinterest $master ) + public function __construct(Request $request, Pinterest $master) { $this->request = $request; $this->master = $master; diff --git a/src/Pinterest/Endpoints/Following.php b/src/Pinterest/Endpoints/Following.php index 13c5313..6e07367 100644 --- a/src/Pinterest/Endpoints/Following.php +++ b/src/Pinterest/Endpoints/Following.php @@ -24,10 +24,10 @@ class Following extends Endpoint { * @throws Exceptions/PinterestExceptions * @return Collection */ - public function users( array $data = [] ) + public function users(array $data = []) { - $response = $this->request->get( "me/following/users", $data ); - return new Collection( $this->master, $response, "User" ); + $response = $this->request->get("me/following/users", $data); + return new Collection($this->master, $response, "User"); } /** @@ -38,10 +38,10 @@ public function users( array $data = [] ) * @throws Exceptions/PinterestExceptions * @return Collection */ - public function boards( array $data = [] ) + public function boards(array $data = []) { - $response = $this->request->get( "me/following/boards", $data ); - return new Collection( $this->master, $response, "Board" ); + $response = $this->request->get("me/following/boards", $data); + return new Collection($this->master, $response, "Board"); } /** @@ -52,10 +52,10 @@ public function boards( array $data = [] ) * @throws Exceptions/PinterestExceptions * @return Collection */ - public function interests( array $data = [] ) + public function interests(array $data = []) { - $response = $this->request->get( "me/following/interests", $data ); - return new Collection( $this->master, $response, "Interest" ); + $response = $this->request->get("me/following/interests", $data); + return new Collection($this->master, $response, "Interest"); } /** @@ -66,11 +66,11 @@ public function interests( array $data = [] ) * @throws Exceptions/PinterestExceptions * @return boolean */ - public function followUser( $user ) + public function followUser($user) { - $this->request->post( "me/following/users", array( + $this->request->post("me/following/users", array( "user" => $user - ) ); + )); return true; } @@ -82,9 +82,9 @@ public function followUser( $user ) * @throws Exceptions/PinterestExceptions * @return boolean */ - public function unfollowUser( $user ) + public function unfollowUser($user) { - $this->request->delete( sprintf("me/following/users/%s", $user) ); + $this->request->delete(sprintf("me/following/users/%s", $user)); return true; } @@ -96,11 +96,11 @@ public function unfollowUser( $user ) * @throws Exceptions/PinterestExceptions * @return boolean */ - public function followBoard( $board ) + public function followBoard($board) { - $this->request->post( "me/following/boards", array( + $this->request->post("me/following/boards", array( "board" => $board - ) ); + )); return true; } @@ -112,9 +112,9 @@ public function followBoard( $board ) * @throws Exceptions/PinterestExceptions * @return boolean */ - public function unfollowBoard( $board_id ) + public function unfollowBoard($board_id) { - $this->request->delete( sprintf("me/following/boards/%s", $board_id) ); + $this->request->delete(sprintf("me/following/boards/%s", $board_id)); return true; } @@ -126,11 +126,11 @@ public function unfollowBoard( $board_id ) * @throws Exceptions/PinterestExceptions * @return boolean */ - public function followInterest( $interest ) + public function followInterest($interest) { - $this->request->post( "me/following/interests", array( + $this->request->post("me/following/interests", array( "interest" => $interest - ) ); + )); return true; } @@ -142,9 +142,9 @@ public function followInterest( $interest ) * @throws Exceptions/PinterestExceptions * @return boolean */ - public function unfollowInterest( $interest_id ) + public function unfollowInterest($interest_id) { - $this->request->delete( sprintf("me/following/interests/%s", $interest_id) ); + $this->request->delete(sprintf("me/following/interests/%s", $interest_id)); return true; } } \ No newline at end of file diff --git a/src/Pinterest/Endpoints/Pins.php b/src/Pinterest/Endpoints/Pins.php index 6a3dda9..37e74b3 100644 --- a/src/Pinterest/Endpoints/Pins.php +++ b/src/Pinterest/Endpoints/Pins.php @@ -22,12 +22,12 @@ class Pins extends Endpoint { * @param string $pin_id * @param array $data * @throws Exceptions/PinterestExceptions - * @return Models\Pin + * @return Pin */ - public function get( $pin_id, array $data = [] ) + public function get($pin_id, array $data = []) { - $response = $this->request->get( sprintf("pins/%s", $pin_id), $data ); - return new Pin( $this->master, $response ); + $response = $this->request->get(sprintf("pins/%s", $pin_id), $data); + return new Pin($this->master, $response); } /** @@ -37,12 +37,12 @@ public function get( $pin_id, array $data = [] ) * @param string $board_id * @param array $data * @throws Exceptions/PinterestExceptions - * @return Models\Collection + * @return Collection */ - public function fromBoard( $board_id, array $data = [] ) + public function fromBoard($board_id, array $data = []) { - $response = $this->request->get( sprintf("boards/%s/pins", $board_id), $data ); - return new Collection( $this->master, $response, "Pin" ); + $response = $this->request->get(sprintf("boards/%s/pins", $board_id), $data); + return new Collection($this->master, $response, "Pin"); } /** @@ -51,21 +51,21 @@ public function fromBoard( $board_id, array $data = [] ) * @access public * @param array $data * @throws Exceptions/PinterestExceptions - * @return Models\Pin + * @return Pin */ - public function create( array $data ) + public function create(array $data) { - if( array_key_exists("image", $data) ){ - if(class_exists("\CURLFile")){ + if (array_key_exists("image", $data)) { + if (class_exists("\CURLFile")) { $data["image"] = new \CURLFile($data['image']); } - else{ + else { $data["image"] = '@' . $data['image']; } } - $response = $this->request->post( "pins", $data ); - return new Pin( $this->master, $response ); + $response = $this->request->post("pins", $data); + return new Pin($this->master, $response); } /** @@ -75,12 +75,12 @@ public function create( array $data ) * @param string $pin_id * @param array $data * @throws Exceptions/PinterestExceptions - * @return Models\Pin + * @return Pin */ - public function update( $pin_id, array $data ) + public function update($pin_id, array $data) { - $response = $this->request->update( sprintf("pins/%s", $pin_id), $data ); - return new Pin( $this->master, $response ); + $response = $this->request->update(sprintf("pins/%s", $pin_id), $data); + return new Pin($this->master, $response); } /** @@ -91,9 +91,9 @@ public function update( $pin_id, array $data ) * @throws Exceptions/PinterestExceptions * @return boolean */ - public function delete( $pin_id ) + public function delete($pin_id) { - $this->request->delete( sprintf("pins/%s", $pin_id) ); + $this->request->delete(sprintf("pins/%s", $pin_id)); return true; } } \ No newline at end of file diff --git a/src/Pinterest/Endpoints/Users.php b/src/Pinterest/Endpoints/Users.php index 500956b..6076a96 100644 --- a/src/Pinterest/Endpoints/Users.php +++ b/src/Pinterest/Endpoints/Users.php @@ -21,12 +21,12 @@ class Users extends Endpoint { * @access public * @param array $data * @throws Exceptions/PinterestExceptions - * @return Models\User + * @return User */ - public function me( array $data = [] ) + public function me(array $data = []) { - $response = $this->request->get("me", $data ); - return new User( $this->master, $response ); + $response = $this->request->get("me", $data); + return new User($this->master, $response); } /** @@ -36,12 +36,12 @@ public function me( array $data = [] ) * @param string $username * @param array $data * @throws Exceptions/PinterestExceptions - * @return Models\User + * @return User */ - public function find( $username, array $data = [] ) + public function find($username, array $data = []) { - $response = $this->request->get( sprintf("users/%s", $username), $data ); - return new User( $this->master, $response ); + $response = $this->request->get(sprintf("users/%s", $username), $data); + return new User($this->master, $response); } /** @@ -52,10 +52,10 @@ public function find( $username, array $data = [] ) * @throws Exceptions/PinterestExceptions * @return Collection */ - public function getMePins( array $data = [] ) + public function getMePins(array $data = []) { - $response = $this->request->get( "me/pins", $data ); - return new Collection( $this->master, $response, "Pin" ); + $response = $this->request->get("me/pins", $data); + return new Collection($this->master, $response, "Pin"); } /** @@ -66,11 +66,11 @@ public function getMePins( array $data = [] ) * @throws Exceptions/PinterestExceptions * @return Collection */ - public function searchMePins( $query, array $data = [] ) + public function searchMePins($query, array $data = []) { $data["query"] = $query; - $response = $this->request->get( "me/search/pins", $data ); - return new Collection( $this->master, $response, "Pin" ); + $response = $this->request->get("me/search/pins", $data); + return new Collection($this->master, $response, "Pin"); } /** @@ -81,12 +81,12 @@ public function searchMePins( $query, array $data = [] ) * @throws Exceptions/PinterestExceptions * @return Collection */ - public function searchMeBoards( $query, array $data = [] ) + public function searchMeBoards($query, array $data = []) { $data["query"] = $query; - $response = $this->request->get( "me/search/boards", $data ); - return new Collection( $this->master, $response, "Board" ); + $response = $this->request->get("me/search/boards", $data); + return new Collection($this->master, $response, "Board"); } /** @@ -97,10 +97,10 @@ public function searchMeBoards( $query, array $data = [] ) * @throws Exceptions/PinterestExceptions * @return Collection */ - public function getMeBoards( array $data = [] ) + public function getMeBoards(array $data = []) { - $response = $this->request->get( "me/boards", $data ); - return new Collection( $this->master, $response, "Board" ); + $response = $this->request->get("me/boards", $data); + return new Collection($this->master, $response, "Board"); } /** @@ -111,10 +111,10 @@ public function getMeBoards( array $data = [] ) * @throws Exceptions/PinterestExceptions * @return Collection */ - public function getMeLikes( array $data = [] ) + public function getMeLikes(array $data = []) { - $response = $this->request->get( "me/likes", $data ); - return new Collection( $this->master, $response, "Pin" ); + $response = $this->request->get("me/likes", $data); + return new Collection($this->master, $response, "Pin"); } /** @@ -127,8 +127,8 @@ public function getMeLikes( array $data = [] ) */ public function getMeFollowers(array $data = []) { - $response = $this->request->get( "me/followers", $data ); - return new Collection( $this->master, $response, "User" ); + $response = $this->request->get("me/followers", $data); + return new Collection($this->master, $response, "User"); } } diff --git a/src/Pinterest/Models/Collection.php b/src/Pinterest/Models/Collection.php index a1546c3..c743acd 100644 --- a/src/Pinterest/Models/Collection.php +++ b/src/Pinterest/Models/Collection.php @@ -61,25 +61,25 @@ class Collection implements \JsonSerializable, \ArrayAccess, \IteratorAggregate{ * @param string $model * @throws InvalidModelException */ - public function __construct( Pinterest $master, $items, $model ){ + public function __construct(Pinterest $master, $items, $model) { $this->master = $master; // Create class path - $this->model = ucfirst( strtolower($model) ); + $this->model = ucfirst(strtolower($model)); - if(!class_exists("\\DirkGroenen\\Pinterest\\Models\\" . $this->model)) + if (!class_exists("\\DirkGroenen\\Pinterest\\Models\\" . $this->model)) throw new InvalidModelException; // Get items and response instance - if( is_array($items) ){ + if (is_array($items)) { $this->response = null; $this->items = $items; } - else if( $items instanceof \DirkGroenen\Pinterest\Transport\Response ){ + else if ($items instanceof \DirkGroenen\Pinterest\Transport\Response) { $this->response = $items; $this->items = $items->data; } - else{ + else { throw new PinterestException("$items needs to be an instance of Transport\Response or an array."); } @@ -87,10 +87,10 @@ public function __construct( Pinterest $master, $items, $model ){ $this->items = $this->buildCollectionModels($this->items); // Add pagination object - if( isset($this->response->page) && !empty($this->response->page['next']) ){ + if (isset($this->response->page) && !empty($this->response->page['next'])) { $this->pagination = $this->response->page; } - else{ + else { $this->pagination = false; } } @@ -117,9 +117,9 @@ private function buildCollectionModels(array $items) { $modelcollection = []; - foreach($items as $item){ + foreach ($items as $item) { $class = new \ReflectionClass("\\DirkGroenen\\Pinterest\\Models\\" . $this->model); - $modelcollection[] = $class->newInstanceArgs( [$this->master, $item] ); + $modelcollection[] = $class->newInstanceArgs([$this->master, $item]); } return $modelcollection; @@ -133,7 +133,7 @@ private function buildCollectionModels(array $items) */ public function hasNextPage() { - return ($this->response != null && isset($this->response->page['next']) ); + return ($this->response != null && isset($this->response->page['next'])); } /** @@ -143,7 +143,7 @@ public function hasNextPage() * @param int $index * @return Model */ - public function get( $index ) + public function get($index) { return $this->items[$index]; } @@ -158,7 +158,7 @@ public function toArray() { $items = []; - foreach($this->items as $item){ + foreach ($this->items as $item) { $items[] = $item->toArray(); } diff --git a/src/Pinterest/Pinterest.php b/src/Pinterest/Pinterest.php index c99c0ea..5d922c8 100644 --- a/src/Pinterest/Pinterest.php +++ b/src/Pinterest/Pinterest.php @@ -54,11 +54,11 @@ class Pinterest { */ public function __construct($client_id, $client_secret, $curlbuilder = null) { - if($curlbuilder == null) + if ($curlbuilder == null) $curlbuilder = new CurlBuilder(); // Create new instance of Transport\Request - $this->request = new Request( $curlbuilder ); + $this->request = new Request($curlbuilder); // Create and set new instance of the OAuth class $this->auth = new PinterestOAuth($client_id, $client_secret, $this->request); @@ -78,15 +78,15 @@ public function __get($endpoint) $class = "\\DirkGroenen\\Pinterest\\Endpoints\\" . ucfirst($endpoint); // Check if an instance has already been initiated - if(!isset($this->cachedEndpoints[$endpoint])){ + if (!isset($this->cachedEndpoints[$endpoint])) { // Check endpoint existence - if(!class_exists($class)) + if (!class_exists($class)) throw new InvalidEndpointException; // Create a reflection of the called class and initialize it // with a reference to the request class $ref = new \ReflectionClass($class); - $obj = $ref->newInstanceArgs([ $this->request, $this ]); + $obj = $ref->newInstanceArgs([$this->request, $this]); $this->cachedEndpoints[$endpoint] = $obj; } diff --git a/src/Pinterest/Transport/Request.php b/src/Pinterest/Transport/Request.php index 9c3fb07..1e6a520 100644 --- a/src/Pinterest/Transport/Request.php +++ b/src/Pinterest/Transport/Request.php @@ -48,7 +48,7 @@ class Request { * * @param CurlBuilder $curlbuilder */ - public function __construct( CurlBuilder $curlbuilder ) + public function __construct(CurlBuilder $curlbuilder) { $this->curlbuilder = $curlbuilder; } @@ -60,7 +60,7 @@ public function __construct( CurlBuilder $curlbuilder ) * @param string $token * @return void */ - public function setAccessToken( $token ) + public function setAccessToken($token) { $this->access_token = $token; } @@ -73,12 +73,11 @@ public function setAccessToken( $token ) * @param array $parameters * @return Response */ - public function get( $endpoint, array $parameters = array() ) + public function get($endpoint, array $parameters = array()) { - if(!empty($parameters)) { + if (!empty($parameters)) { $path = sprintf("%s/?%s", $endpoint, http_build_query($parameters)); - } - else { + } else { $path = $endpoint; } @@ -93,9 +92,9 @@ public function get( $endpoint, array $parameters = array() ) * @param array $parameters * @return Response */ - public function post( $endpoint, array $parameters = array() ) + public function post($endpoint, array $parameters = array()) { - return $this->execute("POST", sprintf("%s%s", $this->host, $endpoint), $parameters ); + return $this->execute("POST", sprintf("%s%s", $this->host, $endpoint), $parameters); } /** @@ -106,9 +105,9 @@ public function post( $endpoint, array $parameters = array() ) * @param array $parameters * @return Response */ - public function delete( $endpoint, array $parameters = array() ) + public function delete($endpoint, array $parameters = array()) { - return $this->execute("DELETE", sprintf("%s%s", $this->host, $endpoint) . "/", $parameters ); + return $this->execute("DELETE", sprintf("%s%s", $this->host, $endpoint) . "/", $parameters); } /** @@ -119,9 +118,9 @@ public function delete( $endpoint, array $parameters = array() ) * @param array $parameters * @return Response */ - public function update( $endpoint, array $parameters = array() ) + public function update($endpoint, array $parameters = array()) { - return $this->execute("PATCH", sprintf("%s%s", $this->host, $endpoint) . "/", $parameters ); + return $this->execute("PATCH", sprintf("%s%s", $this->host, $endpoint) . "/", $parameters); } /** @@ -144,10 +143,10 @@ public function getHeaders() * @param array $headers * @return Response */ - public function execute( $method, $apiCall, array $parameters = array(), $headers = array() ) + public function execute($method, $apiCall, array $parameters = array(), $headers = array()) { // Check if the access token needs to be added - if($this->access_token != null){ + if ($this->access_token != null) { $headers = array_merge($headers, array( "Authorization: Bearer " . $this->access_token, "Content-ype: multipart/form-data", @@ -158,7 +157,7 @@ public function execute( $method, $apiCall, array $parameters = array(), $header $ch = $this->curlbuilder->create(); // Set default options - $ch->setOptions( array( + $ch->setOptions(array( CURLOPT_URL => $apiCall, CURLOPT_HTTPHEADER => $headers, CURLOPT_CONNECTTIMEOUT => 20, @@ -178,8 +177,9 @@ public function execute( $method, $apiCall, array $parameters = array(), $header CURLOPT_POSTFIELDS => $parameters ) ); - if(!class_exists("\CURLFile") && defined('CURLOPT_SAFE_UPLOAD')) - $ch->setOption( CURLOPT_SAFE_UPLOAD, false ); + if(!class_exists("\CURLFile") && defined('CURLOPT_SAFE_UPLOAD')) { + $ch->setOption( CURLOPT_SAFE_UPLOAD, false ); + } break; case 'DELETE': @@ -198,16 +198,16 @@ public function execute( $method, $apiCall, array $parameters = array(), $header $response_data = $ch->execute(); // Check if we have a valid response - if ( !$response_data || $ch->hasErrors() ) { - throw new PinterestException( 'Error: execute() - cURL error: ' . $ch->getErrors(), $ch->getErrorNumber() ); + if (!$response_data || $ch->hasErrors()) { + throw new PinterestException('Error: execute() - cURL error: ' . $ch->getErrors(), $ch->getErrorNumber()); } // Initiate the response $response = new Response($response_data, $ch); // Check the response code - if ( $response->getResponseCode() >= 400 ) { - throw new PinterestException( 'Pinterest error (code: ' . $response->getResponseCode() . ') with message: ' . $response->message, $response->getResponseCode() ); + if ($response->getResponseCode() >= 400) { + throw new PinterestException('Pinterest error (code: ' . $response->getResponseCode() . ') with message: ' . $response->message, $response->getResponseCode()); } $this->headers = $ch->getHeaders(); diff --git a/src/Pinterest/Transport/Response.php b/src/Pinterest/Transport/Response.php index 5c2799a..902fefa 100644 --- a/src/Pinterest/Transport/Response.php +++ b/src/Pinterest/Transport/Response.php @@ -13,11 +13,11 @@ use DirkGroenen\Pinterest\Utils\CurlBuilder; use DirkGroenen\Pinterest\Exceptions\PinterestException; - /** - * @property array $page - * @property array $data - * @property string $message - */ + /** + * @property array $page + * @property array $data + * @property string $message + */ class Response { /** @@ -37,16 +37,16 @@ class Response { /** * Constructor * - * @param array $response + * @param string $response * @param CurlBuilder $curl * @param curl $curl */ - public function __construct( $response, CurlBuilder $curl ) + public function __construct($response, CurlBuilder $curl) { $this->response = $response; $this->curl = $curl; - if( is_string($response) ){ + if (is_string($response)) { $this->response = $this->decodeString($response); } } @@ -58,7 +58,7 @@ public function __construct( $response, CurlBuilder $curl ) * @param string $response * @return array */ - private function decodeString( $response ) + private function decodeString($response) { return json_decode($response, true); } @@ -80,7 +80,7 @@ public function __get($key) * * @access public * @param string $key - * @return array + * @return boolean */ public function __isset($key) { diff --git a/src/Pinterest/Utils/CurlBuilder.php b/src/Pinterest/Utils/CurlBuilder.php index c57693d..a0813a2 100644 --- a/src/Pinterest/Utils/CurlBuilder.php +++ b/src/Pinterest/Utils/CurlBuilder.php @@ -10,8 +10,6 @@ namespace DirkGroenen\Pinterest\Utils; -use DirkGroenen\Pinterest\Exceptions\PinterestException; - class CurlBuilder { /** @@ -52,12 +50,12 @@ public function create() * * @access public * @param string $option - * @param mixed $value + * @param false|string $value * @return $this */ - public function setOption( $option, $value ) + public function setOption($option, $value) { - curl_setopt($this->curl, $option, $value ); + curl_setopt($this->curl, $option, $value); return $this; } @@ -69,7 +67,7 @@ public function setOption( $option, $value ) * @param array $options * @return $this */ - public function setOptions( array $options = [] ) + public function setOptions(array $options = []) { curl_setopt_array($this->curl, $options); @@ -80,7 +78,7 @@ public function setOptions( array $options = [] ) * Execute the curl request * * @access public - * @return mixed + * @return false|string */ public function execute() { @@ -91,7 +89,7 @@ public function execute() * Check if the curl request ended up with errors * * @access public - * @return boolean + * @return integer */ public function hasErrors() { @@ -158,17 +156,18 @@ public function close() * Parse string headers into array * * @access private - * @param array $headers + * @param string $headers * @return array */ private function parseHeaders($headers) { $result = array(); - foreach(explode("\n", $headers) as $row){ + foreach (explode("\n", $headers) as $row) { $header = explode(':', $row, 2); - if (count($header) == 2) - $result[$header[0]] = trim($header[1]); - else - $result[] = $header[0]; + if (count($header) == 2) { + $result[$header[0]] = trim($header[1]); + } else { + $result[] = $header[0]; + } } return $result; } @@ -180,7 +179,7 @@ private function parseHeaders($headers) { * * @see http://slopjong.de/2012/03/31/curl-follow-locations-with-safe_mode-enabled-or-open_basedir-set/ * @access private - * @return mixed + * @return false|string */ private function execFollow() { $mr = 5; @@ -189,8 +188,7 @@ private function execFollow() { if(ini_get("open_basedir") == "" && ini_get("safe_mode" == "Off")){ curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, $mr > 0); curl_setopt($this->curl, CURLOPT_MAXREDIRS, $mr); - } - else{ + } else{ $this->setOption(CURLOPT_FOLLOWLOCATION, false); if($CURLOPT_MAXREDIRS > 0){ @@ -202,7 +200,7 @@ private function execFollow() { curl_setopt($rch, CURLOPT_HEADER, true); curl_setopt($rch, CURLOPT_FORBID_REUSE, false); - do{ + do { curl_setopt($rch, CURLOPT_URL, $newurl); $response = curl_exec($rch); @@ -212,15 +210,13 @@ private function execFollow() { if(curl_errno($rch)){ $code = 0; - } - else{ + } else{ $code = curl_getinfo($rch, CURLINFO_HTTP_CODE); if ($code == 301 || $code == 302) { preg_match('/Location:(.*?)\n/i', $header, $matches); $newurl = trim(array_pop($matches)); - } - else{ + } else{ $code = 0; } } @@ -241,7 +237,7 @@ private function execFollow() { } } - if (!$body){ + if (!$body) { curl_setopt($this->curl, CURLOPT_HEADER, true); $response = curl_exec($this->curl); From 31605aa2fe80aaf81047fbbcd8d19e2dd92ea0fd Mon Sep 17 00:00:00 2001 From: Scrutinizer Auto-Fixer Date: Sat, 9 Jan 2016 16:01:40 +0000 Subject: [PATCH 46/85] Scrutinizer Auto-Fixes This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com --- src/Pinterest/Endpoints/Pins.php | 3 +-- src/Pinterest/Models/Collection.php | 14 ++++++-------- src/Pinterest/Pinterest.php | 10 ++++++---- src/Pinterest/Transport/Request.php | 16 ++++++++-------- src/Pinterest/Utils/CurlBuilder.php | 18 +++++++++--------- 5 files changed, 30 insertions(+), 31 deletions(-) diff --git a/src/Pinterest/Endpoints/Pins.php b/src/Pinterest/Endpoints/Pins.php index 37e74b3..44b700c 100644 --- a/src/Pinterest/Endpoints/Pins.php +++ b/src/Pinterest/Endpoints/Pins.php @@ -58,8 +58,7 @@ public function create(array $data) if (array_key_exists("image", $data)) { if (class_exists("\CURLFile")) { $data["image"] = new \CURLFile($data['image']); - } - else { + } else { $data["image"] = '@' . $data['image']; } } diff --git a/src/Pinterest/Models/Collection.php b/src/Pinterest/Models/Collection.php index c743acd..4eef3b7 100644 --- a/src/Pinterest/Models/Collection.php +++ b/src/Pinterest/Models/Collection.php @@ -67,19 +67,18 @@ public function __construct(Pinterest $master, $items, $model) { // Create class path $this->model = ucfirst(strtolower($model)); - if (!class_exists("\\DirkGroenen\\Pinterest\\Models\\" . $this->model)) - throw new InvalidModelException; + if (!class_exists("\\DirkGroenen\\Pinterest\\Models\\" . $this->model)) { + throw new InvalidModelException; + } // Get items and response instance if (is_array($items)) { $this->response = null; $this->items = $items; - } - else if ($items instanceof \DirkGroenen\Pinterest\Transport\Response) { + } else if ($items instanceof \DirkGroenen\Pinterest\Transport\Response) { $this->response = $items; $this->items = $items->data; - } - else { + } else { throw new PinterestException("$items needs to be an instance of Transport\Response or an array."); } @@ -89,8 +88,7 @@ public function __construct(Pinterest $master, $items, $model) { // Add pagination object if (isset($this->response->page) && !empty($this->response->page['next'])) { $this->pagination = $this->response->page; - } - else { + } else { $this->pagination = false; } } diff --git a/src/Pinterest/Pinterest.php b/src/Pinterest/Pinterest.php index 5d922c8..c7f89ee 100644 --- a/src/Pinterest/Pinterest.php +++ b/src/Pinterest/Pinterest.php @@ -54,8 +54,9 @@ class Pinterest { */ public function __construct($client_id, $client_secret, $curlbuilder = null) { - if ($curlbuilder == null) - $curlbuilder = new CurlBuilder(); + if ($curlbuilder == null) { + $curlbuilder = new CurlBuilder(); + } // Create new instance of Transport\Request $this->request = new Request($curlbuilder); @@ -80,8 +81,9 @@ public function __get($endpoint) // Check if an instance has already been initiated if (!isset($this->cachedEndpoints[$endpoint])) { // Check endpoint existence - if (!class_exists($class)) - throw new InvalidEndpointException; + if (!class_exists($class)) { + throw new InvalidEndpointException; + } // Create a reflection of the called class and initialize it // with a reference to the request class diff --git a/src/Pinterest/Transport/Request.php b/src/Pinterest/Transport/Request.php index 1e6a520..2bb633b 100644 --- a/src/Pinterest/Transport/Request.php +++ b/src/Pinterest/Transport/Request.php @@ -167,29 +167,29 @@ public function execute($method, $apiCall, array $parameters = array(), $headers CURLOPT_SSL_VERIFYHOST => false, CURLOPT_HEADER => false, CURLINFO_HEADER_OUT => true - ) ); + )); switch ($method) { case 'POST': - $ch->setOptions( array( + $ch->setOptions(array( CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POST => count($parameters), CURLOPT_POSTFIELDS => $parameters - ) ); + )); - if(!class_exists("\CURLFile") && defined('CURLOPT_SAFE_UPLOAD')) { - $ch->setOption( CURLOPT_SAFE_UPLOAD, false ); + if (!class_exists("\CURLFile") && defined('CURLOPT_SAFE_UPLOAD')) { + $ch->setOption(CURLOPT_SAFE_UPLOAD, false); } break; case 'DELETE': - $ch->setOption( CURLOPT_CUSTOMREQUEST, "DELETE" ); + $ch->setOption(CURLOPT_CUSTOMREQUEST, "DELETE"); break; case 'PATCH': - $ch->setOption( CURLOPT_CUSTOMREQUEST, "PATCH" ); + $ch->setOption(CURLOPT_CUSTOMREQUEST, "PATCH"); break; default: - $ch->setOption( CURLOPT_CUSTOMREQUEST, "GET" ); + $ch->setOption(CURLOPT_CUSTOMREQUEST, "GET"); break; } diff --git a/src/Pinterest/Utils/CurlBuilder.php b/src/Pinterest/Utils/CurlBuilder.php index a0813a2..c331229 100644 --- a/src/Pinterest/Utils/CurlBuilder.php +++ b/src/Pinterest/Utils/CurlBuilder.php @@ -185,13 +185,13 @@ private function execFollow() { $mr = 5; $body = null; - if(ini_get("open_basedir") == "" && ini_get("safe_mode" == "Off")){ + if (ini_get("open_basedir") == "" && ini_get("safe_mode" == "Off")) { curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, $mr > 0); curl_setopt($this->curl, CURLOPT_MAXREDIRS, $mr); - } else{ + } else { $this->setOption(CURLOPT_FOLLOWLOCATION, false); - if($CURLOPT_MAXREDIRS > 0){ + if ($CURLOPT_MAXREDIRS > 0) { $original_url = $this->getInfo(CURLINFO_EFFECTIVE_URL); $newurl = $original_url; @@ -208,24 +208,24 @@ private function execFollow() { $header = substr($response, 0, $header_size); $body = substr($response, $header_size); - if(curl_errno($rch)){ + if (curl_errno($rch)) { $code = 0; - } else{ + } else { $code = curl_getinfo($rch, CURLINFO_HTTP_CODE); if ($code == 301 || $code == 302) { preg_match('/Location:(.*?)\n/i', $header, $matches); $newurl = trim(array_pop($matches)); - } else{ + } else { $code = 0; } } - } while($code && --$mr); + } while ($code && --$mr); curl_close($rch); - if(!$mr){ - if ($mr === null){ + if (!$mr) { + if ($mr === null) { trigger_error('Too many redirects.', E_USER_WARNING); } From da6f893b8ccf97f49c6b61b9eca9905bcb3c950a Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Sat, 9 Jan 2016 17:05:22 +0100 Subject: [PATCH 47/85] Fix weird autofix indenting --- src/Pinterest/Models/Collection.php | 4 ++-- src/Pinterest/Pinterest.php | 4 ++-- src/Pinterest/Transport/Request.php | 2 +- src/Pinterest/Utils/CurlBuilder.php | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Pinterest/Models/Collection.php b/src/Pinterest/Models/Collection.php index 4eef3b7..97f768e 100644 --- a/src/Pinterest/Models/Collection.php +++ b/src/Pinterest/Models/Collection.php @@ -68,7 +68,7 @@ public function __construct(Pinterest $master, $items, $model) { $this->model = ucfirst(strtolower($model)); if (!class_exists("\\DirkGroenen\\Pinterest\\Models\\" . $this->model)) { - throw new InvalidModelException; + throw new InvalidModelException; } // Get items and response instance @@ -79,7 +79,7 @@ public function __construct(Pinterest $master, $items, $model) { $this->response = $items; $this->items = $items->data; } else { - throw new PinterestException("$items needs to be an instance of Transport\Response or an array."); + throw new PinterestException("$items needs to be an instance of Transport\Response or an array."); } // Transform the raw collection data to models diff --git a/src/Pinterest/Pinterest.php b/src/Pinterest/Pinterest.php index c7f89ee..de96734 100644 --- a/src/Pinterest/Pinterest.php +++ b/src/Pinterest/Pinterest.php @@ -55,7 +55,7 @@ class Pinterest { public function __construct($client_id, $client_secret, $curlbuilder = null) { if ($curlbuilder == null) { - $curlbuilder = new CurlBuilder(); + $curlbuilder = new CurlBuilder(); } // Create new instance of Transport\Request @@ -82,7 +82,7 @@ public function __get($endpoint) if (!isset($this->cachedEndpoints[$endpoint])) { // Check endpoint existence if (!class_exists($class)) { - throw new InvalidEndpointException; + throw new InvalidEndpointException; } // Create a reflection of the called class and initialize it diff --git a/src/Pinterest/Transport/Request.php b/src/Pinterest/Transport/Request.php index 2bb633b..225ec0d 100644 --- a/src/Pinterest/Transport/Request.php +++ b/src/Pinterest/Transport/Request.php @@ -178,7 +178,7 @@ public function execute($method, $apiCall, array $parameters = array(), $headers )); if (!class_exists("\CURLFile") && defined('CURLOPT_SAFE_UPLOAD')) { - $ch->setOption(CURLOPT_SAFE_UPLOAD, false); + $ch->setOption(CURLOPT_SAFE_UPLOAD, false); } break; diff --git a/src/Pinterest/Utils/CurlBuilder.php b/src/Pinterest/Utils/CurlBuilder.php index c331229..cb7ba95 100644 --- a/src/Pinterest/Utils/CurlBuilder.php +++ b/src/Pinterest/Utils/CurlBuilder.php @@ -164,9 +164,9 @@ private function parseHeaders($headers) { foreach (explode("\n", $headers) as $row) { $header = explode(':', $row, 2); if (count($header) == 2) { - $result[$header[0]] = trim($header[1]); + $result[$header[0]] = trim($header[1]); } else { - $result[] = $header[0]; + $result[] = $header[0]; } } return $result; From 2e76477a77eaadf339b6efa75f8ae74b88cfd063 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Sat, 9 Jan 2016 17:06:55 +0100 Subject: [PATCH 48/85] Added changes for next release --- CHANGELOG.md | 4 + coverage-report | 582 ------------------------------------------------ 2 files changed, 4 insertions(+), 582 deletions(-) delete mode 100644 coverage-report diff --git a/CHANGELOG.md b/CHANGELOG.md index c164946..c0d2827 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### x.x.x (UNRELEASED) + +- A lot of code cleanup based on Scruntinizer + ### 0.2.5 (09-01-2016) - Fixed disabling CURL safe_mode issue in PHP 7.0 [#21](https://github.com/dirkgroenen/Pinterest-API-PHP/issues/21) diff --git a/coverage-report b/coverage-report deleted file mode 100644 index ac193f4..0000000 --- a/coverage-report +++ /dev/null @@ -1,582 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From 960b14d9d9837911ee3cfdcb32aec70cc3fb4bc0 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Sat, 9 Jan 2016 17:22:16 +0100 Subject: [PATCH 49/85] Removed double batch --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index ba18549..14f80b1 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,6 @@ [![](https://travis-ci.org/dirkgroenen/Pinterest-API-PHP.svg)](https://travis-ci.org/dirkgroenen/Pinterest-API-PHP) [![](https://img.shields.io/scrutinizer/g/dirkgroenen/Pinterest-API-PHP.svg)](https://scrutinizer-ci.com/g/dirkgroenen/Pinterest-API-PHP/?branch=master) -[![](https://img.shields.io/scrutinizer/g/dirkgroenen/Pinterest-API-PHP.svg)](https://scrutinizer-ci.com/g/dirkgroenen/Pinterest-API-PHP/?branch=master) [![](https://img.shields.io/scrutinizer/coverage/g/dirkgroenen/Pinterest-API-PHP.svg)](https://scrutinizer-ci.com/g/dirkgroenen/Pinterest-API-PHP/?branch=master) [![Packagist](https://img.shields.io/packagist/v/dirkgroenen/pinterest-api-php.svg)](https://packagist.org/packages/dirkgroenen/pinterest-api-php) [![Support me with some coffee](https://img.shields.io/badge/donate-paypal-orange.svg)](https://www.paypal.me/dirkgroenen) From a60ca763581263e9cf3d10709f3a9902df8db429 Mon Sep 17 00:00:00 2001 From: James Morley Date: Sat, 9 Jan 2016 16:44:17 +0000 Subject: [PATCH 50/85] Added orignal_link to available object keys --- src/Pinterest/Models/Pin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Pinterest/Models/Pin.php b/src/Pinterest/Models/Pin.php index 732c262..698c9b4 100644 --- a/src/Pinterest/Models/Pin.php +++ b/src/Pinterest/Models/Pin.php @@ -17,6 +17,6 @@ class Pin extends Model { * * @var array */ - protected $fillable = ["id", "link", "url", "creator", "board", "created_at", "note", "color", "counts", "media", "attribution", "image", "metadata"]; + protected $fillable = ["id", "link", "url", "creator", "board", "created_at", "note", "color", "counts", "media", "attribution", "image", "metadata", "original_link"]; } From 60835ac3919e1591ab0dedaf73d9aa3a8fab61c0 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Sat, 9 Jan 2016 20:39:07 +0100 Subject: [PATCH 51/85] Added changes --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0d2827..249cde3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ -### x.x.x (UNRELEASED) +### 0.2.6 (UNRELEASED) - A lot of code cleanup based on Scruntinizer +- Added `original_url` attribute to Pin model [#24](https://github.com/dirkgroenen/Pinterest-API-PHP/pull/24) ### 0.2.5 (09-01-2016) From 4d5124775da861e528b00378d19596795ac328d0 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Sat, 9 Jan 2016 20:42:56 +0100 Subject: [PATCH 52/85] Fixed some code issues --- src/Pinterest/Auth/PinterestOAuth.php | 4 ++-- src/Pinterest/Endpoints/Boards.php | 4 ++-- src/Pinterest/Models/Model.php | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Pinterest/Auth/PinterestOAuth.php b/src/Pinterest/Auth/PinterestOAuth.php index daf32ae..60f1abd 100644 --- a/src/Pinterest/Auth/PinterestOAuth.php +++ b/src/Pinterest/Auth/PinterestOAuth.php @@ -40,7 +40,7 @@ class PinterestOAuth { /** * A reference to the request instance * - * @var Transport\Request + * @var Request */ private $request; @@ -54,7 +54,7 @@ class PinterestOAuth { * * @param string $client_id * @param string $client_secret - * @param Request $request + * @param Request $request */ public function __construct($client_id, $client_secret, $request) { diff --git a/src/Pinterest/Endpoints/Boards.php b/src/Pinterest/Endpoints/Boards.php index a2d526f..c55b5ec 100644 --- a/src/Pinterest/Endpoints/Boards.php +++ b/src/Pinterest/Endpoints/Boards.php @@ -18,8 +18,8 @@ class Boards extends Endpoint { * Find the provided board * * @access public - * @param string $board_id - * @param array $data + * @param string $board_id + * @param array $data * @throws Exceptions/PinterestExceptions * @return Board */ diff --git a/src/Pinterest/Models/Model.php b/src/Pinterest/Models/Model.php index d367cfa..a38e8b5 100644 --- a/src/Pinterest/Models/Model.php +++ b/src/Pinterest/Models/Model.php @@ -40,8 +40,8 @@ class Model implements \JsonSerializable { /** * Create a new model instance * - * @param Pinterest $master - * @param array|Response $modeldata + * @param Pinterest $master + * @param mixed $modeldata */ public function __construct( Pinterest $master, $modeldata = null ) { From a5437490a581ded2ac403b69b7e5c6b3eb362f65 Mon Sep 17 00:00:00 2001 From: German Popoter Date: Fri, 22 Jan 2016 17:57:34 -0500 Subject: [PATCH 53/85] Fixing a typo Adding a `t` to `Content-type` --- src/Pinterest/Transport/Request.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Pinterest/Transport/Request.php b/src/Pinterest/Transport/Request.php index 225ec0d..cda03f2 100644 --- a/src/Pinterest/Transport/Request.php +++ b/src/Pinterest/Transport/Request.php @@ -149,7 +149,7 @@ public function execute($method, $apiCall, array $parameters = array(), $headers if ($this->access_token != null) { $headers = array_merge($headers, array( "Authorization: Bearer " . $this->access_token, - "Content-ype: multipart/form-data", + "Content-type: multipart/form-data", )); } @@ -218,4 +218,4 @@ public function execute($method, $apiCall, array $parameters = array(), $headers return $response; } -} \ No newline at end of file +} From 0cd4df68f9e872da8e9f29590ebbf14ab9c4fd57 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Mon, 1 Feb 2016 10:51:40 +0100 Subject: [PATCH 54/85] Add changes --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 249cde3..e84f5a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ -### 0.2.6 (UNRELEASED) +### 0.2.6 (01-02-2016) - A lot of code cleanup based on Scruntinizer - Added `original_url` attribute to Pin model [#24](https://github.com/dirkgroenen/Pinterest-API-PHP/pull/24) +- Fixed typo in header [#27](https://github.com/dirkgroenen/Pinterest-API-PHP/pull/27) ### 0.2.5 (09-01-2016) @@ -10,7 +11,7 @@ ### 0.2.3 (03-01-2016) - Add error codes to PinterestException ( [#17](https://github.com/dirkgroenen/Pinterest-API-PHP/issues/17) ) -- Remove `whoops` as dependency +- Remove `whoops` as dependency ### 0.2.2 (31-12-2015) From e4fa2bcccf8e6dc52d728a8d2490dc99d1ef5299 Mon Sep 17 00:00:00 2001 From: Scrutinizer Auto-Fixer Date: Mon, 1 Feb 2016 09:57:01 +0000 Subject: [PATCH 55/85] Scrutinizer Auto-Fixes This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com --- src/Pinterest/Auth/PinterestOAuth.php | 2 +- src/Pinterest/Models/Model.php | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Pinterest/Auth/PinterestOAuth.php b/src/Pinterest/Auth/PinterestOAuth.php index 60f1abd..dc8b85b 100644 --- a/src/Pinterest/Auth/PinterestOAuth.php +++ b/src/Pinterest/Auth/PinterestOAuth.php @@ -127,7 +127,7 @@ public function setState($state) * Change the code for an access_token * * @param string $code - * @return array + * @return \DirkGroenen\Pinterest\Transport\Response */ public function getOAuthToken($code) { diff --git a/src/Pinterest/Models/Model.php b/src/Pinterest/Models/Model.php index a38e8b5..e08ebaf 100644 --- a/src/Pinterest/Models/Model.php +++ b/src/Pinterest/Models/Model.php @@ -79,11 +79,11 @@ public function __get($key) */ public function __set($key, $value) { - if($this->isFillable($key)){ + if ($this->isFillable($key)) { $this->attributes[$key] = $value; } - else{ - throw new PinterestException( sprintf("%s is not a fillable attribute.", $key) ); + else { + throw new PinterestException(sprintf("%s is not a fillable attribute.", $key)); } } @@ -107,8 +107,8 @@ public function __isset($key) */ private function fill(array $attributes) { - foreach($attributes as $key => $value){ - if($this->isFillable($key)){ + foreach ($attributes as $key => $value) { + if ($this->isFillable($key)) { $this->attributes[$key] = $value; } } From 4e158b59f5236535aa63177ba79701a187e9a518 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Mon, 1 Feb 2016 10:58:39 +0100 Subject: [PATCH 56/85] Cleanup --- src/Pinterest/Transport/Response.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Pinterest/Transport/Response.php b/src/Pinterest/Transport/Response.php index 902fefa..3d3a511 100644 --- a/src/Pinterest/Transport/Response.php +++ b/src/Pinterest/Transport/Response.php @@ -11,7 +11,6 @@ namespace DirkGroenen\Pinterest\Transport; use DirkGroenen\Pinterest\Utils\CurlBuilder; -use DirkGroenen\Pinterest\Exceptions\PinterestException; /** * @property array $page From ad2a04d04aaae5d7e33440ac554d361207d6f138 Mon Sep 17 00:00:00 2001 From: Scrutinizer Auto-Fixer Date: Mon, 1 Feb 2016 10:25:40 +0000 Subject: [PATCH 57/85] Scrutinizer Auto-Fixes This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com --- src/Pinterest/Models/Model.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Pinterest/Models/Model.php b/src/Pinterest/Models/Model.php index e08ebaf..dddcf81 100644 --- a/src/Pinterest/Models/Model.php +++ b/src/Pinterest/Models/Model.php @@ -43,15 +43,15 @@ class Model implements \JsonSerializable { * @param Pinterest $master * @param mixed $modeldata */ - public function __construct( Pinterest $master, $modeldata = null ) + public function __construct(Pinterest $master, $modeldata = null) { $this->master = $master; // Fill the model - if( is_array($modeldata) ){ + if (is_array($modeldata)) { $this->fill($modeldata); } - else if( $modeldata instanceof \DirkGroenen\Pinterest\Transport\Response ){ + else if ($modeldata instanceof \DirkGroenen\Pinterest\Transport\Response) { $this->fill($modeldata->data); } } @@ -81,8 +81,7 @@ public function __set($key, $value) { if ($this->isFillable($key)) { $this->attributes[$key] = $value; - } - else { + } else { throw new PinterestException(sprintf("%s is not a fillable attribute.", $key)); } } @@ -136,7 +135,7 @@ public function toArray() { $array = array(); - foreach($this->fillable as $key){ + foreach ($this->fillable as $key) { $array[$key] = $this->{$key}; } From c9ad01993dec5c4cdb34d71795d6e869adb453d5 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Mon, 1 Feb 2016 16:04:47 +0100 Subject: [PATCH 58/85] Fix wrong var, fixes #30 --- src/Pinterest/Utils/CurlBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Pinterest/Utils/CurlBuilder.php b/src/Pinterest/Utils/CurlBuilder.php index cb7ba95..9403581 100644 --- a/src/Pinterest/Utils/CurlBuilder.php +++ b/src/Pinterest/Utils/CurlBuilder.php @@ -191,7 +191,7 @@ private function execFollow() { } else { $this->setOption(CURLOPT_FOLLOWLOCATION, false); - if ($CURLOPT_MAXREDIRS > 0) { + if ($mr > 0) { $original_url = $this->getInfo(CURLINFO_EFFECTIVE_URL); $newurl = $original_url; From 3758f0c9f9529c4174929ab82b22fd0f13022147 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Mon, 1 Feb 2016 16:05:27 +0100 Subject: [PATCH 59/85] Add change --- CHANGELOG.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e84f5a6..1091afa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +### 0.2.7 (01-02-2016) + +- Fix wrong variable name +[#30](https://github.com/dirkgroenen/Pinterest-API-PHP/issues/30) + ### 0.2.6 (01-02-2016) - A lot of code cleanup based on Scruntinizer @@ -25,4 +30,4 @@ - Changed default authentication response_type to `code` ( #4 / #7 / #14 ) - Fixed `getAccessToken()` path -- Added fallback for servers using open_basedir ( #9 ) \ No newline at end of file +- Added fallback for servers using open_basedir ( #9 ) From 44722c5e4553661d67f29e16b1f9fd3e0a166d06 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Tue, 2 Feb 2016 15:44:23 +0100 Subject: [PATCH 60/85] Add demo --- demo/.env.example | 2 ++ demo/.gitignore | 1 + demo/boot.php | 26 ++++++++++++++++++++++++++ demo/callback.php | 13 +++++++++++++ demo/index.php | 10 ++++++++++ 5 files changed, 52 insertions(+) create mode 100644 demo/.env.example create mode 100644 demo/.gitignore create mode 100644 demo/boot.php create mode 100644 demo/callback.php create mode 100644 demo/index.php diff --git a/demo/.env.example b/demo/.env.example new file mode 100644 index 0000000..778a082 --- /dev/null +++ b/demo/.env.example @@ -0,0 +1,2 @@ +APP_ID= +APP_SECRET= \ No newline at end of file diff --git a/demo/.gitignore b/demo/.gitignore new file mode 100644 index 0000000..2eea525 --- /dev/null +++ b/demo/.gitignore @@ -0,0 +1 @@ +.env \ No newline at end of file diff --git a/demo/boot.php b/demo/boot.php new file mode 100644 index 0000000..2c02d9f --- /dev/null +++ b/demo/boot.php @@ -0,0 +1,26 @@ +load(); + + $pinterest = new DirkGroenen\Pinterest\Pinterest(getenv("APP_ID"), getenv("APP_SECRET")); + + if (isset($_GET["code"])) { + $token = $pinterest->auth->getOAuthToken($_GET["code"]); + $pinterest->auth->setOAuthToken($token->access_token); + + setcookie("access_token", $token->access_token); + } + else if (isset($_GET["access_token"])) { + $pinterest->auth->setOAuthToken($_GET["access_token"]); + } + else if (isset($_COOKIE["access_token"])) { + $pinterest->auth->setOAuthToken($_COOKIE["access_token"]); + } + +?> \ No newline at end of file diff --git a/demo/callback.php b/demo/callback.php new file mode 100644 index 0000000..c52702b --- /dev/null +++ b/demo/callback.php @@ -0,0 +1,13 @@ + + + + + + +

Hey you!

+

$pinterest->boards->create()

+ + users->getMeBoards(); ?> + + + \ No newline at end of file diff --git a/demo/index.php b/demo/index.php new file mode 100644 index 0000000..5cfa86e --- /dev/null +++ b/demo/index.php @@ -0,0 +1,10 @@ + + + + + + +

Login with Pinterest

+

Use this link to login with your Pinterest account.

+ + \ No newline at end of file From 35f790253f6430387a485c389c69e42688979a86 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Tue, 2 Feb 2016 15:44:55 +0100 Subject: [PATCH 61/85] Cleanup execfollow and fix error handling, fixes #31 --- .gitignore | 2 - composer.json | 3 +- composer.lock | 116 ++++++++++++++++++++------- src/Pinterest/Transport/Request.php | 4 +- src/Pinterest/Transport/Response.php | 12 +++ src/Pinterest/Utils/CurlBuilder.php | 34 ++++---- 6 files changed, 119 insertions(+), 52 deletions(-) diff --git a/.gitignore b/.gitignore index c28e66f..b3ffa78 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,2 @@ README.html -/demo/ /vendor/ -/tests/Pinterest/env diff --git a/composer.json b/composer.json index ddef230..287c19d 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,8 @@ "php": ">=5.4" }, "require-dev": { - "phpunit/phpunit": "4.7.*" + "phpunit/phpunit": "4.7.*", + "vlucas/phpdotenv": "^2.2" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 10a3a69..f31a220 100644 --- a/composer.lock +++ b/composer.lock @@ -4,65 +4,59 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "2689f6158455cc0bb46a3effa931c3b1", + "hash": "c6bcc662f55eb3343d7da43d147d12fb", + "content-hash": "8603e6707b4cb0440d66d2f7f02eb9a1", "packages": [ { - "name": "filp/whoops", - "version": "1.1.7", + "name": "vlucas/phpdotenv", + "version": "v2.2.0", "source": { "type": "git", - "url": "https://github.com/filp/whoops.git", - "reference": "72538eeb70bbfb11964412a3d098d109efd012f7" + "url": "https://github.com/vlucas/phpdotenv.git", + "reference": "9caf304153dc2288e4970caec6f1f3b3bc205412" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/filp/whoops/zipball/72538eeb70bbfb11964412a3d098d109efd012f7", - "reference": "72538eeb70bbfb11964412a3d098d109efd012f7", + "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/9caf304153dc2288e4970caec6f1f3b3bc205412", + "reference": "9caf304153dc2288e4970caec6f1f3b3bc205412", "shasum": "" }, "require": { - "php": ">=5.3.0" + "php": ">=5.3.9" }, "require-dev": { - "mockery/mockery": "0.9.*" + "phpunit/phpunit": "^4.8|^5.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.2-dev" + "dev-master": "2.2-dev" } }, "autoload": { - "psr-0": { - "Whoops": "src/" - }, - "classmap": [ - "src/deprecated" - ] + "psr-4": { + "Dotenv\\": "src/" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ - "MIT" + "BSD" ], "authors": [ { - "name": "Filipe Dobreira", - "homepage": "https://github.com/filp", - "role": "Developer" + "name": "Vance Lucas", + "email": "vance@vancelucas.com", + "homepage": "http://www.vancelucas.com" } ], - "description": "php error handling for cool kids", - "homepage": "https://github.com/filp/whoops", + "description": "Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.", + "homepage": "http://github.com/vlucas/phpdotenv", "keywords": [ - "error", - "exception", - "handling", - "library", - "silex-provider", - "whoops", - "zf2" + "dotenv", + "env", + "environment" ], - "time": "2015-06-29 05:42:04" + "time": "2015-12-29 15:10:30" } ], "packages-dev": [ @@ -120,6 +114,64 @@ ], "time": "2015-06-14 21:17:01" }, + { + "name": "filp/whoops", + "version": "1.1.7", + "source": { + "type": "git", + "url": "https://github.com/filp/whoops.git", + "reference": "72538eeb70bbfb11964412a3d098d109efd012f7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/filp/whoops/zipball/72538eeb70bbfb11964412a3d098d109efd012f7", + "reference": "72538eeb70bbfb11964412a3d098d109efd012f7", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "mockery/mockery": "0.9.*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2-dev" + } + }, + "autoload": { + "psr-0": { + "Whoops": "src/" + }, + "classmap": [ + "src/deprecated" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Filipe Dobreira", + "homepage": "https://github.com/filp", + "role": "Developer" + } + ], + "description": "php error handling for cool kids", + "homepage": "https://github.com/filp/whoops", + "keywords": [ + "error", + "exception", + "handling", + "library", + "silex-provider", + "whoops", + "zf2" + ], + "time": "2015-06-29 05:42:04" + }, { "name": "phpdocumentor/reflection-docblock", "version": "2.0.4", @@ -1023,6 +1075,8 @@ "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, - "platform": [], + "platform": { + "php": ">=5.4" + }, "platform-dev": [] } diff --git a/src/Pinterest/Transport/Request.php b/src/Pinterest/Transport/Request.php index cda03f2..a7f477a 100644 --- a/src/Pinterest/Transport/Request.php +++ b/src/Pinterest/Transport/Request.php @@ -207,8 +207,10 @@ public function execute($method, $apiCall, array $parameters = array(), $headers // Check the response code if ($response->getResponseCode() >= 400) { - throw new PinterestException('Pinterest error (code: ' . $response->getResponseCode() . ') with message: ' . $response->message, $response->getResponseCode()); + throw new PinterestException('Pinterest error (code: ' . $response->getResponseCode() . ') with message: ' . $response->getMessage(), $response->getResponseCode()); } + + // Get headers from last request $this->headers = $ch->getHeaders(); // Close curl resource diff --git a/src/Pinterest/Transport/Response.php b/src/Pinterest/Transport/Response.php index 3d3a511..eada426 100644 --- a/src/Pinterest/Transport/Response.php +++ b/src/Pinterest/Transport/Response.php @@ -86,6 +86,18 @@ public function __isset($key) return isset($this->response[$key]); } + /** + * Returns the error message which should normaly + * by located in the response->message key, but can + * also be localed in the response->error key. + * + * @return string + */ + public function getMessage() + { + return (isset($this->message)) ? $this->message : $this->error; + } + /** * Get the response code from the request * diff --git a/src/Pinterest/Utils/CurlBuilder.php b/src/Pinterest/Utils/CurlBuilder.php index 9403581..1575220 100644 --- a/src/Pinterest/Utils/CurlBuilder.php +++ b/src/Pinterest/Utils/CurlBuilder.php @@ -186,8 +186,10 @@ private function execFollow() { $body = null; if (ini_get("open_basedir") == "" && ini_get("safe_mode" == "Off")) { - curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, $mr > 0); - curl_setopt($this->curl, CURLOPT_MAXREDIRS, $mr); + $this->setOptions(array( + CURLOPT_FOLLOWLOCATION => $mr > 0, + CURLOPT_MAXREDIRS => $mr + )); } else { $this->setOption(CURLOPT_FOLLOWLOCATION, false); @@ -195,23 +197,24 @@ private function execFollow() { $original_url = $this->getInfo(CURLINFO_EFFECTIVE_URL); $newurl = $original_url; - $rch = curl_copy_handle($this->curl); - - curl_setopt($rch, CURLOPT_HEADER, true); - curl_setopt($rch, CURLOPT_FORBID_REUSE, false); + $this->setOptions(array( + CURLOPT_HEADER => true, + CURLOPT_FORBID_REUSE => false + )); do { - curl_setopt($rch, CURLOPT_URL, $newurl); - $response = curl_exec($rch); + $this->setOption(CURLOPT_URL, $newurl); + + $response = curl_exec($this->curl); - $header_size = curl_getinfo($rch, CURLINFO_HEADER_SIZE); + $header_size = $this->getInfo(CURLINFO_HEADER_SIZE); $header = substr($response, 0, $header_size); $body = substr($response, $header_size); - if (curl_errno($rch)) { + if ($this->getErrorNumber()) { $code = 0; } else { - $code = curl_getinfo($rch, CURLINFO_HTTP_CODE); + $code = $this->getInfo(CURLINFO_HTTP_CODE); if ($code == 301 || $code == 302) { preg_match('/Location:(.*?)\n/i', $header, $matches); @@ -222,8 +225,6 @@ private function execFollow() { } } while ($code && --$mr); - curl_close($rch); - if (!$mr) { if ($mr === null) { trigger_error('Too many redirects.', E_USER_WARNING); @@ -231,17 +232,16 @@ private function execFollow() { return false; } - $this->setOption(CURLOPT_URL, $newurl); $this->headers = $this->parseHeaders($header); } } if (!$body) { - curl_setopt($this->curl, CURLOPT_HEADER, true); - $response = curl_exec($this->curl); + $this->setOption(CURLOPT_HEADER, true); + $response = $this->execute(); - $header_size = curl_getinfo($rch, CURLINFO_HEADER_SIZE); + $header_size = $this->getInfo(CURLINFO_HEADER_SIZE); $header = substr($response, 0, $header_size); $body = substr($response, $header_size); From 0a4cf0f42a830a2173320a71b9664737c79ad56b Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Tue, 2 Feb 2016 15:45:41 +0100 Subject: [PATCH 62/85] Add changes --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1091afa..a2fdbea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ +### 0.2.8 (02-02-2016) + +- Fix Curl execFollow and error handling [#31](https://github.com/dirkgroenen/Pinterest-API-PHP/issues/31) + ### 0.2.7 (01-02-2016) -- Fix wrong variable name +- Fix wrong variable name [#30](https://github.com/dirkgroenen/Pinterest-API-PHP/issues/30) ### 0.2.6 (01-02-2016) From 74b0c2a250a1651d78997559fcab4742bd8c2e66 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Tue, 2 Feb 2016 17:28:27 +0100 Subject: [PATCH 63/85] Create board on callback --- demo/callback.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/demo/callback.php b/demo/callback.php index c52702b..e69c145 100644 --- a/demo/callback.php +++ b/demo/callback.php @@ -7,7 +7,9 @@

Hey you!

$pinterest->boards->create()

- users->getMeBoards(); ?> + boards->create(array( + "name" => "Test from Pinterest API" + )); ?> \ No newline at end of file From 0c8efdb7ed19ce2676eccbfc3ceecc45a423e167 Mon Sep 17 00:00:00 2001 From: Scrutinizer Auto-Fixer Date: Tue, 2 Feb 2016 16:32:22 +0000 Subject: [PATCH 64/85] Scrutinizer Auto-Fixes This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com --- demo/boot.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/demo/boot.php b/demo/boot.php index 2c02d9f..3b87ec0 100644 --- a/demo/boot.php +++ b/demo/boot.php @@ -15,11 +15,9 @@ $pinterest->auth->setOAuthToken($token->access_token); setcookie("access_token", $token->access_token); - } - else if (isset($_GET["access_token"])) { + } else if (isset($_GET["access_token"])) { $pinterest->auth->setOAuthToken($_GET["access_token"]); - } - else if (isset($_COOKIE["access_token"])) { + } else if (isset($_COOKIE["access_token"])) { $pinterest->auth->setOAuthToken($_COOKIE["access_token"]); } From c4023ecb59c1aec7ead89f0b9b70e45e28e36981 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Fri, 5 Feb 2016 16:25:42 +0100 Subject: [PATCH 65/85] Change board ID to boardname --- README.md | 46 +++++++++++++++++++++++----------------------- demo/callback.php | 8 +++++--- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 14f80b1..e946643 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -## ![](http://i.imgur.com/cacgQlq.png) Pinterest API - PHP +## ![](http://i.imgur.com/cacgQlq.png) Pinterest API - PHP -[![](https://travis-ci.org/dirkgroenen/Pinterest-API-PHP.svg)](https://travis-ci.org/dirkgroenen/Pinterest-API-PHP) -[![](https://img.shields.io/scrutinizer/g/dirkgroenen/Pinterest-API-PHP.svg)](https://scrutinizer-ci.com/g/dirkgroenen/Pinterest-API-PHP/?branch=master) -[![](https://img.shields.io/scrutinizer/coverage/g/dirkgroenen/Pinterest-API-PHP.svg)](https://scrutinizer-ci.com/g/dirkgroenen/Pinterest-API-PHP/?branch=master) -[![Packagist](https://img.shields.io/packagist/v/dirkgroenen/pinterest-api-php.svg)](https://packagist.org/packages/dirkgroenen/pinterest-api-php) +[![](https://travis-ci.org/dirkgroenen/Pinterest-API-PHP.svg)](https://travis-ci.org/dirkgroenen/Pinterest-API-PHP) +[![](https://img.shields.io/scrutinizer/g/dirkgroenen/Pinterest-API-PHP.svg)](https://scrutinizer-ci.com/g/dirkgroenen/Pinterest-API-PHP/?branch=master) +[![](https://img.shields.io/scrutinizer/coverage/g/dirkgroenen/Pinterest-API-PHP.svg)](https://scrutinizer-ci.com/g/dirkgroenen/Pinterest-API-PHP/?branch=master) +[![Packagist](https://img.shields.io/packagist/v/dirkgroenen/pinterest-api-php.svg)](https://packagist.org/packages/dirkgroenen/pinterest-api-php) [![Support me with some coffee](https://img.shields.io/badge/donate-paypal-orange.svg)](https://www.paypal.me/dirkgroenen) ------------------- @@ -16,7 +16,7 @@ A PHP wrapper for the official [Pinterest API](https://dev.pinterest.com). - Registered Pinterest App # Get started -To use the Pinterest API you have to register yourself as a developer and [create](https://dev.pinterest.com/apps/) an application. After you've created your app you will receive a `app_id` and `app_secret`. +To use the Pinterest API you have to register yourself as a developer and [create](https://dev.pinterest.com/apps/) an application. After you've created your app you will receive a `app_id` and `app_secret`. > The terms `client_id` and `client_secret` are in this case `app_id` and `app_secret`. @@ -27,7 +27,7 @@ The Pinterest API wrapper is available on Composer. composer require dirkgroenen/Pinterest-API-PHP ``` -## Simple Example +## Simple Example ```php use DirkGroenen\Pinterest\Pinterest; @@ -41,9 +41,9 @@ $loginurl = $pinterest->auth->getLoginUrl(CALLBACK_URL, array('read_public')); echo 'Authorize Pinterest'; ``` -Check the [Pinterest documentation](https://dev.pinterest.com/docs/api/overview/#scopes) for the available scopes. +Check the [Pinterest documentation](https://dev.pinterest.com/docs/api/overview/#scopes) for the available scopes. -After your user has used the login link to authorize he will be send back to the given `CALLBACK_URL`. The URL will contain the `code` which can be exchanged into an `access_token`. To exchange the code for an `access_token` and set it you can use the following code: +After your user has used the login link to authorize he will be send back to the given `CALLBACK_URL`. The URL will contain the `code` which can be exchanged into an `access_token`. To exchange the code for an `access_token` and set it you can use the following code: ```php if(isset($_GET["code"])){ @@ -54,7 +54,7 @@ if(isset($_GET["code"])){ ## Get the user's profile -To get the profile of the current logged in user you can use the `Users::me();` method. +To get the profile of the current logged in user you can use the `Users::me();` method. ```php $me = $pinterest->users->me(); @@ -62,11 +62,11 @@ echo $me; ``` # Models -The API wrapper will parse all data through it's corresponding model. This results in the possibility to (for example) directly `echo` your model into a JSON string. +The API wrapper will parse all data through it's corresponding model. This results in the possibility to (for example) directly `echo` your model into a JSON string. -Models also show the available fields (which are also described in the Pinterest documentation). By default, not all fields are returned, so this can help you when providing extra fields to the request. +Models also show the available fields (which are also described in the Pinterest documentation). By default, not all fields are returned, so this can help you when providing extra fields to the request. -## Available models +## Available models ### [User](https://dev.pinterest.com/docs/api/users/#user-object) @@ -100,7 +100,7 @@ Response: } ``` -By default, not all fields are returned. The returned data from the API has been parsed into the `User` model. Every field in this model can be filled by parsing an extra `$data` array with the key `fields`. Say we want the user's username, first_name, last_name and image (small and large): +By default, not all fields are returned. The returned data from the API has been parsed into the `User` model. Every field in this model can be filled by parsing an extra `$data` array with the key `fields`. Say we want the user's username, first_name, last_name and image (small and large): ```php $pinterest->users->me(array( @@ -108,7 +108,7 @@ $pinterest->users->me(array( )); ``` -The response will now be: +The response will now be: ```json { @@ -176,9 +176,9 @@ Returns: `Boolean` # Available methods -> Every method containing a `data` array can be filled with extra data. This can be for example extra fields or pagination. +> Every method containing a `data` array can be filled with extra data. This can be for example extra fields or pagination. -## Authentication +## Authentication The methods below are available through `$pinterest->auth`. @@ -189,7 +189,7 @@ The methods below are available through `$pinterest->auth`. $pinterest->auth->getLoginUrl("https://pinterest.dev/callback.php", array("read_public")); ``` -Check the [Pinterest documentation](https://dev.pinterest.com/docs/api/overview/#scopes) for the available scopes. +Check the [Pinterest documentation](https://dev.pinterest.com/docs/api/overview/#scopes) for the available scopes. **Note: since 0.2.0 the default authentication method has changed to `code` instead of `token`. This means you have to exchange the returned code for an access_token.** @@ -219,7 +219,7 @@ Returns: `string` ### Set state `setState( string $state );` -This method can be used to set a state manually, but this isn't required since the API will automatically generate a random state on initialize. +This method can be used to set a state manually, but this isn't required since the API will automatically generate a random state on initialize. ```php $pinterest->auth->setState($state); @@ -378,7 +378,7 @@ Returns: `Pin` `fromBoard( string $board_id, array $data );` ```php -$pinterest->pins->fromBoard("503066289565421201"); +$pinterest->pins->fromBoard("dirkgroenen/pinterest-api-test"); ``` Returns: `Collection` @@ -392,7 +392,7 @@ Creating a pin with an image hosted somewhere else: $pinterest->pins->create(array( "note" => "Test board from API", "image_url" => "https://download.unsplash.com/photo-1438216983993-cdcd7dea84ce", - "board" => "503066289565421201" + "board" => "dirkgroenen/pinterest-api-test" )); ``` @@ -402,7 +402,7 @@ Creating a pin with an image located on the server: $pinterest->pins->create(array( "note" => "Test board from API", "image" => "/path/to/image.png", - "board" => "503066289565421201" + "board" => "dirkgroenen/pinterest-api-test" )); ``` @@ -412,7 +412,7 @@ Creating a pin with a base64 encoded image: $pinterest->pins->create(array( "note" => "Test board from API", "image_base64" => "[base64 encoded image]", - "board" => "503066289565421201" + "board" => "dirkgroenen/pinterest-api-test" )); ``` diff --git a/demo/callback.php b/demo/callback.php index e69c145..245159e 100644 --- a/demo/callback.php +++ b/demo/callback.php @@ -5,10 +5,12 @@

Hey you!

-

$pinterest->boards->create()

+

$pinterest->pins->create()

- boards->create(array( - "name" => "Test from Pinterest API" + pins->create(array( + "board" => "pinterest-api-test", + "note" => "Test from API", + "image_url" => "https://download.unsplash.com/photo-1438216983993-cdcd7dea84ce" )); ?> From db14bab6035769b44592bca1aef31826fea5c7a8 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Fri, 5 Feb 2016 16:29:04 +0100 Subject: [PATCH 66/85] Change in demo --- demo/callback.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/demo/callback.php b/demo/callback.php index 245159e..95b3d7d 100644 --- a/demo/callback.php +++ b/demo/callback.php @@ -7,8 +7,7 @@

Hey you!

$pinterest->pins->create()

- pins->create(array( - "board" => "pinterest-api-test", + pins->delete("503066220857361559", array( "note" => "Test from API", "image_url" => "https://download.unsplash.com/photo-1438216983993-cdcd7dea84ce" )); ?> From a82931df3419752880cd625181baf5a94570c0cd Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Wed, 10 Feb 2016 13:33:56 +0100 Subject: [PATCH 67/85] Add flattr button --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 14f80b1..c397964 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![](https://img.shields.io/scrutinizer/g/dirkgroenen/Pinterest-API-PHP.svg)](https://scrutinizer-ci.com/g/dirkgroenen/Pinterest-API-PHP/?branch=master) [![](https://img.shields.io/scrutinizer/coverage/g/dirkgroenen/Pinterest-API-PHP.svg)](https://scrutinizer-ci.com/g/dirkgroenen/Pinterest-API-PHP/?branch=master) [![Packagist](https://img.shields.io/packagist/v/dirkgroenen/pinterest-api-php.svg)](https://packagist.org/packages/dirkgroenen/pinterest-api-php) -[![Support me with some coffee](https://img.shields.io/badge/donate-paypal-orange.svg)](https://www.paypal.me/dirkgroenen) +[![Support me with some coffee](https://img.shields.io/badge/donate-paypal-orange.svg)](https://www.paypal.me/dirkgroenen) [![Support me with some coffee](https://button.flattr.com/flattr-badge-large.png)](https://flattr.com/submit/auto?fid=j95k2l&url=https%3A%2F%2Fgithub.com%2Fdirkgroenen%2FPinterest-API-PHP) ------------------- A PHP wrapper for the official [Pinterest API](https://dev.pinterest.com). @@ -532,4 +532,4 @@ Returns: `True|PinterestException` # Examples -There are no examples available yet. Let me know if you have an (example) project using the this library. \ No newline at end of file +There are no examples available yet. Let me know if you have an (example) project using the this library. From e1e2bdc45f3d29e6d358fc8d698d1061721daaab Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Wed, 10 Feb 2016 20:04:04 +0100 Subject: [PATCH 68/85] Add autoload #37 --- autoload.php | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 autoload.php diff --git a/autoload.php b/autoload.php new file mode 100644 index 0000000..f108c50 --- /dev/null +++ b/autoload.php @@ -0,0 +1,39 @@ + Date: Wed, 10 Feb 2016 20:19:55 +0100 Subject: [PATCH 69/85] Add board edit endpoint --- README.md | 17 +++++++++++++++-- demo/boot.php | 2 +- src/Pinterest/Endpoints/Boards.php | 15 +++++++++++++++ tests/Pinterest/Endpoints/BoardsTest.php | 18 ++++++++++++++---- tests/Pinterest/env | 6 ++++++ .../responses/BoardsTest/testEdit.json | 7 +++++++ 6 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 tests/Pinterest/env create mode 100644 tests/Pinterest/responses/BoardsTest/testEdit.json diff --git a/README.md b/README.md index e946643..25c1a3f 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,8 @@ The Pinterest API wrapper is available on Composer. composer require dirkgroenen/Pinterest-API-PHP ``` +If you're not using Composer (which you should start using, unless you've got a good reason not to) you can include the `autoload.php` file in your project. + ## Simple Example ```php use DirkGroenen\Pinterest\Pinterest; @@ -335,7 +337,7 @@ The methods below are available through `$pinterest->boards`. `get( string $board_id, array $data );` ```php -$pinterest->boards->get("503066289565421201"); +$pinterest->boards->get("dirkgroenen/pinterest-api-test"); ``` Returns: `Board` @@ -352,11 +354,22 @@ $pinterest->boards->create(array( Returns: `Board` +### Edit board +`edit( string $board_id, array $data );` + +```php +$pinterest->boards-edit("dirkgroenen/pinterest-api-test", array( + "name" => "Test board after edit" +)); +``` + +Returns: `Board` + ### Delete board `delete( string $board_id, array $data );` ```php -$pinterest->boards->delete("503066289565421201"); +$pinterest->boards->delete("dirkgroenen/pinterest-api-test"); ``` Returns: `True|PinterestException` diff --git a/demo/boot.php b/demo/boot.php index 2c02d9f..7992dae 100644 --- a/demo/boot.php +++ b/demo/boot.php @@ -3,7 +3,7 @@ ini_set('display_startup_errors', 1); error_reporting(E_ALL); - require "../vendor/autoload.php"; + require "../autoload.php"; $dotenv = new Dotenv\Dotenv(__DIR__); $dotenv->load(); diff --git a/src/Pinterest/Endpoints/Boards.php b/src/Pinterest/Endpoints/Boards.php index c55b5ec..694420e 100644 --- a/src/Pinterest/Endpoints/Boards.php +++ b/src/Pinterest/Endpoints/Boards.php @@ -43,6 +43,21 @@ public function create(array $data) return new Board($this->master, $response); } + /** + * Edit a board + * + * @access public + * @param string $board_id + * @param array $data + * @throws Exceptions/PinterestExceptions + * @return Board + */ + public function edit($board_id, array $data) + { + $response = $this->request->update(sprintf("boards/%s", $board_id), $data); + return new Board($this->master, $response); + } + /** * Delete a board * diff --git a/tests/Pinterest/Endpoints/BoardsTest.php b/tests/Pinterest/Endpoints/BoardsTest.php index b2d3eb6..63e1fff 100644 --- a/tests/Pinterest/Endpoints/BoardsTest.php +++ b/tests/Pinterest/Endpoints/BoardsTest.php @@ -1,9 +1,9 @@ - * + * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ @@ -17,7 +17,7 @@ class BoardsTest extends \PHPUnit_Framework_TestCase{ /** * The Pinterest instance - * + * * @var Pinterest */ private $pinterest; @@ -30,7 +30,7 @@ class BoardsTest extends \PHPUnit_Framework_TestCase{ public function setUp() { $curlbuilder = CurlBuilderMock::create( $this ); - + // Setup Pinterest $this->pinterest = new Pinterest("0", "0", $curlbuilder); $this->pinterest->auth->setOAuthToken( "0" ); @@ -65,6 +65,16 @@ public function testCreate() $this->assertEquals( $response->id , "503066289565421205" ); } + public function testEdit() + { + $response = $this->pinterest->boards->edit("503066289565421201", array( + "name" => "Test board from API" + )); + + $this->assertInstanceOf( "DirkGroenen\Pinterest\Models\Board", $response ); + $this->assertEquals( $response->id , "503066289565421205" ); + } + public function testDelete() { $response = $this->pinterest->boards->delete("503066289565421205"); diff --git a/tests/Pinterest/env b/tests/Pinterest/env new file mode 100644 index 0000000..5c8bfa8 --- /dev/null +++ b/tests/Pinterest/env @@ -0,0 +1,6 @@ +# Note: the API will perform live actions on the provided account + +export CLIENT_ID=4782712381411165558 +export CLIENT_SECRET=4489d440ae5d42f40170bf1f5073c5c9d1ddcf565ab4e120e1d1af180a663024 +export ACCESS_TOKEN=AbRHLxfhh1aBeK80gX98RSuvbCT2FBreHhmUMRpCW5Jw2MAJ6AAAAAA +export CALLBACK_URL=https://bitlabs.dev diff --git a/tests/Pinterest/responses/BoardsTest/testEdit.json b/tests/Pinterest/responses/BoardsTest/testEdit.json new file mode 100644 index 0000000..2221e4d --- /dev/null +++ b/tests/Pinterest/responses/BoardsTest/testEdit.json @@ -0,0 +1,7 @@ +{ + "data": { + "url": "https://www.pinterest.com/dirkgroenen/test-board-from-api/", + "id": "503066289565421205", + "name": "Test Board From API" + } +} \ No newline at end of file From 91d8e0464daaac86fb59d2e4fa623902e54e4812 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Wed, 10 Feb 2016 20:21:38 +0100 Subject: [PATCH 70/85] Add changes --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2fdbea..a359cb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +### 0.2.9 (10-02-2016) + +- Add autoload.php as Composer alternative [#37](https://github.com/dirkgroenen/Pinterest-API-PHP/issues/37) +- Add board update endpoint [#34](https://github.com/dirkgroenen/Pinterest-API-PHP/issues/34) + ### 0.2.8 (02-02-2016) - Fix Curl execFollow and error handling [#31](https://github.com/dirkgroenen/Pinterest-API-PHP/issues/31) From f8fb1b037608ba19216b49e8023131b32763da56 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Wed, 10 Feb 2016 20:27:51 +0100 Subject: [PATCH 71/85] add formdata to patch request --- src/Pinterest/Transport/Request.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Pinterest/Transport/Request.php b/src/Pinterest/Transport/Request.php index a7f477a..6ce2c3e 100644 --- a/src/Pinterest/Transport/Request.php +++ b/src/Pinterest/Transport/Request.php @@ -186,7 +186,11 @@ public function execute($method, $apiCall, array $parameters = array(), $headers $ch->setOption(CURLOPT_CUSTOMREQUEST, "DELETE"); break; case 'PATCH': - $ch->setOption(CURLOPT_CUSTOMREQUEST, "PATCH"); + $ch->setOptions(array( + CURLOPT_CUSTOMREQUEST => "PATCH", + CURLOPT_POST => count($parameters), + CURLOPT_POSTFIELDS => $parameters + )); break; default: $ch->setOption(CURLOPT_CUSTOMREQUEST, "GET"); From 05fc6cbc5ff53c32854eda3124505a2bddbe4e4a Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Wed, 10 Feb 2016 20:41:54 +0100 Subject: [PATCH 72/85] Add fields --- README.md | 8 +++++--- src/Pinterest/Endpoints/Boards.php | 5 +++-- src/Pinterest/Endpoints/Pins.php | 5 +++-- src/Pinterest/Transport/Request.php | 11 +++++++++-- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 25c1a3f..df213b0 100644 --- a/README.md +++ b/README.md @@ -355,7 +355,7 @@ $pinterest->boards->create(array( Returns: `Board` ### Edit board -`edit( string $board_id, array $data );` +`edit( string $board_id, array $data, array $fields = array() );` ```php $pinterest->boards-edit("dirkgroenen/pinterest-api-test", array( @@ -435,10 +435,12 @@ Returns: `Pin` ### Update pin > According to the Pinterest documentation this endpoint exists, but for some reason their API is returning an error at the moment of writing. -`update( string $pin_id, array $data );` +`update( string $pin_id, array $data, array $fields = array() );` ```php -$pinterest->pins->update("181692166190246650"); +$pinterest->pins->update("181692166190246650", array( + "note" => "Updated name" +)); ``` Returns: `Pin` diff --git a/src/Pinterest/Endpoints/Boards.php b/src/Pinterest/Endpoints/Boards.php index 694420e..4eae558 100644 --- a/src/Pinterest/Endpoints/Boards.php +++ b/src/Pinterest/Endpoints/Boards.php @@ -49,12 +49,13 @@ public function create(array $data) * @access public * @param string $board_id * @param array $data + * @param array $fields * @throws Exceptions/PinterestExceptions * @return Board */ - public function edit($board_id, array $data) + public function edit($board_id, array $data, array $fields = array()) { - $response = $this->request->update(sprintf("boards/%s", $board_id), $data); + $response = $this->request->update(sprintf("boards/%s", $board_id), $data, $fields); return new Board($this->master, $response); } diff --git a/src/Pinterest/Endpoints/Pins.php b/src/Pinterest/Endpoints/Pins.php index 44b700c..6905eaf 100644 --- a/src/Pinterest/Endpoints/Pins.php +++ b/src/Pinterest/Endpoints/Pins.php @@ -73,12 +73,13 @@ public function create(array $data) * @access public * @param string $pin_id * @param array $data + * @param array $fields * @throws Exceptions/PinterestExceptions * @return Pin */ - public function update($pin_id, array $data) + public function update($pin_id, array $data, array $fields = array()) { - $response = $this->request->update(sprintf("pins/%s", $pin_id), $data); + $response = $this->request->update(sprintf("pins/%s", $pin_id), $data, $fields); return new Pin($this->master, $response); } diff --git a/src/Pinterest/Transport/Request.php b/src/Pinterest/Transport/Request.php index 6ce2c3e..aad7d16 100644 --- a/src/Pinterest/Transport/Request.php +++ b/src/Pinterest/Transport/Request.php @@ -116,11 +116,18 @@ public function delete($endpoint, array $parameters = array()) * @access public * @param string $endpoint * @param array $parameters + * @param array $queryparameters * @return Response */ - public function update($endpoint, array $parameters = array()) + public function update($endpoint, array $parameters = array(), array $queryparameters = array()) { - return $this->execute("PATCH", sprintf("%s%s", $this->host, $endpoint) . "/", $parameters); + if (!empty($queryparameters)) { + $path = sprintf("%s/?%s", $endpoint, http_build_query($parameters)); + } else { + $path = $endpoint; + } + + return $this->execute("PATCH", sprintf("%s%s", $this->host, $path) . "/", $parameters); } /** From 5a249842428a5c7d1f238cb228b23a8680e830ee Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Wed, 10 Feb 2016 21:10:41 +0100 Subject: [PATCH 73/85] Fix src --- autoload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload.php b/autoload.php index f108c50..e08a02d 100644 --- a/autoload.php +++ b/autoload.php @@ -15,7 +15,7 @@ $prefix = 'DirkGroenen\\Pinterest\\'; // base directory for the namespace prefix - $base_dir = __DIR__ . '/src/'; + $base_dir = __DIR__ . '/src/Pinterest/'; // does the class use the namespace prefix? $len = strlen($prefix); From f826ceb0caddf291b5a18efe2ac3719ca6ab04c0 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Wed, 10 Feb 2016 21:59:38 +0100 Subject: [PATCH 74/85] try to get patch working, added fields to patch requests --- CHANGELOG.md | 2 ++ README.md | 11 +++++------ demo/boot.php | 2 +- demo/callback.php | 15 +++++++++------ demo/index.php | 2 +- src/Pinterest/Endpoints/Boards.php | 8 +++++--- src/Pinterest/Endpoints/Pins.php | 10 ++++++---- src/Pinterest/Transport/Request.php | 9 ++++----- 8 files changed, 33 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a359cb6..66a01d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ - Add autoload.php as Composer alternative [#37](https://github.com/dirkgroenen/Pinterest-API-PHP/issues/37) - Add board update endpoint [#34](https://github.com/dirkgroenen/Pinterest-API-PHP/issues/34) +- Fix patch requests +- Add `$field` to update requests ### 0.2.8 (02-02-2016) diff --git a/README.md b/README.md index df213b0..6cb1b1e 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ Models also show the available fields (which are also described in the Pinterest - name ## Retrieving extra fields -If you want more fields you can specify these in the `$data` array. Example: +If you want more fields you can specify these in the `$data` (GET requests) or `$fields` (PATCH requests) array. Example: ```php $pinterest->users->me(); @@ -355,7 +355,7 @@ $pinterest->boards->create(array( Returns: `Board` ### Edit board -`edit( string $board_id, array $data, array $fields = array() );` +`edit( string $board_id, array $data, string $fields = null );` ```php $pinterest->boards-edit("dirkgroenen/pinterest-api-test", array( @@ -432,13 +432,12 @@ $pinterest->pins->create(array( Returns: `Pin` -### Update pin -> According to the Pinterest documentation this endpoint exists, but for some reason their API is returning an error at the moment of writing. +### Edit pin -`update( string $pin_id, array $data, array $fields = array() );` +`edit( string $pin_id, array $data, string $fields = null );` ```php -$pinterest->pins->update("181692166190246650", array( +$pinterest->pins->edit("181692166190246650", array( "note" => "Updated name" )); ``` diff --git a/demo/boot.php b/demo/boot.php index 7992dae..2c02d9f 100644 --- a/demo/boot.php +++ b/demo/boot.php @@ -3,7 +3,7 @@ ini_set('display_startup_errors', 1); error_reporting(E_ALL); - require "../autoload.php"; + require "../vendor/autoload.php"; $dotenv = new Dotenv\Dotenv(__DIR__); $dotenv->load(); diff --git a/demo/callback.php b/demo/callback.php index 95b3d7d..a05900f 100644 --- a/demo/callback.php +++ b/demo/callback.php @@ -4,13 +4,16 @@ -

Hey you!

-

$pinterest->pins->create()

+ boards->edit("dirkgroenen/test-from-api", array( + "name" => "Test from API - update", + "description" => "Test" + ));*/ - pins->delete("503066220857361559", array( - "note" => "Test from API", - "image_url" => "https://download.unsplash.com/photo-1438216983993-cdcd7dea84ce" - )); ?> + echo $pinterest->pins->edit("503066220857432361", array( + "note" => "Noted update" + ), "id,link,note,url,image"); + ?> \ No newline at end of file diff --git a/demo/index.php b/demo/index.php index 5cfa86e..cbf9e5b 100644 --- a/demo/index.php +++ b/demo/index.php @@ -5,6 +5,6 @@

Login with Pinterest

-

Use this link to login with your Pinterest account.

+

Use this link to login with your Pinterest account.

\ No newline at end of file diff --git a/src/Pinterest/Endpoints/Boards.php b/src/Pinterest/Endpoints/Boards.php index 4eae558..9219a98 100644 --- a/src/Pinterest/Endpoints/Boards.php +++ b/src/Pinterest/Endpoints/Boards.php @@ -49,13 +49,15 @@ public function create(array $data) * @access public * @param string $board_id * @param array $data - * @param array $fields + * @param string $fields * @throws Exceptions/PinterestExceptions * @return Board */ - public function edit($board_id, array $data, array $fields = array()) + public function edit($board_id, array $data, array $fields = null) { - $response = $this->request->update(sprintf("boards/%s", $board_id), $data, $fields); + $query = (!$fields) ? array() : array("fields" => $fields); + + $response = $this->request->update(sprintf("boards/%s", $board_id), $data, $query); return new Board($this->master, $response); } diff --git a/src/Pinterest/Endpoints/Pins.php b/src/Pinterest/Endpoints/Pins.php index 6905eaf..777e691 100644 --- a/src/Pinterest/Endpoints/Pins.php +++ b/src/Pinterest/Endpoints/Pins.php @@ -68,18 +68,20 @@ public function create(array $data) } /** - * Update a pin + * Edit a pin * * @access public * @param string $pin_id * @param array $data - * @param array $fields + * @param string $fields * @throws Exceptions/PinterestExceptions * @return Pin */ - public function update($pin_id, array $data, array $fields = array()) + public function edit($pin_id, array $data, $fields = null) { - $response = $this->request->update(sprintf("pins/%s", $pin_id), $data, $fields); + $query = (!$fields) ? array() : array("fields" => $fields); + + $response = $this->request->update(sprintf("pins/%s", $pin_id), $data, $query); return new Pin($this->master, $response); } diff --git a/src/Pinterest/Transport/Request.php b/src/Pinterest/Transport/Request.php index aad7d16..57ade60 100644 --- a/src/Pinterest/Transport/Request.php +++ b/src/Pinterest/Transport/Request.php @@ -122,12 +122,12 @@ public function delete($endpoint, array $parameters = array()) public function update($endpoint, array $parameters = array(), array $queryparameters = array()) { if (!empty($queryparameters)) { - $path = sprintf("%s/?%s", $endpoint, http_build_query($parameters)); + $path = sprintf("%s/?%s", $endpoint, http_build_query($queryparameters)); } else { $path = $endpoint; } - return $this->execute("PATCH", sprintf("%s%s", $this->host, $path) . "/", $parameters); + return $this->execute("PATCH", sprintf("%s%s", $this->host, $path), $parameters); } /** @@ -156,7 +156,7 @@ public function execute($method, $apiCall, array $parameters = array(), $headers if ($this->access_token != null) { $headers = array_merge($headers, array( "Authorization: Bearer " . $this->access_token, - "Content-type: multipart/form-data", + "Content-type: application/x-www-form-urlencoded; charset=UTF-8", )); } @@ -179,7 +179,7 @@ public function execute($method, $apiCall, array $parameters = array(), $headers switch ($method) { case 'POST': $ch->setOptions(array( - CURLOPT_CUSTOMREQUEST => 'POST', + CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POST => count($parameters), CURLOPT_POSTFIELDS => $parameters )); @@ -204,7 +204,6 @@ public function execute($method, $apiCall, array $parameters = array(), $headers break; } - // Execute request and catch response $response_data = $ch->execute(); From 764369cd733ace296dfb22c46c1b0b3e0bffe791 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Wed, 10 Feb 2016 22:03:51 +0100 Subject: [PATCH 75/85] fix patch requests --- demo/callback.php | 2 +- src/Pinterest/Transport/Request.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/demo/callback.php b/demo/callback.php index a05900f..4cb1e26 100644 --- a/demo/callback.php +++ b/demo/callback.php @@ -11,7 +11,7 @@ ));*/ echo $pinterest->pins->edit("503066220857432361", array( - "note" => "Noted update" + "note" => "Noted update 2" ), "id,link,note,url,image"); ?> diff --git a/src/Pinterest/Transport/Request.php b/src/Pinterest/Transport/Request.php index 57ade60..dee632e 100644 --- a/src/Pinterest/Transport/Request.php +++ b/src/Pinterest/Transport/Request.php @@ -196,7 +196,7 @@ public function execute($method, $apiCall, array $parameters = array(), $headers $ch->setOptions(array( CURLOPT_CUSTOMREQUEST => "PATCH", CURLOPT_POST => count($parameters), - CURLOPT_POSTFIELDS => $parameters + CURLOPT_POSTFIELDS => http_build_query($parameters) )); break; default: From 29960d399fdd4b4b0683ee561de1678e6d783960 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Wed, 10 Feb 2016 22:10:25 +0100 Subject: [PATCH 76/85] add fields to demo, fix typehint --- demo/callback.php | 6 +++--- src/Pinterest/Endpoints/Boards.php | 2 +- src/Pinterest/Models/Board.php | 10 +++++----- src/Pinterest/Models/Model.php | 1 - 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/demo/callback.php b/demo/callback.php index 4cb1e26..9df2a87 100644 --- a/demo/callback.php +++ b/demo/callback.php @@ -10,9 +10,9 @@ "description" => "Test" ));*/ - echo $pinterest->pins->edit("503066220857432361", array( - "note" => "Noted update 2" - ), "id,link,note,url,image"); + echo $pinterest->boards->edit("dirkgroenen/test-from-api", array( + "name" => "Noted update 2 - API" + ), "description,creator"); ?> diff --git a/src/Pinterest/Endpoints/Boards.php b/src/Pinterest/Endpoints/Boards.php index 9219a98..d4c1832 100644 --- a/src/Pinterest/Endpoints/Boards.php +++ b/src/Pinterest/Endpoints/Boards.php @@ -53,7 +53,7 @@ public function create(array $data) * @throws Exceptions/PinterestExceptions * @return Board */ - public function edit($board_id, array $data, array $fields = null) + public function edit($board_id, array $data, $fields = null) { $query = (!$fields) ? array() : array("fields" => $fields); diff --git a/src/Pinterest/Models/Board.php b/src/Pinterest/Models/Board.php index 23becb0..0763d54 100644 --- a/src/Pinterest/Models/Board.php +++ b/src/Pinterest/Models/Board.php @@ -1,9 +1,9 @@ - - * + * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ @@ -11,10 +11,10 @@ namespace DirkGroenen\Pinterest\Models; class Board extends Model { - + /** * The available object keys - * + * * @var array */ protected $fillable = ["id", "name", "url", "description", "creator", "created_at", "counts", "image"]; diff --git a/src/Pinterest/Models/Model.php b/src/Pinterest/Models/Model.php index dddcf81..9a33e77 100644 --- a/src/Pinterest/Models/Model.php +++ b/src/Pinterest/Models/Model.php @@ -174,5 +174,4 @@ public function __toString() { return $this->toJson(); } - } \ No newline at end of file From cc60de283461ed21aea3c31ca3c00906570ff951 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Wed, 10 Feb 2016 22:11:13 +0100 Subject: [PATCH 77/85] Add extra demo fields --- demo/callback.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demo/callback.php b/demo/callback.php index 9df2a87..c735a20 100644 --- a/demo/callback.php +++ b/demo/callback.php @@ -12,7 +12,7 @@ echo $pinterest->boards->edit("dirkgroenen/test-from-api", array( "name" => "Noted update 2 - API" - ), "description,creator"); + ), "id,name,url,description,creator,created_at,counts,image"); ?> From e7059ca8416a7eaa4661ae947be25aa306568a23 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Wed, 10 Feb 2016 22:13:06 +0100 Subject: [PATCH 78/85] add test --- tests/Pinterest/Endpoints/PinsTest.php | 18 ++++++++++++++---- .../Pinterest/responses/PinsTest/testEdit.json | 8 ++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 tests/Pinterest/responses/PinsTest/testEdit.json diff --git a/tests/Pinterest/Endpoints/PinsTest.php b/tests/Pinterest/Endpoints/PinsTest.php index 91d58ae..6f18526 100644 --- a/tests/Pinterest/Endpoints/PinsTest.php +++ b/tests/Pinterest/Endpoints/PinsTest.php @@ -1,9 +1,9 @@ - * + * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ @@ -17,7 +17,7 @@ class PinsTest extends \PHPUnit_Framework_TestCase{ /** * The Pinterest instance - * + * * @var Pinterest */ private $pinterest; @@ -30,7 +30,7 @@ class PinsTest extends \PHPUnit_Framework_TestCase{ public function setUp() { $curlbuilder = CurlBuilderMock::create( $this ); - + // Setup Pinterest $this->pinterest = new Pinterest("0", "0", $curlbuilder); $this->pinterest->auth->setOAuthToken( "0" ); @@ -64,6 +64,16 @@ public function testCreate() $this->assertEquals( $response->id , "503066220854919983" ); } + public function testEdit() + { + $response = $this->pinterest->pins->edit("503066220854919983", array( + "note" => "Test pin from API wrapper - update" + )); + + $this->assertInstanceOf( "DirkGroenen\Pinterest\Models\Pin", $response ); + $this->assertEquals( $response->id , "503066220854919983" ); + } + public function testDelete() { $response = $this->pinterest->pins->delete("503066220854919983"); diff --git a/tests/Pinterest/responses/PinsTest/testEdit.json b/tests/Pinterest/responses/PinsTest/testEdit.json new file mode 100644 index 0000000..c501531 --- /dev/null +++ b/tests/Pinterest/responses/PinsTest/testEdit.json @@ -0,0 +1,8 @@ +{ + "data": { + "url": "http://pinterest.com/pin/503066220854919983/", + "note": "Test pin from API wrapper - update", + "link": "", + "id": "503066220854919983" + } +} \ No newline at end of file From ab0695915003a51d2adb879c59275dcfed5a4132 Mon Sep 17 00:00:00 2001 From: Scrutinizer Auto-Fixer Date: Wed, 10 Feb 2016 21:13:52 +0000 Subject: [PATCH 79/85] Scrutinizer Auto-Fixes This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com --- autoload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload.php b/autoload.php index e08a02d..0489259 100644 --- a/autoload.php +++ b/autoload.php @@ -9,7 +9,7 @@ * Based on the standard PSR-4 autoloader: * https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md */ -spl_autoload_register(function ($class) { +spl_autoload_register(function($class) { // project-specific namespace prefix $prefix = 'DirkGroenen\\Pinterest\\'; From e3a0cfdaaaee4621a3d2d7da24b300c08c626804 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Thu, 11 Feb 2016 10:40:16 +0100 Subject: [PATCH 80/85] add http_build_query to POST, fixes #39 --- demo/callback.php | 9 ++++++--- src/Pinterest/Transport/Request.php | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/demo/callback.php b/demo/callback.php index c735a20..ff1bf54 100644 --- a/demo/callback.php +++ b/demo/callback.php @@ -10,9 +10,12 @@ "description" => "Test" ));*/ - echo $pinterest->boards->edit("dirkgroenen/test-from-api", array( - "name" => "Noted update 2 - API" - ), "id,name,url,description,creator,created_at,counts,image"); + echo $pinterest->pins->create(array( + "board" => "dirkgroenen/test-from-api", + 'image_url' => 'https://images.unsplash.com/photo-1453974336165-b5c58464f1ed?crop=entropy&fit=crop&fm=jpg&h=1000&ixjsv=2.1.0&ixlib=rb-0.3.5&q=80&w=1925', + 'note' => 'test', + 'link' => 'http://tld.com/072AE601DF7DB00445386F5C9CC46F74' + )); ?> diff --git a/src/Pinterest/Transport/Request.php b/src/Pinterest/Transport/Request.php index dee632e..aec9b78 100644 --- a/src/Pinterest/Transport/Request.php +++ b/src/Pinterest/Transport/Request.php @@ -181,7 +181,7 @@ public function execute($method, $apiCall, array $parameters = array(), $headers $ch->setOptions(array( CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POST => count($parameters), - CURLOPT_POSTFIELDS => $parameters + CURLOPT_POSTFIELDS => http_build_query($parameters) )); if (!class_exists("\CURLFile") && defined('CURLOPT_SAFE_UPLOAD')) { From ac02f6617f5eeab9c2485e11e7ad5cb76f908cb8 Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Thu, 11 Feb 2016 10:41:40 +0100 Subject: [PATCH 81/85] add changes --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66a01d7..11a3842 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### 0.2.10 (11-02-2016) + +- Fixed missing `http_build_query` in post requests [#39](https://github.com/dirkgroenen/Pinterest-API-PHP/issues/39) + ### 0.2.9 (10-02-2016) - Add autoload.php as Composer alternative [#37](https://github.com/dirkgroenen/Pinterest-API-PHP/issues/37) From 362477b6e400a18dd2c8a60548c82f0ec4dab2fe Mon Sep 17 00:00:00 2001 From: Dirk Groenen Date: Sat, 13 Feb 2016 13:23:23 +0100 Subject: [PATCH 82/85] Temp remove flattr unitil it works --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6e4205b..58af386 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![](https://img.shields.io/scrutinizer/g/dirkgroenen/Pinterest-API-PHP.svg)](https://scrutinizer-ci.com/g/dirkgroenen/Pinterest-API-PHP/?branch=master) [![](https://img.shields.io/scrutinizer/coverage/g/dirkgroenen/Pinterest-API-PHP.svg)](https://scrutinizer-ci.com/g/dirkgroenen/Pinterest-API-PHP/?branch=master) [![Packagist](https://img.shields.io/packagist/v/dirkgroenen/pinterest-api-php.svg)](https://packagist.org/packages/dirkgroenen/pinterest-api-php) -[![Support me with some coffee](https://img.shields.io/badge/donate-paypal-orange.svg)](https://www.paypal.me/dirkgroenen) [![Support me with some coffee](https://button.flattr.com/flattr-badge-large.png)](https://flattr.com/submit/auto?fid=j95k2l&url=https%3A%2F%2Fgithub.com%2Fdirkgroenen%2FPinterest-API-PHP) +[![Support me with some coffee](https://img.shields.io/badge/donate-paypal-orange.svg)](https://www.paypal.me/dirkgroenen) ------------------- A PHP wrapper for the official [Pinterest API](https://dev.pinterest.com). From d3465c7dd6d385b6249d4c41c5a2e830d969acf7 Mon Sep 17 00:00:00 2001 From: Mukesh Yadav Date: Wed, 17 Feb 2016 15:16:43 +0530 Subject: [PATCH 83/85] Documentation comment update... "Get an Instagram API endpoint" to "Get an Pinterest API endpoint" --- src/Pinterest/Pinterest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Pinterest/Pinterest.php b/src/Pinterest/Pinterest.php index de96734..94b8cc9 100644 --- a/src/Pinterest/Pinterest.php +++ b/src/Pinterest/Pinterest.php @@ -66,7 +66,7 @@ public function __construct($client_id, $client_secret, $curlbuilder = null) } /** - * Get an Instagram API endpoint + * Get an Pinterest API endpoint * * @access public * @param string $endpoint From d66f82c0eedb04f7811e7106b6442980c764f488 Mon Sep 17 00:00:00 2001 From: Mukesh Yadav Date: Wed, 24 Feb 2016 13:42:26 +0530 Subject: [PATCH 84/85] 2 items added to user modal. 2 items(url & account_type) added to user modal fillable. --- src/Pinterest/Models/User.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Pinterest/Models/User.php b/src/Pinterest/Models/User.php index d53947d..ac92429 100644 --- a/src/Pinterest/Models/User.php +++ b/src/Pinterest/Models/User.php @@ -19,6 +19,6 @@ class User extends Model { * * @var array */ - protected $fillable = ["id", "username", "first_name", "last_name", "bio", "created_at", "counts", "image"]; + protected $fillable = ["id", "username", "first_name", "last_name", "bio", "created_at", "counts", "image", "url", "account_type"]; -} \ No newline at end of file +} From 50b2fccaa81ebdd63e4770c56d0504556b16e471 Mon Sep 17 00:00:00 2001 From: Nino Date: Sun, 10 Apr 2016 05:08:18 +0700 Subject: [PATCH 85/85] Update boot.php Always end if/elseif with an else. --- demo/boot.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/demo/boot.php b/demo/boot.php index 3b87ec0..a4b9b09 100644 --- a/demo/boot.php +++ b/demo/boot.php @@ -19,6 +19,8 @@ $pinterest->auth->setOAuthToken($_GET["access_token"]); } else if (isset($_COOKIE["access_token"])) { $pinterest->auth->setOAuthToken($_COOKIE["access_token"]); + } else { + assert(false); } -?> \ No newline at end of file +?>