-
Notifications
You must be signed in to change notification settings - Fork 97
/
codebird.es7.js
1757 lines (1651 loc) · 49.6 KB
/
codebird.es7.js
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* A Twitter library in JavaScript
*
* @package codebird
* @version 3.0.0-dev
* @author Jublo Limited <support@jublo.net>
* @copyright 2010-2018 Jublo Limited <support@jublo.net>
* @license http://opensource.org/licenses/GPL-3.0 GNU Public License 3.0
* @link https://github.com/jublonet/codebird-php
*/
/* global window,
document,
navigator,
Ti,
ActiveXObject,
module,
define,
require */
(() => {
/**
* A Twitter library in JavaScript
*
* @package codebird
* @subpackage codebird-js
*/
class Codebird {
constructor() {
/**
* The OAuth consumer key of your registered app
*/
this._oauth_consumer_key = null;
/**
* The corresponding consumer secret
*/
this._oauth_consumer_secret = null;
/**
* The app-only bearer token. Used to authorize app-only requests
*/
this._oauth_bearer_token = null;
/**
* The API endpoint base to use
*/
this._endpoint_base = "https://api.twitter.com/";
/**
* The media API endpoint base to use
*/
this._endpoint_base_media = "https://upload.twitter.com/";
/**
* The API endpoint to use
*/
this._endpoint = `${this._endpoint_base}1.1/`;
/**
* The media API endpoint to use
*/
this._endpoint_media = `${this._endpoint_base_media}1.1/`;
/**
* The publish API endpoint to use
*/
this._endpoint_publish = "https://publish.twitter.com/";
/**
* The API endpoint base to use
*/
this._endpoint_oauth = this._endpoint_base;
/**
* API proxy endpoint
*/
this._endpoint_proxy = "https://api.jublo.net/codebird/";
/**
* Whether to access the API via a proxy that is allowed by CORS
* Assume that CORS is only necessary in browsers
*/
this._use_proxy =
typeof navigator !== "undefined" &&
typeof navigator.userAgent !== "undefined";
/**
* The Request or access token. Used to sign requests
*/
this._oauth_token = null;
/**
* The corresponding request or access token secret
*/
this._oauth_token_secret = null;
/**
* The current Codebird version
*/
this._version = "3.0.0-dev";
this.b64_alphabet =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
}
/**
* Sets the OAuth consumer key and secret (App key)
*
* @param string key OAuth consumer key
* @param string secret OAuth consumer secret
*
* @return void
*/
setConsumerKey(key, secret) {
this._oauth_consumer_key = key;
this._oauth_consumer_secret = secret;
}
/**
* Sets the OAuth2 app-only auth bearer token
*
* @param string token OAuth2 bearer token
*
* @return void
*/
setBearerToken(token) {
this._oauth_bearer_token = token;
}
/**
* Gets the current Codebird version
*
* @return string The version number
*/
getVersion() {
return this._version;
}
/**
* Sets the OAuth request or access token and secret (User key)
*
* @param string token OAuth request or access token
* @param string secret OAuth request or access token secret
*
* @return void
*/
setToken(token, secret) {
this._oauth_token = token;
this._oauth_token_secret = secret;
}
/**
* Forgets the OAuth request or access token and secret (User key)
*
* @return bool
*/
logout(callback) {
const dfd = this._getDfd();
if (!dfd && typeof callback === "undefined") {
callback = () => {};
}
this.__call("oauth_invalidateToken", {
access_key: this._oauth_token,
access_key_secret: this._oauth_token_secret
}).then(() => {
this._oauth_token = this._oauth_token_secret = null;
if (typeof callback === "function") {
callback(true);
}
if (dfd) {
dfd.resolve(true);
}
});
if (dfd) {
return this._getPromise(dfd);
}
}
/**
* Enables or disables CORS proxy
*
* @param bool use_proxy Whether to use CORS proxy or not
*
* @return void
*/
setUseProxy(use_proxy) {
this._use_proxy = !!use_proxy;
}
/**
* Sets custom CORS proxy server
*
* @param string proxy Address of proxy server to use
*
* @return void
*/
setProxy(proxy) {
// add trailing slash if missing
if (!proxy.match(/\/$/)) {
proxy += "/";
}
this._endpoint_proxy = proxy;
}
/**
* Signing helpers
*/
/**
* URL-encodes the given data
*
* @param mixed data
*
* @return mixed The encoded data
*/
_url(data) {
if (/boolean|number|string/.test(typeof data)) {
return encodeURIComponent(data)
.replace(/!/g, "%21")
.replace(/'/g, "%27")
.replace(/\(/g, "%28")
.replace(/\)/g, "%29")
.replace(/\*/g, "%2A");
} else {
return "";
}
}
/**
* Gets the base64-encoded SHA1 hash for the given data
*
* A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
* in FIPS PUB 180-1
* Based on version 2.1 Copyright Paul Johnston 2000 - 2002.
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
* Distributed under the BSD License
* See http://pajhome.org.uk/crypt/md5 for details.
*
* @param string data The data to calculate the hash from
*
* @return string The hash
*/
_sha1(e) {
function n(e, b) {
e[b >> 5] |= 128 << (24 - (b % 32));
e[(((b + 64) >> 9) << 4) + 15] = b;
for (
var c = new Array(80),
a = 1732584193,
d = -271733879,
h = -1732584194,
k = 271733878,
g = -1009589776,
p = 0;
p < e.length;
p += 16
) {
for (var o = a, q = d, r = h, s = k, t = g, f = 0; 80 > f; f++) {
let m;
if (f < 16) {
m = e[p + f];
} else {
m = c[f - 3] ^ c[f - 8] ^ c[f - 14] ^ c[f - 16];
m = (m << 1) | (m >>> 31);
}
c[f] = m;
m = l(
l(
(a << 5) | (a >>> 27),
20 > f
? (d & h) | (~d & k)
: 40 > f
? d ^ h ^ k
: 60 > f
? (d & h) | (d & k) | (h & k)
: d ^ h ^ k
),
l(
l(g, c[f]),
20 > f
? 1518500249
: 40 > f
? 1859775393
: 60 > f
? -1894007588
: -899497514
)
);
g = k;
k = h;
h = (d << 30) | (d >>> 2);
d = a;
a = m;
}
a = l(a, o);
d = l(d, q);
h = l(h, r);
k = l(k, s);
g = l(g, t);
}
return [a, d, h, k, g];
}
function l(e, b) {
var c = (e & 65535) + (b & 65535);
return (((e >> 16) + (b >> 16) + (c >> 16)) << 16) | (c & 65535);
}
function q(e) {
for (var b = [], c = (1 << g) - 1, a = 0; a < e.length * g; a += g) {
b[a >> 5] |= (e.charCodeAt(a / g) & c) << (24 - (a % 32));
}
return b;
}
var g = 8;
let b = `${this._oauth_consumer_secret}&${
null !== this._oauth_token_secret ? this._oauth_token_secret : ""
}`;
if (this._oauth_consumer_secret === null) {
throw "To generate a hash, the consumer secret must be set.";
}
let c = q(b);
if (c.length > 16) {
c = n(c, b.length * g);
}
let bb = new Array(16);
for (var a = new Array(16), d = 0; d < 16; d++) {
a[d] = c[d] ^ 909522486;
bb[d] = c[d] ^ 1549556828;
}
c = n(a.concat(q(e)), 512 + e.length * g);
bb = n(bb.concat(c), 672);
b = "";
for (g = 0; g < 4 * bb.length; g += 3) {
for (
d =
(((bb[g >> 2] >> (8 * (3 - (g % 4)))) & 255) << 16) |
(((bb[(g + 1) >> 2] >> (8 * (3 - ((g + 1) % 4)))) & 255) << 8) |
((bb[(g + 2) >> 2] >> (8 * (3 - ((g + 2) % 4)))) & 255),
e = 0;
4 > e;
e++
) {
b =
8 * g + 6 * e > 32 * bb.length
? b + "="
: b + this.b64_alphabet.charAt((d >> (6 * (3 - e))) & 63);
}
}
return b;
}
/*
* Gets the base64 representation for the given data
*
* http://phpjs.org
* + original by: Tyler Akins (http://rumkin.com)
* + improved by: Bayron Guevara
* + improved by: Thunder.m
* + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
* + bugfixed by: Pellentesque Malesuada
* + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
* + improved by: Rafał Kukawski (http://kukawski.pl)
*
* @param string data The data to calculate the base64 representation from
*
* @return string The base64 representation
*/
_base64_encode(a) {
let d,
e,
f,
b,
g = 0,
h = 0,
i = this.b64_alphabet,
c = [];
if (!a) {
return a;
}
do {
d = a.charCodeAt(g++);
e = a.charCodeAt(g++);
f = a.charCodeAt(g++);
b = (d << 16) | (e << 8) | f;
d = (b >> 18) & 63;
e = (b >> 12) & 63;
f = (b >> 6) & 63;
b &= 63;
c[h++] = i.charAt(d) + i.charAt(e) + i.charAt(f) + i.charAt(b);
} while (g < a.length);
i = c.join("");
a = a.length % 3;
return (a ? i.slice(0, a - 3) : i) + "===".slice(a || 3);
}
/*
* Builds a HTTP query string from the given data
*
* http://phpjs.org
* + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
* + improved by: Legaev Andrey
* + improved by: Michael White (http://getsprink.com)
* + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
* + improved by: Brett Zamir (http://brett-zamir.me)
* + revised by: stag019
* + input by: Dreamer
* + bugfixed by: Brett Zamir (http://brett-zamir.me)
* + bugfixed by: MIO_KODUKI (http://mio-koduki.blogspot.com/)
*
* @param string data The data to concatenate
*
* @return string The HTTP query
*/
_http_build_query(e, f, b) {
function g(c, a, d) {
let b,
e = [];
if (a === true) {
a = "1";
} else if (a === false) {
a = "0";
}
if (null !== a) {
if (typeof a === "object") {
for (b in a) {
if (a.hasOwnProperty(b) && a[b] !== null) {
e.push(g.call(this, c + "[" + b + "]", a[b], d));
}
}
return e.join(d);
}
if (typeof a !== "function") {
return this._url(c) + "=" + this._url(a);
}
throw "There was an error processing for http_build_query().";
} else {
return "";
}
}
var d,
c,
h = [];
if (!b) {
b = "&";
}
for (c in e) {
if (!e.hasOwnProperty(c)) {
continue;
}
d = e[c];
if (f && !isNaN(c)) {
c = String(f) + c;
}
d = g.call(this, c, d, b);
if (d !== "") {
h.push(d);
}
}
return h.join(b);
}
/**
* Generates a (hopefully) unique random string
*
* @param int optional length The length of the string to generate
*
* @return string The random string
*/
_nonce(length = 8) {
if (length < 1) {
throw "Invalid nonce length.";
}
let nonce = "";
for (let i = 0; i < length; i++) {
let character = Math.floor(Math.random() * 61);
nonce += this.b64_alphabet.substring(character, character + 1);
}
return nonce;
}
/**
* Sort array elements by key
*
* @param array input_arr The array to sort
*
* @return array The sorted keys
*/
_ksort(input_arr) {
let keys = [],
sorter,
k;
sorter = (a, b) => {
let a_float = parseFloat(a),
b_float = parseFloat(b),
a_numeric = a_float + "" === a,
b_numeric = b_float + "" === b;
if (a_numeric && b_numeric) {
return a_float > b_float ? 1 : a_float < b_float ? -1 : 0;
} else if (a_numeric && !b_numeric) {
return 1;
} else if (!a_numeric && b_numeric) {
return -1;
}
return a > b ? 1 : a < b ? -1 : 0;
};
// Make a list of key names
for (k in input_arr) {
if (input_arr.hasOwnProperty(k)) {
keys.push(k);
}
}
keys.sort(sorter);
return keys;
}
/**
* Clone objects
*
* @param object obj The object to clone
*
* @return object clone The cloned object
*/
_clone(obj) {
let clone = {};
for (let i in obj) {
if (typeof obj[i] === "object") {
clone[i] = this._clone(obj[i]);
} else {
clone[i] = obj[i];
}
}
return clone;
}
/**
* Gets the XML HTTP Request object, trying to load it in various ways
*
* @return object The XMLHttpRequest object instance
*/
_getXmlRequestObject() {
let xml = null;
// first, try the W3-standard object
if (
typeof window === "object" &&
window &&
typeof window.XMLHttpRequest !== "undefined"
) {
xml = new window.XMLHttpRequest();
// then, try Titanium framework object
} else if (
typeof Ti === "object" &&
Ti &&
typeof Ti.Network.createHTTPClient !== "undefined"
) {
xml = Ti.Network.createHTTPClient();
// are we in an old Internet Explorer?
} else if (typeof ActiveXObject !== "undefined") {
try {
xml = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
throw "ActiveXObject object not defined.";
}
// now, consider RequireJS and/or Node.js objects
} else if (typeof require === "function") {
var XMLHttpRequest;
// look for xmlhttprequest module
try {
XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
xml = new XMLHttpRequest();
} catch (e1) {
// or maybe the user is using xhr2
try {
XMLHttpRequest = require("xhr2");
xml = new XMLHttpRequest();
} catch (e2) {
throw "xhr2 object not defined, cancelling.";
}
}
}
return xml;
}
/**
* Parse URL-style parameters into object
*
* version: 1109.2015
* discuss at: http://phpjs.org/functions/parse_str
* + original by: Cagri Ekin
* + improved by: Michael White (http://getsprink.com)
* + tweaked by: Jack
* + bugfixed by: Onno Marsman
* + reimplemented by: stag019
* + bugfixed by: Brett Zamir (http://brett-zamir.me)
* + bugfixed by: stag019
* - depends on: urldecode
* + input by: Dreamer
* + bugfixed by: Brett Zamir (http://brett-zamir.me)
* % note 1: When no argument is specified, will put variables in global scope.
*
* @param string str String to parse
* @param array array to load data into
*
* @return object
*/
_parse_str(str, array) {
var glue1 = "=",
glue2 = "&",
array2 = String(str)
.replace(/^&?([\s\S]*?)&?$/, "$1")
.split(glue2),
i,
j,
chr,
tmp,
key,
value,
bracket,
keys,
evalStr,
fixStr = str => {
return decodeURIComponent(str)
.replace(/([\\"'])/g, "\\$1")
.replace(/\n/g, "\\n")
.replace(/\r/g, "\\r");
};
if (!array) {
array = this.window;
}
for (i = 0; i < array2.length; i++) {
tmp = array2[i].split(glue1);
if (tmp.length < 2) {
tmp = [tmp, ""];
}
key = fixStr(tmp[0]);
value = fixStr(tmp[1]);
while (key.charAt(0) === " ") {
key = key.substr(1);
}
if (key.indexOf("\0") > -1) {
key = key.substr(0, key.indexOf("\0"));
}
if (key && key.charAt(0) !== "[") {
keys = [];
bracket = 0;
for (j = 0; j < key.length; j++) {
if (key.charAt(j) === "[" && !bracket) {
bracket = j + 1;
} else if (key.charAt(j) === "]") {
if (bracket) {
if (!keys.length) {
keys.push(key.substr(0, bracket - 1));
}
keys.push(key.substr(bracket, j - bracket));
bracket = 0;
if (key.charAt(j + 1) !== "[") {
break;
}
}
}
}
if (!keys.length) {
keys = [key];
}
for (j = 0; j < keys[0].length; j++) {
chr = keys[0].charAt(j);
if (chr === " " || chr === "." || chr === "[") {
keys[0] = keys[0].substr(0, j) + "_" + keys[0].substr(j + 1);
}
if (chr === "[") {
break;
}
}
evalStr = "array";
for (j = 0; j < keys.length; j++) {
key = keys[j];
if ((key !== "" && key !== " ") || j === 0) {
key = `'${key}'`;
} else {
key = eval(evalStr + ".push([]);") - 1;
}
evalStr += `[${key}]`;
if (
j !== keys.length - 1 &&
eval("typeof " + evalStr) === "undefined"
) {
eval(evalStr + " = [];");
}
}
evalStr += " = '" + value + "';\n";
eval(evalStr);
}
}
}
/**
* Get allowed API methods, sorted by GET or POST
* Watch out for multiple-method "account/settings"!
*
* @return array $apimethods
*/
getApiMethods() {
const httpmethods = {
GET: [
"account/settings",
"account/verify_credentials",
"account_activity/all/:env_name/subscriptions",
"account_activity/all/:env_name/subscriptions/list",
"account_activity/all/:env_name/webhooks",
"account_activity/all/webhooks",
"account_activity/subscriptions/count",
"account_activity/webhooks",
"account_activity/webhooks/:webhook_id/subscriptions/all",
"account_activity/webhooks/:webhook_id/subscriptions/all/list",
"application/rate_limit_status",
"blocks/ids",
"blocks/list",
"collections/entries",
"collections/list",
"collections/show",
"custom_profiles/:id",
"custom_profiles/list",
"direct_messages/events/list",
"direct_messages/events/show",
"direct_messages/welcome_messages/list",
"direct_messages/welcome_messages/rules/list",
"direct_messages/welcome_messages/rules/show",
"direct_messages/welcome_messages/show",
"favorites/list",
"feedback/events",
"feedback/show/:id",
"followers/ids",
"followers/list",
"friends/ids",
"friends/list",
"friendships/incoming",
"friendships/lookup",
"friendships/lookup",
"friendships/no_retweets/ids",
"friendships/outgoing",
"friendships/show",
"geo/id/:place_id",
"geo/reverse_geocode",
"geo/search",
"help/configuration",
"help/languages",
"help/privacy",
"help/tos",
"lists/list",
"lists/members",
"lists/members/show",
"lists/memberships",
"lists/ownerships",
"lists/show",
"lists/statuses",
"lists/subscribers",
"lists/subscribers/show",
"lists/subscriptions",
"mutes/users/ids",
"mutes/users/list",
"oauth/authenticate",
"oauth/authorize",
"saved_searches/list",
"saved_searches/show/:id",
"search/tweets",
"statuses/home_timeline",
"statuses/mentions_timeline",
"statuses/oembed",
"statuses/retweeters/ids",
"statuses/retweets/:id",
"statuses/retweets_of_me",
"statuses/sample",
"statuses/show/:id",
"statuses/user_timeline",
"trends/available",
"trends/closest",
"trends/place",
"users/profile_banner",
"users/search",
"users/show",
"users/suggestions",
"users/suggestions/:slug",
"users/suggestions/:slug/members"
],
POST: [
"account/remove_profile_banner",
"account/settings__post",
"account/update_profile",
"account/update_profile_banner",
"account/update_profile_image",
"account_activity/all/:env_name/subscriptions",
"account_activity/all/:env_name/webhooks",
"account_activity/webhooks",
"account_activity/webhooks/:webhook_id/subscriptions/all",
"blocks/create",
"blocks/destroy",
"collections/create",
"collections/destroy",
"collections/entries/add",
"collections/entries/curate",
"collections/entries/move",
"collections/entries/remove",
"collections/update",
"custom_profiles/new",
"direct_messages/events/new",
"direct_messages/indicate_typing",
"direct_messages/mark_read",
"direct_messages/welcome_messages/new",
"direct_messages/welcome_messages/rules/new",
"favorites/create",
"favorites/destroy",
"feedback/create",
"friendships/create",
"friendships/destroy",
"friendships/update",
"lists/create",
"lists/destroy",
"lists/members/create",
"lists/members/create_all",
"lists/members/destroy",
"lists/members/destroy_all",
"lists/subscribers/create",
"lists/subscribers/destroy",
"lists/update",
"media/metadata/create",
"media/upload",
"mutes/users/create",
"mutes/users/destroy",
"oauth/access_token",
"oauth/invalidate_token",
"oauth/request_token",
"oauth2/invalidate_token",
"oauth2/token",
"saved_searches/create",
"saved_searches/destroy/:id",
"statuses/destroy/:id",
"statuses/filter",
"statuses/lookup",
"statuses/retweet/:id",
"statuses/unretweet/:id",
"statuses/update",
"users/lookup",
"users/report_spam"
]
};
return httpmethods;
}
/**
* Promise helpers
*/
/**
* Get a deferred object
*/
_getDfd() {
if (typeof window !== "undefined") {
if (typeof window.jQuery !== "undefined" && window.jQuery.Deferred) {
return window.jQuery.Deferred();
}
if (typeof window.Q !== "undefined" && window.Q.defer) {
return window.Q.defer();
}
if (typeof window.RSVP !== "undefined" && window.RSVP.defer) {
return window.RSVP.defer();
}
if (typeof window.when !== "undefined" && window.when.defer) {
return window.when.defer();
}
}
if (typeof require !== "undefined") {
let promise_class = false;
try {
promise_class = require("jquery");
} catch (e) {}
if (promise_class) {
return promise_class.Deferred();
}
try {
promise_class = require("q");
} catch (e) {}
if (!promise_class) {
try {
promise_class = require("rsvp");
} catch (e) {}
}
if (!promise_class) {
try {
promise_class = require("when");
} catch (e) {}
}
if (promise_class) {
try {
return promise_class.defer();
} catch (e) {}
}
}
return false;
}
/**
* Get a promise from the dfd object
*/
_getPromise(dfd) {
if (typeof dfd.promise === "function") {
return dfd.promise();
}
return dfd.promise; // object
}
/**
* __call() helpers
*/
/**
* Parse given params, detect query-style params
*
* @param array|string params Parameters to parse
*
* @return array apiparams
*/
_parseApiParams(params) {
let apiparams = {};
if (typeof params === "object") {
apiparams = params;
} else {
this._parse_str(params, apiparams); //TODO
}
return apiparams;
}
/**
* Replace null and boolean parameters with their string representations
*
* @param array apiparams Parameter array to replace in
*
* @return array apiparams
*/
_stringifyNullBoolParams(apiparams) {
for (let key in apiparams) {
if (!apiparams.hasOwnProperty(key)) {
continue;
}
let value = apiparams[key];
if (value === null) {
apiparams[key] = "null";
} else if (value === true || value === false) {
apiparams[key] = value ? "true" : "false";
}
}
return apiparams;
}
/**
* API method mapping: Replaces _ with / character
*
* @param string fn Function called
*
* @return string API method to call
*/
_mapFnInsertSlashes(fn) {
return fn.split("_").join("/");
}
/**
* API method mapping: Restore _ character in named parameters
*
* @param string method API method to call
*
* @return string API method with restored underscores
*/
_mapFnRestoreParamUnderscores(method) {
const url_parameters_with_underscore = ["screen_name", "place_id"];
let i, param, replacement_was;
for (i = 0; i < url_parameters_with_underscore.length; i++) {
param = url_parameters_with_underscore[i].toUpperCase();
replacement_was = param.split("_").join("/");
method = method.split(replacement_was).join(param);
}
return method;
}
/**
* Maps called PHP magic method name to Twitter API method
*
* @param string $fn Function called
* @param array $apiparams byref API parameters