/
vnca_api.php
204 lines (165 loc) · 4.29 KB
/
vnca_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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?php
/*
VNCA CLIENT API
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is VoiceNetwork.ca API Client Lib
The Initial Developer of the Original Code is
Ken Rice
Portions created by the Initial Developer are Copyright (C) 2011
the Initial Developer. All Rights Reserved.
Contributor(s):
Ken Rice
*/
function vnca_api_did($call, $params) {
switch(strtolower($call)) {
case 'regions':
return get_did_regions($params);
break;
case 'ratecenters':
return get_did_ratecenters($params);
break;
case 'list':
return get_did_list($params);
break;
case 'didinfo':
return get_did_info($params);
break;
case 'orderdid':
return get_did_order($params);
break;
case 'updatepeerid':
return get_did_update_peer_id($params);
break;
case 'forward':
return NULL;
break;
}
}
function do_curl_get($method_in, $get_params){
$api_key='API_KEY_GOES_HERE';
// $api_key='TESTLK83MGAPIJL56LR5LKKEYGQEUJL5UYAFZDAG';
$post_fields = '';
if(is_array($get_params)) {
foreach($get_params as $key => $val){
$post_fields .= "$key=" . urlencode($val) . "&";
}
}
$post_fields .= 'X-API-KEY='.$api_key.'&format=json';
$method = 'http://api.voicenetwork.ca/api/v1/' . $method_in . "?" . $post_fields;;
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,$method);
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
return $buffer;
}
function get_did_regions($params) {
if (!isset($params['country'])){
return false;
}
$results = json_decode(do_curl_get('did/regions', $params), true);
if ($results['status'] != 'success') {
return false;
} else {
return $results['regions'];
}
}
function get_did_ratecenters($params) {
if (!isset($params['country'])){
return false;
}
$data = json_decode(do_curl_get('did/RateCenters', $params), true);
if ($data['status'] != 'success') {
return false;
} else {
$ratecenters = $data['ratecenters'];
if (isset($params['region'])) {
$x = 0;
foreach($ratecenters as $ratecenter) {
$rc = $ratecenter;
if ($rc['region'] == $params['region']) {
$results[$x] = $rc;
$x++;
}
}
} else {
$x = 0;
foreach($ratecenters as $ratecenter) {
$rc = $ratecenter;
$results[$x] = $rc;
$x++;
}
}
return $results;
}
}
function get_did_list($params) {
if (!isset($params['country'])){
echo "no Country";
return false;
}
if (!isset($params['region'])){
echo "no region";
return false;
}
if (!isset($params['ratecenter'])){
echo "no ratecenter";
return false;
}
$results = json_decode(do_curl_get('did/list', $params), true);
if ($results['status'] != 'success') {
print_r($results);
return false;
} else {
return $results['dids'];
}
}
function get_did_info($params) {
if (!isset($params['did'])){
return false;
}
$results = json_decode(do_curl_get('did/didinfo', $params), true);
if ($results['status'] != 'success') {
return false;
} else {
return array('dids' => $results['dids'], 'packages' => $results['packages']);
}
}
function get_did_order($params) {
if (!isset($params['did'])){
return false;
}
if (!isset($params['package_id'])){
return false;
}
$results = json_decode(do_curl_get('did/orderdid', $params), true);
if ($results['status'] != 'success') {
return false;
} else {
return $results['success'];
}
}
function get_did_update_peer_id($params) {
if (!isset($params['did'])){
return false;
}
if (!isset($params['peer_id'])){
return false;
}
$results = json_decode(do_curl_get('did/updatepeerid', $params), true);
if ($results['status'] != 'success') {
return false;
} else {
return $results['success'];
}
}
?>