|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace seregazhuk\PinterestBot\Api\Providers; |
|
4
|
|
|
|
|
5
|
|
|
use seregazhuk\PinterestBot\Api\Request; |
|
6
|
|
|
use seregazhuk\PinterestBot\Api\Response; |
|
7
|
|
|
use seregazhuk\PinterestBot\Contracts\RequestInterface; |
|
8
|
|
|
use seregazhuk\PinterestBot\Contracts\ResponseInterface; |
|
9
|
|
|
use seregazhuk\PinterestBot\Helpers\Providers\Traits\ProviderTrait; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class Provider |
|
13
|
|
|
* |
|
14
|
|
|
* @package seregazhuk\PinterestBot\Contracts |
|
15
|
|
|
*/ |
|
16
|
|
|
abstract class Provider |
|
17
|
|
|
{ |
|
18
|
|
|
use ProviderTrait; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* List of methods that require logged status |
|
22
|
|
|
* @var array |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $loginRequired = []; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Instance of the API RequestInterface |
|
28
|
|
|
* |
|
29
|
|
|
* @var RequestInterface |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $request; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Instance of the API ResponseInterface |
|
35
|
|
|
* |
|
36
|
|
|
* @var ResponseInterface |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $response; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param RequestInterface $request |
|
42
|
|
|
* @param ResponseInterface $response |
|
43
|
|
|
*/ |
|
44
|
|
|
public function __construct(RequestInterface $request, ResponseInterface $response) |
|
45
|
|
|
{ |
|
46
|
|
|
$this->request = $request; |
|
47
|
|
|
$this->response = $response; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Executes a POST request to Pinterest API |
|
52
|
|
|
* |
|
53
|
|
|
* @param array $requestOptions |
|
54
|
|
|
* @param string $resourceUrl |
|
55
|
|
|
* @param bool $returnData |
|
56
|
|
|
* @return mixed |
|
57
|
|
|
*/ |
|
58
|
|
|
public function callPostRequest($requestOptions, $resourceUrl, $returnData = false) |
|
59
|
|
|
{ |
|
60
|
|
|
$data = array("options" => $requestOptions); |
|
61
|
|
|
$postString = Request::createQuery($data); |
|
62
|
|
|
$response = $this->request->exec($resourceUrl, $postString); |
|
63
|
|
|
|
|
64
|
|
|
if ($returnData) { |
|
65
|
|
|
return $this->response->getData($response); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return $this->response->checkResponse($response); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @return Request |
|
73
|
|
|
*/ |
|
74
|
|
|
public function getRequest() |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->request; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @return Response |
|
81
|
|
|
*/ |
|
82
|
|
|
public function getResponse() |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->response; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @param string $method |
|
89
|
|
|
* @return bool |
|
90
|
|
|
*/ |
|
91
|
|
|
public function checkMethodRequiresLogin($method) |
|
92
|
|
|
{ |
|
93
|
|
|
return in_array($method, $this->loginRequired); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|