1 | <?php |
||
16 | class OAuth |
||
17 | { |
||
18 | |||
19 | /** |
||
20 | * OAuth signature method algorithm. |
||
21 | */ |
||
22 | const HASH_ALGORITHM = 'SHA256'; |
||
23 | |||
24 | /** |
||
25 | * API endpoint URL. |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $url; |
||
30 | |||
31 | /** |
||
32 | * Consumer key. |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $consumerKey; |
||
37 | |||
38 | /** |
||
39 | * Consumer secret. |
||
40 | * |
||
41 | * @var string |
||
42 | */ |
||
43 | protected $consumerSecret; |
||
44 | |||
45 | /** |
||
46 | * API version. |
||
47 | * |
||
48 | * @var string |
||
49 | */ |
||
50 | protected $apiVersion; |
||
51 | |||
52 | /** |
||
53 | * Request method. |
||
54 | * |
||
55 | * @var string |
||
56 | */ |
||
57 | protected $method; |
||
58 | |||
59 | /** |
||
60 | * Request parameters. |
||
61 | * |
||
62 | * @var array |
||
63 | */ |
||
64 | protected $parameters; |
||
65 | |||
66 | /** |
||
67 | * Timestamp. |
||
68 | * |
||
69 | * @var string |
||
70 | */ |
||
71 | protected $timestamp; |
||
72 | |||
73 | /** |
||
74 | * Initialize oAuth class. |
||
75 | * |
||
76 | * @param string $url Store URL. |
||
77 | * @param string $consumerKey Consumer key. |
||
78 | * @param string $consumerSecret Consumer Secret. |
||
79 | * @param string $method Request method. |
||
80 | * @param string $apiVersion API version. |
||
81 | * @param array $parameters Request parameters. |
||
82 | * @param string $timestamp Timestamp. |
||
83 | */ |
||
84 | public function __construct($url, $consumerKey, $consumerSecret, $apiVersion, $method, $parameters = [], $timestamp = '') |
||
94 | |||
95 | /** |
||
96 | * Encode according to RFC 3986. |
||
97 | * |
||
98 | * @param string|array $value Value to be normalized. |
||
99 | * |
||
100 | * @return string |
||
101 | */ |
||
102 | protected function encode($value) |
||
110 | |||
111 | /** |
||
112 | * Normalize parameters. |
||
113 | * |
||
114 | * @param array $parameters Parameters to normalize. |
||
115 | * |
||
116 | * @return array |
||
117 | */ |
||
118 | protected function normalizeParameters($parameters) |
||
132 | |||
133 | /** |
||
134 | * Process filters. |
||
135 | * |
||
136 | * @param array $parameters Request parameters. |
||
137 | * |
||
138 | * @return array |
||
139 | */ |
||
140 | protected function processFilters($parameters) |
||
152 | |||
153 | /** |
||
154 | * Get secret. |
||
155 | * |
||
156 | * @return string |
||
157 | */ |
||
158 | protected function getSecret() |
||
169 | |||
170 | /** |
||
171 | * Generate oAuth1.0 signature. |
||
172 | * |
||
173 | * @param array $parameters Request parameters including oauth. |
||
174 | * |
||
175 | * @return string |
||
176 | */ |
||
177 | protected function generateOauthSignature($parameters) |
||
195 | |||
196 | /** |
||
197 | * Creates an array of urlencoded strings out of each array key/value pairs. |
||
198 | * |
||
199 | * @param array $params Array of parameters to convert. |
||
200 | * @param array $queryParams Array to extend. |
||
201 | * @param string $key Optional Array key to append |
||
202 | * @return string Array of urlencoded strings |
||
203 | */ |
||
204 | protected function joinWithEqualsSign($params, $queryParams = [], $key = '') { |
||
220 | |||
221 | /** |
||
222 | * Sort parameters. |
||
223 | * |
||
224 | * @param array $parameters Parameters to sort in byte-order. |
||
225 | * |
||
226 | * @return array |
||
227 | */ |
||
228 | protected function getSortedParameters($parameters) |
||
240 | |||
241 | /** |
||
242 | * Get oAuth1.0 parameters. |
||
243 | * |
||
244 | * @return string |
||
245 | */ |
||
246 | public function getParameters() |
||
260 | } |
||
261 |