-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstreamlabs.class.php
More file actions
148 lines (133 loc) · 4.29 KB
/
Copy pathstreamlabs.class.php
File metadata and controls
148 lines (133 loc) · 4.29 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
/*
*
* Author: omerfarukucuk.com - Ömer Faruk Küçük
* github.com/omerfarukucuk
*
* */
class StreamLabs
{
const API_URL = 'https://streamlabs.com/api/';
private $API_VERSION = 'v1.0';
private $CLIENT_ID = '';
private $CLIENT_SECRET_KEY = '';
private $REDIRECT_URL = '';
private $APP_NAME = '';
public $access_token = '';
public $token_type = 'Bearer';
public $expires_in = 3600;
public $refresh_token = '';
public function __construct(array $_arr = array())
{
$this->CLIENT_ID = $_arr['client_id'];
$this->CLIENT_SECRET_KEY = $_arr['client_secret'];
$this->REDIRECT_URL = $_arr['redirect_url'];
if (isset($_arr['app_name'])){
$this->APP_NAME = $_arr['app_name'];
}
if (isset($_arr['api_version'])) {
$this->API_VERSION = $_arr['api_version'];
}
}
public function post_donate($name, $message, $identifier, $amount, $currency = 'TRY', $created_at = '')
{
$created_at = ($created_at == '' ? date('m/d/Y h:i A') : date('m/d/Y h:i A', strtotime($created_at)));
$params = [
'name' => $name,
'message' => $message,
'identifier' => $identifier,
'amount' => $amount,
'currency' => $currency,
'created_at' => $created_at,
'skip_alert' => 'no',
'access_token' => $this->token->access_token
];
return $this->_response(
$this->_curl($this->buildApiUrl('donations'), $params),
false
);
}
public function donations()
{
$params = [
'access_token' => $this->token->access_token
];
return $this->_response(
$this->_curl($this->buildApiUrl('donations') . '?' . http_build_query($params))
);
}
public function user()
{
$params = [
'access_token' => $this->token->access_token
];
return $this->_response(
$this->_curl($this->buildApiUrl('user') . '?' . http_build_query($params))
);
}
public function token($code = null, $grant_type = 'authorization_code', $refresh_token = null)
{
$params = [
'grant_type' => $grant_type,
'client_id' => $this->CLIENT_ID,
'client_secret' => $this->CLIENT_SECRET_KEY,
'redirect_uri' => $this->REDIRECT_URL,
'code' => $code,
'refresh_token' => $refresh_token
];
$jsonResponse = $this->_response(
$this->_curl($this->buildApiUrl('token'), $params),
);
if (isset($jsonResponse->access_token)) {
$this->token = $jsonResponse;
}
return $jsonResponse;
}
public function authorize($scope = '')
{
$params = [
'response_type' => 'code',
'client_id' => $this->CLIENT_ID,
'redirect_uri' => $this->REDIRECT_URL,
'scope' => $scope
];
return $this->buildApiUrl('authorize') . '?' . http_build_query($params);
}
private function buildApiUrl($endpoint = '')
{
return self::API_URL . $this->API_VERSION . '/' . $endpoint;
}
private function _response($response, $returnJson = true)
{
if ($returnJson)
return json_decode($response);
else
return $response;
}
private function _curl($url, $post = null)
{
if (!extension_loaded("curl")) {
die('You must install CURL');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: application/json'
));
curl_setopt($ch, CURLOPT_VERBOSE, true);
if (is_array($post)) {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
}
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
curl_close($ch);
if (!$response)
die('CURL ERROR: ' . curl_error($ch));
else
return $response;
}
}