1 | <?php |
||
12 | class CurlHttpClient implements HttpClient |
||
13 | { |
||
14 | const COOKIE_NAME = 'pinterest_cookie'; |
||
15 | |||
16 | /** |
||
17 | * @var array |
||
18 | */ |
||
19 | protected $options; |
||
20 | |||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $userAgent = 'Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0'; |
||
25 | |||
26 | /** |
||
27 | * @var array |
||
28 | */ |
||
29 | protected $headers; |
||
30 | |||
31 | /** |
||
32 | * Contains the curl instance. |
||
33 | * |
||
34 | * @var resource |
||
35 | */ |
||
36 | protected $curl; |
||
37 | protected $cookieJar; |
||
38 | |||
39 | public function __construct() |
||
43 | |||
44 | /** |
||
45 | * Executes curl request. |
||
46 | * |
||
47 | * @param string $url |
||
48 | * @param string $postString |
||
49 | * @param array $headers |
||
50 | * @return string |
||
51 | */ |
||
52 | public function execute($url, $postString, array $headers = []) |
||
62 | |||
63 | /** |
||
64 | * Get curl errors. |
||
65 | * |
||
66 | * @return string |
||
67 | */ |
||
68 | public function getErrors() |
||
72 | |||
73 | /** |
||
74 | * @return null|string |
||
75 | */ |
||
76 | public function getToken() |
||
80 | |||
81 | /** |
||
82 | * @param string $userAgent |
||
83 | * @return $this |
||
84 | */ |
||
85 | public function setUserAgent($userAgent) |
||
93 | |||
94 | /** |
||
95 | * Close the curl resource. |
||
96 | * |
||
97 | * @return void |
||
98 | */ |
||
99 | protected function close() |
||
103 | |||
104 | /** |
||
105 | * Initializes curl resource. |
||
106 | * |
||
107 | * @param string $url |
||
108 | * |
||
109 | * @return $this |
||
110 | */ |
||
111 | protected function init($url) |
||
117 | |||
118 | /** |
||
119 | * Sets multiple options at the same time. |
||
120 | * |
||
121 | * @param string $postString |
||
122 | * @return static |
||
123 | */ |
||
124 | protected function setOptions($postString) |
||
132 | |||
133 | /** |
||
134 | * @return array |
||
135 | */ |
||
136 | protected function setDefaultHttpOptions() |
||
150 | |||
151 | /** |
||
152 | * Adds necessary curl options for query. |
||
153 | * |
||
154 | * @param string $postString POST query string |
||
155 | * |
||
156 | * @return $this |
||
157 | */ |
||
158 | protected function makeHttpOptions($postString = '') |
||
169 | } |
||
170 |