1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright 2015 Dirk Groenen |
4
|
|
|
* |
5
|
|
|
* (c) Dirk Groenen <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace DirkGroenen\Pinterest\Endpoints; |
12
|
|
|
|
13
|
|
|
use DirkGroenen\Pinterest\Models\Pin; |
14
|
|
|
use DirkGroenen\Pinterest\Models\Collection; |
15
|
|
|
|
16
|
|
|
class Pins extends Endpoint { |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Get a pin object |
20
|
|
|
* |
21
|
|
|
* @access public |
22
|
|
|
* @param string $pin_id |
23
|
|
|
* @param array $data |
24
|
|
|
* @throws Exceptions/PinterestExceptions |
25
|
|
|
* @return Pin |
26
|
|
|
*/ |
27
|
3 |
|
public function get($pin_id, array $data = []) |
28
|
|
|
{ |
29
|
3 |
|
$response = $this->request->get(sprintf("pins/%s", $pin_id), $data); |
30
|
3 |
|
return new Pin($this->master, $response); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Get all pins from the given board |
35
|
|
|
* |
36
|
|
|
* @access public |
37
|
|
|
* @param string $board_id |
38
|
|
|
* @param array $data |
39
|
|
|
* @throws Exceptions/PinterestExceptions |
40
|
|
|
* @return Collection |
41
|
|
|
*/ |
42
|
1 |
|
public function fromBoard($board_id, array $data = []) |
43
|
|
|
{ |
44
|
1 |
|
$response = $this->request->get(sprintf("boards/%s/pins", $board_id), $data); |
45
|
1 |
|
return new Collection($this->master, $response, "Pin"); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Create a pin |
50
|
|
|
* |
51
|
|
|
* @access public |
52
|
|
|
* @param array $data |
53
|
|
|
* @throws Exceptions/PinterestExceptions |
54
|
|
|
* @return Pin |
55
|
|
|
*/ |
56
|
1 |
|
public function create(array $data) |
57
|
|
|
{ |
58
|
1 |
|
if (array_key_exists("image", $data)) { |
59
|
|
|
if (class_exists("\CURLFile")) { |
60
|
|
|
$data["image"] = new \CURLFile($data['image']); |
61
|
|
|
} else { |
62
|
|
|
$data["image"] = '@' . $data['image']; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
1 |
|
$response = $this->request->post("pins", $data); |
67
|
1 |
|
return new Pin($this->master, $response); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Edit a pin |
72
|
|
|
* |
73
|
|
|
* @access public |
74
|
|
|
* @param string $pin_id |
75
|
|
|
* @param array $data |
76
|
|
|
* @param string $fields |
77
|
|
|
* @throws Exceptions/PinterestExceptions |
78
|
|
|
* @return Pin |
79
|
|
|
*/ |
80
|
1 |
View Code Duplication |
public function edit($pin_id, array $data, $fields = null) |
|
|
|
|
81
|
|
|
{ |
82
|
1 |
|
$query = (!$fields) ? array() : array("fields" => $fields); |
83
|
|
|
|
84
|
1 |
|
$response = $this->request->update(sprintf("pins/%s", $pin_id), $data, $query); |
85
|
1 |
|
return new Pin($this->master, $response); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Delete a pin |
90
|
|
|
* |
91
|
|
|
* @access public |
92
|
|
|
* @param string $pin_id |
93
|
|
|
* @throws Exceptions/PinterestExceptions |
94
|
|
|
* @return boolean |
95
|
|
|
*/ |
96
|
1 |
|
public function delete($pin_id) |
97
|
|
|
{ |
98
|
1 |
|
$this->request->delete(sprintf("pins/%s", $pin_id)); |
99
|
1 |
|
return true; |
100
|
|
|
} |
101
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.