@telegenta/webclient 2.0.11 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/README.md +102 -81
  2. package/demos/add_phone_number.html +8 -7
  3. package/demos/calldata_available.html +5 -5
  4. package/demos/embedded_config.html +95 -95
  5. package/demos/event_client.html +226 -226
  6. package/demos/phone_client.html +564 -558
  7. package/dist/telegenta.js +3627 -0
  8. package/dist/telegenta.min.js +1 -0
  9. package/docs/EventClient.html +3 -1093
  10. package/docs/InvalidMediaDevice.html +3 -0
  11. package/docs/InvalidOptions.html +3 -0
  12. package/docs/InvalidParameter.html +3 -0
  13. package/docs/LogHandler.html +7 -0
  14. package/docs/MediaNotPrepared.html +3 -0
  15. package/docs/NoActiveSession.html +3 -0
  16. package/docs/NotAllowed.html +3 -0
  17. package/docs/NotReady.html +3 -0
  18. package/docs/Phone.html +4 -2837
  19. package/docs/Request.html +3 -0
  20. package/docs/Requestor.html +3 -0
  21. package/docs/Session.html +3 -2599
  22. package/docs/UnableToConnect.html +3 -0
  23. package/docs/data/search.json +1 -0
  24. package/docs/event-client.js.html +346 -0
  25. package/docs/exceptions.js.html +94 -0
  26. package/docs/fonts/Inconsolata-Regular.ttf +0 -0
  27. package/docs/fonts/OpenSans-Regular.ttf +0 -0
  28. package/docs/fonts/WorkSans-Bold.ttf +0 -0
  29. package/docs/global.html +5 -4950
  30. package/docs/index.html +3 -66
  31. package/docs/logger.js.html +106 -0
  32. package/docs/phone-client.js.html +2155 -0
  33. package/docs/requestor.js.html +223 -0
  34. package/docs/scripts/core.js +726 -0
  35. package/docs/scripts/core.min.js +23 -0
  36. package/docs/scripts/resize.js +90 -0
  37. package/docs/scripts/search.js +265 -0
  38. package/docs/scripts/search.min.js +6 -0
  39. package/docs/scripts/{prettify → third-party}/Apache-License-2.0.txt +202 -202
  40. package/docs/scripts/third-party/fuse.js +9 -0
  41. package/docs/scripts/third-party/hljs-line-num-original.js +369 -0
  42. package/docs/scripts/third-party/hljs-line-num.js +1 -0
  43. package/docs/scripts/third-party/hljs-original.js +5171 -0
  44. package/docs/scripts/third-party/hljs.js +1 -0
  45. package/docs/scripts/third-party/popper.js +5 -0
  46. package/docs/scripts/third-party/tippy.js +1 -0
  47. package/docs/scripts/third-party/tocbot.js +672 -0
  48. package/docs/scripts/third-party/tocbot.min.js +1 -0
  49. package/docs/styles/clean-jsdoc-theme-base.css +1159 -0
  50. package/docs/styles/clean-jsdoc-theme-dark.css +412 -0
  51. package/docs/styles/clean-jsdoc-theme-light.css +482 -0
  52. package/docs/styles/clean-jsdoc-theme-scrollbar.css +30 -0
  53. package/docs/styles/clean-jsdoc-theme-without-scrollbar.min.css +1 -0
  54. package/docs/styles/clean-jsdoc-theme.min.css +1 -0
  55. package/package.json +46 -34
  56. package/babel.config.js +0 -16
  57. package/browser/telegenta.min.js +0 -1
  58. package/docs/fonts/OpenSans-Bold-webfont.eot +0 -0
  59. package/docs/fonts/OpenSans-Bold-webfont.svg +0 -1830
  60. package/docs/fonts/OpenSans-Bold-webfont.woff +0 -0
  61. package/docs/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
  62. package/docs/fonts/OpenSans-BoldItalic-webfont.svg +0 -1830
  63. package/docs/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
  64. package/docs/fonts/OpenSans-Italic-webfont.eot +0 -0
  65. package/docs/fonts/OpenSans-Italic-webfont.svg +0 -1830
  66. package/docs/fonts/OpenSans-Italic-webfont.woff +0 -0
  67. package/docs/fonts/OpenSans-Light-webfont.eot +0 -0
  68. package/docs/fonts/OpenSans-Light-webfont.svg +0 -1831
  69. package/docs/fonts/OpenSans-Light-webfont.woff +0 -0
  70. package/docs/fonts/OpenSans-LightItalic-webfont.eot +0 -0
  71. package/docs/fonts/OpenSans-LightItalic-webfont.svg +0 -1835
  72. package/docs/fonts/OpenSans-LightItalic-webfont.woff +0 -0
  73. package/docs/fonts/OpenSans-Regular-webfont.eot +0 -0
  74. package/docs/fonts/OpenSans-Regular-webfont.svg +0 -1831
  75. package/docs/fonts/OpenSans-Regular-webfont.woff +0 -0
  76. package/docs/fonts/OpenSans-Semibold-webfont.eot +0 -0
  77. package/docs/fonts/OpenSans-Semibold-webfont.svg +0 -1830
  78. package/docs/fonts/OpenSans-Semibold-webfont.ttf +0 -0
  79. package/docs/fonts/OpenSans-Semibold-webfont.woff +0 -0
  80. package/docs/fonts/OpenSans-SemiboldItalic-webfont.eot +0 -0
  81. package/docs/fonts/OpenSans-SemiboldItalic-webfont.svg +0 -1830
  82. package/docs/fonts/OpenSans-SemiboldItalic-webfont.ttf +0 -0
  83. package/docs/fonts/OpenSans-SemiboldItalic-webfont.woff +0 -0
  84. package/docs/scripts/linenumber.js +0 -25
  85. package/docs/scripts/prettify/lang-css.js +0 -2
  86. package/docs/scripts/prettify/prettify.js +0 -28
  87. package/docs/styles/jsdoc-default.css +0 -692
  88. package/docs/styles/prettify-jsdoc.css +0 -111
  89. package/docs/styles/prettify-tomorrow.css +0 -132
  90. package/embedded_client/embedded_phone.js +0 -325
  91. package/embedded_client/index.html +0 -201
  92. package/embedded_client/server.php +0 -28
  93. package/embedded_client/styles.css +0 -310
  94. package/embedded_client/tiny_rest_client.php +0 -73
  95. package/embedded_client/webphone_sprites.png +0 -0
  96. package/es5/event-client.js +0 -322
  97. package/es5/index.js +0 -44
  98. package/es5/phone-client.js +0 -1739
  99. package/src/event-client.js +0 -1
  100. package/src/index.js +0 -10
  101. package/src/phone-client.js +0 -1
  102. package/webpack.config.js +0 -39
@@ -1,201 +0,0 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8"/>
5
-
6
- <!-- include phone library -->
7
- <script src="telegenta.min.js"></script>
8
- <!-- included embedded phone JS -->
9
- <script src="embedded_phone.js"></script>
10
- <!-- include stylesheet -->
11
- <link rel="stylesheet" type="text/css" href="styles.css">
12
-
13
- <script>
14
- // SIP account username and password
15
- var USERNAME = '<your username>';
16
- var PASSWORD = '<your password>';
17
-
18
- window.onload = function () {
19
- // When using server.php this (provisionToken) will be replaced with correct provisionToken dynamically.
20
- // We are doing it like this, even though it would more sense to just have everything inside the php file,
21
- // but this would mean maintaining two almost identical embedded_client html for just examples.
22
- var provisionToken = null;
23
-
24
- // Client can be started both with username+password or using provisionToken
25
- // If provisionToken is set, use this or else use normal username/password
26
- if (provisionToken) {
27
- tg37.initialize({provisionToken: provisionToken});
28
- } else {
29
- tg37.initialize({username: USERNAME, password: PASSWORD});
30
- }
31
- };
32
- </script>
33
- </head>
34
-
35
-
36
- <body>
37
- <div class="Container">
38
- <div>
39
- <!-- Top Navigation -->
40
- <div>
41
-
42
- <!-- Settings -->
43
- <div class="topIcon">
44
- <div class="top-settings" title="Audio Settings"
45
- onclick="document.getElementById('Settings').classList.toggle('showElement');"></div>
46
- </div>
47
- <!-- /Settings -->
48
-
49
- <!-- Log -->
50
- <div class="topIcon">
51
- <div class="top-log" title="Show Phone Log" onclick="document.getElementById('log_window').classList.toggle('showElement');"></div>
52
- </div>
53
- <!-- /Log -->
54
-
55
- <!-- Record -->
56
- <div class="topIcon">
57
- <div class="top-record" id="RecButton" onclick="tg37.phone.toggleRecording()" title="Start Recording"></div>
58
- </div>
59
- <!-- /Record -->
60
-
61
- <!-- Mute -->
62
- <div class="topIcon">
63
- <div class="top-unmute" id="MuteButton" onclick="tg37.phone.toggleMute()" title="Mute microphone"></div>
64
- </div>
65
- <!-- /Mute -->
66
- </div>
67
-
68
- <!-- Log Drop Down -->
69
- <div class="LogContainer" id="log_window">
70
- <div class="DropdownField">
71
- <h3>Log</h3>
72
- <p>Show recent phone activities</p>
73
- </div>
74
-
75
- <div class="DropdownField" align="center">
76
- <textarea id="log_element" placeholder="Log is empty..." style="height:300px; width: 100%;"></textarea>
77
- </div>
78
-
79
- <div align="right">
80
- <div class="closeButton NumberButton" onclick="document.getElementById('log_window').classList.remove('showElement');">Hide Log</div>
81
- </div>
82
- </div>
83
-
84
- <!-- Settings Drop Down -->
85
- <div class="LogContainer" id="Settings">
86
- <div class="DropdownField">
87
- <h3>Audio Settings</h3>
88
- <p>Choose the preferred audio devices</p>
89
- </div>
90
- <div class="DropdownField">
91
- <label for="audio_input_selector">Input audio devices</label><br>
92
- <select id="audio_input_selector"></select>
93
- </div>
94
- <div class="DropdownField">
95
- <label for="audio_output_selector">Output Devices</label>
96
- <select id="audio_output_selector"></select>
97
- </div>
98
-
99
- <div onclick="tg37.saveAndCloseConfig()">
100
- <div class="closeButton NumberButton">Apply Audio Devices</div>
101
- </div>
102
- </div>
103
- </div>
104
-
105
- <!-- DESTINATION NUMBER -->
106
- <div class="DisplayContainer">
107
- <div style="padding: 5px">
108
- <input type="text" id="destination_number">
109
- </div>
110
- </div>
111
-
112
- <!-- KEY PAD -->
113
- <div class="ButtonContainer">
114
- <div class="NumberButton" onclick="tg37.pressNumberBtn('1')">
115
- <h1>1</h1>
116
- <p>&nbsp;</p>
117
- </div>
118
- </div>
119
- <div class="ButtonContainer">
120
- <div class="NumberButton" onclick="tg37.pressNumberBtn('2')">
121
- <h1>2</h1>
122
- <p>A B C</p>
123
- </div>
124
- </div>
125
- <div class="ButtonContainer">
126
- <div class="NumberButton" onclick="tg37.pressNumberBtn('3')">
127
- <h1>3</h1>
128
- <p>D E F</p>
129
- </div>
130
- </div>
131
- <div class="ButtonContainer">
132
- <div class="NumberButton" onclick="tg37.pressNumberBtn('4')">
133
- <h1>4</h1>
134
- <p>G H I</p>
135
- </div>
136
- </div>
137
- <div class="ButtonContainer">
138
- <div class="NumberButton" onclick="tg37.pressNumberBtn('5')">
139
- <h1>5</h1>
140
- <p>J K L</p>
141
- </div>
142
- </div>
143
- <div class="ButtonContainer">
144
- <div class="NumberButton" onclick="tg37.pressNumberBtn('6')">
145
- <h1>6</h1>
146
- <p>M N O</p>
147
- </div>
148
- </div>
149
- <div class="ButtonContainer">
150
- <div class="NumberButton" onclick="tg37.pressNumberBtn('7')">
151
- <h1>7</h1>
152
- <p>P Q R S</p>
153
- </div>
154
- </div>
155
- <div class="ButtonContainer">
156
- <div class="NumberButton" onclick="tg37.pressNumberBtn('8')">
157
- <h1>8</h1>
158
- <p>T U V</p>
159
- </div>
160
- </div>
161
- <div class="ButtonContainer">
162
- <div class="NumberButton" onclick="tg37.pressNumberBtn('9')">
163
- <h1>9</h1>
164
- <p>W X Y Z</p>
165
- </div>
166
- </div>
167
- <div class="ButtonContainer">
168
- <div class="NumberButton" onclick="tg37.pressNumberBtn('*')">
169
- <h1>*</h1>
170
- <p>&nbsp;</p>
171
- </div>
172
- </div>
173
- <div class="ButtonContainer">
174
- <div class="NumberButton" onclick="tg37.pressNumberBtn('0')">
175
- <h1>0</h1>
176
- <p>+</p>
177
- </div>
178
- </div>
179
- <div class="ButtonContainer">
180
- <div class="NumberButton" onclick="tg37.pressNumberBtn('#')">
181
- <h1>#</h1>
182
- <p>&nbsp;</p>
183
- </div>
184
- </div>
185
-
186
- <div class="DialButtonContainer">
187
- <div class="NumberButton btn-gray" id="dial_button" onclick="tg37.pressDialBtn()">
188
- <h1 id="dial_button_text">Uninitialized</h1>
189
- <p>
190
- <span id="dial_button_subtext">&nbsp;</span>
191
- <span id="dial_button_duration"></span>
192
- </p>
193
- </div>
194
- </div>
195
-
196
- </div>
197
- <audio id="remote_audio"></audio>
198
- </body>
199
-
200
-
201
- </html>
@@ -1,28 +0,0 @@
1
- <?php
2
- include "tiny_rest_client.php";
3
-
4
- /*
5
- * EXAMPLE: Get SIP Flex account
6
- */
7
-
8
- // Your API Token
9
- $api_auth_token = '<your token>';
10
-
11
- // The flex account identification (this is set when configuring your flex accounts)
12
- // It possible to have multiple sip flex accounts with different configurations
13
- $flex_identification = 'test';
14
-
15
- // Public IP address of client allowed for this session
16
- // Note: Here we just use ipify to get my public ip, but you could get this from your $_SERVER['HTTP_CLIENT_IP'] or equiv.
17
- $my_ipaddr = get_my_public_ipaddr();
18
-
19
- // Now do API request and get sip flex account info
20
- $flex_info = api_get_request('https://admin.telegenta.com/api/get-flex-session/?flex='.$flex_identification.'&client_ip='.$my_ipaddr, $api_auth_token);
21
-
22
- // Get provision token from API request
23
- $provisionToken = $flex_info['provision_token'];
24
-
25
- // Dynamically replace provisionToken in html and output result
26
- $html = file_get_contents("index.html");
27
- echo str_replace("var provisionToken = null;", "var provisionToken = '$provisionToken';", $html);
28
- ?>
@@ -1,310 +0,0 @@
1
- body {
2
- font-family: Arial, Helvetica, sans-serif;
3
- }
4
-
5
- input[type=button], input[type=submit], input[type=reset] {
6
- background-color: #3399cc;
7
- border: #000 1px solid;
8
- /*border-radius: 5px;*/
9
- color: white;
10
- padding: 5px;
11
- text-decoration: none;
12
- margin: 0 5px 0 5px;
13
- cursor: pointer;
14
- text-align: center;
15
- width: 100%;
16
- }
17
-
18
- input[type=text], select, textarea {
19
- width: 100%;
20
- padding: 10px 0px 10px 0px;
21
- /*border: 1px solid #ccc;*/
22
- resize: vertical;
23
- }
24
-
25
- select {
26
- font-size: medium;
27
- }
28
-
29
- #destination_number {
30
- border: #ccc 1px solid;
31
- border-radius: 3px;
32
- font-size: large;
33
- /*width: 100%;*/
34
- text-align: center;
35
- }
36
-
37
- #dial_button {
38
- color: #fff;
39
- border-radius: 3px;
40
- text-align: center;
41
- padding: 5px;
42
- margin: 5px;
43
- cursor: pointer;
44
- }
45
-
46
- .Container {
47
- width: 300px;
48
- margin: auto;
49
- display: block;
50
- background-color: #3399cc;
51
- }
52
-
53
- .NumberButton {
54
- /*background: linear-gradient(#fff, #ccc);*/
55
- background-color: #FFFFFF;
56
- border: #cccccc 1px solid;
57
- border-radius: 3px;
58
- text-align: center;
59
- padding: 5px;
60
- margin: 5px;
61
- cursor: pointer;
62
- transition: 0.3s;
63
- /*box-shadow: 0 3px 3px 1px grey;*/
64
- }
65
-
66
- .NumberButton:hover {
67
- color: #fff;
68
- border: #3399cc 1px solid;
69
- background: #3399cc;
70
- /*box-shadow: 0 0px 0px 0px #3399cc;*/
71
- }
72
-
73
- .NumberButton:active {
74
- color: #fff;
75
- border: #fff 1px solid;
76
- background: #3399cc;
77
- /*box-shadow: 0 0px 3px 2px #3399cc;*/
78
- transition: 0s;
79
- }
80
-
81
- .btn-green {
82
- background: linear-gradient(#33cc00, #339900);
83
- border: #339900 1px solid;
84
- }
85
-
86
- .btn-blue {
87
- background: linear-gradient(#3399cc, #2969cc);
88
- border: #2969cc 1px solid;
89
- }
90
-
91
- .btn-yellow {
92
- background: linear-gradient(#ffcc00, #aa8800);
93
- border: #aa9900 1px solid;
94
- }
95
-
96
- .btn-red {
97
- background: linear-gradient(#cc0000, #990000);
98
- border: #990000 1px solid;
99
- }
100
-
101
- .btn-gray {
102
- background: linear-gradient(#999999, #777777);
103
- border: #777777 1px solid;
104
- }
105
-
106
- .NumberButton h1 {
107
- font-size: large;
108
- padding: 0;
109
- margin: 0;
110
- }
111
-
112
- .NumberButton p {
113
- font-size: x-small;
114
- padding: 0;
115
- margin: 0;
116
- opacity: .5;
117
- }
118
-
119
- .ActionButton {
120
- background: linear-gradient(#fff, #ccc);
121
- border: #cccccc 1px solid;
122
- text-align: center;
123
- padding: 0;
124
- margin: 0 10px 0 10px;
125
- cursor: pointer;
126
- font-size: 8px;
127
- }
128
-
129
- .ButtonContainer {
130
- width: 33.33%;
131
- float: left;
132
- }
133
-
134
- .DisplayContainer, .DialButtonContainer {
135
- width: 100%;
136
- float: left;
137
- display: block;
138
- }
139
-
140
- .RecButtonContainer {
141
- width: 50%;
142
- float: left;
143
-
144
- }
145
-
146
- .LogContainer {
147
- width: 100%;
148
- height: 450px;
149
- z-index: 2;
150
- position: fixed;
151
- opacity: 0;
152
- display: none;
153
- max-width: 300px;
154
- background: #FFFFFF;
155
- }
156
-
157
- .SettingsContainer {
158
- display: none; /* Set to block to show */
159
- }
160
-
161
- .DropdownField {
162
- padding: 5px;
163
- text-align: left;
164
- background: #ffffff;
165
- }
166
-
167
- @-webkit-keyframes dropdowndiv {
168
- from {
169
- top: -400px;
170
- }
171
- to {
172
- top: 0px;
173
- }
174
- }
175
-
176
- @keyframes dropdowndiv {
177
- from {
178
- top: -400px;
179
- }
180
- to {
181
- top: 0px;
182
- }
183
- }
184
-
185
- .showElement {
186
- -webkit-animation-name: example; /* Safari 4.0 - 8.0 */
187
- -webkit-animation-duration: .5s; /* Safari 4.0 - 8.0 */
188
- -webkit-animation-fill-mode: forwards; /* Safari 4.0 - 8.0 */
189
- animation-name: dropdowndiv;
190
- animation-duration: 1s;
191
- animation-fill-mode: forwards;
192
- opacity: 1;
193
- display: block;
194
- cursor: pointer;
195
- }
196
-
197
- .topIcon {
198
- border: #cccccc 1px solid;
199
- float: right;
200
- /*background: linear-gradient(#fff, #ccc);*/
201
- background-color: #FFFFFF;
202
- width: 30px;
203
- border-radius: 3px;
204
- height: 30px;
205
- margin: 5px;
206
- transition: 0.3s;
207
- }
208
-
209
- .topIcon:hover {
210
- border: #3399cc 1px solid;
211
- }
212
-
213
- .top-settings {
214
- background: url('webphone_sprites.png');
215
- width: 30px;
216
- height: 30px;
217
- cursor: pointer;
218
- }
219
-
220
- .top-settings:hover {
221
- background: url('webphone_sprites.png') 0 -30px;
222
- background-color: #3399cc;
223
- }
224
-
225
- .top-mute {
226
- background: url('webphone_sprites.png') -30px 0;
227
- width: 30px;
228
- height: 30px;
229
- cursor: pointer;
230
- }
231
-
232
- .top-mute:hover {
233
- background: url('webphone_sprites.png') -30px -30px;
234
- background-color: #3399cc;
235
- }
236
-
237
- .top-unmute {
238
- background: url('webphone_sprites.png') -60px 0;
239
- width: 30px;
240
- height: 30px;
241
- cursor: pointer;
242
- }
243
-
244
- .top-unmute:hover {
245
- background: url('webphone_sprites.png') -60px -30px;
246
- background-color: #3399cc;
247
- }
248
-
249
- .top-record {
250
- background: url('webphone_sprites.png') -90px 0;
251
- width: 30px;
252
- height: 30px;
253
- cursor: pointer;
254
- }
255
-
256
- .top-record:hover {
257
- background: url('webphone_sprites.png') -90px -30px;
258
- background-color: #3399cc;
259
- }
260
-
261
- .top-stoprecord {
262
- background: url('webphone_sprites.png') -90px -30px;
263
- width: 30px;
264
- height: 30px;
265
- cursor: pointer;
266
- background-color: #cc0000;
267
- }
268
-
269
- .top-stoprecord:hover {
270
- background: url('webphone_sprites.png') -90px -30px;
271
- background-color: #990000;
272
- }
273
-
274
- .top-log {
275
- background: url('webphone_sprites.png') -180px 0;
276
- width: 30px;
277
- height: 30px;
278
- cursor: pointer;
279
- }
280
-
281
- .top-log:hover {
282
- background: url('webphone_sprites.png') -180px -30px;
283
- background-color: #3399cc;
284
- }
285
-
286
- .top-phone {
287
- background: url('webphone_sprites.png') -120px 0;
288
- width: 30px;
289
- height: 30px;
290
- float: left;
291
- margin: 5px;
292
- }
293
-
294
- /*.topIcons {*/
295
- /*float: right;*/
296
- /*margin: 5px;*/
297
- /*background: linear-gradient(#fff, #ccc);*/
298
- /*padding: 5px;*/
299
- /*cursor: pointer;*/
300
- /*border: #cccccc 1px solid;*/
301
- /*!*border-radius: 5px;*!*/
302
- /*}*/
303
-
304
- /*.topIcons:hover {*/
305
- /*background: #3399cc;*/
306
- /*}*/
307
-
308
- .closeButton {
309
- float: right;
310
- }
@@ -1,73 +0,0 @@
1
- <?php
2
-
3
- // If you really want to see whats going on
4
- define('DEBUG', 0);
5
-
6
- /*
7
- * Perform an authenticated request towards Telegenta API service
8
- *
9
- * PARAMETERS:
10
- * path = API endpoint path to use the request
11
- * auth_token = API Auth token
12
- * partner_customer_id = Perform request on behalf of one of your customers
13
- *
14
- */
15
- function api_get_request($path, $auth_token, $partner_customer_id = NULL) {
16
- // Prepare request headers
17
- $headers = [
18
- 'Authorization: Bearer ' . $auth_token,
19
- 'Accept: application/json',
20
- ];
21
-
22
- // Add partner account id header if needed
23
- if ($partner_customer_id) {
24
- array_push($headers, 'x-use-partner-id: ' . $partner_customer_id);
25
- }
26
-
27
- // Initialize CURL handle
28
- $ch = curl_init();
29
- $opt = array(
30
- CURLOPT_URL => $path,
31
- CURLOPT_RETURNTRANSFER => 1,
32
- CURLOPT_VERBOSE => DEBUG,
33
- CURLOPT_HTTPHEADER => $headers,
34
- );
35
- curl_setopt_array($ch, $opt);
36
-
37
- // Perform request
38
- if (!$http_result = curl_exec($ch)) {
39
- throw new Exception('CURL ERROR: '.curl_error($ch));
40
- }
41
-
42
- // Reply status non 200?
43
- $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
44
- if ($http_code !== 200) {
45
- throw new Exception('HTTP ERROR: '. $http_code . PHP_EOL . $http_result);
46
- }
47
-
48
- // Decode json ok?
49
- if (!$result = json_decode($http_result, 1)) {
50
- throw new Exception('MALFORMED JSON:' . json_last_error());
51
- }
52
-
53
- // Print reply if debug enabled
54
- if (DEBUG) {
55
- print "API REPLY:".PHP_EOL;
56
- print_r($result);
57
- }
58
-
59
- // Close handle and return result
60
- curl_close($ch);
61
- return $result;
62
- }
63
-
64
- // Just a small helper function for these examples, returning your public ip address
65
- function get_my_public_ipaddr() {
66
- $ch = curl_init();
67
- curl_setopt($ch, CURLOPT_URL, "https://api.ipify.org/");
68
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
69
- $resp = curl_exec($ch);
70
- curl_close($ch);
71
- return $resp;
72
- }
73
- ?>