-
Notifications
You must be signed in to change notification settings - Fork 2
/
Base.class.php
100 lines (92 loc) · 2.54 KB
/
Base.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
// Namespace overhead
namespace onassar\Pexels;
use onassar\RemoteRequests;
/**
* Base
*
* PHP wrapper for Pexels.
*
* @link https://github.com/onassar/PHP-Pexels
* @link https://www.pexels.com/api/
* @link https://www.pexels.com/api/documentation/
* @author Oliver Nassar <[email protected]>
* @extends RemoteRequests\Base
*/
class Base extends RemoteRequests\Base
{
/**
* Traits
*
*/
use RemoteRequests\Traits\Pagination;
use RemoteRequests\Traits\RateLimits;
use RemoteRequests\Traits\SearchAPI;
/**
* _host
*
* @access protected
* @var string (default: 'api.pexels.com')
*/
protected $_host = 'api.pexels.com';
/**
* _paths
*
* @access protected
* @var array
*/
protected $_paths = array(
'search' => '/v1/search'
);
/**
* __construct
*
* @link https://www.pexels.com/api/documentation/#photos-search__per_page
* @see https://i.imgur.com/JUkbKpC.png
* @access public
* @return void
*/
public function __construct()
{
$this->_maxResultsSupportedPerRequest = 80;
$this->_responseResultsIndexKey = 'photos';
}
/**
* _getAuthorizationHeader
*
* @access protected
* @return string
*/
protected function _getAuthorizationHeader(): string
{
$apiKey = $this->_apiKey;
$header = 'Authorization: ' . ($apiKey);
return $header;
}
/**
* _getCURLRequestHeaders
*
* @access protected
* @return array
*/
protected function _getCURLRequestHeaders(): array
{
$headers = parent::_getCURLRequestHeaders();
$header = $this->_getAuthorizationHeader();
array_push($headers, $header);
return $headers;
}
/**
* _getRequestStreamContextOptions
*
* @access protected
* @return array
*/
protected function _getRequestStreamContextOptions(): array
{
$options = parent::_getRequestStreamContextOptions();
$header = $this->_getAuthorizationHeader();
$options['http']['header'] = $header;
return $options;
}
}