-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDevRant.php
69 lines (57 loc) · 1.67 KB
/
DevRant.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
<?php
class DevRant {
private $token_id;
private $token_key;
private $user_id;
function login($username, $password) {
// The data to send
$postdata = [
"app" => 3,
"plat" => 3,
"username" => $username,
"password" => $password
];
// Make data useable for request
$postdata = http_build_query($postdata);
$url = 'https://devrant.com/api/users/auth-token';
// Curl options
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// Execute curl and get response
$response = json_decode(curl_exec($curl), true);
curl_close($curl);
$this->token_id = $response["auth_token"]["id"];
$this->token_key = $response["auth_token"]["key"];
$this->user_id = $response["auth_token"]["user_id"];
return $response;
}
function postRant($msg, $tags) {
// The data to send
$postdata = [
"app" => 3,
"rant" => $msg,
"tags" => $tags,
"token_id" => $this->token_id,
"token_key" => $this->token_key,
"user_id" => $this->user_id
];
// Make data useable for request
$postdata = http_build_query($postdata);
$url = 'https://devrant.com/api/devrant/rants';
// Curl options
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// Execute curl and get response
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
}