Skip to content
This repository has been archived by the owner on Nov 7, 2020. It is now read-only.

Commit

Permalink
Add method to get the pins of a board
Browse files Browse the repository at this point in the history
- Add test
- Update docs
- Add method `getBoardPins`

Closes #15
  • Loading branch information
hansott committed Apr 15, 2016
1 parent f27a783 commit c9f87bd
Show file tree
Hide file tree
Showing 4 changed files with 195 additions and 6 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ $updatedBoard = $response->result(); // $updatedBoard instanceof Objects\Board
```php
$response = $api->getUserBoards();
if ($response->ok()) {
$pagedList = $response->result(); // $boards instanceof Objects\PagedList
$pagedList = $response->result(); // $pagedList instanceof Objects\PagedList
$boards = $pagedList->items(); // array of Objects\Board objects
}
```
Expand All @@ -148,7 +148,19 @@ if ($response->ok()) {
```php
$response = $api->getUserLikes();
if ($response->ok()) {
$pagedList = $response->result(); // $boards instanceof Objects\PagedList
$pagedList = $response->result(); // $pagedList instanceof Objects\PagedList
$pins = $pagedList->items(); // array of Objects\Pin objects
}
```

See [Get the next items of a paged list](#get-the-next-items-of-a-paged-list)

### Get the pins of a board

```php
$response = $api->getBoardPins();
if ($response->ok()) {
$pagedList = $response->result(); // $pagedList instanceof Objects\PagedList
$pins = $pagedList->items(); // array of Objects\Pin objects
}
```
Expand Down
19 changes: 19 additions & 0 deletions src/Pinterest/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -559,4 +559,23 @@ private function buildRequestForPagedList(PagedList $pagedList)

return new Request('GET', $path, $params);
}

/**
* Get the pins of a board.
*
* @param string $boardId
*
* @return Response
*/
public function getBoardPins($boardId)
{
if (empty($boardId)) {
throw new InvalidArgumentException('The board id should not be empty.');
}

$endpoint = sprintf('boards/%s/pins/', $boardId);
$request = new Request('GET', $endpoint);

return $this->fetchMultiplePins($request);
}
}
13 changes: 9 additions & 4 deletions tests/Pinterest/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ApiTest extends TestCase
*/
protected $api;

protected $board;
protected $boardId;

public function setUp()
{
Expand All @@ -39,7 +39,7 @@ public function setUp()
$mocked = new MockClient($client, $cacheDir);
$auth = Authentication::withAccessToken($mocked, null, null, getenv('ACCESS_TOKEN'));
$this->api = new Api($auth);
$this->board = getenv('BOARD_ID');
$this->boardId = getenv('BOARD_ID');
}

public function test_it_gets_users()
Expand Down Expand Up @@ -114,7 +114,7 @@ public function test_it_follows_a_user()
public function test_it_creates_a_pin(Image $image, $note)
{
$response = $this->api->createPin(
$this->board,
$this->boardId,
$note,
$image
);
Expand Down Expand Up @@ -145,7 +145,7 @@ public function test_it_deletes_a_pin()
{
$data = $this->imageProvider();
$createResponse = $this->api->createPin(
$this->board,
$this->boardId,
$data[0][1],
$data[0][0]
);
Expand Down Expand Up @@ -185,4 +185,9 @@ public function test_it_cannot_get_more_items_for_an_empty_list()
$this->setExpectedException('InvalidArgumentException');
$this->api->getNextItems($pagedList);
}

public function test_it_returns_the_pins_of_a_board()
{
$this->assertMultiplePins($this->api->getBoardPins($this->boardId));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
{
"body": {
"data": {
"0": {
"attribution": null,
"creator": {
"url": "https:\/\/www.pinterest.com\/otthans\/",
"first_name": "Hans",
"last_name": "Ott",
"id": "314196648911734959"
},
"url": "https:\/\/www.pinterest.com\/pin\/314196511484779371\/",
"media": {
"type": "image"
},
"created_at": "2016-03-13T14:59:56",
"note": "Command Line Cheat Sheet for Mac and Linux. I know these, but always good to have on hand!",
"color": "#e7e8ea",
"link": "https:\/\/www.pinterest.com\/r\/pin\/314196511484779371\/4795844593113372404\/8452b7c3737372ce040537e4bd030ab4dbdb34c9290520c3cd73ed8bbbfa0a5a",
"board": {
"url": "https:\/\/www.pinterest.com\/otthans\/test\/",
"id": "314196580192658592",
"name": "Test"
},
"image": {
"original": {
"url": "https:\/\/s-media-cache-ak0.pinimg.com\/originals\/cc\/ba\/66\/ccba6681ac9c3e6ed93034a7a4693394.jpg",
"width": 818,
"height": 3321
}
},
"counts": {
"likes": 0,
"comments": 0,
"repins": 4
},
"id": "314196511484779371",
"metadata": {}
},
"1": {
"attribution": null,
"creator": {
"url": "https:\/\/www.pinterest.com\/otthans\/",
"first_name": "Hans",
"last_name": "Ott",
"id": "314196648911734959"
},
"url": "https:\/\/www.pinterest.com\/pin\/314196511484779368\/",
"media": {
"type": "image"
},
"created_at": "2016-03-13T14:59:45",
"note": "Which Coding Language Should You Learn?",
"color": "#ae92ad",
"link": "https:\/\/www.pinterest.com\/r\/pin\/314196511484779368\/4795844593113372404\/30c86db5d8e574bdc38b284aa390eee21ccc3786f1b025e8f087075bc5032396",
"board": {
"url": "https:\/\/www.pinterest.com\/otthans\/test\/",
"id": "314196580192658592",
"name": "Test"
},
"image": {
"original": {
"url": "https:\/\/s-media-cache-ak0.pinimg.com\/originals\/3e\/6a\/b4\/3e6ab4a62a7facb3170911e51484ddba.jpg",
"width": 800,
"height": 9424
}
},
"counts": {
"likes": 0,
"comments": 0,
"repins": 0
},
"id": "314196511484779368",
"metadata": {
"article": {
"published_at": "2014-09-27T00:00:00",
"description": "Read Which Coding Language Should You Learn?",
"name": "Which Coding Language Should You Learn?",
"authors": {
"0": {
"name": "Oliur"
}
}
},
"link": {
"locale": "en",
"title": "Which Coding Language Should You Learn?",
"site_name": "UltraLinx",
"description": "Read Which Coding Language Should You Learn?",
"favicon": "https:\/\/s-media-cache-ak0.pinimg.com\/favicons\/1c6096a37e41f1582c4ff942baa93686b01d768349bcfd71e2f2458c.ico?14b1fc4ff5a2251c16f18da1fbe9c1ba"
}
}
},
"2": {
"attribution": null,
"creator": {
"url": "https:\/\/www.pinterest.com\/otthans\/",
"first_name": "Hans",
"last_name": "Ott",
"id": "314196648911734959"
},
"url": "https:\/\/www.pinterest.com\/pin\/314196511484779365\/",
"media": {
"type": "image"
},
"created_at": "2016-03-13T14:59:34",
"note": "How to Teach Yourself Code Infographic - http:\/\/elearninginfographics.com\/teach-yourself-code\/",
"color": "#0e163b",
"link": "https:\/\/www.pinterest.com\/r\/pin\/314196511484779365\/4795844593113372404\/d7406e8eb853c19256cb17de15bdcf10d761f101b60f14d72f0d2e8dc10fbb1c",
"board": {
"url": "https:\/\/www.pinterest.com\/otthans\/test\/",
"id": "314196580192658592",
"name": "Test"
},
"image": {
"original": {
"url": "https:\/\/s-media-cache-ak0.pinimg.com\/originals\/71\/f5\/64\/71f56468c6aaef1da0e4580d4e687914.jpg",
"width": 800,
"height": 3630
}
},
"counts": {
"likes": 0,
"comments": 0,
"repins": 0
},
"id": "314196511484779365",
"metadata": {}
}
},
"page": {
"cursor": null,
"next": null
}
},
"statusCode": 200,
"headers": {
"Access-Control-Allow-Origin": "*",
"Cache-Control": "private",
"Content-Type": "application\/json",
"Pinterest-Generated-By": "None",
"Pinterest-Version": "4f0abf0",
"Server": "nginx",
"X-Content-Type-Options": "nosniff",
"X-Pinterest-RID": "732904799569",
"X-Ratelimit-Limit": "200",
"X-Ratelimit-Remaining": "199",
"X-Varnish": "1390648253",
"Date": "Fri, 15 Apr 2016 16:10:16 GMT",
"Content-Length": "3232",
"Connection": "keep-alive"
}
}

0 comments on commit c9f87bd

Please sign in to comment.