aboutsummaryrefslogtreecommitdiff
path: root/models/lib/class.vimeo.php
blob: 03508d148980732faeef6f9293384e648ceb7422 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
<?php
/**
* SimpleVimeo
* 
* API Framework for vimeo.com
* @package      SimpleVimeo
* @author       Adrian Rudnik <adrian@periocode.de>
* @link         http://code.google.com/p/php5-simplevimeo/
*/

/**
* Enable debug to output raw request and response information
*/

define('VIMEO_DEBUG_REQUEST', true);
define('VIMEO_DEBUG_RESPONSE', true);

/**
* Vimeo base class
*
* Provides vital functions to API (access, permission and object handling)
*
* @package     SimpleVimeo
* @subpackage  Base
*/

class VimeoBase {

    const PROJECT_NAME      = 'php5-simplevimeo';
    
    /**
    * Currently logged in user object
    * @var  VimeoUserEntity
    */
    private static $oUser = false;
    
    /**
    * Currently logged in user permission
    * @var  string
    */
    private static $ePermission = false;
    
    /**
    * Currently logged in user token
    * @var  string
    */
    private static $sToken = false;
    
    /**
    * Vimeo Application API key
    * @var  string
    */
    private static $sApiKey = '7a223534b3c1d0979a954f93cb746173  ';
    
    /**
    * Vimeo Application API secret key
    * @var  string
    */
    private static $sApiSecret = 'b11e83370';

    const VIMEO_REST_URL    = 'http://vimeo.com/api/rest/';
    const VIMEO_AUTH_URL    = 'http://vimeo.com/services/auth/';
    const VIMEO_UPLOAD_URL  = 'http://vimeo.com/services/upload/';
    const VIMEO_LOGIN_URL   = 'http://vimeo.com/log_in';

    /**
    * You can choose between the following engines:
    * executeRemoteCall_FSOCK = PHP5 file_get_content and stream_contexts (bad error handling)
    * executeRemoteCall_CURL = CURL is used for file transfer (better error handling)
    */
    const REQUEST_ENGINE_CURL           = 'executeRemoteCall_CURL';
    const VIDEOPOST_ENGINE_FSOCK        = 'executeVideopostCall_CURL';
    
    const PERMISSION_NONE               = false;
    const PERMISSION_READ               = 'read';
    const PERMISSION_WRITE              = 'write';
    const PERMISSION_DELETE             = 'delete';
    
    const COOKIE_FILE                   = '/tmp/simplevimeo.cookies';
    
    const DEBUG_ENABLE					= false;
    const DEBUG_LOGFILE					= '/tmp/simplevimeo.debug';
    
    /**
    * Debug output function
    */
    public static function debug($sTitle, $sContent) {
    	if(self::DEBUG_ENABLE) {
			$sMessage = 'DEBUG ' . date('Y-m-d H:i:s', time()) . "\n";
			$sMessage .= 'CONTENT: ' . $sContent . "\n";
			$sMesasge .= $sContent . "\n\n";
			
			$fhLog = fopen(self::DEBUG_LOGFILE, 'a+');
			
			if(!$fhLog) {
				throw new VimeoBaseException('Debug Logfile "' . self::DEBUG_LOGFILE . '" could not be found or written');
			} else {
				fputs($fhLog, $sMessage);
				fclose($fhLog);
			}
    	}
    }
    
    /**
    * Update Authentication
    * 
    * Initializes user and permission information if a token is present.
    * You can alter this method or skip it if you store user information
    * and permission in an external database. Then i would recommend a
    * VimeoAuthRequest::checkLoogin for confirmation.
    * 
    * @access   private
    * @return   void
    */
    private function updateAuthentication() {
        if(self::$sToken && (!self::$ePermission || !self::$oUser)) {
            $oResponse = VimeoAuthRequest::checkToken(self::$sToken);
            
            // Parse user
            self::$oUser = $oResponse->getUser();
            
            // Parse permission
            self::$ePermission = $oResponse->getPermission();
        }
    }
    
    /**
    * Check permission
    * 
    * Checks the current user permission with the given one. This will be
    * heavily used by the executeRemoteCall method to ensure the user
    * will not run into trouble.
    * 
    * @access   public
    * @param    string      Needed Permission
    * @return   boolean     TRUE if access can be granted, FALSE if permission denied
    */
    public function checkPermission($ePermissionNeeded) {
        // Update authentication data before permission check
        self::updateAuthentication();
        
        // Permission DELETE check
        if($ePermissionNeeded == self::PERMISSION_DELETE && self::$ePermission == self::PERMISSION_DELETE) {
            return true;
        }
        
        // Permission WRITE check
        if($ePermissionNeeded == self::PERMISSION_WRITE && (self::$ePermission == self::PERMISSION_DELETE || self::$ePermission == self::PERMISSION_WRITE)) {
            return true;
        }
        
        // Permission READ check
        if($ePermissionNeeded == self::PERMISSION_READ && (self::$ePermission == self::PERMISSION_DELETE || self::$ePermission == self::PERMISSION_WRITE || self::$ePermission == self::PERMISSION_READ)) {
            return true;
        }
        
        return false;
    }
    
    /**
    * Proxy for API queries
    * 
    * Will check permission for the requested API method as well as type
    * of the object result response or exception. Will call the given
    * API query handler method (default: executeRemoteCall_CURL) for
    * the raw connection stuff
    * 
    * @access   public
    * @param    string          API method name
    * @param    array           Additional arguments that need to be passed to the API
    * @return   VimeoResponse   Response object of API corresponding query (for vimeo.test.login you will get VimeoTestLoginResponse object)
    */
    public function executeRemoteCall($sMethod, $aArgs = array()) {
        // Get exception handler
        $sExceptionClass = VimeoMethod::getExceptionObjectForMethod($sMethod);
        
        // Check for errors in parameters
        $sTargetClass = VimeoMethod::getTargetObjectForMethod($sMethod);
        
        // Get the permission needed to run this method
        $ePermissionNeeded = VimeoMethod::getPermissionRequirementForMethod($sMethod);
        
        // If permission requirement is not met refuse to even call the API, safes bandwith for both ends
        if($ePermissionNeeded != VimeoBase::PERMISSION_NONE && !self::checkPermission($ePermissionNeeded)) {
            throw new $sExceptionClass('Permission error: "' . VimeoMethod::getPermissionRequirementForMethod($sMethod) . '" needed, "' . self::$ePermission . '" given');
        }
        
        // Append method to request arguments
        $aArgs['method'] = $sMethod;
        
        // Check that the API query handler method exists and can be called
        if(!method_exists(__CLASS__, self::REQUEST_ENGINE_CURL)) {
            throw new VimeoBaseException('Internal error: Request engine handler method not found', 2);
        }
        
        // Build up the needed API arguments

        // Set API key
        $aArgs['api_key']       = self::$sApiKey;
        
        // Set request format
        $aArgs['format']        = 'php';

        // Set token
        if(self::$sToken) $aArgs['auth_token'] = self::$sToken;
        
        // Generate signature
        $aArgs['api_sig']       = self::buildSignature($aArgs);

        // Do the request
        $aResponse = call_user_func(array(__CLASS__, self::REQUEST_ENGINE_CURL), $aArgs);

        // Debug request
        if(defined('VIMEO_DEBUG_REQUEST') && VIMEO_DEBUG_REQUEST) {
            self::debug('API request', print_r($aArgs, true));
        }
        
        // Debug response
        if(defined('VIMEO_DEBUG_RESPONSE') && VIMEO_DEBUG_RESPONSE) {
            self::debug('API response', print_r($aResponse, true));
        }
        
        // Transform the result into a result class
        $oResult = new $sTargetClass($aResponse);
        
        // Check if request was successfull
        if(!$oResult->getStatus()) {
            // If not, create an given exception class for the given method and pass through error code and message
            throw new $sExceptionClass($oResult->getError()->getMessage(), $oResult->getError()->getCode());
        }
        
        // Return the base class object instance for the corresponding API query
        return $oResult;
    }
    
    /**
    * Execute raw API query with CURL
    * 
    * Implements CURL API queries in php format response
    * 
    * @author   Ted Roden
    * @access   private
    * @param    array       Additional arguments for the API query
    * @return   stdClass    Simple PHP object enclosing the API result
    */
    private function executeRemoteCall_CURL($aArgs) {
        $ch = curl_init(self::VIMEO_REST_URL);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $aArgs);
        curl_setopt($ch, CURLOPT_USERAGENT, self::PROJECT_NAME);

        $data = curl_exec($ch);
        if(curl_errno($ch))
            throw new VimeoRequestException('executeRemoteCall_CURL error: ' . curl_error($ch), curl_errno($ch));
        else {
            curl_close($ch);
            
            if(!$data || strlen(trim($data)) < 2) {
                throw new VimeoRequestException('API request error: No result returned.', 1);
            }
            return unserialize($data);
        }
    }
    
    /**
    * Execute raw API query with FSOCK
    * 
    * Implements FSOCK API queries in php format response
    * 
    * @access   private
    * @param    array       Additional arguemnts for the API query
    * @return   stdClass    Simple PHP object enclosing the API result
    */
    private function executeRemoteCall_FSOCK($aArgs) {
        $sResponse = file_get_contents(self::VIMEO_REST_URL, NULL, stream_context_create(array('http' => array('method' => 'POST', 'header'=> 'Content-type: application/x-www-form-urlencoded', 'content' => http_build_query($aArgs)))));
        if(!$sResponse || strlen(trim($sResponse)) < 2) {
            throw new VimeoRequestException('API request error: No result returned.', 1);
        } else {
            return unserialize($sResponse);
        }
    }

    /**
    * Proxy for video uploads
    * 
    * Will call the given video upload handler method (default: executeVideopostCall_FSOCK)
    * for the raw connection and send stuff
    * 
    * @access   public
    * @param    string          Local filename to be transfered
    * @param    string          Ticket
    * @return   string          VimeoVideosCheckUploadStatusResponse
    */
    public function executeVideopostCall($sFilename, $sTicket = false) {
        // Check that the upload query handler method exists and can be called
        if(!method_exists(__CLASS__, self::VIDEOPOST_ENGINE_FSOCK)) {
            throw new VimeoUploadException('Upload error: Videopost engine handler method not found', 1);
        }
        
        // If permission requirement is not met refuse to even call the API, safes bandwith for both ends
        if(!self::checkPermission(VimeoBase::PERMISSION_WRITE)) {
            throw new VimeoUploadException('Upload error: Missing "write" permission for current user', 2);
        }

        // Check that the file exists
        if(!file_exists($sFilename)) {
            throw new VimeoUploadException('Upload error: Local file does not exists', 3);
        }
        
        // Check that the file is readable
        if(!is_readable($sFilename)) {
            throw new VimeoUploadException('Upload error: Local file is not readable', 4);
        }
        
        // Check that the file size is not larger then the allowed size you can upload
        $oResponse = VimeoPeopleRequest::getUploadStatus();
        if(filesize($sFilename) > $oResponse->getRemainingBytes()) {
            throw new VimeoUploadException('Upload error: Videosize exceeds remaining bytes', 5);
        }
        
        // Try to get a upload ticket
        if(!$sTicket) {
            $oResponse = VimeoVideosRequest::getUploadTicket();
            $sTicket = $oResponse->getTicket();
        }
        
        // Build up the needed API arguments

        // Set API key
        $aArgs['api_key']       = self::$sApiKey;
        
        // Set request format
        $aArgs['format']        = 'php';

        // Set token
        if(self::$sToken) $aArgs['auth_token'] = self::$sToken;
        
        // Set ticket
        $aArgs['ticket_id']     = $sTicket;
        
        // Generate signature
        $aArgs['api_sig']       = self::buildSignature($aArgs);
        
        // Set file
        $aArgs['file']          = "@$sFilename";
        
        // Do the upload
        $sResponse = call_user_func(array(__CLASS__, self::VIDEOPOST_ENGINE_FSOCK), $aArgs);

        // Call vimeo.videos.checkUploadStatus to prevent abandoned status
        return VimeoVideosRequest::checkUploadStatus($sTicket);
    }
    
    private function executeVideopostCall_CURL($aArgs) {
        // Disable time limit
        set_time_limit(0);
        
        $ch = curl_init(self::VIMEO_UPLOAD_URL);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $aArgs);
        curl_setopt($ch, CURLOPT_USERAGENT, self::PROJECT_NAME);

        $data = curl_exec($ch);
        if(curl_errno($ch))
            throw new VimeoRequestException('executeRemoteCall_CURL error: ' . curl_error($ch), curl_errno($ch));
        else {
            curl_close($ch);
            return unserialize($data);
        }
    }
    
    /**
    * Build API query signature
    * 
    * Composes the signature needed to verify its really us doing the query
    * 
    * @author   Ted Roden
    * @access   private
    * @param    array       Additional arguments for the API query
    * @return   string      MD5 signature
    */
    private static function buildSignature($aArgs) {
        $s = '';
        
        // sort by name
        ksort($aArgs);

        foreach($aArgs as $k => $v) 
            $s .= $k . $v;

        return(md5(self::$sApiSecret . $s));    
    }
    
    /**
    * Build authentication URL
    * 
    * Easy way to build a correct authentication url. You can use this
    * to link the user directly to the correct vimeo authentication page.
    * 
    * @access   public
    * @param    string      Permission level you need the user to give you (i.e. VimeoBase::PERMISSION_READ)
    * @return   string      URL you can use to directly link the user to the vimeo authentication page
    */
    public static function buildAuthenticationUrl($ePermission) {
        
        $aArgs = array(
            'api_key' => self::$sApiKey,
            'perms' => $ePermission
        );
        
        return self::VIMEO_AUTH_URL . '?api_key=' . self::$sApiKey . '&perms=' . $ePermission . '&api_sig=' . self::buildSignature($aArgs);
    }
    
    /**
    * Get current logged in user token
    * 
    * @access   public
    * @return   string      Token or FALSE if not logged in
    */
    public static function getToken() {
        return self::$sToken;
    }
    
    /**
    * Set current logged in user token
    * 
    * @access   public
    * @param    string      Authentication token
    * @return   void
    */
    public static function setToken($sToken) {
        self::$sToken = $sToken;
    }
    
    /**
    * Clear current logged in user token
    * 
    * Removes the current logged in user from the cache. Next API query
    * will be made as clean, not logged in, request.
    * 
    * @access   public
    * @return   void
    */
    public static function clearToken() {
        self::$sToken = false;
    }
    
    /**
    * Execute a permit request
    * 
    * ONLY USED IN SITE-MODE, see howto.autologin.php
    * Permits the current CURL cached user with your vimeo API application
    * 
    * @access   public
    * @param    string      Permission
    * @return   string      Vimeo Token
    */
    public function permit($ePermission) {
        // Disable time limit
        set_time_limit(0);
        
        // Construct login data
        $aArgs = array(
            'api_key' => VimeoBase::$sApiKey,
            'perms' => $ePermission,
            'accept' => 'yes'
        );
        $ch = curl_init(VimeoBase::buildAuthenticationUrl($ePermission));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $aArgs);
        curl_setopt($ch, CURLOPT_USERAGENT, self::PROJECT_NAME);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_COOKIEFILE, VimeoBase::COOKIE_FILE);
        curl_setopt($ch, CURLOPT_COOKIEJAR, VimeoBase::COOKIE_FILE);
        
        $sPageContent = curl_exec($ch);
        if(curl_errno($ch)) {
            throw new VimeoRequestException('Error: Tried to login failed ' . curl_error($ch), curl_errno($ch));
            return false;
        } else {
            $sResponseUrl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
            
        }
        return $sPageContent;
    }
    
    /**
    * Ensures that the user is logged in
    * 
    * ONLY USED IN SITE-MODE, see howto.autologin.php
    * Ensures the site-account is logged in
    * 
    * @access   public
    * @param    string          Username
    * @param    string          Password
    * @return   boolean         TRUE if user could be logged in, FALSE if an error occured (try manually to see error)
    */
    public function login($sUsername, $sPassword) {
        // Disable time limit
        set_time_limit(0);
        
        // Construct login data
        $aArgs = array(
            'sign_in[email]' => $sUsername,
            'sign_in[password]' => $sPassword,
            'redirect' => ''
        );
        
        $ch = curl_init(VimeoBase::VIMEO_LOGIN_URL);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $aArgs);
        curl_setopt($ch, CURLOPT_USERAGENT, self::PROJECT_NAME);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_COOKIEFILE, VimeoBase::COOKIE_FILE);
        curl_setopt($ch, CURLOPT_COOKIEJAR, VimeoBase::COOKIE_FILE);
        
        $sPageContent = curl_exec($ch);
        
        if(curl_errno($ch)) {
            throw new VimeoRequestException('Error: Tried to login failed ' . curl_error($ch), curl_errno($ch));
            return false;
        } else {
            $sResponseUrl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
            curl_close($ch);
        }                           
        
        if(stristr($sResponseUrl, 'log_in') !== false) {
            // Login failed
            return false;
        } else {
            return true;
        }
    }
}

/**
* Vimeo base exception class
*
* Every exception caused by VimeoBase class will be of this type
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoBaseException extends VimeoException {}

/**
* Vimeo request exception class
*
* Exception thrown when requesting the API failed
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoRequestException extends VimeoException {}

/**
* Vimeo upload exception class
*
* Exception thrown when uploading a video failed
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoUploadException extends VimeoException {}

/**
* Vimeo API method handler class
*
* This class will ensure that only functions can be called if the method is implemented
* and the permission is right (p). It also states what the source (s), result (t) and
* exception (e) object will be.
* 
* @package     SimpleVimeo
* @subpackage  Base
*/

class VimeoMethod {
    
    private static $aMethods = array(
        // Vimeo Test methods
        'vimeo.test.login'                  => array(       's' => 'VimeoTestRequest',
                                                            't' => 'VimeoTestLoginResponse',
                                                            'e' => 'VimeoTestLoginException',
                                                            'p' => VimeoBase::PERMISSION_READ),
        
        'vimeo.test.echo'                   => array(       's' => 'VimeoTestRequest',
                                                            't' => 'VimeoTestEchoResponse',
                                                            'e' => 'VimeoTestEchoException',
                                                            'p' => VimeoBase::PERMISSION_NONE),
                                                            
        'vimeo.test.null'                   => array(       's' => 'VimeoTestRequest',
                                                            't' => 'VimeoTestNullResponse',
                                                            'e' => 'VimeoTestNullException',
                                                            'p' => VimeoBase::PERMISSION_READ),
                                                            
        // Vimeo Auth methods
        'vimeo.auth.getToken'               => array(       's' => 'VimeoAuthRequest',
                                                            't' => 'VimeoAuthGetTokenResponse',
                                                            'e' => 'VimeoAuthGetTokenException',
                                                            'p' => VimeoBase::PERMISSION_NONE),
                                                            
        'vimeo.auth.getFrob'                => array(       's' => 'VimeoAuthRequest',
                                                            't' => 'VimeoAuthGetFrobResponse',
                                                            'e' => 'VimeoAuthGetFrobException',
                                                            'p' => VimeoBase::PERMISSION_NONE),

        'vimeo.auth.checkToken'             => array(       's' => 'VimeoAuthRequest',
                                                            't' => 'VimeoAuthCheckTokenResponse',
                                                            'e' => 'VimeoAuthCheckTokenException',
                                                            'p' => VimeoBase::PERMISSION_NONE),
        
        // Vimeo Videos methods
        'vimeo.videos.getList'              => array(       's' => 'VimeoVideosRequest',
                                                            't' => 'VimeoVideosGetListResponse',
                                                            'e' => 'VimeoVideosGetListException',
                                                            'p' => VimeoBase::PERMISSION_NONE),

        'vimeo.videos.getUploadedList'      => array(       's' => 'VimeoVideosRequest',
                                                            't' => 'VimeoVideosGetUploadedListResponse',
                                                            'e' => 'VimeoVideosGetUploadedListException',
                                                            'p' => VimeoBase::PERMISSION_NONE),

        'vimeo.videos.getAppearsInList'     => array(       's' => 'VimeoVideosRequest',
                                                            't' => 'VimeoVideosGetAppearsInListResponse',
                                                            'e' => 'VimeoVideosGetAppearsInListException',
                                                            'p' => VimeoBase::PERMISSION_NONE),
                                                            
        'vimeo.videos.getSubscriptionsList' => array(       's' => 'VimeoVideosRequest',
                                                            't' => 'VimeoVideosGetSubscriptionsListResponse',
                                                            'e' => 'VimeoVideosGetSubscriptionsListException',
                                                            'p' => VimeoBase::PERMISSION_NONE),

        'vimeo.videos.getListByTag'         => array(       's' => 'VimeoVideosRequest',
                                                            't' => 'VimeoVideosGetListByTagResponse',
                                                            'e' => 'VimeoVideosGetListByTagException',
                                                            'p' => VimeoBase::PERMISSION_NONE),

        'vimeo.videos.getLikeList'          => array(       's' => 'VimeoVideosRequest',
                                                            't' => 'VimeoVideosGetLikeListResponse',
                                                            'e' => 'VimeoVideosGetLikeListException',
                                                            'p' => VimeoBase::PERMISSION_NONE),

        'vimeo.videos.getContactsList'      => array(       's' => 'VimeoVideosRequest',
                                                            't' => 'VimeoVideosGetContactsListResponse',
                                                            'e' => 'VimeoVideosGetContactsListException',
                                                            'p' => VimeoBase::PERMISSION_NONE),

        'vimeo.videos.getContactsLikeList'  => array(       's' => 'VimeoVideosRequest',
                                                            't' => 'VimeoVideosGetContactsLikeListResponse',
                                                            'e' => 'VimeoVideosGetContactsLikeListException',
                                                            'p' => VimeoBase::PERMISSION_NONE),
                                                            
        'vimeo.videos.search'               => array(       's' => 'VimeoVideosRequest',
                                                            't' => 'VimeoVideosSearchResponse',
                                                            'e' => 'VimeoVideosSearchException',
                                                            'p' => VimeoBase::PERMISSION_NONE),
                                                            
        'vimeo.videos.getInfo'              => array(       's' => 'VimeoVideosRequest',
                                                            't' => 'VimeoVideosGetInfoResponse',
                                                            'e' => 'VimeoVideosGetInfoException',
                                                            'p' => VimeoBase::PERMISSION_NONE),
                                                            
        'vimeo.videos.getUploadTicket'      => array(       's' => 'VimeoVideosRequest',
                                                            't' => 'VimeoVideosGetUploadTicketResponse',
                                                            'e' => 'VimeoVideosGetUploadTicketException',
                                                            'p' => VimeoBase::PERMISSION_WRITE),

        'vimeo.videos.checkUploadStatus'    => array(       's' => 'VimeoVideosRequest',
                                                            't' => 'VimeoVideosCheckUploadStatusResponse',
                                                            'e' => 'VimeoVideosCheckUploadStatusException',
                                                            'p' => VimeoBase::PERMISSION_WRITE),
                                                            
        'vimeo.videos.delete'               => array(       's' => 'VimeoVideosRequest',
                                                            't' => 'VimeoVideosDeleteResponse',
                                                            'e' => 'VimeoVideosDeleteException',
                                                            'p' => VimeoBase::PERMISSION_DELETE),

        'vimeo.videos.setTitle'             => array(       's' => 'VimeoVideosRequest',
                                                            't' => 'VimeoVideosSetTitleResponse',
                                                            'e' => 'VimeoVideosSetTitleException',
                                                            'p' => VimeoBase::PERMISSION_WRITE),

        'vimeo.videos.setCaption'           => array(       's' => 'VimeoVideosRequest',
                                                            't' => 'VimeoVideosSetCaptionResponse',
                                                            'e' => 'VimeoVideosSetCaptionException',
                                                            'p' => VimeoBase::PERMISSION_WRITE),
                                                            
        'vimeo.videos.setFavorite'          => array(       's' => 'VimeoVideosRequest',
                                                            't' => 'VimeoVideosSetFavoriteResponse',
                                                            'e' => 'VimeoVideosSetFavoriteException',
                                                            'p' => VimeoBase::PERMISSION_WRITE),
                                                            
        'vimeo.videos.addTags'              => array(       's' => 'VimeoVideosRequest',
                                                            't' => 'VimeoVideosAddTagsResponse',
                                                            'e' => 'VimeoVideosAddTagsException',
                                                            'p' => VimeoBase::PERMISSION_WRITE),
                                                            
        'vimeo.videos.removeTag'            => array(       's' => 'VimeoVideosRequest',
                                                            't' => 'VimeoVideosRemoveTagResponse',
                                                            'e' => 'VimeoVideosRemoveTagException',
                                                            'p' => VimeoBase::PERMISSION_WRITE),

        'vimeo.videos.clearTags'            => array(       's' => 'VimeoVideosRequest',
                                                            't' => 'VimeoVideosClearTagsResponse',
                                                            'e' => 'VimeoVideosClearTagsException',
                                                            'p' => VimeoBase::PERMISSION_WRITE),

        'vimeo.videos.setPrivacy'           => array(       's' => 'VimeoVideosRequest',
                                                            't' => 'VimeoVideosSetPrivacyResponse',
                                                            'e' => 'VimeoVideosSetPrivacyException',
                                                            'p' => VimeoBase::PERMISSION_WRITE),

        // Vimeo People methods
        'vimeo.people.findByUserName'       => array(       's' => 'VimeoPeopleRequest',
                                                            't' => 'VimeoPeopleFindByUsernameResponse',
                                                            'e' => 'VimeoPeopleFindByUsernameException',
                                                            'p' => VimeoBase::PERMISSION_NONE),

        'vimeo.people.findByEmail'          => array(       's' => 'VimeoPeopleRequest',
                                                            't' => 'VimeoPeopleFindByEmailResponse',
                                                            'e' => 'VimeoPeopleFindByEmailException',
                                                            'p' => VimeoBase::PERMISSION_NONE),

        'vimeo.people.getInfo'              => array(       's' => 'VimeoPeopleRequest',
                                                            't' => 'VimeoPeopleGetInfoResponse',
                                                            'e' => 'VimeoPeopleGetInfoException',
                                                            'p' => VimeoBase::PERMISSION_NONE),
                                                            
        'vimeo.people.getPortraitUrl'       => array(       's' => 'VimeoPeopleRequest',
                                                            't' => 'VimeoPeopleGetPortraitUrlResponse',
                                                            'e' => 'VimeoPeopleGetPortraitUrlException',
                                                            'p' => VimeoBase::PERMISSION_NONE),
        
        'vimeo.people.addContact'           => array(       's' => 'VimeoPeopleRequest',
                                                            't' => 'VimeoPeopleAddContactResponse',
                                                            'e' => 'VimeoPeopleAddContactException',
                                                            'p' => VimeoBase::PERMISSION_WRITE),
                                                            
        'vimeo.people.removeContact'        => array(       's' => 'VimeoPeopleRequest',
                                                            't' => 'VimeoPeopleRemoveContactResponse',
                                                            'e' => 'VimeoPeopleRemoveContactException',
                                                            'p' => VimeoBase::PERMISSION_WRITE),
                                                            
        'vimeo.people.getUploadStatus'      => array(       's' => 'VimeoPeopleRequest',
                                                            't' => 'VimeoPeopleGetUploadStatusResponse',
                                                            'e' => 'VimeoPeopleGetUploadStatusException',
                                                            'p' => VimeoBase::PERMISSION_READ),

        'vimeo.people.addSubscription'      => array(       's' => 'VimeoPeopleRequest',
                                                            't' => 'VimeoPeopleAddSubscriptionResponse',
                                                            'e' => 'VimeoPeopleAddSubscriptionException',
                                                            'p' => VimeoBase::PERMISSION_WRITE),

        'vimeo.people.removeSubscription'   => array(       's' => 'VimeoPeopleRequest',
                                                            't' => 'VimeoPeopleRemoveSubscriptionResponse',
                                                            'e' => 'VimeoPeopleRemoveSubscriptionException',
                                                            'p' => VimeoBase::PERMISSION_WRITE)
    );
        
    public static function getSourceObjectForMethod($sMethod) {
        // Check if the method can be handled
        self::checkMethod($sMethod);
        
        return self::$aMethods[$sMethod]['s'];
    }
    
    public static function getTargetObjectForMethod($sMethod) {
        // Check if the method can be handled
        self::checkMethod($sMethod);
        
        return self::$aMethods[$sMethod]['t'];
    }
    
    public static function getExceptionObjectForMethod($sMethod) {
        // Check if the method can be handled
        self::checkMethod($sMethod);
        
        return self::$aMethods[$sMethod]['e'];
    }

    public static function getPermissionRequirementForMethod($sMethod) {
        // Check if the method can be handled
        self::checkMethod($sMethod);
        
        return self::$aMethods[$sMethod]['p'];
    }
    
    public static function checkMethod($sMethod) {
        // Check if the method can be handled
        if(!isset(self::$aMethods[$sMethod])) {
            throw new VimeoMethodException('Unhandled vimeo method "' . $sMethod . '" given', 2);
        }
    }
}

/**
* Vimeo method exception class
*
* Every exception caused by VimeoMethod class will be of this type
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoMethodException extends Exception {}

/*
* Abstract class constructs that the whole api stuff will be based on
*/

/**
* Vimeo exception class
*
* Every exception the whole SimpleVimeo throws will be extended of this base
* class. You can extend this one to alter all exceptions.
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
* @abstract
*/

abstract class VimeoException extends Exception {}

/**
* Vimeo array of object handler class
* 
* This class is for array of object handling. i.e.: An array of video objects.
* It ensures that you can work with foreach and count without getting into a hassle.
* 
* @package      SimpleVimeo
* @subpackage   Base
* @abstract
*/

abstract class VimeoObjectList implements Iterator, Countable {
    /**
    * Array for instanced objects
    * @var  array
    */
    private $aInstances = array();
    
    /**
    * Integer how many results
    * @var  integer
    */
    private $iCount = 0;
    
    /**
    * Class name
    * @var  string
    */
    private $sClassName;
    
    private $aIDs = array();
    
    /**
    * Constructor
    * 
    * @access   public
    * @return   void
    */
    public function __construct() {
        // Parse class name
        $this->sClassName = str_replace('List', '', get_class($this));
    }
    
    /**
    * Add object to array
    * 
    * @access   public
    * @param    object      Object to be added to array
    * @param    integer     Array index to be used for the given object
    * @return   void
    */
    public function add($oObject, $iID = false) {
        if($iID !== false) {
            $this->aInstances[$iID] = $oObject;
        } else {
            $this->aInstances[] = $oObject;
        }
        
        $this->aIDs[] = $iID;
        
        $this->iCount++;
    }

    /**
    * Returns all array indexes for further parsing
    * 
    * @access   public
    * @return   array       Array with object array indexes
    */
    public function getAllUniqueIDs() {
        return $this->getIDs();
    }
    
    /**
    * @ignore
    */
    public function rewind() {
        reset($this->aInstances);
    }
    
    /**
    * @ignore
    */
    public function current() {
        return current($this->aInstances);
    }
    
    /**
    * @ignore
    */
    public function key() {
        return key($this->aInstances);
    }
    
    /**
    * @ignore
    */
    public function next() {
        return next($this->aInstances);
    }
    
    /**
    * @ignore
    */
    public function valid() {
        return $this->current() !== FALSE;
    }
    
    /**
    * @ignore
    */
    public function count() {
        return $this->iCount;
    }
}

/**
* Vimeo request class
*
* Every API query collection class will be based on this.
* 
* @package     SimpleVimeo
* @subpackage  ApiRequest
* @abstract
*/

abstract class VimeoRequest {}

/**
* Vimeo response class
*
* Every API response class will be based on this. It also handles
* everytime response variables like if the query was successfull and
* the generation time.
* 
* @package     SimpleVimeo
* @subpackage  ApiResponse
* @abstract
*/

abstract class VimeoResponse {
    private $bStatus = false;
    private $fPerformance = false;
    private $iErrorCode = false;
    private $oError = false;
    
    /**
    * Constructor
    * 
    * Parses the API response
    * You dont need to pass a response if you need to give a hint your coding tool for code completion
    * 
    * @access   public
    * @param    stdClass    API response
    * @return   void
    */
    public function __construct($aResponse = false) {
        if($aResponse) {
            // Parse status
            $this->setStatus($aResponse->stat);
            
            // Parse performance
            $this->fPerformance = (float) $aResponse->generated_in;
            
            // Parse error information
            if(!$this->bStatus) {
                $this->oError = new VimeoErrorEntity($aResponse->err->code, $aResponse->err->msg);
            }
        }
    }
    
    private function setStatus($sStatus) {
        if($sStatus === 'ok') {
            $this->bStatus = true;
        }
    }
    
    public function getStatus() {
        return $this->bStatus;
    }
    
    public function getPerformance() {
        return $this->fPerformance;
    }
    
    public function getError() {
        return $this->oError;
    }
}

/*
* Entity classes for default instances of users etc. they are always the same
* and their array of object handlers
*/

/**
* Vimeo API error entity class
*
* Implements API delivered error entities into an PHP 5 object with given result parameters.
* 
* @package     SimpleVimeo
* @subpackage  Entities
*/

class VimeoErrorEntity {
    private $iErrorCode = false;
    private $sErrorMessage = false;
    
    public function __construct($iErrorCode, $sErrorMessage) {
        $this->iErrorCode = $iErrorCode;
        $this->sErrorMessage = $sErrorMessage;
    }
    
    public function getCode() {
        return $this->iErrorCode;
    }
    
    public function getMessage() {
        return $this->sErrorMessage;
    }
}

/**
* Vimeo API user entity class
*
* Implements API delivered user entities into an PHP 5 object with given result parameters.
* 
* @package     SimpleVimeo
* @subpackage  Entities
*/

class VimeoUserEntity {
    private $iUserNsId = false;
    private $iUserId = false;
    private $sUsername = false;
    private $sFullname = false;
    
    // Optional information when vimeo.person.getInfo is called
    private $sLocation = false;
    private $sUrl = false;
    private $iNumberOfContacts = false;
    private $iNumberOfUploads = false;
    private $iNumberOfLikes = false;
    private $iNumberOfVideos = false;
    private $iNumberOfVideosAppearsIn = false;
    private $sProfileUrl = false;
    private $sVideosUrl = false;
    
    public function __construct($aResponseSnippet) {
        if(isset($aResponseSnippet->id)) {
            $this->iUserId = $aResponseSnippet->id;
        }
        
        if(isset($aResponseSnippet->nsid)) {
            $this->iUserNsId = $aResponseSnippet->nsid;
        }
        
        if(isset($aResponseSnippet->username)) {
            $this->sUsername = $aResponseSnippet->username;
        }
        
        if(isset($aResponseSnippet->fullname)) {
            $this->sFullname = $aResponseSnippet->fullname;
        }
        
        if(isset($aResponseSnippet->display_name)) {
            $this->sFullname = $aResponseSnippet->display_name;
        }
        
        // Optional stuff
        if(isset($aResponseSnippet->location)) {
            $this->sLocation = $aResponseSnippet->location;
        }
        
        if(isset($aResponseSnippet->url)) {
            $this->sUrl = $aResponseSnippet->url;
        }
        
        if(isset($aResponseSnippet->number_of_contacts)) {
            $this->iNumberOfContacts = $aResponseSnippet->number_of_contacts;
        }
        
        if(isset($aResponseSnippet->number_of_uploads)) {
            $this->iNumberOfUploads = $aResponseSnippet->number_of_uploads;
        }
        
        if(isset($aResponseSnippet->number_of_likes)) {
            $this->iNumberOfLikes = $aResponseSnippet->number_of_likes;
        }
        
        if(isset($aResponseSnippet->number_of_videos)) {
            $this->iNumberOfVideos = $aResponseSnippet->number_of_videos;
        }
        
        if(isset($aResponseSnippet->number_of_videos_appears_in)) {
            $this->iNumberOfVideosAppearsIn = $aResponseSnippet->number_of_videos_appears_in;
        }
        
        if(isset($aResponseSnippet->profileurl)) {
            $this->sProfileUrl = $aResponseSnippet->profileurl;
        }

        if(isset($aResponseSnippet->videosurl)) {
            $this->sVideosUrl = $aResponseSnippet->videosurl;
        }
    }
    
    public function getNsID() {
        return $this->iUserNsId;
    }

    public function getID() {
        return $this->iUserId;
    }
    
    public function getUsername() {
        return $this->sUsername;
    }
    
    public function getFullname() {
        return $this->sFullname;
    }
    
    public function getLocation() {
        return $this->sLocation;
    }
    
    public function getUrl() {
        return $this->sUrl;
    }
    
    public function getNumberOfContacts() {
        return $this->iNumberOfContacts;
    }
    
    public function getNumberOfUploads() {
        return $this->iNumberOfUploads;
    }
    
    public function getNumberOfLikes() {
        return $this->iNumberOfLikes;
    }
    
    public function getNumberOfVideos() {
        return $this->iNumberOfVideos;
    }
    
    public function getNumberOfVideosAppearsIn() {
        return $this->iNumberOfVideosAppearsIn;
    }
    
    public function getProfileUrl() {
        return $this->sProfileUrl;
    }
    
    public function getVideosUrl() {
        return $this->sVideosUrl;
    }
}

/**
* Vimeo API video entity class
*
* Implements API delivered video into an PHP 5 object with given result parameters.
* 
* @package     SimpleVimeo
* @subpackage  Entities
*/

class VimeoVideoEntity {
    private $iID = false;
    private $ePrivacy = false;
    private $bIsUploading = false;
    private $bIsTranscoding = false;
    private $bIsHD = false;
    
    private $sTitle = false;
    private $sCaption = false;
    private $iUploadTime = false;
    private $iNumberOfLikes = false;
    private $iNumberOfPlays = false;
    private $iNumberOfComments = false;

    private $sUrl = false;
        
    private $iWidth = false;
    private $iHeight = false;
    private $oOwner = false;
    
    private $oTagList = false;
    
    private $oThumbnailList = false;
    
    public function __construct($aResponseSnippet = false) {
        if($aResponseSnippet) {
            // Set basic information
            $this->iID = $aResponseSnippet->id;
            $this->ePrivacy = $aResponseSnippet->privacy;
            $this->bIsUploading = $aResponseSnippet->is_uploading;
            $this->bIsTranscoding = $aResponseSnippet->is_transcoding;
            $this->bIsHD = $aResponseSnippet->is_hd;
            
            $this->sTitle = $aResponseSnippet->title;
            $this->sCaption = $aResponseSnippet->caption;
            $this->iUploadTime = strtotime($aResponseSnippet->upload_date);
            $this->iNumberOfLikes = (int) $aResponseSnippet->number_of_likes;
            $this->iNumberOfPlays = (int) $aResponseSnippet->number_of_plays;
            $this->iNumberOfComments = (int) $aResponseSnippet->number_of_comments;
            
            $this->sUrl = $aResponseSnippet->urls->url->_content;
            
            $this->iWidth = (int) $aResponseSnippet->width;
            $this->iHeight = (int) $aResponseSnippet->height;
            
            $this->oOwner = new VimeoUserEntity($aResponseSnippet->owner);
            
            // Parse Tags
            $this->oTagList = new VimeoTagList();
            if(isset($aResponseSnippet->tags->tag)) {
                foreach($aResponseSnippet->tags->tag as $aTagInformation) {
                    $oTag = new VimeoTagEntity($aTagInformation);
                    $this->oTagList->add($oTag, $oTag->getID());
                }
            }
            
            // Parse Thumbnails
            $this->oThumbnailList = new VimeoThumbnailList();
            if(isset($aResponseSnippet->thumbnails->thumbnail)) {
                foreach($aResponseSnippet->thumbnails->thumbnail as $aThumbnailInformation) {
                    $oThumbnail = new VimeoThumbnailEntity($aThumbnailInformation);
                    $this->oThumbnailList->add($oThumbnail, ($oThumbnail->getWidth() * $oThumbnail->getHeight()));
                }
            }
        }
    }
    
    public function getID() {
        return $this->iID;
    }
    
    public function getPrivacy() {
        return $this->ePrivacy;
    }
    
    public function isUploading() {
        return $this->bIsUploading;
    }
    
    public function isTranscoding() {
        return $this->bIsTranscoding;
    }
    
    public function isHD() {
        return $this->bIsHD;
    }
    
    public function getTitle() {
        return $this->sTitle;
    }
    
    public function getCaption() {
        return $this->sCaption;
    }
    
    public function getUploadTimestamp() {
        return $this->iUploadTime;
    }
    
    public function getNumberOfLikes() {
        return (int) $this->iNumberOfLikes;
    }
    
    public function getNumberOfPlays() {
        return (int) $this->iNumberOfPlays;
    }
    
    public function getNumberOfComments() {
        return (int) $this->iNumberOfComments;
    }
    
    public function getWidth() {
        return (int) $this->iWidth;
    }
    
    public function getHeight() {
        return (int) $this->iHeight;
    }
    
    public function getOwner() {
        return $this->oOwner;
    }
    
    public function getTags() {
        return $this->oTagList;
    }
    
    public function getUrl() {
        return $this->sUrl;
    }
    
    public function getThumbnails() {
        return $this->oThumbnailList;
    }
}

/**
* Vimeo API video list class
*
* Implements API delivered video list entities into an PHP 5 array of objects.
* 
* @package     SimpleVimeo
* @subpackage  Lists
*/

class VimeoVideoList extends VimeoObjectList {}

/**
* Vimeo API tag entity class
*
* Implements API delivered tag entities into an PHP 5 object with given result parameters.
* 
* @package     SimpleVimeo
* @subpackage  Entities
*/

class VimeoTagEntity {
    private $iID = false;
    private $sContent = false;
    
    public function __construct($aResponseSnippet = false) {
        if($aResponseSnippet) {
            $this->iID = $aResponseSnippet->id;
            $this->sContent = $aResponseSnippet->_content;
        }
    }
    
    public function getID() {
        return $this->iID;
    }
    
    public function getTag() {
        return $this->sContent;
    }
}

/**
* Vimeo API tag list class
*
* Implements API delivered tag list entities into an PHP 5 array of objects.
* 
* @package     SimpleVimeo
* @subpackage  Lists
*/

class VimeoTagList extends VimeoObjectList {}

/**
* Vimeo API thumbnail entity class
*
* Implements API delivered thumbnail entities into an PHP 5 object with given result parameters.
* 
* @package     SimpleVimeo
* @subpackage  Entities
*/

class VimeoThumbnailEntity {
    private $iWidth = false;
    private $iHeight = false;
    private $sContent = false;
    
    public function __construct($aResponseSnippet = false) {
        if($aResponseSnippet) {
            $this->iWidth = (int) $aResponseSnippet->width;
            $this->iHeight = (int) $aResponseSnippet->height;
            $this->sContent = $aResponseSnippet->_content;
        }
    }
    
    public function getWidth() {
        return (int) $this->iWidth;
    }
    
    public function getHeight() {
        return (int) $this->iHeight;
    }
    
    public function getImageContent() {
        return $this->sContent;
    }
}

/**
* Vimeo API thumbnail list class
*
* Implements API delivered thumbnail list entities into an PHP 5 array of objects.
* 
* @package     SimpleVimeo
* @subpackage  Lists
*/

class VimeoThumbnailList extends VimeoObjectList {
    public function getByWidth($iWidth, $bAlsoLower = false) {
        /**
        * @todo
        */
    }
    
    public function getByHeight($iHeight, $bAlsoLower = false) {
        /**
        * @todo
        */
    }
    
    public function getByWidthAndHeight($iWidth, $iHeight, $bAlsoLower = false) {
        /**
        * @todo
        */
    }
}


/*
* vimeo.test.* methods
*/

/**
* Vimeo Test request handler class
*
* Implements all API queries in the vimeo.test.* category
* 
* @package     SimpleVimeo
* @subpackage  ApiRequest
*/

class VimeoTestRequest extends VimeoRequest {
    
    /**
    * Is the user logged in?
    * 
    * @access   public
    * @return   VimeoTestLoginResponse 
    */
    
    public function login() {
        return VimeoBase::executeRemoteCall('vimeo.test.login');
    }
    
    /**
    * This will just repeat back any parameters that you send.
    * 
    * @access   public
    * @param    array       Additional arguments that need to be passed to the API
    * @return   VimeoTestEchoResponse
    */
    
    public function echoback($aArgs) {
        return VimeoBase::executeRemoteCall('vimeo.test.echo', $aArgs);
    }
    
    /**
    * This is just a simple null/ping test...
    * 
    * @access   public
    * @return   VimeoTestNullResponse 
    */
    
    public function ping() {
        return VimeoBase::executeRemoteCall('vimeo.test.null');
    }
}

/**
* Vimeo Test Login response handler class
*
* Handles the API response for vimeo.test.login queries.
* 
* @package     SimpleVimeo
* @subpackage  ApiResponse
*/

class VimeoTestLoginResponse extends VimeoResponse {}

/**
* Vimeo Test Login exception handler class
*
* Handles exceptions caused by API response for vimeo.test.login queries.
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoTestLoginException extends VimeoException {}

/**
* Vimeo Test Echo response handler class
*
* Handles the API response for vimeo.test.echo queries.
* 
* @package     SimpleVimeo
* @subpackage  ApiResponse
*/

class VimeoTestEchoResponse extends VimeoResponse {
    private $aArgs = false;

    /**
    * Constructor
    * 
    * Parses the API response
    * 
    * @access   public
    * @param    stdClass    API response
    * @return   void
    */
    public function __construct($aResponse = false) {
        parent::__construct($aResponse);
        
        $this->aArgs = get_object_vars($aResponse);
        
        // Unset default response stuff
        if(isset($this->aArgs['stat'])) unset($this->aArgs['stat']);
        if(isset($this->aArgs['generated_in'])) unset($this->aArgs['generated_in']);
    }
    
    /**
    * Returns an array of variables the request bounced back
    * 
    * @access   public
    * @return   array       Echoed variables
    */
    public function getResponseArray() {
        return $this->aArgs;
    }
}

/**
* Vimeo Test Echo exception handler class
*
* Handles exceptions caused by API response for vimeo.test.echo queries.
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoTestEchoException extends VimeoException {}

/**
* Vimeo Test Null response handler class
*
* Handles the API response for vimeo.test.null queries.
* 
* @package     SimpleVimeo
* @subpackage  ApiResponse
*/

class VimeoTestNullResponse extends VimeoResponse {}

/**
* Vimeo Test Null exception handler class
*
* Handles exceptions caused by API response for vimeo.test.null queries.
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoTestNullException extends VimeoException {}

/*
* vimeo.auth.* methods
*/

/**
* Vimeo Auth request handler class
*
* Implements all API queries in the vimeo.auth.* category
* 
* @package     SimpleVimeo
* @subpackage  ApiRequest
*/

class VimeoAuthRequest extends VimeoRequest {
    
    /**
    * Get Token
    * 
    * @access   public
    * @param    string      Frob taken from the vimeo authentication
    * @return   VimeoAuthGetTokenResponse
    */
    public function getToken($sFrob) {
        $aArgs = array(
            'frob' => $sFrob
        );
        
        return VimeoBase::executeRemoteCall('vimeo.auth.getToken', $aArgs);
    }
    
    /**
    * Check Token
    * 
    * Checks the validity of the token. Returns the user associated with it.
    * Returns the same as vimeo.auth.getToken
    * 
    * @access   public
    * @param    string      Authentication token
    * @return   VimeoAuthCheckTokenResponse
    */
    public function checkToken($sToken = false) {
        if(!$sToken) $sToken = VimeoBase::getToken();
        
        $aArgs = array(
            'auth_token' => $sToken
        );
        
        return VimeoBase::executeRemoteCall('vimeo.auth.checkToken', $aArgs);
    }
    
    /**
    * Get Frob
    * 
    * This is generally used by desktop applications. If the user doesn't already have
    * a token, you'll need to get the frob, send it to us at /services/auth. Then,
    * after the user, clicks continue on your app, you call vimeo.auth.getToken($frob)
    * and we give you the actual token. 
    * 
    * @access   public
    * @return   VimeoAuthGetFrobResponse
    */
    public function getFrob() {
        return VimeoBase::executeRemoteCall('vimeo.auth.getFrob');
    } 
}

/**
* Vimeo Auth GetToken response handler class
*
* Handles the API response for vimeo.auth.getToken queries.
* 
* @package     SimpleVimeo
* @subpackage  ApiResponse
*/

class VimeoAuthGetTokenResponse extends VimeoResponse {
    
    private $sToken = false;
    private $ePermission = false;
    private $oUser = false;

    /**
    * Constructor
    * 
    * Parses the API response
    * 
    * @access   public
    * @param    stdClass    API response
    * @return   void
    */
    public function __construct($aResponse) {
        parent::__construct($aResponse);
        
        $this->sToken = $aResponse->auth->token;
        $this->ePermission = $aResponse->auth->perms;
        
        $this->oUser = new VimeoUserEntity($aResponse->auth->user);
    }
    
    /**
    * Get token value
    * 
    * @access   public
    * @return   token
    */
    public function getToken() {
        return $this->sToken;
    }
    
    /**
    * Get permission value
    * 
    * @access   public
    * @return   permission
    */
    
    public function getPermission() {
        return $this->ePermission;
    }
    
    /**
    * Get user information object
    * 
    * @access   public
    * @return VimeoUserEntity
    */
    public function getUser() {
        return $this->oUser;
    }
}

/**
* Vimeo Auth GetToken exception handler class
*
* Handles exceptions caused by API response for vimeo.auth.getToken queries.
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoAuthGetTokenException extends Exception {}

/**
* Vimeo Auth CheckToken response handler class
*
* Handles the API response for vimeo.auth.checkToken queries.
* 
* @package     SimpleVimeo
* @subpackage  ApiResponse
*/

class VimeoAuthCheckTokenResponse extends VimeoAuthGetTokenResponse {}

/**
* Vimeo Auth CheckToken exception handler class
*
* Handles exceptions caused by API response for vimeo.auth.checkToken queries.
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoAuthCheckTokenException extends VimeoAuthGetTokenException {}

/**
* Vimeo Auth GetFrob response handler class
*
* Handles the API response for vimeo.auth.getFrob queries.
* 
* @package     SimpleVimeo
* @subpackage  ApiResponse
*/

class VimeoAuthGetFrobResponse extends VimeoResponse {
    private $sFrob = false;
    
    /**
    * Constructor
    * 
    * Parses the API response
    * 
    * @access   public
    * @param    stdClass    API response
    * @return   void
    */
    public function __construct($aResponse) {
        parent::__construct($aResponse);
        
        $this->sFrob = $aResponse->frob;
    }
    
    /**
    * Get Frob value
    * 
    * @access   public
    * @return   frob
    */
    public function getFrob() {
        return $this->sFrob;
    }
}

/**
* Vimeo Auth GetFrob exception handler class
*
* Handles exceptions caused by API response for vimeo.auth.getFrob queries.
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoAuthGetFrobException extends VimeoException {}

/**
* vimeo.videos.* methods
*/

/**
* Vimeo Videos request handler class
*
* Implements all API queries in the vimeo.videos.* category
* 
* @package     SimpleVimeo
* @subpackage  ApiRequest
*/

class VimeoVideosRequest extends VimeoRequest {

    const PRIVACY_ANYBODY = 'anybody';
    const PRIVACY_CONTACTS = 'contacts';
    const PRIVACY_NOBODY = 'nobody';
    const PRIVACY_USERS = 'users';
    
    /**
    * Search videos! 
    * 
    * If the calling user is logged in, this will return information that calling user
    * has access to (including private videos). If the calling user is not authenticated,
    * this will only return public information, or a permission denied error if none is available.
    * 
    * @access   public
    * @param    string      Search query
    * @param    integer     User ID, this can be the ID number (151542) or the username (ted)
    * @param    boolean     If TRUE, we'll only search the users contacts. If this is set, you must specifiy a User ID. Otherwise it will be ignored without error.
    * @param    integer     ow many results per page?
    * @return VimeoVideosSearchResponse  
    */
    public function search($sQuery, $iUserID = false, $bContactsOnly = false, $iItemsPerPage = false) {
        
        // Pass query (required)
        $aArgs = array(
            'query' => $sQuery
        );
        
        // Pass user
        if($iUserID) {
            $aArgs['user_id'] = $iUserID;
        }
        
        // Pass contacts
        if($bContactsOnly) {
            $aArgs['contacts_only'] = $bContactsOnly;
        }
        
        // Pass items
        if($iItemsPerPage) {
            $aArgs['per_page'] = $iItemsPerPage;
        }
        
        // Please deliver full response so we can handle videos with unified classes
        $aArgs['fullResponse'] = 1;
        
        return VimeoBase::executeRemoteCall('vimeo.videos.search', $aArgs);
    }
    
    /**
    * This gets a list of videos for the specified user.
    * 
    * This is the functionality of "My Videos" or "Ted's Videos." At the moment, this is the same list
    * as vimeo.videos.getAppearsInList. If you need uploaded or appears in, those are available too.
    * 
    * @access   public
    * @param    integer     User ID, this can be the ID number (151542) or the username (ted)
    * @param    integer     Which page to show.
    * @param    integer     How many results per page?
    * @return   VimeoVideosGetListResponse
    */
    public function getList($iUserID, $iPage = false, $iItemsPerPage = false) {
        // Extend query
        $aArgs = array(
            'user_id'       => $iUserID
        );
        
        if($iPage) {
            $aArgs['page'] =    $iPage;
        }

        if($iItemsPerPage) {
            $aArgs['per_page'] = $iItemsPerPage;
        }
        
        // Please deliver full response so we can handle videos with unified classes
        $aArgs['fullResponse'] = 1;
        
        return VimeoBase::executeRemoteCall('vimeo.videos.getList', $aArgs);
    }
    
    /**
    * This gets a list of videos uploaded by the specified user.
    * 
    * If the calling user is logged in, this will return information that calling user has access to
    * (including private videos). If the calling user is not authenticated, this will only return
    * public information, or a permission denied error if none is available.
    * 
    * @access   public
    * @param    integer     User ID, this can be the ID number (151542) or the username (ted)
    * @param    integer     Which page to show.
    * @param    integer     How many results per page?
    * @return   VimeoVideosGetUploadedListResponse
    */
    public function getUploadedList($iUserID, $iPage = false, $iItemsPerPage = false) {
        // Extend query
        $aArgs = array(
            'user_id'       => $iUserID
        );
        
        if($iPage) {
            $aArgs['page'] =    $iPage;
        }

        if($iItemsPerPage) {
            $aArgs['per_page'] = $iItemsPerPage;
        }
        
        // Please deliver full response so we can handle videos with unified classes
        $aArgs['fullResponse'] = 1;
        
        return VimeoBase::executeRemoteCall('vimeo.videos.getUploadedList', $aArgs);
    }
    
    /**
    * This gets a list of videos that the specified user appears in. 
    * 
    * If the calling user is logged in, this will return information that calling user has access
    * to (including private videos). If the calling user is not authenticated, this will only return
    * public information, or a permission denied error if none is available. 
    * 
    * @access   public
    * @param    integer     User ID, this can be the ID number (151542) or the username (ted)
    * @param    integer     Which page to show.
    * @param    integer     How many results per page?
    * @return   VimeoVideosGetAppearsInListResponse
    */
    public function getAppearsInList($iUserID, $iPage = false, $iItemsPerPage = false) {
        // Extend query
        $aArgs = array(
            'user_id'       => $iUserID
        );
        
        if($iPage) {
            $aArgs['page'] =    $iPage;
        }

        if($iItemsPerPage) {
            $aArgs['per_page'] = $iItemsPerPage;
        }
        
        // Please deliver full response so we can handle videos with unified classes
        $aArgs['fullResponse'] = 1;
        
        return VimeoBase::executeRemoteCall('vimeo.videos.getAppearsInList', $aArgs);
    }
    
    /**
    * This gets a list of subscribed videos for a particular user.  
    * 
    * If the calling user is logged in, this will return information that calling user
    * has access to (including private videos). If the calling user is not authenticated,
    * this will only return public information, or a permission denied error if none is available.
    * 
    * @access   public
    * @param    integer     User ID, this can be the ID number (151542) or the username (ted)
    * @param    integer     Which page to show.
    * @param    integer     How many results per page?
    * @return   VimeoVideosGetSubscriptionsListResponse
    */
    public function getSubscriptionsList($iUserID, $iPage = false, $iItemsPerPage = false) {
        // Extend query
        $aArgs = array(
            'user_id'       => $iUserID
        );
        
        if($iPage) {
            $aArgs['page'] =    $iPage;
        }

        if($iItemsPerPage) {
            $aArgs['per_page'] = $iItemsPerPage;
        }
        
        // Please deliver full response so we can handle videos with unified classes
        $aArgs['fullResponse'] = 1;
        
        return VimeoBase::executeRemoteCall('vimeo.videos.getSubscriptionsList', $aArgs);
    }

    /**
    * This gets a list of videos by tag    
    * 
    * If you specify a user_id, we'll only get video uploaded by that user with the specified tag.
    * If the calling user is logged in, this will return information that calling user has access
    * to (including private videos). If the calling user is not authenticated, this will only
    * return public information, or a permission denied error if none is available.
    * 
    * @access   public
    * @param    string      A single tag: "cat" "new york" "cheese" 
    * @param    integer     User ID, this can be the ID number (151542) or the username (ted)
    * @param    integer     Which page to show.
    * @param    integer     How many results per page?
    * @return   VimeoVideosGetListByTagResponse
    */
    public function getListByTag($sTag, $iUserID = false, $iPage = false, $iItemsPerPage = false) {
        // Extend query
        $aArgs = array(
            'tag'       => $sTag
        );
        
        if($iUserID) {
            $aArgs['user_id'] = $iUserID;
        }
        
        if($iPage) {
            $aArgs['page'] =    $iPage;
        }

        if($iItemsPerPage) {
            $aArgs['per_page'] = $iItemsPerPage;
        }
        
        // Please deliver full response so we can handle videos with unified classes
        $aArgs['fullResponse'] = 1;
        
        return VimeoBase::executeRemoteCall('vimeo.videos.getListByTag', $aArgs);
    }

    /**
    * Get a list of videos that the specified user likes.   
    * 
    * If the calling user is logged in, this will return information that calling user has
    * access to (including private videos). If the calling user is not authenticated, this will
    * only return public information, or a permission denied error if none is available.
    * 
    * @access   public
    * @param    integer     User ID, this can be the ID number (151542) or the username (ted)
    * @param    integer     Which page to show.
    * @param    integer     How many results per page?
    * @return   VimeoVideosGetLikeListResponse
    */
    public function getLikeList($iUserID, $iPage = false, $iItemsPerPage = false) {
        // Extend query
        $aArgs = array(
            'user_id'       => $iUserID
        );
        
        if($iPage) {
            $aArgs['page'] =    $iPage;
        }

        if($iItemsPerPage) {
            $aArgs['per_page'] = $iItemsPerPage;
        }
        
        // Please deliver full response so we can handle videos with unified classes
        $aArgs['fullResponse'] = 1;
        
        return VimeoBase::executeRemoteCall('vimeo.videos.getLikeList', $aArgs);
    }
    
    /**
    * Get a list of videos made by the contacts of a specific user.
    * 
    * If the calling user is logged in, this will return information that calling user has
    * access to (including private videos). If the calling user is not authenticated, this will
    * only return public information, or a permission denied error if none is available.
    * 
    * @access   public
    * @param    integer     User ID, this can be the ID number (151542) or the username (ted)
    * @param    integer     Which page to show.
    * @param    integer     How many results per page?
    * @return   VimeoVideosGetContactsListResponse
    */
    public function getContactsList($iUserID, $iPage = false, $iItemsPerPage = false) {
        // Extend query
        $aArgs = array(
            'user_id'       => $iUserID
        );
        
        if($iPage) {
            $aArgs['page'] =    $iPage;
        }

        if($iItemsPerPage) {
            $aArgs['per_page'] = $iItemsPerPage;
        }
        
        // Please deliver full response so we can handle videos with unified classes
        $aArgs['fullResponse'] = 1;
        
        return VimeoBase::executeRemoteCall('vimeo.videos.getContactsList', $aArgs);
    }
    
    /**
    * Get a list of videos that the specified users contacts like.
    * 
    * If the calling user is logged in, this will return information that calling user has
    * access to (including private videos). If the calling user is not authenticated, this will
    * only return public information, or a permission denied error if none is available.
    * 
    * @access   public
    * @param    integer     User ID, this can be the ID number (151542) or the username (ted)
    * @param    integer     Which page to show.
    * @param    integer     How many results per page?
    * @return   VimeoVideosGetContactsLikeListResponse
    */
    public function getContactsLikeList($iUserID, $iPage = false, $iItemsPerPage = false) {
        // Extend query
        $aArgs = array(
            'user_id'       => $iUserID
        );
        
        if($iPage) {
            $aArgs['page'] =    $iPage;
        }

        if($iItemsPerPage) {
            $aArgs['per_page'] = $iItemsPerPage;
        }
        
        // Please deliver full response so we can handle videos with unified classes
        $aArgs['fullResponse'] = 1;
        
        return VimeoBase::executeRemoteCall('vimeo.videos.getContactsLikeList', $aArgs);
    }
    
    /**
    * Get all kinds of information about a photo.
    * 
    * If the calling user is logged in, this will return information that calling user has
    * access to (including private videos). If the calling user is not authenticated, this will
    * only return public information, or a permission denied error if none is available.
    * 
    * @access   public
    * @param    integer     Video ID
    * @return   VimeoVideosGetInfoResponse
    */
    public function getInfo($iVideoID) {
        // Extend query
        $aArgs = array(
            'video_id'      => $iVideoID
        );
        
        return VimeoBase::executeRemoteCall('vimeo.videos.getInfo', $aArgs);
    }
    
    /**
    * Generate a new upload Ticket.
    * 
    * You'll need to pass this to the uploader. It's only good for one upload, only good for one user.
    * 
    * @access   public
    * @return   VimeoVideosGetUploadTicketResponse
    */
    public function getUploadTicket() {
        return VimeoBase::executeRemoteCall('vimeo.videos.getUploadTicket');
    }
    
    /**
    * Check the status of an upload started via the API  
    * 
    * This is how you get the video_id of a clip uploaded from the API
    * If you never call this to check in, we assume it was abandoned and don't process it
    * 
    * @access   public
    * @param    string      The ticket number of the upload
    * @return   VimeoVideosCheckUploadStatusResponse
    */
    public function checkUploadStatus($sTicket) {
        $aArgs = array(
            'ticket_id' => $sTicket
        );
        
        return VimeoBase::executeRemoteCall('vimeo.videos.checkUploadStatus', $aArgs);
    }
    
    /**
    * Simple video upload
    * 
    * @access   public
    * @param    string      Absolute path to file
    * @param    string      Existing ticket or false to generate a new one
    * @return   VimeoVideosCheckUploadStatusResponse
    */
    public function doUpload($sFilename, $sTicket = false) {
        return VimeoBase::executeVideopostCall($sFilename, $sTicket);
    }
    
    /**
    * Delete a video
    * 
    * The authenticated user must own the video and have granted delete permission
    * 
    * @access   public
    * @param    integer     Video ID
    * @return   VimeoVideosDeleteResponse 
    */
    public function delete($iVideoID) {
        $aArgs = array(
            'video_id' => $iVideoID
        );
        
        return VimeoBase::executeRemoteCall('vimeo.videos.delete', $aArgs);
    }
    
    /**
    * Set the title of a video (overwrites previous title)
    * 
    * @access   public
    * @param    integer     Video ID
    * @param    string      Title
    * @return   VimeoVideosSetTitleResponse
    */
    public function setTitle($iVideoID, $sVideoTitle) {
        $aArgs = array(
            'video_id' => $iVideoID,
            'title' => $sVideoTitle
        );
        
        return VimeoBase::executeRemoteCall('vimeo.videos.setTitle', $aArgs);
    }
    
    /**
    * Set a new caption for a video (overwrites previous caption)
    * 
    * @access   public
    * @param    integer     Video ID
    * @param    string      Caption
    * @return   VimeoVideosSetCaptionResponse
    */
    public function setCaption($iVideoID, $sVideoCaption) {
        $aArgs = array(
            'video_id' => $iVideoID,
            'caption' => $sVideoCaption
        );
        
        return VimeoBase::executeRemoteCall('vimeo.videos.setCaption', $aArgs);
    }
    
    /**
    * Set a video as a favorite.
    * 
    * @access   public
    * @param    integer     Video ID
    * @param    boolean     TRUE to favorite, FALSE to return to normal
    * @return   VimeoVideosSetFavoriteResponse
    */
    public function setFavorite($iVideoID, $bFavorite = true) {
        $aArgs = array(
            'video_id' => $iVideoID,
            'favorite' => (int) $bFavorite
        );
        
        return VimeoBase::executeRemoteCall('vimeo.videos.setFavorite', $aArgs);
    }
    
    /**
    * Add specified tags to the video, this does not replace any tags.
    * 
    * Tags should be comma separated lists. 
    * 
    * If the calling user is logged in, this will return information that calling
    * user has access to (including private videos). If the calling user is not authenticated,
    * this will only return public information, or a permission denied error if none is available.
    * 
    * @access   public
    * @param    integer     Video ID
    * @param    mixed       Array with tags or Comma separated list of tags ("lions, tigers, bears")
    * @return   VimeoVideosAddTagsResponse
    */
    public function addTags($iVideoID, $mTags) {
        // Catch array of tags
        if(is_array($mTags)) {
            $mTags = implode(',', $mTags);
        }
        
        // Prepare arguments
        $aArgs = array(
            'video_id' => $iVideoID,
            'tags' => $mTags
        );
        
        return VimeoBase::executeRemoteCall('vimeo.videos.addTags', $aArgs);
    }
    
    /**
    * Remove specified tag from the video.
    * 
    * @access   public
    * @param    integer     Video ID
    * @param    integer     Tag ID, this should be a tag id returned by vimeo.videos.getInfo
    * @return   VimeoVideosRemoveTagResponse
    */
    public function removeTag($iVideoID, $iTagID) {
        $aArgs = array(
            'video_id' => $iVideoID,
            'tag_id' => $iTagID
        );
        
        return VimeoBase::executeRemoteCall('vimeo.videos.removeTag', $aArgs);
    }
    
    /**
    * Remove ALL of the tags from the video
    * 
    * @access   public
    * @param    integer     Video ID
    * @return   VimeoVideosClearTags 
    */
    public function clearTags($iVideoID) {
        $aArgs = array(
            'video_id' => $iVideoID
        );
        
        return VimeoBase::executeRemoteCall('vimeo.videos.clearTags', $aArgs);
    }
    
    /**
    * Set the privacy of the video
    * 
    * @access   public
    * @param    integer     Video ID
    * @param    integer     Privacy enum see VimeoVideosRequest::PRIVACY_*
    * @param    mixed       Array or comma separated list of users who can view the video. PRIVACY_USERS must be set.
    */
    public function setPrivacy($iVideoID, $ePrivacy, $mUsers = array()) {
        // Catch array of users
        if(is_array($mUsers)) {
            $mUsers = implode(', ', $mUsers);
        }
        
        $aArgs = array(
            'video_id' => $iVideoID,
            'privacy' => $ePrivacy,
            'users' => $mUsers
        );
        
        return VimeoBase::executeRemoteCall('vimeo.videos.setPrivacy', $aArgs);
    }
}

/**
* Vimeo Videos Search response handler class
*
* Handles the API response for vimeo.videos.search queries.
* 
* @package     SimpleVimeo
* @subpackage  ApiResponse
*/                                                 

class VimeoVideosSearchResponse extends VimeoResponse {
    private $iPage = false;
    private $iItemsPerPage = false;
    private $iOnThisPage = false;
    
    private $aoVideos = array();

    /**
    * Constructor
    * 
    * Parses the API response
    * 
    * @access   public
    * @param    stdClass    API response
    * @return   void
    */
    public function __construct($aResponse) {
        parent::__construct($aResponse);
        
        // Parse information
        if($aResponse && isset($aResponse->videos) && $this->getStatus()) {
            // Create an video list instance
            $this->aoVideos = new VimeoVideoList();
            
            // Page information
            $this->iPage = $aResponse->videos->page;
            $this->iItemsPerPage = $aResponse->videos->perpage;
            $this->iOnThisPage = $aResponse->videos->on_this_page;
            
            // Parse videos
            if(isset($aResponse->videos->video)) {
            	// We should check if the subelement is an object (single hit) or an result array (multiple hits)
            	if(is_array($aResponse->videos->video)) {
					// We got a couple of results
					$aParseableData = $aResponse->videos->video;
            	} else {
            		// We only got one result
					$aParseableData = array(
						0 => $aResponse->videos->video
					);
            	}

            	// Parse the results
                foreach($aParseableData as $aVideoInformation) {
                    $oVideo = new VimeoVideoEntity($aVideoInformation);

                    $this->aoVideos->add($oVideo, $oVideo->getID());
                }
            }
        }
    }
    
    /**
    * Current page
    * 
    * @access   public
    * @return   integer     Page number
    */
    public function getPage() {
        return $this->iPage;
    }
    
    /**
    * Items per page
    * 
    * @access   public
    * @return   integer     Items per page
    */
    
    public function getItemsPerPage() {
        return $this->iItemsPerPage;
    }
    
    /**
    * Items on the current page
    * 
    * @access   public
    * @return   integer     Items on the current page
    */
    
    public function getOnThisPage() {
        return $this->iOnThisPage;
    }
    
    /**
    * Get array of video objects
    * 
    * @access   public
    * @return   array       Video objects
    */
    
    public function getVideos() {
        return $this->aoVideos;
    }
}

/**
* Vimeo Videos Search exception handler class
*
* Handles exceptions caused by API response for vimeo.videos.search queries.
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoVideosSearchException extends VimeoException {}

/**
* Vimeo Videos GetList response handler class
*
* Handles the API response for vimeo.videos.getList queries.
* Currently the response is exact the same as vimeo.videos.search
* 
* @package     SimpleVimeo
* @subpackage  ApiResponse
*/

class VimeoVideosGetListResponse extends VimeoVideosSearchResponse {}

/**
* Vimeo Videos Search exception handler class
*
* Handles exceptions caused by API response for vimeo.videos.search queries.
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoVideosGetListException extends VimeoException {}

/**
* Vimeo Videos GetUploadedList response handler class
*
* Handles the API response for vimeo.videos.getUploadedList queries.
* Currently the response is exact the same as vimeo.videos.search
* 
* @package     SimpleVimeo
* @subpackage  ApiResponse
*/

class VimeoVideosGetUploadedListResponse extends VimeoVideosSearchResponse {}

/**
* Vimeo Videos GetUploadedList exception handler class
*
* Handles exceptions caused by API response for vimeo.videos.getUploadedList queries.
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoVideosGetUploadedListException extends VimeoException {}

/**
* Vimeo Videos GetAppearsInList response handler class
*
* Handles the API response for vimeo.videos.getAppearsInList queries.
* Currently the response is exact the same as vimeo.videos.search
* 
* @package     SimpleVimeo
* @subpackage  ApiResponse
*/

class VimeoVideosGetAppearsInListResponse extends VimeoVideosSearchResponse {}

/**
* Vimeo Videos GetAppearsInList exception handler class
*
* Handles exceptions caused by API response for vimeo.videos.getAppearsInList queries.
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoVideosGetAppearsInListException extends VimeoException {}

/**
* Vimeo Videos GetSubscriptionsList response handler class
*
* Handles the API response for vimeo.videos.getSubscriptionsList queries.
* Currently the response is exact the same as vimeo.videos.search
* 
* @package     SimpleVimeo
* @subpackage  ApiResponse
*/

class VimeoVideosGetSubscriptionsListResponse extends VimeoVideosSearchResponse {}

/**
* Vimeo Videos GetSubscriptionsList exception handler class
*
* Handles exceptions caused by API response for vimeo.videos.getSubscriptionsList queries.
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoVideosGetSubscriptionsListException extends VimeoException {}

/**
* Vimeo Videos GetListByTag response handler class
*
* Handles the API response for vimeo.videos.getListByTag queries.
* Currently the response is exact the same as vimeo.videos.search
* 
* @package     SimpleVimeo
* @subpackage  ApiResponse
*/

class VimeoVideosGetListByTagResponse extends VimeoVideosSearchResponse {}

/**
* Vimeo Videos GetListByTag exception handler class
*
* Handles exceptions caused by API response for vimeo.videos.getListByTag queries.
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoVideosGetListByTagException extends VimeoException {}

/**
* Vimeo Videos GetLikeList response handler class
*
* Handles the API response for vimeo.videos.getLikeList queries.
* Currently the response is exact the same as vimeo.videos.search
* 
* @package     SimpleVimeo
* @subpackage  ApiResponse
*/

class VimeoVideosGetLikeListResponse extends VimeoVideosSearchResponse {}

/**
* Vimeo Videos GetLikeList exception handler class
*
* Handles exceptions caused by API response for vimeo.videos.getLikeList queries.
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoVideosGetLikeListException extends VimeoException {}

/**
* Vimeo Videos GetContactsList response handler class
*
* Handles the API response for vimeo.videos.getContactsList queries.
* Currently the response is exact the same as vimeo.videos.search
* 
* @package     SimpleVimeo
* @subpackage  ApiResponse
*/

class VimeoVideosGetContactsListResponse extends VimeoVideosSearchResponse {}

/**
* Vimeo Videos GetContactsList exception handler class
*
* Handles exceptions caused by API response for vimeo.videos.getContactsList queries.
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoVideosGetContactsListException extends VimeoException {}

/**
* Vimeo Videos getContactsLikeList response handler class
*
* Handles the API response for vimeo.videos.getContactsLikeList queries.
* Currently the response is exact the same as vimeo.videos.search
* 
* @package     SimpleVimeo
* @subpackage  ApiResponse
*/

class VimeoVideosgetContactsLikeListResponse extends VimeoVideosSearchResponse {}

/**
* Vimeo Videos getContactsLikeList exception handler class
*
* Handles exceptions caused by API response for vimeo.videos.getContactsLikeList queries.
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoVideosGetContactsLikeListException extends VimeoException {}

/**
* Vimeo Videos GetInfo response handler class
*
* Handles the API response for vimeo.videos.getInfo queries.
* 
* @package     SimpleVimeo
* @subpackage  ApiResponse
*/

class VimeoVideosGetInfoResponse extends VimeoResponse {
    private $oVideo = false;

    /**
    * Constructor
    * 
    * Parses the API response
    * 
    * @access   public
    * @param    stdClass    API response
    * @return   void
    */
    public function __construct($aResponse) {
        parent::__construct($aResponse);
        
        $this->oVideo = new VimeoVideoEntity($aResponse->video);
    }
    
    /**
    * Get video information as object
    * 
    * @access   public
    * @return   VimeoVideoEntity
    */
    public function getVideo() {
        return $this->oVideo;
    }
}

/**
* Vimeo Videos GetInfo exception handler class
*
* Handles exceptions caused by API response for vimeo.videos.getInfo queries.
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoVideosGetInfoException extends VimeoException {}

/**
* Vimeo Videos getUploadTicket response handler class
*
* Handles the API response for vimeo.videos.getUploadTicket queries.
* 
* @package     SimpleVimeo
* @subpackage  ApiResponse
*/

class VimeoVideosGetUploadTicketResponse extends VimeoResponse {
    private $sTicket = false;

    /**
    * Constructor
    * 
    * Parses the API response
    * 
    * @access   public
    * @param    stdClass    API response
    * @return   void
    */
    public function __construct($aResponse = false) {
        parent::__construct($aResponse);
        
        $this->sTicket = $aResponse->ticket->id;
    }
    
    /**
    * Get generated upload ticket
    * 
    * @access   public
    * @return   string      The ticket number of the upload
    */
    public function getTicket() {
        return $this->sTicket;
    }
}

/**
* Vimeo Videos getUploadTicket exception handler class
*
* Handles exceptions caused by API response for vimeo.videos.getUploadTicket queries.
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoVideosGetUploadTicketException extends VimeoException {}

/**
* Vimeo Videos checkUploadStatus response handler class
*
* Handles the API response for vimeo.videos.checkUploadStatus queries.
* 
* @package     SimpleVimeo
* @subpackage  ApiResponse
*/

class VimeoVideosCheckUploadStatusResponse extends VimeoResponse {
    private $sTicket = false;
    private $iVideoID = false;
    private $bIsUploading = false;
    private $bIsTranscoding = false;
    private $iTranscodingProgress = false;

    /**
    * Constructor
    * 
    * Parses the API response
    * 
    * @access   public
    * @param    stdClass    API response
    * @return   void
    */
    public function __construct($aResponse = false) {
        parent::__construct($aResponse);
        
        $this->sTicket = $aResponse->ticket->id;
        $this->iVideoID = $aResponse->ticket->video_id;
        $this->bIsUploading = (bool) $aResponse->ticket->is_uploading;
        $this->bIsTranscoding = (bool) $aResponse->ticket->is_transcoding;
        $this->iTranscodingProgress = $aResponse->ticket->transcoding_progress;
    } 
    
    /**
    * Get Ticket
    * 
    * @access   public
    * @return   string      Ticket
    */
    public function getTicket() {
        return $this->sTicket;
    }
    
    /**
    * Get Video ID
    * 
    * @access   public
    * @return   integer     Video ID
    */
    public function getVideoID() {
        return $this->iVideoID;
    }
    
    /**
    * Is the video uploading?
    * 
    * @access   public
    * @return   boolean     TRUE if uploading, FALSE if not
    */
    public function isUploading() {
        return $this->bIsUploading;
    }
    
    /**
    * Is the video transcoding?
    * 
    * Also check getTranscodingProgress() for percentage in transcoding
    * 
    * @access   public
    * @return   boolean     TRUE if uploading, FALSE if not
    */
    public function isTranscoding() {
        return $this->bIsTranscoding;
    }
    
    /**
    * Get the transcoding progress
    * 
    * Should only be called if isTranscoding() returns true
    * 
    * @access   public
    * @return   integer     Percentage
    */
    public function getTranscodingProgress() {
        return $this->iTranscodingProgress;
    }
}

/**
* Vimeo Videos checkUploadStatus exception handler class
*
* Handles exceptions caused by API response for vimeo.videos.checkUploadStatus queries.
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoVideosCheckUploadStatusException extends VimeoException {}

/**
* Vimeo Videos delete response handler class
*
* Handles the API response for vimeo.videos.delete queries.
* 
* @package     SimpleVimeo
* @subpackage  ApiResponse
*/

class VimeoVideosDeleteResponse extends VimeoResponse {}

/**
* Vimeo Videos delete exception handler class
*
* Handles exceptions caused by API response for vimeo.videos.delete queries.
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoVideosDeleteException extends VimeoException {}

/**
* Vimeo Videos setTitle response handler class
*
* Handles the API response for vimeo.videos.setTitle queries.
* 
* @package     SimpleVimeo
* @subpackage  ApiResponse
*/

class VimeoVideosSetTitleResponse extends VimeoResponse {}

/**
* Vimeo Videos setTitle exception handler class
*
* Handles exceptions caused by API response for vimeo.videos.setTitle queries.
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoVideosSetTitleException extends VimeoException {}

/**
* Vimeo Videos setCaption response handler class
*
* Handles the API response for vimeo.videos.setCaption queries.
* 
* @package     SimpleVimeo
* @subpackage  ApiResponse
*/

class VimeoVideosSetCaptionResponse extends VimeoResponse {}

/**
* Vimeo Videos setCaption exception handler class
*
* Handles exceptions caused by API response for vimeo.videos.setCaption queries.
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoVideosSetCaptionException extends VimeoException {}

/**
* Vimeo Videos setFavorite response handler class
*
* Handles the API response for vimeo.videos.setFavorite queries.
* 
* @package     SimpleVimeo
* @subpackage  ApiResponse
*/

class VimeoVideosSetFavoriteResponse extends VimeoResponse {}

/**
* Vimeo Videos setFavorite exception handler class
*
* Handles exceptions caused by API response for vimeo.videos.setFavorite queries.
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoVideosSetFavoriteException extends VimeoException {}

/**
* Vimeo Videos addTags response handler class
*
* Handles the API response for vimeo.videos.addTags queries.
* 
* @package     SimpleVimeo
* @subpackage  ApiResponse
*/

class VimeoVideosAddTagsResponse extends VimeoResponse {}

/**
* Vimeo Videos addTags exception handler class
*
* Handles exceptions caused by API response for vimeo.videos.addTags queries.
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoVideosAddTagsException extends VimeoException {}

/**
* Vimeo Videos removeTag response handler class
*
* Handles the API response for vimeo.videos.removeTag queries.
* 
* @package     SimpleVimeo
* @subpackage  ApiResponse
*/

class VimeoVideosRemoveTagResponse extends VimeoResponse {}

/**
* Vimeo Videos removeTag exception handler class
*
* Handles exceptions caused by API response for vimeo.videos.removeTag queries.
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoVideosRemoveTagException extends VimeoException {}

/**
* Vimeo Videos clearTags response handler class
*
* Handles the API response for vimeo.videos.clearTags queries.
* 
* @package     SimpleVimeo
* @subpackage  ApiResponse
*/

class VimeoVideosClearTagsResponse extends VimeoResponse {}

/**
* Vimeo Videos clearTags exception handler class
*
* Handles exceptions caused by API response for vimeo.videos.clearTags queries.
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoVideosClearTagsException extends VimeoException {}

/**
* Vimeo Videos setPrivacy response handler class
*
* Handles the API response for vimeo.videos.setPrivacy queries.
* 
* @package     SimpleVimeo
* @subpackage  ApiResponse
*/

class VimeoVideosSetPrivacyResponse extends VimeoResponse {}

/**
* Vimeo Videos setPrivacy exception handler class
*
* Handles exceptions caused by API response for vimeo.videos.setPrivacy queries.
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoVideosSetPrivacyException extends VimeoException {}

/**
* vimeo.people.* methods
*/

/**
* Vimeo People request handler class
*
* Implements all API queries in the vimeo.people.* category
* 
* @package     SimpleVimeo
* @subpackage  ApiRequest
*/

class VimeoPeopleRequest extends VimeoRequest {
    const TYPE_LIKES        = 'likes';
    const TYPE_APPEARS      = 'appears';
    const TYPE_BOTH         = 'likes,appears';
    
    /**
    * Get a user id and full/display name with a username.  
    * 
    * You shouldn't need this to get the User ID, we allow you to use the
    * username instead of User ID everywhere, it's much nicer that way.
    * 
    * @access   public
    * @param    string      The username to lookup
    * @return   VimeoPeopleFindByUsernameResponse
    */
    public function findByUsername($sUsername) {
        $aArgs = array(
            'username' => $sUsername
        );
        
        return VimeoBase::executeRemoteCall('vimeo.people.findByUserName', $aArgs);
    }
    
    /**
    * Get tons of info about a user.
    * 
    * @access   public
    * @param    integer     The id of the user we want. 
    * @return   VimeoPeopleGetInfoResponse
    */
    public function getInfo($iUserID) {
        $aArgs = array(
            'user_id' => $iUserID
        );
        
        return VimeoBase::executeRemoteCall('vimeo.people.getInfo', $aArgs);
    }
    
    /**
    * Get a user id and full/display name via an Email Address.  
    * 
    * You shouldn't need to use this to get the User ID, we allow you
    * to use the username instead of User ID everywhere, it's much nicer that way.
    * 
    * @access   public
    * @param    string      Email
    * @return   VimeoPeopleFindByEmailResponse
    */
    public function findByEmail($sEmail) {
        $aArgs = array(
            'find_email' => $sEmail
        );
        
        return VimeoBase::executeRemoteCall('vimeo.people.findByEmail', $aArgs);
    }
    
    /**
    * Get a portrait URL for a given user/size
    * 
    * Portraits are square, so you only need to pass one size parameter.
    * Possible sizes are 20, 24, 28, 30, 40, 50, 60, 75, 100, 140, 278 and 300
    * 
    * @access   public
    * @param    string      The username to lookup
    * @param    integer     The size of the portrait you you want. (defaults to 75)
    * @return   VimeoPeopleGetPortraitUrlResponse
    * 
    * @todo Check functionality. Did not work, god knows why
    */
    public function getPortraitUrl($sUser, $iSize = false) {
        $aArgs = array(
            'user' => $sUser
        );
        
        if($iSize) {
            $aArgs['size'] = $iSize;
        }
        
        return VimeoBase::executeRemoteCall('vimeo.people.getPortraitUrl', $aArgs);
    }
    
    /**
    * Add a user as a contact for the authenticated user.
    * 
    * If Jim is authenticated, and the $user is sally. Sally will be Jim's contact. 
    * It won't work the other way around. Depending on Sally's settings, this may 
    * send her an email notifying her that Jim Added her as a contact. 
    * 
    * @access   public
    * @param    string      The user to add. User ID, this can be the ID number (151542) or the username (ted)
    * @return   VimeoPeopleAddContactResponse
    */
    public function addContact($sUser) {
        $aArgs = array(
            'user' => $sUser
        );
        
        return VimeoBase::executeRemoteCall('vimeo.people.addContact', $aArgs);
    }
    
    /**
    * Remove a user as a contact for the authenticated user.
    * 
    * @access   public
    * @param    string      The user to remove. User ID, this can be the ID number (151542) or the username (ted)
    * @return   VimeoPeopleRemoveContactResponse
    */
    public function removeContact($sUser) {
        $aArgs = array(
            'user' => $sUser
        );
        
        return VimeoBase::executeRemoteCall('vimeo.people.removeContact', $aArgs);
    }
    
    /**
    * This tells you how much space the user has remaining for uploads.
    * 
    * We provide info in bytes and kilobytes. It probably makes sense for you to use kilobytes. 
    * 
    * @access   public
    * @return   VimeoPeopleGetUploadStatusResponse
    */
    public function getUploadStatus() {
        return VimeoBase::executeRemoteCall('vimeo.people.getUploadStatus');
    }
    
    /**
    * Subscribe to a user's videos.
    * 
    * Just like on the site, you can subscribe to videos a user "appears" in or "likes." Or both!  
    * This will not remove any subscriptions. So if the user is subscribed to a user for both "likes"
    * and "appears," this will not change anything if you only specify one of them. If you want to
    * remove one, you must call vimeo.people.removeSubscription().
    * 
    * @access   public
    * @param    string      User ID, this can be the ID number (151542) or the username (ted)
    * @param    string      with self::TYPE_LIKES or self::TYPE_APPEARS or self::TYPE_BOTH
    * @return   VimeoPeopleAddSubscriptionResponse
    */
    public function addSubscription($sUser, $eType = self::TYPE_BOTH) {
        $aArgs = array(
            'user' => $sUser,
            'type' => $eType
        );
        
        return VimeoBase::executeRemoteCall('vimeo.people.addSubscription', $aArgs);
    }
    
    /**
    * Unsubscribe to a user's videos.
    * 
    * @access   public
    * @param    string      User ID, this can be the ID number (151542) or the username (ted)
    * @param    string      with self::TYPE_LIKES or self::TYPE_APPEARS or self::TYPE_BOTH
    * @return   VimeoPeopleRemoveSubscriptionResponse
    */
    public function removeSubscription($sUser, $eType = self::TYPE_BOTH) {
        $aArgs = array(
            'user' => $sUser,
            'type' => $eType
        );
        
        return VimeoBase::executeRemoteCall('vimeo.people.removeSubscription', $aArgs);
    }
}

/**
* Vimeo People FindByUserName response handler class
*
* Handles the API response for vimeo.people.findByUserName queries.
* 
* @package     SimpleVimeo
* @subpackage  ApiResponse
*/

class VimeoPeopleFindByUserNameResponse extends VimeoResponse {
    private $oUser = false;

    /**
    * Constructor
    * 
    * Parses the API response
    * 
    * @access   public
    * @param    stdClass    API response
    * @return   void
    */
    public function __construct($aResponse = false) {
        parent::__construct($aResponse);
        
        $this->oUser = new VimeoUserEntity($aResponse->user);
    }
    
    /**
    * Get user entity object
    * 
    * @access   public
    * @return   VimeoUserEntity
    */
    public function getUser() {
        return $this->oUser;
    }
}

/**
* Vimeo People FindByUserName exception handler class
*
* Handles exceptions caused by API response for vimeo.people.findByUserName queries.
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoPeopleFindByUserNameException extends VimeoException {}

/**
* Vimeo People FindByEmail response handler class
*
* Handles the API response for vimeo.people.findByEmail queries.
* 
* @package     SimpleVimeo
* @subpackage  ApiResponse
*/

class VimeoPeopleFindByEmailResponse extends VimeoResponse {
    private $oUser = false;

    /**
    * Constructor
    * 
    * Parses the API response
    * 
    * @access   public
    * @param    stdClass    API response
    * @return   void
    */
    public function __construct($aResponse = false) {
        parent::__construct($aResponse);
        
        $this->oUser = new VimeoUserEntity($aResponse->user);
    }

    /**
    * Get user entity object
    * 
    * @access   public
    * @return   VimeoUserEntity
    */
    public function getUser() {
        return $this->oUser;
    }
}

/**
* Vimeo People FindByEmail exception handler class
*
* Handles exceptions caused by API response for vimeo.people.findByEmail queries.
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoPeopleFindByEmailException extends VimeoException {}

/**
* Vimeo People GetInfo response handler class
*
* Handles the API response for vimeo.people.getInfo queries.
* 
* @package     SimpleVimeo
* @subpackage  ApiResponse
*/

class VimeoPeopleGetInfoResponse extends VimeoResponse {
    private $oUser = false;

    /**
    * Constructor
    * 
    * Parses the API response
    * 
    * @access   public
    * @param    stdClass    API response
    * @return   void
    */
    public function __construct($aResponse = false) {
        parent::__construct($aResponse);
        
        $this->oUser = new VimeoUserEntity($aResponse->person);
    }

    /**
    * Get user entity object
    * 
    * @access   public
    * @return   VimeoUserEntity
    */
    public function getUser() {
        return $this->oUser;
    }
}

/**
* Vimeo People GetInfo exception handler class
*
* Handles exceptions caused by API response for vimeo.people.getInfo queries.
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoPeopleGetInfoException extends VimeoException {}

/**
* Vimeo People getPortraitUrl response handler class
*
* Handles the API response for vimeo.people.getPortraitUrl queries.
* 
* @package     SimpleVimeo
* @subpackage  ApiResponse
*/

class VimeoPeopleGetPortraitUrlResponse extends VimeoResponse {}

/**
* Vimeo People getPortraitUrl exception handler class
*
* Handles exceptions caused by API response for vimeo.people.getPortraitUrl queries.
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoPeopleGetPortraitUrlException extends VimeoException {}

/**
* Vimeo People addContact response handler class
*
* Handles the API response for vimeo.people.addContact queries.
* 
* @package     SimpleVimeo
* @subpackage  ApiResponse
*/

class VimeoPeopleAddContactResponse extends VimeoResponse {}

/**
* Vimeo People addContact exception handler class
*
* Handles exceptions caused by API response for vimeo.people.addContact queries.
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoPeopleAddContactException extends VimeoException {}

/**
* Vimeo People removeContact response handler class
*
* Handles the API response for vimeo.people.removeContact queries.
* 
* @package     SimpleVimeo
* @subpackage  ApiResponse
*/

class VimeoPeopleRemoveContactResponse extends VimeoResponse {}

/**
* Vimeo People removeContact exception handler class
*
* Handles exceptions caused by API response for vimeo.people.removeContact queries.
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoPeopleRemoveContactException extends VimeoException {}

/**
* Vimeo People getUploadStatus response handler class
*
* Handles the API response for vimeo.people.getUploadStatus queries.
* 
* @package     SimpleVimeo
* @subpackage  ApiResponse
*/

class VimeoPeopleGetUploadStatusResponse extends VimeoResponse {
    private $iMaxBytes = false;
    private $iMaxKBytes = false;
    
    private $iUsedBytes = false;
    private $iUsedKBytes = false;
    
    private $iRemainingBytes = false;
    private $iRemainingKBytes = false;

    /**
    * Constructor
    * 
    * Parses the API response
    * 
    * @access   public
    * @param    stdClass    API response
    * @return   void
    */
    public function __construct($aResponse = false) {
        parent::__construct($aResponse);
        
        $this->iMaxBytes = $aResponse->user->bandwidth->maxbytes;
        $this->iMaxKBytes = $aResponse->user->bandwidth->maxkb;
        
        $this->iUsedBytes = $aResponse->user->bandwidth->usedbytes;
        $this->iUsedKBytes = $aResponse->user->bandwidth->usedkb;
        
        $this->iRemainingBytes = $aResponse->user->bandwidth->remainingbytes;
        $this->iRemainingKBytes = $aResponse->user->bandwidth->remainingkb;
    }
    
    /**
    * Get maximum upload for this week in BYTES
    * 
    * @access   public
    * @return   integer     Maximum bytes this week
    */
    public function getMaxBytes() {
        return $this->iMaxBytes;
    }
    
    /**
    * Get maximum upload for this week in KILOBYTES
    * 
    * @access   public
    * @return   integer     Maximum kbytes this week
    */
    public function getMaxKiloBytes() {
        return $this->iMaxKBytes;
    }
    
    /**
    * Get used upload for this week in BYTES
    * 
    * @access   public
    * @return   integer     Used bytes this week
    */
    public function getUsedBytes() {
        return $this->iUsedBytes;
    }
    
    /**
    * Get used upload for this week in KILOBYTES
    * 
    * @access   public
    * @return   integer     Used kbytes this week
    */
    public function getUsedKiloBytes() {
        return $this->iUsedKBytes;
    }
    
    /**
    * Get remaining upload for this week in BYTES
    * 
    * @access   public
    * @return   integer     Remaining bytes this week
    */
    public function getRemainingBytes() {
        return $this->iRemainingBytes;
    }
    
    /**
    * Get remaining upload for this week in KILOBYTES
    * 
    * @access   public
    * @return   integer     Remaining kbytes this week
    */
    public function getRemainingKiloBytes() {
        return $this->iRemainingKBytes;
    }
}

/**
* Vimeo People getUploadStatus exception handler class
*
* Handles exceptions caused by API response for vimeo.people.getUploadStatus queries.
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoPeopleGetUploadStatusException extends VimeoException {}

/**
* Vimeo People addSubscription response handler class
*
* Handles the API response for vimeo.people.addSubscription queries.
* 
* @package     SimpleVimeo
* @subpackage  ApiResponse
*/

class VimeoPeopleAddSubscriptionResponse extends VimeoResponse {}

/**
* Vimeo People addSubscription exception handler class
*
* Handles exceptions caused by API response for vimeo.people.addSubscription queries.
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoPeopleAddSubscriptionException extends VimeoException {}

/**
* Vimeo People removeSubscription response handler class
*
* Handles the API response for vimeo.people.removeSubscription queries.
* 
* @package     SimpleVimeo
* @subpackage  ApiResponse
*/

class VimeoPeopleRemoveSubscriptionResponse extends VimeoResponse {}

/**
* Vimeo People removeSubscription exception handler class
*
* Handles exceptions caused by API response for vimeo.people.removeSubscription queries.
* 
* @package     SimpleVimeo
* @subpackage  Exceptions
*/

class VimeoPeopleRemoveSubscriptionException extends VimeoException {}

?>