-
Notifications
You must be signed in to change notification settings - Fork 0
/
txty.api.php
78 lines (56 loc) · 1.39 KB
/
txty.api.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
70
71
72
73
74
75
76
77
78
<?php
class Txty
{
private static $url = 'https://login.txty.dk/api/4/';
private static $ua = 'EventSignup';
private static $user;
private static $key;
public function __construct($user, $key)
{
self::$user = $user;
self::$key = $key;
}
private static function call($url, $data = null)
{
if($url)
{
$data['user'] = self::$user;
$data['key'] = self::$key;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, self::$url . $url . '/api.json' . '?' . http_build_query($data));
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, self::$ua);
$result = json_decode(curl_exec($ch), true);
curl_close($ch);
return $result;
}
}
public function getDialcodes()
{
return self::call('get/dialcodes');
}
public function viewGroups()
{
return self::call('view/groups');
}
public function createContact($fullname, $msisdn, $groups)
{
$contact = self::call('contact/create', array('fullname' => $fullname, 'msisdn' => $msisdn));
if($contact['status'] == 'success')
{
if($groups)
{
foreach($groups as $value)
self::assignGroup($contact['contact']['controlcontact'], $value);
}
return true;
} else {
return false;
}
}
public function assignGroup($contact, $group)
{
self::call('contact/addgroup', array('contact' => $contact, 'group' => $group));
}
}