Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fixed api paths #109

Merged
merged 4 commits into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Pinterest/Endpoints/Boards.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Boards extends Endpoint {
*/
public function get($board_id, array $data = [])
{
$response = $this->request->get(sprintf("boards/%s", $board_id), $data);
$response = $this->request->get(sprintf("boards/%s/", $board_id), $data);
return new Board($this->master, $response);
}

Expand All @@ -39,7 +39,7 @@ public function get($board_id, array $data = [])
*/
public function create(array $data)
{
$response = $this->request->post("boards", $data);
$response = $this->request->post("boards/", $data);
return new Board($this->master, $response);
}

Expand All @@ -57,7 +57,7 @@ public function edit($board_id, array $data, $fields = null)
{
$query = (!$fields) ? array() : array("fields" => $fields);

$response = $this->request->update(sprintf("boards/%s", $board_id), $data, $query);
$response = $this->request->update(sprintf("boards/%s/", $board_id), $data, $query);
return new Board($this->master, $response);
}

Expand All @@ -71,7 +71,7 @@ public function edit($board_id, array $data, $fields = null)
*/
public function delete($board_id)
{
$this->request->delete(sprintf("boards/%s", $board_id));
$this->request->delete(sprintf("boards/%s/", $board_id));
return true;
}
}
18 changes: 9 additions & 9 deletions src/Pinterest/Endpoints/Following.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Following extends Endpoint {
*/
public function users(array $data = [])
{
$response = $this->request->get("me/following/users", $data);
$response = $this->request->get("me/following/users/", $data);
return new Collection($this->master, $response, "User");
}

Expand All @@ -40,7 +40,7 @@ public function users(array $data = [])
*/
public function boards(array $data = [])
{
$response = $this->request->get("me/following/boards", $data);
$response = $this->request->get("me/following/boards/", $data);
return new Collection($this->master, $response, "Board");
}

Expand All @@ -54,7 +54,7 @@ public function boards(array $data = [])
*/
public function interests(array $data = [])
{
$response = $this->request->get("me/following/interests", $data);
$response = $this->request->get("me/following/interests/", $data);
return new Collection($this->master, $response, "Interest");
}

Expand All @@ -68,7 +68,7 @@ public function interests(array $data = [])
*/
public function followUser($user)
{
$this->request->post("me/following/users", array(
$this->request->post("me/following/users/", array(
"user" => $user
));
return true;
Expand All @@ -84,7 +84,7 @@ public function followUser($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;
}

Expand All @@ -98,7 +98,7 @@ public function unfollowUser($user)
*/
public function followBoard($board)
{
$this->request->post("me/following/boards", array(
$this->request->post("me/following/boards/", array(
"board" => $board
));
return true;
Expand All @@ -114,7 +114,7 @@ public function followBoard($board)
*/
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;
}

Expand All @@ -128,7 +128,7 @@ public function unfollowBoard($board_id)
*/
public function followInterest($interest)
{
$this->request->post("me/following/interests", array(
$this->request->post("me/following/interests/", array(
"interest" => $interest
));
return true;
Expand All @@ -144,7 +144,7 @@ public function followInterest($interest)
*/
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;
}
}
8 changes: 4 additions & 4 deletions src/Pinterest/Endpoints/Pins.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Pins extends Endpoint {
*/
public function get($pin_id, array $data = [])
{
$response = $this->request->get(sprintf("pins/%s", $pin_id), $data);
$response = $this->request->get(sprintf("pins/%s/", $pin_id), $data);
return new Pin($this->master, $response);
}

Expand All @@ -41,7 +41,7 @@ public function get($pin_id, array $data = [])
*/
public function fromBoard($board_id, array $data = [])
{
$response = $this->request->get(sprintf("boards/%s/pins", $board_id), $data);
$response = $this->request->get(sprintf("boards/%s/pins/", $board_id), $data);
return new Collection($this->master, $response, "Pin");
}

Expand All @@ -63,7 +63,7 @@ public function create(array $data)
}
}

$response = $this->request->post("pins", $data);
$response = $this->request->post("pins/", $data);
return new Pin($this->master, $response);
}

Expand Down Expand Up @@ -95,7 +95,7 @@ public function edit($pin_id, array $data, $fields = null)
*/
public function delete($pin_id)
{
$this->request->delete(sprintf("pins/%s", $pin_id));
$this->request->delete(sprintf("pins/%s/", $pin_id));
return true;
}
}
6 changes: 3 additions & 3 deletions src/Pinterest/Endpoints/Sections.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Sections extends Endpoint {
*/
public function create(string $board, array $data)
{
$response = $this->request->put(sprintf("board/%s/sections", $board), $data);
$response = $this->request->put(sprintf("board/%s/sections/", $board), $data);
return new Section($this->master, ['id' => $response->data]);
}

Expand Down Expand Up @@ -58,7 +58,7 @@ public function get(string $board, array $data = [])
*/
public function pins(string $section, array $data = [])
{
$response = $this->request->get(sprintf("board/sections/%s/pins", $section), $data);
$response = $this->request->get(sprintf("board/sections/%s/pins/", $section), $data);
return new Collection($this->master, $response, "Pin");
}

Expand All @@ -72,7 +72,7 @@ public function pins(string $section, array $data = [])
*/
public function delete($section)
{
$this->request->delete(sprintf("board/sections/%s", $section));
$this->request->delete(sprintf("board/sections/%s/", $section));
return true;
}
}
16 changes: 8 additions & 8 deletions src/Pinterest/Endpoints/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Users extends Endpoint {
*/
public function me(array $data = [])
{
$response = $this->request->get("me", $data);
$response = $this->request->get("me/", $data);
return new User($this->master, $response);
}

Expand All @@ -40,7 +40,7 @@ public function me(array $data = [])
*/
public function find($username, array $data = [])
{
$response = $this->request->get(sprintf("users/%s", $username), $data);
$response = $this->request->get(sprintf("users/%s/", $username), $data);
return new User($this->master, $response);
}

Expand All @@ -54,7 +54,7 @@ public function find($username, array $data = [])
*/
public function getMePins(array $data = [])
{
$response = $this->request->get("me/pins", $data);
$response = $this->request->get("me/pins/", $data);
return new Collection($this->master, $response, "Pin");
}

Expand All @@ -69,7 +69,7 @@ public function getMePins(array $data = [])
public function searchMePins($query, array $data = [])
{
$data["query"] = $query;
$response = $this->request->get("me/search/pins", $data);
$response = $this->request->get("me/search/pins/", $data);
return new Collection($this->master, $response, "Pin");
}

Expand All @@ -85,7 +85,7 @@ public function searchMeBoards($query, array $data = [])
{
$data["query"] = $query;

$response = $this->request->get("me/search/boards", $data);
$response = $this->request->get("me/search/boards/", $data);
return new Collection($this->master, $response, "Board");
}

Expand All @@ -99,7 +99,7 @@ public function searchMeBoards($query, array $data = [])
*/
public function getMeBoards(array $data = [])
{
$response = $this->request->get("me/boards", $data);
$response = $this->request->get("me/boards/", $data);
return new Collection($this->master, $response, "Board");
}

Expand All @@ -113,7 +113,7 @@ public function getMeBoards(array $data = [])
*/
public function getMeLikes(array $data = [])
{
$response = $this->request->get("me/likes", $data);
$response = $this->request->get("me/likes/", $data);
return new Collection($this->master, $response, "Pin");
}

Expand All @@ -127,7 +127,7 @@ public function getMeLikes(array $data = [])
*/
public function getMeFollowers(array $data = [])
{
$response = $this->request->get("me/followers", $data);
$response = $this->request->get("me/followers/", $data);
return new Collection($this->master, $response, "User");
}

Expand Down
4 changes: 2 additions & 2 deletions src/Pinterest/Transport/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function setAccessToken($token)
public function get($endpoint, array $parameters = array())
{
if (!empty($parameters)) {
$path = sprintf("%s/?%s", $endpoint, http_build_query($parameters));
$path = sprintf("%s?%s", $endpoint, http_build_query($parameters));
} else {
$path = $endpoint;
}
Expand Down Expand Up @@ -136,7 +136,7 @@ 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($queryparameters));
$path = sprintf("%s?%s", $endpoint, http_build_query($queryparameters));
} else {
$path = $endpoint;
}
Expand Down
6 changes: 5 additions & 1 deletion src/Pinterest/Utils/CurlBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

namespace DirkGroenen\Pinterest\Utils;

use DirkGroenen\Pinterest\Exceptions\PinterestException;

class CurlBuilder {

/**
Expand Down Expand Up @@ -216,9 +218,11 @@ private function execFollow() {
} else {
$code = $this->getInfo(CURLINFO_HTTP_CODE);

if ($code == 301 || $code == 302) {
if ($code == 301 || $code == 302 || $code == 308) {
preg_match('/Location:(.*?)\n/i', $header, $matches);
$newurl = trim(array_pop($matches));
} else if ($code >= 300 && $code <= 399) {
throw new PinterestException('Error: Unhandled 3xx HTTP code: ' . $code);
} else {
$code = 0;
}
Expand Down