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\Helpers\UrlHelper; |
8
|
|
|
use seregazhuk\PinterestBot\Interfaces\RequestInterface; |
9
|
|
|
use seregazhuk\PinterestBot\Interfaces\ResponseInterface; |
10
|
|
|
use seregazhuk\PinterestBot\Helpers\Providers\ProviderHelper; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class Provider |
14
|
|
|
* |
15
|
|
|
* @package seregazhuk\PinterestBot\Interfaces |
16
|
|
|
*/ |
17
|
|
|
class Provider |
18
|
|
|
{ |
19
|
|
|
use ProviderHelper; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Instance of the API RequestInterface |
23
|
|
|
* |
24
|
|
|
* @var RequestInterface |
25
|
|
|
*/ |
26
|
|
|
protected $request; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Instance of the API ResponseInterface |
30
|
|
|
* |
31
|
|
|
* @var ResponseInterface |
32
|
|
|
*/ |
33
|
|
|
protected $response; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param RequestInterface $request |
37
|
|
|
* @param ResponseInterface $response |
38
|
|
|
*/ |
39
|
|
|
public function __construct(RequestInterface $request, ResponseInterface $response) |
40
|
|
|
{ |
41
|
|
|
$this->request = $request; |
42
|
|
|
$this->response = $response; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Executes a POST request to Pinterest API |
47
|
|
|
* |
48
|
|
|
* @param array $requestOptions |
49
|
|
|
* @param string $resourceUrl |
50
|
|
|
* @param bool $checkLogin |
51
|
|
|
* @param bool $returnData |
52
|
|
|
* @return mixed |
53
|
|
|
*/ |
54
|
|
|
public function callPostRequest($requestOptions, $resourceUrl, $checkLogin = false, $returnData = null) |
55
|
|
|
{ |
56
|
|
|
if ($checkLogin) { |
57
|
|
|
$this->request->checkLoggedIn(); |
58
|
|
|
} |
59
|
|
|
$data = array("options" => $requestOptions); |
60
|
|
|
$request = Request::createRequestData($data); |
61
|
|
|
|
62
|
|
|
$postString = UrlHelper::buildRequestString($request); |
63
|
|
|
$response = $this->request->exec($resourceUrl, $postString); |
64
|
|
|
|
65
|
|
|
if ($returnData) { |
66
|
|
|
return $this->response->getData($response); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return $this->response->checkResponse($response); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return Request |
75
|
|
|
*/ |
76
|
|
|
protected function getRequest() |
77
|
|
|
{ |
78
|
|
|
return $this->request; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return Response |
83
|
|
|
*/ |
84
|
|
|
protected function getResponse() |
85
|
|
|
{ |
86
|
|
|
return $this->response; |
87
|
|
|
} |
88
|
|
|
} |