summaryrefslogtreecommitdiffstats
path: root/includes/HybridAuth/thirdparty/LinkedIn/LinkedIn.php
blob: d58ed98b0902cfc2929e4ad731e910b41cef1c65 (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
<?php
// http://code.google.com/p/simple-linkedinphp/
// 3.2.0 - November 29, 2011
// hacked into the code to handel new scope (r_basicprofile+r_emailaddress) - until Paul update linkedinphp library!

/**
 * This file defines the 'LinkedIn' class. This class is designed to be a 
 * simple, stand-alone implementation of the LinkedIn API functions.
 * 
 * COPYRIGHT:
 *   
 * Copyright (C) 2011, fiftyMission Inc.
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a 
 * copy of this software and associated documentation files (the "Software"), 
 * to deal in the Software without restriction, including without limitation 
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in 
 * all copies or substantial portions of the Software.  
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 
 * IN THE SOFTWARE.  
 *
 * SOURCE CODE LOCATION:
 * 
 * http://code.google.com/p/simple-linkedinphp/
 *    
 * REQUIREMENTS:
 * 
 * 1. You must have cURL installed on the server and available to PHP.
 * 2. You must be running PHP 5+.  
 *  
 * QUICK START:
 * 
 * There are two files needed to enable LinkedIn API functionality from PHP; the
 * stand-alone OAuth library, and this LinkedIn class. The latest version of 
 * the stand-alone OAuth library can be found on Google Code:
 * 
 * http://code.google.com/p/oauth/
 *   
 * Install these two files on your server in a location that is accessible to 
 * the scripts you wish to use them in. Make sure to change the file 
 * permissions such that your web server can read the files.
 * 
 * Next, make sure the path to the OAuth library is correct (you can change this 
 * as needed, depending on your file organization scheme, etc).
 * 
 * Finally, test the class by attempting to connect to LinkedIn using the 
 * associated demo.php page, also located at the Google Code location
 * referenced above.                   
 *   
 * RESOURCES:
 *    
 * REST API Documentation: http://developer.linkedin.com/rest
 *    
 * @version 3.2.0 - November 8, 2011
 * @author Paul Mennega <paul@fiftymission.net>
 * @copyright Copyright 2011, fiftyMission Inc. 
 * @license http://www.opensource.org/licenses/mit-license.php The MIT License 
 */

/**
 * 'LinkedInException' class declaration.
 *  
 * This class extends the base 'Exception' class.
 * 
 * @access public
 * @package classpackage
 */
class LinkedInException extends Exception {}

/**
 * 'LinkedIn' class declaration.
 *  
 * This class provides generalized LinkedIn oauth functionality.
 * 
 * @access public
 * @package classpackage
 */
class LinkedIn {
  // api/oauth settings
  const _API_OAUTH_REALM             = 'http://api.linkedin.com';
  const _API_OAUTH_VERSION           = '1.0';
  
  // the default response format from LinkedIn
  const _DEFAULT_RESPONSE_FORMAT     = 'xml';
    
  // helper constants used to standardize LinkedIn <-> API communication.  See demo page for usage.
  const _GET_RESPONSE                = 'lResponse';
  const _GET_TYPE                    = 'lType';
  
  // Invitation API constants.
  const _INV_SUBJECT                 = 'Invitation to connect';
  const _INV_BODY_LENGTH             = 200;
  
  // API methods
  const _METHOD_TOKENS               = 'POST';
  
  // Network API constants.
  const _NETWORK_LENGTH              = 1000;
  const _NETWORK_HTML                = '<a>';
  
  // response format type constants, see http://developer.linkedin.com/docs/DOC-1203
  const _RESPONSE_JSON               = 'JSON';
  const _RESPONSE_JSONP              = 'JSONP';
  const _RESPONSE_XML                = 'XML';
  
  // Share API constants
  const _SHARE_COMMENT_LENGTH        = 700;
  const _SHARE_CONTENT_TITLE_LENGTH  = 200;
  const _SHARE_CONTENT_DESC_LENGTH   = 400;
  
  // LinkedIn API end-points
	const _URL_ACCESS                  = 'https://api.linkedin.com/uas/oauth/accessToken';
	const _URL_API                     = 'https://api.linkedin.com';
	const _URL_AUTH                    = 'https://www.linkedin.com/uas/oauth/authenticate?oauth_token=';
	// const _URL_REQUEST                 = 'https://api.linkedin.com/uas/oauth/requestToken';
	const _URL_REQUEST                 = 'https://api.linkedin.com/uas/oauth/requestToken?scope=r_basicprofile+r_emailaddress+rw_nus'; 
	const _URL_REVOKE                  = 'https://api.linkedin.com/uas/oauth/invalidateToken';
	
	// Library version
	const _VERSION                     = '3.2.0';
  
  // oauth properties
  protected $callback;
  protected $token                   = NULL;
  
  // application properties
  protected $application_key, 
            $application_secret;
  
  // the format of the data to return
  protected $response_format         = self::_DEFAULT_RESPONSE_FORMAT;

  // last request fields
  public $last_request_headers, 
         $last_request_url;

	/**
	 * Create a LinkedIn object, used for OAuth-based authentication and 
	 * communication with the LinkedIn API.	 
	 * 
	 * @param arr $config
	 *    The 'start-up' object properties:
	 *           - appKey       => The application's API key
	 *           - appSecret    => The application's secret key
	 *           - callbackUrl  => [OPTIONAL] the callback URL
	 *                 	 
	 * @return obj
	 *    A new LinkedIn object.	 
	 */
	public function __construct($config) {
    if(!is_array($config)) {
      // bad data passed
		  throw new LinkedInException('LinkedIn->__construct(): bad data passed, $config must be of type array.');
    }
    $this->setApplicationKey($config['appKey']);
	  $this->setApplicationSecret($config['appSecret']);
	  $this->setCallbackUrl($config['callbackUrl']);
	}
	
	/**
   * The class destructor.
   * 
   * Explicitly clears LinkedIn object from memory upon destruction.
	 */
  public function __destruct() {
    unset($this);
	}
	
	/**
	 * Bookmark a job.
	 * 
	 * Calling this method causes the current user to add a bookmark for the 
	 * specified job:
	 * 
	 *   http://developer.linkedin.com/docs/DOC-1323
	 * 
	 * @param str $jid
	 *    Job ID you want to bookmark.
	 *         	 
	 * @return arr
	 *    Array containing retrieval success, LinkedIn response.
	 */
	public function bookmarkJob($jid) {
	  // check passed data
	  if(!is_string($jid)) {
	    // bad data passed
		  throw new LinkedInException('LinkedIn->bookmarkJob(): bad data passed, $jid must be of type string.');
	  }
	  
	  // construct and send the request
	  $query    = self::_URL_API . '/v1/people/~/job-bookmarks';
	  $response = $this->fetch('POST', $query, '<job-bookmark><job><id>' . trim($jid) . '</id></job></job-bookmark>');
	  
	  /**
	   * Check for successful request (a 201 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */
		return $this->checkResponse(201, $response);
	}
	
	/**
	 * Get list of jobs you have bookmarked.
	 * 
	 * Returns a list of jobs the current user has bookmarked, per:
	 * 
	 *   http://developer.linkedin.com/docs/DOC-1323   
	 * 	
	 * @return arr
	 *         Array containing retrieval success, LinkedIn response.
	 */
	public function bookmarkedJobs() {	
    // construct and send the request  
	  $query    = self::_URL_API . '/v1/people/~/job-bookmarks';
	  $response = $this->fetch('GET', $query);
	  
	  /**
	   * Check for successful request (a 200 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */
		return $this->checkResponse(200, $response);
	}
	
	/**
	 * Custom addition to make code compatible with PHP 5.2
	 */
	private function intWalker($value, $key) {
        if(!is_int($value)) {
			throw new LinkedInException('LinkedIn->checkResponse(): $http_code_required must be an integer or an array of integer values');
		}
    }
	
	/**
	 * Used to check whether a response LinkedIn object has the required http_code or not and 
	 * returns an appropriate LinkedIn object.
	 * 
	 * @param var $http_code_required
	 * 		The required http response from LinkedIn, passed in either as an integer, 
	 * 		or an array of integers representing the expected values.	 
	 * @param arr $response 
	 *    An array containing a LinkedIn response.
	 * 
	 * @return boolean
	 * 	  TRUE or FALSE depending on if the passed LinkedIn response matches the expected response.
	 */
	private function checkResponse($http_code_required, $response) {
		// check passed data
    if(is_array($http_code_required)) {
		  array_walk($http_code_required, array($this, 'intWalker'));
		} else {
		  if(!is_int($http_code_required)) {
  			throw new LinkedInException('LinkedIn->checkResponse(): $http_code_required must be an integer or an array of integer values');
  		} else {
  		  $http_code_required = array($http_code_required);
  		}
		}
		if(!is_array($response)) {
			throw new LinkedInException('LinkedIn->checkResponse(): $response must be an array');
		}		
		
		// check for a match
		if(in_array($response['info']['http_code'], $http_code_required)) {
		  // response found
		  $response['success'] = TRUE;
		} else {
			// response not found
			$response['success'] = FALSE;
			$response['error']   = 'HTTP response from LinkedIn end-point was not code ' . implode(', ', $http_code_required);
		}
		return $response;
	}
	
	/**
	 * Close a job.
	 * 
	 * Calling this method causes the passed job to be closed, per:
	 * 
	 *   http://developer.linkedin.com/docs/DOC-1151   
	 * 
	 * @param str $jid
	 *    Job ID you want to close.
	 *            	
	 * @return arr
	 *    Array containing retrieval success, LinkedIn response.
	 */
	public function closeJob($jid) {
	  // check passed data
	  if(!is_string($jid)) {
	    // bad data passed
		  throw new LinkedInException('LinkedIn->closeJob(): bad data passed, $jid must be of string value.');
	  }
	  
	  // construct and send the request
	  $query    = self::_URL_API . '/v1/jobs/partner-job-id=' . trim($jid);
	  $response = $this->fetch('DELETE', $query);
	  
	  /**
	   * Check for successful request (a 204 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */
	  return $this->checkResponse(204, $response);
	}
	
	/**
	 * Share comment posting method.
	 * 
	 * Post a comment on an existing connections shared content. API details can
	 * be found here: 
	 * 
	 * http://developer.linkedin.com/docs/DOC-1043 
	 * 
	 * @param str $uid 
	 *    The LinkedIn update ID.   	 
	 * @param str $comment 
	 *    The share comment to be posted.
	 *            	 
	 * @return arr 
	 *    Array containing retrieval success, LinkedIn response.       	 
	 */
	public function comment($uid, $comment) {
	  // check passed data
	  if(!is_string($uid)) {
	    // bad data passed
		  throw new LinkedInException('LinkedIn->comment(): bad data passed, $uid must be of type string.');
	  }
    if(!is_string($comment)) {
      // nothing/non-string passed, raise an exception
		  throw new LinkedInException('LinkedIn->comment(): bad data passed, $comment must be a non-zero length string.');
    }
    
    /**
     * Share comment rules:
     * 
     * 1) No HTML permitted.
     * 2) Comment cannot be longer than 700 characters.     
     */
    $comment = substr(trim(htmlspecialchars(strip_tags($comment))), 0, self::_SHARE_COMMENT_LENGTH);
		$data    = '<?xml version="1.0" encoding="UTF-8"?>
                <update-comment>
  				        <comment>' . $comment . '</comment>
  				      </update-comment>';

    // construct and send the request
    $query    = self::_URL_API . '/v1/people/~/network/updates/key=' . $uid . '/update-comments';
    $response = $this->fetch('POST', $query, $data);
    
    /**
	   * Check for successful request (a 201 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */ 
    return $this->checkResponse(201, $response);
	}
	
	/**
	 * Share comment retrieval.
	 *     
	 * Return all comments associated with a given network update:
	 * 	 
	 *   http://developer.linkedin.com/docs/DOC-1043
	 * 
	 * @param str $uid
	 *    The LinkedIn update ID.
	 *                     	 
	 * @return arr 
	 *    Array containing retrieval success, LinkedIn response.                  
	 */
	public function comments($uid) {
	  // check passed data
	  if(!is_string($uid)) {
	    // bad data passed
		  throw new LinkedInException('LinkedIn->comments(): bad data passed, $uid must be of type string.');
	  }
		
		// construct and send the request
    $query    = self::_URL_API . '/v1/people/~/network/updates/key=' . $uid . '/update-comments';
    $response = $this->fetch('GET', $query);
    
  	/**
	   * Check for successful request (a 200 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */ 
    return $this->checkResponse(200, $response);
	}
	
	/**
	 * Company profile retrieval function.
	 * 
	 * Takes a string of parameters as input and requests company profile data 
	 * from the LinkedIn Company Profile API. See the official documentation for 
	 * $options 'field selector' formatting:
	 * 
	 *   http://developer.linkedin.com/docs/DOC-1014
	 *   http://developer.linkedin.com/docs/DOC-1259   
	 * 
	 * @param str $options
	 *    Data retrieval options.	
	 * @param	bool $by_email
	 *    [OPTIONAL] Search by email domain?
	 * 	 
	 * @return arr 
	 *    Array containing retrieval success, LinkedIn response.
	 */
	public function company($options, $by_email = FALSE) {
	  // check passed data
	  if(!is_string($options)) {
	    // bad data passed
		  throw new LinkedInException('LinkedIn->company(): bad data passed, $options must be of type string.');
	  }
	  if(!is_bool($by_email)) {
	    // bad data passed
		  throw new LinkedInException('LinkedIn->company(): bad data passed, $by_email must be of type boolean.');
	  }
	  
	  // construct and send the request
	  $query    = self::_URL_API . '/v1/companies' . ($by_email ? '' : '/') . trim($options);
	  $response = $this->fetch('GET', $query);
	  
	  /**
	   * Check for successful request (a 200 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */
	  return $this->checkResponse(200, $response);
	}
	
  /**
	 * Company products and their associated recommendations.
	 * 
	 * The product data type contains details about a company's product or 
	 * service, including recommendations from LinkedIn members, and replies from 
	 * company representatives.
	 * 
	 *   http://developer.linkedin.com/docs/DOC-1327   
	 * 
	 * @param str $cid
	 *    Company ID you want the producte for.	
	 * @param str $options
	 *    [OPTIONAL] Data retrieval options.
	 *            	
	 * @return arr
	 *    Array containing retrieval success, LinkedIn response.
	 */
	public function companyProducts($cid, $options = '') {
	  // check passed data
	  if(!is_string($cid)) {
	    // bad data passed
		  throw new LinkedInException('LinkedIn->companyProducts(): bad data passed, $cid must be of type string.');
	  }
	  if(!is_string($options)) {
	    // bad data passed
		  throw new LinkedInException('LinkedIn->companyProducts(): bad data passed, $options must be of type string.');
	  }
	  
	  // construct and send the request
	  $query    = self::_URL_API . '/v1/companies/' . trim($cid) . '/products' . trim($options);
	  $response = $this->fetch('GET', $query);
	  
	  /**
	   * Check for successful request (a 200 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */
	  return $this->checkResponse(200, $response);
	}
  	
	/**
	 * Connection retrieval function.
	 * 
	 * Takes a string of parameters as input and requests connection-related data 
	 * from the Linkedin Connections API. See the official documentation for 
	 * $options 'field selector' formatting:
	 * 
	 *   http://developer.linkedin.com/docs/DOC-1014      	 
	 * 
	 * @param str $options 
	 *    [OPTIONAL] Data retrieval options.
	 *            	 
	 * @return arr 
	 *    Array containing retrieval success, LinkedIn response.
	 */
	public function connections($options = '~/connections') {
	  // check passed data
	  if(!is_string($options)) {
	    // bad data passed
		  throw new LinkedInException('LinkedIn->connections(): bad data passed, $options must be of type string.');
	  }
	  
	  // construct and send the request
	  $query    = self::_URL_API . '/v1/people/' . trim($options);
	  $response = $this->fetch('GET', $query);
	  
	  /**
	   * Check for successful request (a 200 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */
	  return $this->checkResponse(200, $response);
	}
	
	/**
	 * This creates a post in the specified group with the specified title and specified summary.
	 * 
	 *   http://developer.linkedin.com/documents/groups-api
	 * 
	 * @param str $gid
	 * 		The group id.
	 * @param str $title
	 * 		The title of the post. This must be non-empty.
	 * @param str $summary
	 * 		[OPTIONAL] The content or summary of the post. This can be empty.
	 * 
	 * @return arr
	 * 		Array containing retrieval success, LinkedIn response.
	 */
	public function createPost($gid, $title, $summary = '') {
		if(!is_string($gid)) {
			throw new LinkedInException('LinkedIn->createPost(): bad data passed, $gid must be of type string.');
		}
		if(!is_string($title) || empty($title)) {
			throw new LinkedInException('LinkedIn->createPost(): bad data passed, $title must be a non-empty string.');
		}
		if(!is_string($summary)) {
			throw new LinkedInException('LinkedIn->createPost(): bad data passed, $summary must be of type string.');
		}
		
		// construct the XML
		$data = '<?xml version="1.0" encoding="UTF-8"?>
    				 <post>
    					 <title>'. $title . '</title>
    					 <summary>' . $summary . '</summary>
    				 </post>';
		
 		// construct and send the request
		$query    = self::_URL_API . '/v1/groups/' . trim($gid) . '/posts';
		$response = $this->fetch('POST', $query, $data);
		
	  /**
	   * Check for successful request (a 201 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */
		return $this->checkResponse(201, $response);
	}
	
	/**
	 * This deletes the specified post if you are the owner or moderator that post.
	 * Otherwise, it just flags the post as inappropriate.
	 * 
	 * https://developer.linkedin.com/documents/groups-api
	 * 
	 * @param str $pid
	 * 		The post id.
	 * 
	 * @return arr
	 * 		Array containing retrieval success, LinkedIn response.
	 */
	public function deletePost($pid) {
		if(!is_string($pid)) {
			throw new LinkedInException('LinkedIn->deletePost(): bad data passed, $pid must be of type string');
		}
		
		// construct and send the request
		$query    = self::_URL_API . '/v1/posts/' . trim($pid);
		$response = $this->fetch('DELETE', $query);
		
    /**
     * Check for successful request (a 204 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */
		return $this->checkResponse(204, $response);
	}
	
	/**
	 * Edit a job.
	 * 
	 * Calling this method causes the passed job to be edited, with the passed
	 * XML instructing which fields to change, per:
	 * 
	 *   http://developer.linkedin.com/docs/DOC-1154
	 *   http://developer.linkedin.com/docs/DOC-1142      
	 * 
	 * @param str $jid
	 *    Job ID you want to renew.
	 * @param str $xml
	 *    The XML containing the job fields to edit.	 
	 *            	
	 * @return arr
	 *    Array containing retrieval success, LinkedIn response.
	 */
	public function editJob($jid, $xml) {
	  // check passed data
	  if(!is_string($jid)) {
	    // bad data passed
		  throw new LinkedInException('LinkedIn->editJob(): bad data passed, $jid must be of string value.');
	  }
	  if(is_string($xml)) {
	    $xml = trim(stripslashes($xml));
	  } else {
	    // bad data passed
		  throw new LinkedInException('LinkedIn->editJob(): bad data passed, $xml must be of string value.');
	  }
               
	  // construct and send the request
	  $query    = self::_URL_API . '/v1/jobs/partner-job-id=' . trim($jid);
	  $response = $this->fetch('PUT', $query, $xml);
	  
	  /**
	   * Check for successful request (a 200 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */
	  return $this->checkResponse(200, $response);
	}
	
	/**
	 * General data send/request method.
	 * 
	 * @param str $method 
	 *    The data communication method.	 
	 * @param str $url 
	 *    The Linkedin API endpoint to connect with.
	 * @param str $data
	 *    [OPTIONAL] The data to send to LinkedIn.
	 * @param arr $parameters 
	 *    [OPTIONAL] Addition OAuth parameters to send to LinkedIn.
	 *        
	 * @return arr 
	 *    Array containing:
	 * 
	 *           array(
	 *             'info'      =>	Connection information,
	 *             'linkedin'  => LinkedIn response,  
	 *             'oauth'     => The OAuth request string that was sent to LinkedIn	 
	 *           )	 
	 */
	protected function fetch($method, $url, $data = NULL, $parameters = array()) {
	  // check for cURL
	  if(!extension_loaded('curl')) {
	    // cURL not present
      throw new LinkedInException('LinkedIn->fetch(): PHP cURL extension does not appear to be loaded/present.');
	  }
	  
    try {
	    // generate OAuth values
	    $oauth_consumer  = new OAuthConsumer($this->getApplicationKey(), $this->getApplicationSecret(), $this->getCallbackUrl());
	    $oauth_token     = $this->getToken();
	    $oauth_token     = (!is_null($oauth_token)) ? new OAuthToken($oauth_token['oauth_token'], $oauth_token['oauth_token_secret']) : NULL;
      $defaults        = array(
        'oauth_version' => self::_API_OAUTH_VERSION
      );
	    $parameters    = array_merge($defaults, $parameters);
	    
	    // generate OAuth request
  		$oauth_req = OAuthRequest::from_consumer_and_token($oauth_consumer, $oauth_token, $method, $url, $parameters);
      $oauth_req->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $oauth_consumer, $oauth_token);
      
      // start cURL, checking for a successful initiation
      if(!$handle = curl_init()) {
         // cURL failed to start
        throw new LinkedInException('LinkedIn->fetch(): cURL did not initialize properly.');
      }
      
      // set cURL options, based on parameters passed
	    curl_setopt($handle, CURLOPT_CUSTOMREQUEST, $method);
      curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
      curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, FALSE);
      curl_setopt($handle, CURLOPT_URL, $url);
      curl_setopt($handle, CURLOPT_VERBOSE, FALSE);
      
      // configure the header we are sending to LinkedIn - http://developer.linkedin.com/docs/DOC-1203
      $header = array($oauth_req->to_header(self::_API_OAUTH_REALM));
      if(is_null($data)) {
        // not sending data, identify the content type
        $header[] = 'Content-Type: text/plain; charset=UTF-8';
        switch($this->getResponseFormat()) {
          case self::_RESPONSE_JSON:
            $header[] = 'x-li-format: json';
            break;
          case self::_RESPONSE_JSONP:
            $header[] = 'x-li-format: jsonp';
            break;
        }
      } else {
        $header[] = 'Content-Type: text/xml; charset=UTF-8';
        curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
      }
      curl_setopt($handle, CURLOPT_HTTPHEADER, $header);
    
      // set the last url, headers
      $this->last_request_url = $url;
      $this->last_request_headers = $header;
      
      // gather the response
      $return_data['linkedin']        = curl_exec($handle);
      $return_data['info']            = curl_getinfo($handle);
      $return_data['oauth']['header'] = $oauth_req->to_header(self::_API_OAUTH_REALM);
      $return_data['oauth']['string'] = $oauth_req->base_string;
            
      // check for throttling
      if(self::isThrottled($return_data['linkedin'])) {
        throw new LinkedInException('LinkedIn->fetch(): throttling limit for this user/application has been reached for LinkedIn resource - ' . $url);
      }
      
      //TODO - add check for NO response (http_code = 0) from cURL
      
      // close cURL connection
      curl_close($handle);
      
      // no exceptions thrown, return the data
      return $return_data;
    } catch(OAuthException $e) {
      // oauth exception raised
      throw new LinkedInException('OAuth exception caught: ' . $e->getMessage());
    }
	}
	
	/**
	 * This flags a specified post as specified by type.
	 * 
	 *   http://developer.linkedin.com/documents/groups-api
	 * 
	 * @param str $pid
	 * 		The post id.
	 * @param str $type
	 * 		The type to flag the post as.
	 * 
	 * @return arr
	 * 		Array containing retrieval success, LinkedIn response.
	 */
	public function flagPost($pid, $type) {
		if(!is_string($pid)) {
			throw new LinkedInException('LinkedIn->flagPost(): bad data passed, $pid must be of type string');
		}
		if(!is_string($type)) {
			throw new LinkedInException('LinkedIn->flagPost(): bad data passed, $like must be of type string');
		}
		//Constructing the xml
		$data = '<?xml version="1.0" encoding="UTF-8"?>';
		switch($type) {
			case 'promotion':
				$data .= '<code>promotion</code>';
				break;
			case 'job':
				$data .= '<code>job</code>';
				break;
			default: 
				throw new LinkedInException('LinkedIn->flagPost(): invalid value for $type, must be one of: "promotion", "job"');
				break;	
		}
		
		// construct and send the request
		$query    = self::_URL_API . '/v1/posts/' . $pid . '/category/code';
		$response = $this->fetch('PUT', $query, $data);
		  
  	/**
     * Check for successful request (a 204 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */
		return $this->checkResponse(204, $response);
	}
	
	/**
	 * Follow a company.
	 * 
	 * Calling this method causes the current user to start following the 
	 * specified company, per:
	 * 
	 *   http://developer.linkedin.com/docs/DOC-1324
	 * 
	 * @param str $cid
	 *    Company ID you want to follow.
	 *         	 
	 * @return arr
	 *    Array containing retrieval success, LinkedIn response.
	 */
	public function followCompany($cid) {
	  // check passed data
	  if(!is_string($cid)) {
	    // bad data passed
		  throw new LinkedInException('LinkedIn->followCompany(): bad data passed, $cid must be of type string.');
	  }
	  
	  // construct and send the request
	  $query    = self::_URL_API . '/v1/people/~/following/companies';
	  $response = $this->fetch('POST', $query, '<company><id>' . trim($cid) . '</id></company>');
	  
	  /**
	   * Check for successful request (a 201 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */
	  return $this->checkResponse(201, $response);
	}
	
	/**
	 * Follows/Unfollows the specified post.
	 * 
	 * https://developer.linkedin.com/documents/groups-api
	 * 
	 * @param str $pid
	 * 		The post id.
	 * @param bool $follow
	 * 		Determines whether to follow or unfollow the post. TRUE = follow, FALSE = unfollow
	 * 
	 * @return arr
	 * 		Array containing retrieval success, LinkedIn response.
	 */
	
	public function followPost($pid, $follow) {
		if(!is_string($pid)) {
			throw new LinkedInException('LinkedIn->followPost(): bad data passed, $pid must be of type string');
		}
		if(!($follow === TRUE || $follow === FALSE)) {
			throw new LinkedInException('LinkedIn->followPost(): bad data passed, $follow must be of type boolean');
		}
		
		// construct the XML
		$data = '<?xml version="1.0" encoding="UTF-8"?>
				     <is-following>'. (($follow) ? 'true' : 'false'). '</is-following>';
		
		// construct and send the request
		$query    = self::_URL_API . '/v1/posts/' . trim($pid) . '/relation-to-viewer/is-following';
		$response = $this->fetch('PUT', $query, $data);
		
		/**
	   * Check for successful request (a 204 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */
		return $this->checkResponse(204, $response);
	}
	
	/**
	 * Get list of companies you follow.
	 * 
	 * Returns a list of companies the current user is currently following, per:
	 * 
	 *   http://developer.linkedin.com/docs/DOC-1324   
	 * 	
	 * @return arr
	 *    Array containing retrieval success, LinkedIn response.
	 */
	public function followedCompanies() {	  
	  // construct and send the request
    $query    = self::_URL_API . '/v1/people/~/following/companies';
	  $response = $this->fetch('GET', $query);
	  
	  /**
	   * Check for successful request (a 200 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */
	  return $this->checkResponse(200, $response);
	}
	
	/**
	 * Get the application_key property.
	 * 
	 * @return str 
	 *    The application key.       	 
	 */
	public function getApplicationKey() {
	  return $this->application_key;
	}
	
	/**
	 * Get the application_secret property.
	 * 
	 * @return str 
	 *    The application secret.       	 
	 */
	public function getApplicationSecret() {
	  return $this->application_secret;
	}
	
	/**
	 * Get the callback property.
	 * 
	 * @return str 
	 *    The callback url.       	 
	 */
	public function getCallbackUrl() {
	  return $this->callback;
	}
  
  /**
	 * Get the response_format property.
	 * 
	 * @return str 
	 *    The response format.       	 
	 */
	public function getResponseFormat() {
	  return $this->response_format;
	}
	
	/**
	 * Get the token_access property.
	 * 
	 * @return arr 
	 *    The access token.       	 
	 */
	public function getToken() {
	  return $this->token;
	}
	
	/**
	 * [DEPRECATED] Get the token_access property.
	 * 
	 * @return arr 
	 *    The access token.       	 
	 */
	public function getTokenAccess() {
	  return $this->getToken();
	}
	
	/**
	 * 
	 * Get information about a specific group.
	 * 
	 *   http://developer.linkedin.com/documents/groups-api
	 * 
	 * @param str $gid
	 * 	 	The group id.
	 *  
	 * @param str $options
	 * 		[OPTIONAL] Field selectors for the group.
	 * 
	 * @return arr
	 * 		Array containing retrieval success, LinkedIn response.
	 */
	
	public function group($gid, $options = '') {
		if(!is_string($gid)){
			throw new LinkedInException('LinkedIn->group(): bad data passed, $gid must be of type string.');
		}
		if(!is_string($options)) {
			throw new LinkedInException('LinkedIn->group(): bad data passed, $options must be of type string');
		}
	
		// construct and send the request
		$query    = self::_URL_API . '/v1/groups/' . trim($gid) . trim($options); 
		$response = $this->fetch('GET', $query);
		
		/**
	   * Check for successful request (a 200 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */
		return $this->checkResponse(200, $response);
	}
	
	/**
	 * This returns all the groups the user is a member of.
	 * 
	 *   http://developer.linkedin.com/documents/groups-api
	 * 
	 * @param str $options
	 * 		[OPTIONAL] Field selectors for the groups.
	 * 
	 * @return arr
	 * 		Array containing retrieval success, LinkedIn response.
	 */
	public function groupMemberships($options = '') {
		if(!is_string($options)) {
			throw new LinkedInException('LinkedIn->groupMemberships(): bad data passed, $options must be of type string');
		}
		
		// construct and send the request
		$query    = self::_URL_API . '/v1/people/~/group-memberships' . trim($options) . '?membership-state=member';
		$response = $this->fetch('GET', $query);
		
		/**
	   * Check for successful request (a 200 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */
		return $this->checkResponse(200, $response);
	}
	
	/**
	 * This gets a specified post made within a group.
	 * 
	 *   http://developer.linkedin.com/documents/groups-api
	 * 
	 * @param str $pid
	 * 		The post id.
	 * @param str $options
	 * 		[OPTIONAL] Field selectors for the post.
	 * 
	 * @return arr
	 * 		Array containing retrieval success, LinkedIn response.
	 */
	public function groupPost($pid, $options = '') {
		if(!is_string($pid)) {
			throw new LinkedInException('LinkedIn->groupPost(): bad data passed, $pid must be of type string.');
		}
		if(!is_string($options)) {
			throw new LinkedInException('LinkedIn->groupPost(): bad data passed, $options must be of type string.');
		}
		
		// construct and send the request
		$query    = self::_URL_API . '/v1/posts/' . trim($pid) . trim($options);
		$response = $this->fetch('GET', $query);
		
		/**
	   * Check for successful request (a 200 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */
		return $this->checkResponse(200, $response);
	}
	
	/**
	 * This returns all the comments made on the specified post within a group.
	 * 
	 *   http://developer.linkedin.com/documents/groups-api
	 * 
	 * @param str $pid
	 * 		The post id.
	 * @param str $options
	 * 		[OPTIONAL] Field selectors for the post comments.
	 * 
	 * @return arr
	 * 		Array containing retrieval success, LinkedIn response.
	 */
	public function groupPostComments($pid, $options = ''){ 
		if(!is_string($pid)){
			throw new LinkedInException('LinkedIn->groupPostComments(): bad data passed, $pid must be of type string.');
		}
		if(!is_string($options)) {
			throw new LinkedInException('LinkedIn->groupPostComments(): bad data passed, $options must be of type string.');
		}		
		
		// construct and send the request
		$query    = self::_URL_API . '/v1/posts/' . trim($pid) . '/comments' . trim($options);
		$response = $this->fetch('GET', $query);

		/**
	   * Check for successful request (a 200 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */
		return $this->checkResponse(200, $response);
	}
	
	/**
	 * This returns all the posts within a group.
	 * 
	 *   http://developer.linkedin.com/documents/groups-api
	 * 
	 * @param str $gid
	 * 		The group id.
	 * 
	 * @return arr
	 * 		Array containing retrieval success, LinkedIn response.
	 */
	public function groupPosts($gid, $options = '') {
		if(!is_string($gid)){
			throw new LinkedInException('LinkedIn->groupPosts(): bad data passed, $gid must be of type string');
		}
		if(!is_string($options)){
			throw new LinkedInException('LinkedIn->groupPosts(): bad data passed, $options must be of type string');
		}
		
		// construct and send the request
		$query    = self::_URL_API . '/v1/groups/' . trim($gid)  .'/posts' . trim($options);
		$response = $this->fetch('GET', $query);
		
		/**
	   * Check for successful request (a 200 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */
		return $this->checkResponse(200, $response);
	}
	
	/**
	 * This returns the group settings of the specified group
	 * 
	 *   http://developer.linkedin.com/documents/groups-api
	 * 
	 * @param str $gid
	 * 		The group id.
	 * @param str $options
	 * 		[OPTIONAL] Field selectors for the group.
	 * 
	 * @return arr
	 * 		Array containing retrieval success, LinkedIn response.
	 */
	public function groupSettings($gid, $options = '') {
		if(!is_string($gid)) {
			throw new LinkedInException('LinkedIn->groupSettings(): bad data passed, $gid must be of type string');
		}
		if(!is_string($options)) {
			throw new LinkedInException('LinkedIn->groupSettings(): bad data passed, $options must be of type string');
		}
		
		// construct and send the request
		$query    = self::_URL_API . '/v1/people/~/group-memberships/' . trim($gid) . trim($options);
		$response = $this->fetch('GET', $query);
		
		/**
	   * Check for successful request (a 200 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */
		return $this->checkResponse(200, $response);
	}
	
	/**
	 * Send connection invitations.
	 *     
	 * Send an invitation to connect to your network, either by email address or 
	 * by LinkedIn ID. Details on the API here: 
	 * 
	 *   http://developer.linkedin.com/docs/DOC-1012
	 * 
	 * @param str $method 
	 *    The invitation method to process.	 
	 * @param str $recipient 
	 *    The email/id to send the invitation to.	 	 
	 * @param str $subject 
	 *    The subject of the invitation to send.
	 * @param str $body 
	 *    The body of the invitation to send.
	 * @param str $type 
	 *    [OPTIONAL] The invitation request type (only friend is supported at this time by the Invite API).
	 * 
	 * @return arr 
	 *    Array containing retrieval success, LinkedIn response.  	 
	 */
	public function invite($method, $recipient, $subject, $body, $type = 'friend') {
    /**
     * Clean up the passed data per these rules:
     * 
     * 1) Message must be sent to one recipient (only a single recipient permitted for the Invitation API)
     * 2) No HTML permitted
     * 3) 200 characters max in the invitation subject
     * 4) Only able to connect as a friend at this point     
     */
    // check passed data
    if(empty($recipient)) {
   		throw new LinkedInException('LinkedIn->invite(): you must provide an invitation recipient.');
    }
    switch($method) {
      case 'email':
        if(is_array($recipient)) {
          $recipient = array_map('trim', $recipient);
        } else {
          // bad format for recipient for email method
          throw new LinkedInException('LinkedIn->invite(): invitation recipient email/name array is malformed.');
        }
        break;
      case 'id':
        $recipient = trim($recipient);
        if(!self::isId($recipient)) {
          // bad format for recipient for id method
          throw new LinkedInException('LinkedIn->invite(): invitation recipient ID does not match LinkedIn format.');
        }
        break;
      default:
        throw new LinkedInException('LinkedIn->invite(): bad invitation method, must be one of: email, id.');
        break;
    }
    if(!empty($subject)) {
      $subject = trim(htmlspecialchars(strip_tags(stripslashes($subject))));
    } else {
      throw new LinkedInException('LinkedIn->invite(): message subject is empty.');
    }
    if(!empty($body)) {
      $body = trim(htmlspecialchars(strip_tags(stripslashes($body))));
      if(strlen($body) > self::_INV_BODY_LENGTH) {
        throw new LinkedInException('LinkedIn->invite(): message body length is too long - max length is ' . self::_INV_BODY_LENGTH . ' characters.');
      }
    } else {
      throw new LinkedInException('LinkedIn->invite(): message body is empty.');
    }
    switch($type) {
      case 'friend':
        break;
      default:
        throw new LinkedInException('LinkedIn->invite(): bad invitation type, must be one of: friend.');
        break;
    }
    
    // construct the xml data
		$data   = '<?xml version="1.0" encoding="UTF-8"?>
		           <mailbox-item>
		             <recipients>
                   <recipient>';
                     switch($method) {
                       case 'email':
                         // email-based invitation
                         $data .= '<person path="/people/email=' . $recipient['email'] . '">
                                     <first-name>' . htmlspecialchars($recipient['first-name']) . '</first-name>
                                     <last-name>' . htmlspecialchars($recipient['last-name']) . '</last-name>
                                   </person>';
                         break;
                       case 'id':
                         // id-based invitation
                         $data .= '<person path="/people/id=' . $recipient . '"/>';
                         break;
                     }
    $data  .= '    </recipient>
                 </recipients>
                 <subject>' . $subject . '</subject>
                 <body>' . $body . '</body>
                 <item-content>
                   <invitation-request>
                     <connect-type>';
                       switch($type) {
                         case 'friend':
                           $data .= 'friend';
                           break;
                       }
    $data  .= '      </connect-type>';
                     switch($method) {
                       case 'id':
                         // id-based invitation, we need to get the authorization information
                         $query                 = 'id=' . $recipient . ':(api-standard-profile-request)';
                         $response              = self::profile($query);
                         if($response['info']['http_code'] == 200) {
                           $response['linkedin'] = self::xmlToArray($response['linkedin']);
                           if($response['linkedin'] === FALSE) {
                             // bad XML data
                             throw new LinkedInException('LinkedIn->invite(): LinkedIn returned bad XML data.');
                           }
                           $authentication = explode(':', $response['linkedin']['person']['children']['api-standard-profile-request']['children']['headers']['children']['http-header']['children']['value']['content']);
                           
                           // complete the xml        
                           $data .= '<authorization>
                                       <name>' . $authentication[0] . '</name>
                                       <value>' . $authentication[1] . '</value>
                                     </authorization>';
                         } else {
                           // bad response from the profile request, not a valid ID?
                           throw new LinkedInException('LinkedIn->invite(): could not send invitation, LinkedIn says: ' . print_r($response['linkedin'], TRUE));
                         }
                         break;
                     }
    $data  .= '    </invitation-request>
                 </item-content>
               </mailbox-item>';
    
    // send request
    $query    = self::_URL_API . '/v1/people/~/mailbox';
    $response = $this->fetch('POST', $query, $data);
		
		/**
	   * Check for successful request (a 201 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */ 
    return $this->checkResponse(201, $response);
	}
	
	/**
	 * LinkedIn ID validation.
	 *	 
	 * Checks the passed string $id to see if it has a valid LinkedIn ID format, 
	 * which is, as of October 15th, 2010:
	 * 
	 *   10 alpha-numeric mixed-case characters, plus underscores and dashes.          	 
	 * 
	 * @param str $id 
	 *    A possible LinkedIn ID.         	 
	 * 
	 * @return bool 
	 *    TRUE/FALSE depending on valid ID format determination.                  
	 */
	public static function isId($id) {
	  // check passed data
    if(!is_string($id)) {
	    // bad data passed
	    throw new LinkedInException('LinkedIn->isId(): bad data passed, $id must be of type string.');
	  }
	  
	  $pattern = '/^[a-z0-9_\-]{10}$/i';
	  if($match = preg_match($pattern, $id)) {
	    // we have a match
	    $return_data = TRUE;
	  } else {
	    // no match
	    $return_data = FALSE;
	  }
	  return $return_data;
	}
	
	/**
	 * Throttling check.
	 * 
	 * Checks the passed LinkedIn response to see if we have hit a throttling 
	 * limit:
	 * 
	 * http://developer.linkedin.com/docs/DOC-1112
	 * 
	 * @param arr $response 
	 *    The LinkedIn response.
	 *                     	 
	 * @return bool
	 *    TRUE/FALSE depending on content of response.                  
	 */
	public static function isThrottled($response) {
	  $return_data = FALSE;
    
    // check the variable
	  if(!empty($response) && is_string($response)) {
	    // we have an array and have a properly formatted LinkedIn response
	       
      // store the response in a temp variable
      $temp_response = self::xmlToArray($response);
  	  if($temp_response !== FALSE) {
    	  // check to see if we have an error
    	  if(array_key_exists('error', $temp_response) && ($temp_response['error']['children']['status']['content'] == 403) && preg_match('/throttle/i', $temp_response['error']['children']['message']['content'])) {
    	    // we have an error, it is 403 and we have hit a throttle limit
  	      $return_data = TRUE;
    	  }
  	  }
  	}
  	return $return_data;
	}
	
	/**
	 * Job posting detail info retrieval function.
	 * 
	 * The Jobs API returns detailed information about job postings on LinkedIn. 
	 * Find the job summary, description, location, and apply our professional graph 
	 * to present the relationship between the current member and the job poster or 
	 * hiring manager.
	 * 
	 *   http://developer.linkedin.com/docs/DOC-1322  
	 * 
	 * @param	str $jid 
	 *    ID of the job you want to look up.
	 * @param str $options 
	 *    [OPTIONAL] Data retrieval options.
	 *            	
	 * @return arr 
	 *    Array containing retrieval success, LinkedIn response.
	 */
	public function job($jid, $options = '') {
	  // check passed data
	  if(!is_string($jid)) {
	    // bad data passed
		  throw new LinkedInException('LinkedIn->job(): bad data passed, $jid must be of type string.');
	  }
	  if(!is_string($options)) {
	    // bad data passed
		  throw new LinkedInException('LinkedIn->job(): bad data passed, $options must be of type string.');
	  }
	  
	  // construct and send the request
	  $query    = self::_URL_API . '/v1/jobs/' . trim($jid) . trim($options);
	  $response = $this->fetch('GET', $query);
	  
	  /**
	   * Check for successful request (a 200 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */
	  return $this->checkResponse(200, $response);
	}
	
	/**
	 * Join the specified group, per: 
	 * 
	 *   http://developer.linkedin.com/documents/groups-api
	 * 
	 * @param str $gid
	 * 		The group id.
	 * 
	 * @return arr
	 * 		Array containing retrieval success, LinkedIn response.   	 
	 */
	public function joinGroup($gid) {
		if(!is_string($gid)) {
			throw new LinkedInException('LinkedIn->joinGroup(): bad data passed, $gid must be of type string.');
		}
		
		// constructing the XML
		$data = '<?xml version="1.0" encoding="UTF-8"?>
  				   <group-membership>
  				   	 <membership-state>
  				  	 	 <code>member</code>
  				  	 </membership-state>
  				   </group-membership>';
		
		// construct and send the request
		$query    = self::_URL_API . '/v1/people/~/group-memberships/' . trim($gid);
		$response = $this->fetch('PUT', $query, $data);
		
		/**
	   * Check for successful request (a 200 or 201 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */
		return $this->checkResponse(array(200, 201), $response);
	}
	
	/**
	 * Returns the last request header from the previous call to the 
	 * LinkedIn API.
	 * 
	 * @returns str
	 *    The header, in string format.
	 */            	
	public function lastRequestHeader() {
	   return $this->last_request_headers;
	}
	
	/**
	 * Returns the last request url from the previous call to the 
	 * LinkedIn API.
	 * 
	 * @returns str
	 *    The url, in string format.
	 */            	
	public function lastRequestUrl() {
	   return $this->last_request_url;
	}
	
	/**
	 * Leave the specified group, per:.
	 * 
	 *   http://developer.linkedin.com/documents/groups-api
	 * 
	 * @param str $gid
	 * 		The group id.
	 * 
	 * @return arr
	 * 		Array containing retrieval success, LinkedIn response.
	 */
	public function leaveGroup($gid){
		if(!is_string($gid)) {
			throw new LinkedInException('LinkedIn->leaveGroup(): bad data passed, $gid must be of type string');
		}
		
		// construct and send the request
		$query    = self::_URL_API . '/v1/people/~/group-memberships/'  .trim($gid);
		$response = $this->fetch('DELETE', $query);
		
		/**
	   * Check for successful request (a 204 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */ 
		return $this->checkResponse(204, $response);
	}
	
	/**
	 * Like another user's network update, per:
	 * 
	 *   http://developer.linkedin.com/docs/DOC-1043
	 * 
	 * @param str $uid
	 *    The LinkedIn update ID.
	 *                     	 
	 * @return arr
	 *    Array containing retrieval success, LinkedIn response.                  
	 */
	public function like($uid) {
	  // check passed data
	  if(!is_string($uid)) {
	    // bad data passed
		  throw new LinkedInException('LinkedIn->like(): bad data passed, $uid must be of type string.');
	  }
    
    // construct the XML
		$data = '<?xml version="1.0" encoding="UTF-8"?>
		         <is-liked>true</is-liked>';
		
		// construct and send the request
    $query    = self::_URL_API . '/v1/people/~/network/updates/key=' . $uid . '/is-liked';
    $response = $this->fetch('PUT', $query, $data);
    
  	/**
	   * Check for successful request (a 201 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */ 
    return $this->checkResponse(201, $response);
	}
	
	/**
	 * Likes/unlikes the specified post, per:
	 * 
	 *   http://developer.linkedin.com/documents/groups-api
	 * 
	 * @param str $pid
	 * 		The post id.
	 * @param bool $like
	 * 		Determines whether to like or unlike. TRUE = like, FALSE = unlike.
	 * 
	 * @return arr
	 * 		Array containing retrieval success, LinkedIn response.
	 */
	public function likePost($pid, $like) {
		if(!is_string($pid)) {
			throw new LinkedInException ('LinkedIn->likePost(): bad data passed, $pid must be of type string');
		}
		if(!($like === TRUE || $like === FALSE)) {
			throw new LinkedInException('LinkedIn->likePost(): bad data passed, $like must be of type boolean');
		}
		
		// construct the XML
		$data = '<?xml version="1.0" encoding="UTF-8"?>
		         <is-liked>'.(($like) ? 'true': 'false').'</is-liked>';
		
		// construct and send the request
		$query    = self::_URL_API . '/v1/posts/' . trim($pid) . '/relation-to-viewer/is-liked';
		$response = $this->fetch('PUT', $query, $data);
		
		/**
	   * Check for successful request (a 204 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */ 
		return $this->checkResponse(204, $response);
	}
	
	/**
	 * Retrieve network update likes.
	 *    
	 * Return all likes associated with a given network update:
	 * 
	 * http://developer.linkedin.com/docs/DOC-1043
	 * 
	 * @param str $uid
	 *    The LinkedIn update ID.
	 *                     	 
	 * @return arr 
	 *    Array containing retrieval success, LinkedIn response.                  
	 */
	public function likes($uid) {
	  // check passed data
	  if(!is_string($uid)) {
	    // bad data passed
		  throw new LinkedInException('LinkedIn->likes(): bad data passed, $uid must be of type string.');
	  }
		
		// construct and send the request
    $query    = self::_URL_API . '/v1/people/~/network/updates/key=' . $uid . '/likes';
    $response = $this->fetch('GET', $query);
    
  	/**
	   * Check for successful request (a 200 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */ 
    return $this->checkResponse(200, $response);
	}
	
	/**
	 * Connection messaging method.
	 * 	 
	 * Send a message to your network connection(s), optionally copying yourself.  
	 * Full details from LinkedIn on this functionality can be found here: 
	 * 
	 *   http://developer.linkedin.com/docs/DOC-1044
	 * 
	 * @param arr $recipients 
	 *    The connection(s) to send the message to.	 	 
	 * @param str $subject 
	 *    The subject of the message to send.
	 * @param str $body 
	 *    The body of the message to send.
	 * @param bool $copy_self 
	 *    [OPTIONAL] Also update the teathered Twitter account.
	 *    	 
	 * @return arr 
	 *    Array containing retrieval success, LinkedIn response.      	 
	 */
	public function message($recipients, $subject, $body, $copy_self = FALSE) {
    /**
     * Clean up the passed data per these rules:
     * 
     * 1) Message must be sent to at least one recipient
     * 2) No HTML permitted
     */
    if(!empty($subject) && is_string($subject)) {
      $subject = trim(strip_tags(stripslashes($subject)));
    } else {
      throw new LinkedInException('LinkedIn->message(): bad data passed, $subject must be of type string.');
    }
    if(!empty($body) && is_string($body)) {
      $body = trim(strip_tags(stripslashes($body)));
    } else {
      throw new LinkedInException('LinkedIn->message(): bad data passed, $body must be of type string.');
    }
    if(!is_array($recipients) || count($recipients) < 1) {
      // no recipients, and/or bad data
      throw new LinkedInException('LinkedIn->message(): at least one message recipient required.');
    }
    
    // construct the xml data
		$data   = '<?xml version="1.0" encoding="UTF-8"?>
		           <mailbox-item>
		             <recipients>';
    $data  .=     ($copy_self) ? '<recipient><person path="/people/~"/></recipient>' : '';
                  for($i = 0; $i < count($recipients); $i++) {
                    if(is_string($recipients[$i])) {
                      $data .= '<recipient><person path="/people/' . trim($recipients[$i]) . '"/></recipient>';
                    } else {
                      throw new LinkedInException ('LinkedIn->message(): bad data passed, $recipients must be an array of type string.');
                    }
                  }
    $data  .= '  </recipients>
                 <subject>' . htmlspecialchars($subject) . '</subject>
                 <body>' . htmlspecialchars($body) . '</body>
               </mailbox-item>';
    
    // send request
    $query    = self::_URL_API . '/v1/people/~/mailbox';
    $response = $this->fetch('POST', $query, $data);
		
		/**
	   * Check for successful request (a 201 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */ 
    return $this->checkResponse(201, $response);
	}
	
	/**
	 * Job posting method.
	 * 	 
	 * Post a job to LinkedIn, assuming that you have access to this feature. 
	 * Full details from LinkedIn on this functionality can be found here: 
	 * 
	 *   http://developer.linkedin.com/community/jobs?view=documents
	 * 
	 * @param str $xml 
	 *    The XML defining a job to post.	 	 
	 *    	 
	 * @return arr 
	 *    Array containing retrieval success, LinkedIn response.      	 
	 */
	public function postJob($xml) {
    // check passed data
    if(is_string($xml)) {
      $xml = trim(stripslashes($xml));
    } else {
      throw new LinkedInException('LinkedIn->postJob(): bad data passed, $xml must be of type string.');
    }
   
    // construct and send the request
    $query    = self::_URL_API . '/v1/jobs';
    $response = $this->fetch('POST', $query, $xml);
		
		/**
	   * Check for successful request (a 201 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */ 
    return $this->checkResponse(201, $response);
	}
	
	/**
	 * General profile retrieval function.
	 * 
	 * Takes a string of parameters as input and requests profile data from the 
	 * Linkedin Profile API. See the official documentation for $options
	 * 'field selector' formatting:
	 * 
	 *   http://developer.linkedin.com/docs/DOC-1014
	 *   http://developer.linkedin.com/docs/DOC-1002    
	 * 
	 * @param str $options 
	 *    [OPTIONAL] Data retrieval options.
	 *            	 
	 * @return arr 
	 *    Array containing retrieval success, LinkedIn response.
	 */
	public function profile($options = '~') {
	  // check passed data
	  if(!is_string($options)) {
	    // bad data passed
		  throw new LinkedInException('LinkedIn->profile(): bad data passed, $options must be of type string.');
	  }
	  
	  // construct and send the request
	  $query    = self::_URL_API . '/v1/people/' . trim($options);
	  $response = $this->fetch('GET', $query);
	  
	  /**
	   * Check for successful request (a 200 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */
	  return $this->checkResponse(200, $response);
	}
	
	/**
	 * Manual API call method, allowing for support for un-implemented API
	 * functionality to be supported.
	 * 
	 * @param str $method 
	 *    The data communication method.	 
	 * @param str $url 
	 *    The Linkedin API endpoint to connect with - should NOT include the 
	 *    leading https://api.linkedin.com/v1.
	 * @param str $body
	 *    [OPTIONAL] The URL-encoded body data to send to LinkedIn with the request.
	 * 
	 * @return arr
	 * 		Array containing retrieval information, LinkedIn response. Note that you
	 * 		must manually check the return code and compare this to the expected 
	 * 		API response to determine  if the raw call was successful.
	 */
	public function raw($method, $url, $body = NULL) {
	  if(!is_string($method)) {
	    // bad data passed
		  throw new LinkedInException('LinkedIn->raw(): bad data passed, $method must be of string value.');
	  }
	  if(!is_string($url)) {
	    // bad data passed
		  throw new LinkedInException('LinkedIn->raw(): bad data passed, $url must be of string value.');
	  }
	  if(!is_null($body) && !is_string($url)) {
	    // bad data passed
		  throw new LinkedInException('LinkedIn->raw(): bad data passed, $body must be of string value.');
	  }
    
    // construct and send the request
	  $query = self::_URL_API . '/v1' . trim($url);
	  return $this->fetch($method, $query, $body);
	}
	
	/**
	 * This removes the specified group from the group suggestions, per:
	 * 
	 *   http://developer.linkedin.com/documents/groups-api
	 * 
	 * @param str $gid
	 * 		The group id.
	 * 
	 * @return arr
	 * 		Array containing retrieval success, LinkedIn response.
	 */
	public function removeSuggestedGroup($gid) {
		if(!is_string($gid)) {
			throw new LinkedInException('LinkedIn->removeSuggestedGroup(): bad data passed, $gid must be of type string');
		} 
		
		// construct and send the request
		$query    = self::_URL_API . '/v1/people/~/suggestions/groups/'  .trim($gid);
		$response = $this->fetch('DELETE', $query);
		
		/**
	   * Check for successful request (a 204 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */
		return $this->checkResponse(204, $response);
	}
	
	/**
	 * Renew a job.
	 * 
	 * Calling this method causes the passed job to be renewed, per:
	 * 
	 *   http://developer.linkedin.com/docs/DOC-1154   
	 * 
	 * @param str $jid
	 *    Job ID you want to renew.
	 * @param str $cid
	 *    Contract ID that covers the passed Job ID.	 
	 *            	
	 * @return arr
	 *    Array containing retrieval success, LinkedIn response.
	 */
	public function renewJob($jid, $cid) {
	  // check passed data
	  if(!is_string($jid)) {
	    // bad data passed
		  throw new LinkedInException('LinkedIn->renewJob(): bad data passed, $jid must be of string value.');
	  }
	  if(!is_string($cid)) {
	    // bad data passed
		  throw new LinkedInException('LinkedIn->renewJob(): bad data passed, $cid must be of string value.');
	  }
	  
	  // construct the xml data
		$data   = '<?xml version="1.0" encoding="UTF-8"?>
		           <job>
		             <contract-id>' . trim($cid) . '</contract-id>
                 <renewal/>
               </job>';
               
	  // construct and send the request
	  $query    = self::_URL_API . '/v1/jobs/partner-job-id=' . trim($jid);
	  $response = $this->fetch('PUT', $query, $data);
	  
	  /**
	   * Check for successful request (a 200 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */
	  return $this->checkResponse(200, $response);
	}
	
  /**
	 * Access token retrieval.
	 *
	 * Request the user's access token from the Linkedin API.
	 * 
	 * @param str $token
	 *    The token returned from the user authorization stage.
	 * @param str $secret
	 *    The secret returned from the request token stage.
	 * @param str $verifier
	 *    The verification value from LinkedIn.
	 *    	 
	 * @return arr 
	 *    The Linkedin OAuth/http response, in array format.      	 
	 */
	public function retrieveTokenAccess($token, $secret, $verifier) {
	  // check passed data
    if(!is_string($token) || !is_string($secret) || !is_string($verifier)) {
      // nothing passed, raise an exception
		  throw new LinkedInException('LinkedIn->retrieveTokenAccess(): bad data passed, string type is required for $token, $secret and $verifier.');
    }
    
    // start retrieval process
	  $this->setToken(array('oauth_token' => $token, 'oauth_token_secret' => $secret));
    $parameters = array(
      'oauth_verifier' => $verifier
    );
    $response = $this->fetch(self::_METHOD_TOKENS, self::_URL_ACCESS, NULL, $parameters);
    parse_str($response['linkedin'], $response['linkedin']);
    
    /**
	   * Check for successful request (a 200 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */
    if($response['info']['http_code'] == 200) {
      // tokens retrieved
      $this->setToken($response['linkedin']);
      
      // set the response
      $return_data            = $response;
      $return_data['success'] = TRUE;
    } else {
      // error getting the request tokens
       $this->setToken(NULL);
       
      // set the response
      $return_data            = $response;
      $return_data['error']   = 'HTTP response from LinkedIn end-point was not code 200';
      $return_data['success'] = FALSE;
    }
    return $return_data;
	}
	
	/**
	 * Request token retrieval.
	 * 
	 * Get the request token from the Linkedin API.
	 * 
	 * @return arr
	 *    The Linkedin OAuth/http response, in array format.      	 
	 */
	public function retrieveTokenRequest() {
    $parameters = array(
      'oauth_callback' => $this->getCallbackUrl()
    );
    $response = $this->fetch(self::_METHOD_TOKENS, self::_URL_REQUEST, NULL, $parameters);
    parse_str($response['linkedin'], $response['linkedin']);
    
    /**
	   * Check for successful request (a 200 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */
    if(($response['info']['http_code'] == 200) && (array_key_exists('oauth_callback_confirmed', $response['linkedin'])) && ($response['linkedin']['oauth_callback_confirmed'] == 'true')) {
      // tokens retrieved
      $this->setToken($response['linkedin']);
      
      // set the response
      $return_data            = $response;
      $return_data['success'] = TRUE;        
    } else {
      // error getting the request tokens
      $this->setToken(NULL);
      
      // set the response
      $return_data = $response;
      if((array_key_exists('oauth_callback_confirmed', $response['linkedin'])) && ($response['linkedin']['oauth_callback_confirmed'] == 'true')) {
        $return_data['error'] = 'HTTP response from LinkedIn end-point was not code 200';
      } else {
        $return_data['error'] = 'OAuth callback URL was not confirmed by the LinkedIn end-point';
      }
      $return_data['success'] = FALSE;
    }
    return $return_data;
	}
	
	/**
	 * User authorization revocation.
	 * 
	 * Revoke the current user's access token, clear the access token's from 
	 * current LinkedIn object. The current documentation for this feature is 
	 * found in a blog entry from April 29th, 2010:
	 * 
	 *   http://developer.linkedin.com/community/apis/blog/2010/04/29/oauth--now-for-authentication	 
	 * 
	 * @return arr 
	 *    Array containing retrieval success, LinkedIn response.   	 
	 */
	public function revoke() {
	  // construct and send the request
	  $response = $this->fetch('GET', self::_URL_REVOKE);

	  /**
	   * Check for successful request (a 200 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */                	  
    return $this->checkResponse(200, $response);
	}
	
	/**
	 * [DEPRECATED] General people search function.
	 * 
	 * Takes a string of parameters as input and requests profile data from the 
	 * Linkedin People Search API.  See the official documentation for $options
	 * querystring formatting:
	 * 
	 *   http://developer.linkedin.com/docs/DOC-1191 
	 * 
	 * @param str $options 
	 *    [OPTIONAL] Data retrieval options.
	 *            	 
	 * @return arr 
	 *    Array containing retrieval success, LinkedIn response.
	 */
	public function search($options = NULL) {
		return searchPeople($options);
	}
	
	/**
	 * Company search.
	 * 
	 * Uses the Company Search API to find companies using keywords, industry, 
	 * location, or some other criteria. It returns a collection of matching 
	 * companies.
	 * 
	 *   http://developer.linkedin.com/docs/DOC-1325  
	 * 
	 * @param str $options
	 *    [OPTIONAL] Search options.	
	 * @return arr 
	 *    Array containing retrieval success, LinkedIn response.
	 */
	public function searchCompanies($options = '') {
	  // check passed data
	  if(!is_string($options)) {
	    // bad data passed
		  throw new LinkedInException('LinkedIn->searchCompanies(): bad data passed, $options must be of type string.');
	  }
	  
	  // construct and send the request
	  $query    = self::_URL_API . '/v1/company-search' . trim($options);
	  $response = $this->fetch('GET', $query);
	  
	  /**
	   * Check for successful request (a 200 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */
	  return $this->checkResponse(200, $response);
	}
	
	/**
	 * Jobs search.
	 * 
	 * Use the Job Search API to find jobs using keywords, company, location, 
	 * or some other criteria. It returns a collection of matching jobs. Each 
	 * entry can contain much of the information available on the job listing.
	 * 
	 *   http://developer.linkedin.com/docs/DOC-1321  
	 * 
	 * @param str $options 
	 *    [OPTIONAL] Data retrieval options.
	 *            	
	 * @return arr 
	 *    Array containing retrieval success, LinkedIn response.
	 */
	public function searchJobs($options = '') {
	  // check passed data
	  if(!is_string($options)) {
	    // bad data passed
		  throw new LinkedInException('LinkedIn->jobsSearch(): bad data passed, $options must be of type string.');
	  }
	  
	  // construct and send the request
	  $query    = self::_URL_API . '/v1/job-search' . trim($options);
	  $response = $this->fetch('GET', $query);
	  
	  /**
	   * Check for successful request (a 200 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */
	  return $this->checkResponse(200, $response);
	}
	
	/**
	 * General people search function.
	 * 
	 * Takes a string of parameters as input and requests profile data from the 
	 * Linkedin People Search API.  See the official documentation for $options
	 * querystring formatting:
	 * 
	 *   http://developer.linkedin.com/docs/DOC-1191 
	 * 
	 * @param str $options 
	 *    [OPTIONAL] Data retrieval options.
	 *            	 
	 * @return arr 
	 *    Array containing retrieval success, LinkedIn response.
	 */
	public function searchPeople($options = NULL) {
	  // check passed data
    if(!is_null($options) && !is_string($options)) {
	    // bad data passed
		  throw new LinkedInException('LinkedIn->search(): bad data passed, $options must be of type string.');
	  }
	  
	  // construct and send the request
    $query    = self::_URL_API . '/v1/people-search' . trim($options);
		$response = $this->fetch('GET', $query);
		
		/**
	   * Check for successful request (a 200 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */
		return $this->checkResponse(200, $response);
	}
	
	/**
	 * Set the application_key property.
	 * 
	 * @param str $key 
	 *    The application key.       	 
	 */
	public function setApplicationKey($key) {
	  $this->application_key = $key;
	}
	
	/**
	 * Set the application_secret property.
	 * 
	 * @param str $secret 
	 *    The application secret.       	 
	 */
	public function setApplicationSecret($secret) {
	  $this->application_secret = $secret;
	}
	
	/**
	 * Set the callback property.
	 * 
	 * @param str $url 
	 *    The callback url.       	 
	 */
	public function setCallbackUrl($url) {
	  $this->callback = $url;
	}
	
	/**
	 * This sets the group settings of the specified group.
	 * 
	 *   http://developer.linkedin.com/documents/groups-api
	 * 
	 * @param str $gid
	 * 		The group id.
	 * @param str $xml
	 * 		The group settings to set. The settings are:
	 * 		  -<show-group-logo-in-profle>
	 * 		  -<contact-email>
	 * 		  -<email-digest-frequency>
	 * 		  -<email-annoucements-from-managers>
	 * 		  -<allow-messages-from-members>
	 * 		  -<email-for-every-new-post>
	 * 
	 * @return arr
	 * 		Array containing retrieval success, LinkedIn response.
	 */
	public function setGroupSettings($gid, $xml) {
		if(!is_string ($gid)) {
      throw new LinkedInException('LinkedIn->setGroupSettings(): bad data passed, $token_access should be in array format.');
		}
		if(!is_string ($xml)) {
      throw new LinkedInException('LinkedIn->setGroupSettings(): bad data passed, $token_access should be in array format.');
		}
		
		// construct and send the request
		$query    = self::_URL_API . '/v1/people/~/group-memberships/' . trim($gid);
		$response = $this->fetch('PUT', $query, $xml);
		
	  /**
	   * Check for successful request (a 200 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */ 
		return $this->checkResponse(200, $response);
	}
	
	/**
	 * Set the response_format property.
	 * 
	 * @param str $format 
	 *    [OPTIONAL] The response format to specify to LinkedIn.       	 
	 */
	public function setResponseFormat($format = self::_DEFAULT_RESPONSE_FORMAT) {
	  $this->response_format = $format;
	}
	
	/**
	 * Set the token property.
	 * 
	 * @return arr $token 
	 *    The LinkedIn OAuth token.
	 */
	public function setToken($token) {
    // check passed data
    if(!is_null($token) && !is_array($token)) {
      // bad data passed
      throw new LinkedInException('LinkedIn->setToken(): bad data passed, $token_access should be in array format.');
    }
    
    // set token
    $this->token = $token;
	}
	
	/**
	 * [DEPRECATED] Set the token_access property.
	 * 
	 * @return arr $token_access 
	 *    [OPTIONAL] The LinkedIn OAuth access token.
	 */
	public function setTokenAccess($token_access) {
    $this->setToken($token_access);
	}
	
	/**
	 * Post a share. 
	 * 
	 * Create a new or reshare another user's shared content. Full details from 
	 * LinkedIn on this functionality can be found here: 
	 * 
	 *   http://developer.linkedin.com/docs/DOC-1212 
	 * 
	 *   $action values: ('new', 'reshare')      	 
	 *   $content format: 
	 *     $action = 'new'; $content => ('comment' => 'xxx', 'title' => 'xxx', 'submitted-url' => 'xxx', 'submitted-image-url' => 'xxx', 'description' => 'xxx')
	 *     $action = 'reshare'; $content => ('comment' => 'xxx', 'id' => 'xxx')	 
	 * 
	 * @param str $action
	 *    The sharing action to perform.	 
	 * @param str $content
	 *    The share content.
	 * @param bool $private 
	 *    [OPTIONAL] Should we restrict this shared item to connections only?	 
	 * @param bool $twitter 
	 *    [OPTIONAL] Also update the teathered Twitter account.
	 *    	 
	 * @return arr 
	 *    Array containing retrieval success, LinkedIn response.      	 
	 */
	public function share($action, $content, $private = TRUE, $twitter = FALSE) {
	  // check the status itself
    if(!empty($action) && !empty($content)) {
      /**
       * Status is not empty, wrap a cleaned version of it in xml.  Status
       * rules:
       * 
       * 1) Comments are 700 chars max (if this changes, change _SHARE_COMMENT_LENGTH constant)
       * 2) Content/title 200 chars max (if this changes, change _SHARE_CONTENT_TITLE_LENGTH constant)
       * 3) Content/description 400 chars max (if this changes, change _SHARE_CONTENT_DESC_LENGTH constant)
       * 4a) New shares must contain a comment and/or (content/title and content/submitted-url)
       * 4b) Reshared content must contain an attribution id.
       * 4c) Reshared content must contain actual content, not just a comment.             
       * 5) No HTML permitted in comment, content/title, content/description.
       */

      // prepare the share data per the rules above
      $share_flag   = FALSE;
      $content_xml  = NULL;
      switch($action) {
        case 'new':
          // share can be an article
          if(array_key_exists('title', $content) && array_key_exists('submitted-url', $content)) {
            // we have shared content, format it as needed per rules above
            $content_title = trim(htmlspecialchars(strip_tags(stripslashes($content['title']))));
            if(strlen($content_title) > self::_SHARE_CONTENT_TITLE_LENGTH) {
              throw new LinkedInException('LinkedIn->share(): title length is too long - max length is ' . self::_SHARE_CONTENT_TITLE_LENGTH . ' characters.');
            }
            $content_xml .= '<content>
                               <title>' . $content_title . '</title>
                               <submitted-url>' . trim(htmlspecialchars($content['submitted-url'])) . '</submitted-url>';
            if(array_key_exists('submitted-image-url', $content)) {
              $content_xml .= '<submitted-image-url>' . trim(htmlspecialchars($content['submitted-image-url'])) . '</submitted-image-url>';
            }
            if(array_key_exists('description', $content)) {
              $content_desc = trim(htmlspecialchars(strip_tags(stripslashes($content['description']))));
              if(strlen($content_desc) > self::_SHARE_CONTENT_DESC_LENGTH) {
                throw new LinkedInException('LinkedIn->share(): description length is too long - max length is ' . self::_SHARE_CONTENT_DESC_LENGTH . ' characters.');
              }
              $content_xml .= '<description>' . $content_desc . '</description>';
            }
            $content_xml .= '</content>';
            
            $share_flag = TRUE;
          }
          
          // share can be just a comment
          if(array_key_exists('comment', $content)) {
          	// comment located
          	$comment = htmlspecialchars(trim(strip_tags(stripslashes($content['comment']))));
          	if(strlen($comment) > self::_SHARE_COMMENT_LENGTH) {
              throw new LinkedInException('LinkedIn->share(): comment length is too long - max length is ' . self::_SHARE_COMMENT_LENGTH . ' characters.');
            }
            $content_xml .= '<comment>' . $comment . '</comment>';
          	
          	$share_flag = TRUE; 
      	  }
          break;
        case 'reshare':
          if(array_key_exists('id', $content)) {
            // put together the re-share attribution XML
            $content_xml .= '<attribution>
                               <share>
                                 <id>' . trim($content['id']) . '</id>
                               </share>
                             </attribution>';
            
            // optional additional comment
            if(array_key_exists('comment', $content)) {
            	// comment located
            	$comment = htmlspecialchars(trim(strip_tags(stripslashes($content['comment']))));
            	if(strlen($comment) > self::_SHARE_COMMENT_LENGTH) {
                throw new LinkedInException('LinkedIn->share(): comment length is too long - max length is ' . self::_SHARE_COMMENT_LENGTH . ' characters.');
              }
              $content_xml .= '<comment>' . $comment . '</comment>';
        	  }
        	  
        	  $share_flag = TRUE;
          }
          break;
        default:
          // bad action passed
          throw new LinkedInException('LinkedIn->share(): share action is an invalid value, must be one of: share, reshare.');
          break;
      }
      
      // should we proceed?
      if($share_flag) {
        // put all of the xml together
        $visibility = ($private) ? 'connections-only' : 'anyone';
        $data       = '<?xml version="1.0" encoding="UTF-8"?>
                       <share>
                         ' . $content_xml . '
                         <visibility>
                           <code>' . $visibility . '</code>
                         </visibility>
                       </share>';
        
        // create the proper url
        $share_url = self::_URL_API . '/v1/people/~/shares';
  		  if($twitter) {
  			  // update twitter as well
          $share_url .= '?twitter-post=true';
  			}
        
        // send request
        $response = $this->fetch('POST', $share_url, $data);
  		} else {
  		  // data contraints/rules not met, raise an exception
		    throw new LinkedInException('LinkedIn->share(): sharing data constraints not met; check that you have supplied valid content and combinations of content to share.');
  		}
    } else {
      // data missing, raise an exception
		  throw new LinkedInException('LinkedIn->share(): sharing action or shared content is missing.');
    }
    
    /**
	   * Check for successful request (a 201 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */ 
    return $this->checkResponse(201, $response);
	}
	
	/**
	 * Network statistics.
	 * 
	 * General network statistics retrieval function, returns the number of connections, 
	 * second-connections an authenticated user has. More information here:
	 * 
	 *   http://developer.linkedin.com/docs/DOC-1006
	 * 
	 * @return arr 
	 *    Array containing retrieval success, LinkedIn response.
	 */
	public function statistics() {
	  // construct and send the request
    $query    = self::_URL_API . '/v1/people/~/network/network-stats';
		$response = $this->fetch('GET', $query);
		
		/**
	   * Check for successful request (a 200 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */
		return $this->checkResponse(200, $response);
	}
	
	/**
	 * Companies you may want to follow.
	 * 
	 * Returns a list of companies the current user may want to follow, per:
	 * 
	 *   http://developer.linkedin.com/docs/DOC-1324   
	 * 
	 * @return arr
	 *    Array containing retrieval success, LinkedIn response.
	 */
	public function suggestedCompanies() {
	  // construct and send the request
    $query    = self::_URL_API . '/v1/people/~/suggestions/to-follow/companies';
	  $response = $this->fetch('GET', $query);
	  
	  /**
	   * Check for successful request (a 200 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */
	  return $this->checkResponse(200, $response);
	}
	
	/**
	 * Retrieves suggested groups for the user, per:
	 * 
	 *   http://developer.linkedin.com/documents/groups-api
	 * 
	 * @return arr
	 * 		Array containing retrieval success, LinkedIn response.
	 */
	public function suggestedGroups() {
		// construct and send the request
		$query    = self::_URL_API . '/v1/people/~/suggestions/groups:(id,name,is-open-to-non-members)';
		$response = $this->fetch('GET', $query);
		
		/**
	   * Check for successful request (a 200 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */
		return $this->checkResponse (200, $response);
	}

	/**
	 * Jobs you may be interested in.
	 * 
	 * Returns a list of jobs the current user may be interested in, per:
	 * 
	 *   http://developer.linkedin.com/docs/DOC-1323   
	 * 
 	 * @param str $options
 	 *    [OPTIONAL] Data retrieval options.	
 	 *          	 
	 * @return arr
	 *    Array containing retrieval success, LinkedIn response.
	 */
	public function suggestedJobs($options = ':(jobs)') {
	  // check passed data
	  if(!is_string($options)) {
	    // bad data passed
		  throw new LinkedInException('LinkedIn->suggestedJobs(): bad data passed, $options must be of type string.');
	  }
	
	  // construct and send the request
	  $query    = self::_URL_API . '/v1/people/~/suggestions/job-suggestions' . trim($options);
	  $response = $this->fetch('GET', $query);
	  
	  /**
	   * Check for successful request (a 200 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */
	  return $this->checkResponse(200, $response);
	}
	
	/**
	 * Unbookmark a job.
	 * 
	 * Calling this method causes the current user to remove a bookmark for the 
	 * specified job:
	 * 
	 *   http://developer.linkedin.com/docs/DOC-1323   
	 * 
	 * @param str $jid
	 *    Job ID you want to unbookmark.
	 *            	
	 * @return arr
	 *    Array containing retrieval success, LinkedIn response.
	 */
	public function unbookmarkJob($jid) {
	  // check passed data
	  if(!is_string($jid)) {
	    // bad data passed
		  throw new LinkedInException('LinkedIn->unbookmarkJob(): bad data passed, $jid must be of type string.');
	  }
	  
	  // construct and send the request
	  $query    = self::_URL_API . '/v1/people/~/job-bookmarks/' . trim($jid);
	  $response = $this->fetch('DELETE', $query);
	  
	  /**
	   * Check for successful request (a 204 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */
	  return $this->checkResponse(204, $response);
	}
	
	/**
	 * Unfollow a company.
	 * 
	 * Calling this method causes the current user to stop following the specified 
	 * company, per:
	 * 
	 *   http://developer.linkedin.com/docs/DOC-1324   
	 * 
	 * @param str $cid
	 *    Company ID you want to unfollow.	
	 *         	 
	 * @return arr
	 *    Array containing retrieval success, LinkedIn response.
	 */
	public function unfollowCompany($cid) {
	  // check passed data
	  if(!is_string($cid)) {
	    // bad data passed
		  throw new LinkedInException('LinkedIn->unfollowCompany(): bad data passed, $cid must be of string value.');
	  }
	  
	  // construct and send the request
	  $query    = self::_URL_API . '/v1/people/~/following/companies/id=' . trim($cid);
	  $response = $this->fetch('DELETE', $query);
	  
	  /**
	   * Check for successful request (a 204 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */
	  return $this->checkResponse(204, $response);
	}
	
	/**
	 * Unlike a network update.
	 *     
	 * Unlike another user's network update:
	 * 
	 *   http://developer.linkedin.com/docs/DOC-1043
	 * 
	 * @param str $uid 
	 *    The LinkedIn update ID.
	 *                     	 
	 * @return arr
	 *    Array containing retrieval success, LinkedIn response.                  
	 */
	public function unlike($uid) {
	  // check passed data
	  if(!is_string($uid)) {
	    // bad data passed
		  throw new LinkedInException('LinkedIn->unlike(): bad data passed, $uid must be of type string.');
	  }
    
    // construct the xml data
		$data = '<?xml version="1.0" encoding="UTF-8"?>
		         <is-liked>false</is-liked>';
		
		// send request
    $query    = self::_URL_API . '/v1/people/~/network/updates/key=' . $uid . '/is-liked';
    $response = $this->fetch('PUT', $query, $data);
    
  	/**
	   * Check for successful request (a 201 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */ 
    return $this->checkResponse(201, $response);
	}
	
	/**
	 * Post network update.
	 * 
	 * Update the user's Linkedin network status. Full details from LinkedIn 
	 * on this functionality can be found here: 
	 * 
	 *   http://developer.linkedin.com/docs/DOC-1009
	 *   http://developer.linkedin.com/docs/DOC-1009#comment-1077 
	 * 
	 * @param str $update
	 *    The network update.	 
	 * 
	 * @return arr 
	 *    Array containing retrieval success, LinkedIn response.       	 
	 */
	public function updateNetwork($update) {
	  // check passed data
    if(!is_string($update)) {
      // nothing/non-string passed, raise an exception
		  throw new LinkedInException('LinkedIn->updateNetwork(): bad data passed, $update must be a non-zero length string.');
    }
    
    /**
     * Network update is not empty, wrap a cleaned version of it in xml.  
     * Network update rules:
     * 
     * 1) No HTML permitted except those found in _NETWORK_HTML constant
     * 2) Update cannot be longer than 140 characters.     
     */
    // get the user data
    $response = self::profile('~:(first-name,last-name,site-standard-profile-request)');
    if($response['success'] === TRUE) {
      /** 
       * We are converting response to usable data.  I'd use SimpleXML here, but
       * to keep the class self-contained, we will use a portable XML parsing
       * routine, self::xmlToArray.       
       */
      $person = self::xmlToArray($response['linkedin']);
      if($person === FALSE) {
        // bad xml data
        throw new LinkedInException('LinkedIn->updateNetwork(): LinkedIn returned bad XML data.');
      }
  		$fields = $person['person']['children'];
  
  		// prepare user data
  		$first_name   = trim($fields['first-name']['content']);
  		$last_name    = trim($fields['last-name']['content']);
  		$profile_url  = trim($fields['site-standard-profile-request']['children']['url']['content']);
  
      // create the network update 
      $update = trim(htmlspecialchars(strip_tags($update, self::_NETWORK_HTML)));
      if(strlen($update) > self::_NETWORK_LENGTH) {
        throw new LinkedInException('LinkedIn->share(): update length is too long - max length is ' . self::_NETWORK_LENGTH . ' characters.');
      }
      $user   = htmlspecialchars('<a href="' . $profile_url . '">' . $first_name . ' ' . $last_name . '</a>');
  		$data   = '<activity locale="en_US">
    				       <content-type>linkedin-html</content-type>
    				       <body>' . $user . ' ' . $update . '</body>
    				     </activity>';
  
      // send request
      $query    = self::_URL_API . '/v1/people/~/person-activities';
      $response = $this->fetch('POST', $query, $data);
      
      /**
  	   * Check for successful request (a 201 response from LinkedIn server) 
  	   * per the documentation linked in method comments above.
  	   */ 
      return $this->checkResponse(201, $response);
    } else {
      // profile retrieval failed
      throw new LinkedInException('LinkedIn->updateNetwork(): profile data could not be retrieved.');
    }
	}
	
  /**
	 * General network update retrieval function.
	 * 
	 * Takes a string of parameters as input and requests update-related data 
	 * from the Linkedin Network Updates API. See the official documentation for 
	 * $options parameter formatting:
	 * 
	 *   http://developer.linkedin.com/docs/DOC-1006
	 * 
	 * For getting more comments, likes, etc, see here:
	 * 
	 *   http://developer.linkedin.com/docs/DOC-1043         	 
	 * 
	 * @param str $options 
	 *    [OPTIONAL] Data retrieval options.
	 * @param str $id 
	 *    [OPTIONAL] The LinkedIn ID to restrict the updates for.
	 *               	 
	 * @return arr
	 *    Array containing retrieval success, LinkedIn response.
	 */
	public function updates($options = NULL, $id = NULL) {
	  // check passed data
    if(!is_null($options) && !is_string($options)) {
	    // bad data passed
		  throw new LinkedInException('LinkedIn->updates(): bad data passed, $options must be of type string.');
	  }
	  if(!is_null($id) && !is_string($id)) {
	    // bad data passed
		  throw new LinkedInException('LinkedIn->updates(): bad data passed, $id must be of type string.');
	  }
	  
	  // construct and send the request
	  if(!is_null($id) && self::isId($id)) {
	    $query = self::_URL_API . '/v1/people/' . $id . '/network/updates' . trim($options);
	  } else {
      $query = self::_URL_API . '/v1/people/~/network/updates' . trim($options);
    }
	  $response = $this->fetch('GET', $query);
	  
	  /**
	   * Check for successful request (a 200 response from LinkedIn server) 
	   * per the documentation linked in method comments above.
	   */
	  return $this->checkResponse(200, $response);
	}
	
	/**
	 * Converts passed XML data to an array.
	 * 
	 * @param str $xml 
	 *    The XML to convert to an array.
	 *            	 
	 * @return arr 
	 *    Array containing the XML data.     
	 * @return bool 
	 *    FALSE if passed data cannot be parsed to an array.     	 
	 */
	public static function xmlToArray($xml) {
	  // check passed data
    if(!is_string($xml)) {
	    // bad data possed
      throw new LinkedInException('LinkedIn->xmlToArray(): bad data passed, $xml must be a non-zero length string.');
	  }
	  
	  $parser = xml_parser_create();
	  xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
    xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
    if(xml_parse_into_struct($parser, $xml, $tags)) {
	    $elements = array();
      $stack    = array();
      foreach($tags as $tag) {
        $index = count($elements);
        if($tag['type'] == 'complete' || $tag['type'] == 'open') {
          $elements[$tag['tag']]               = array();
          $elements[$tag['tag']]['attributes'] = (array_key_exists('attributes', $tag)) ? $tag['attributes'] : NULL;
          $elements[$tag['tag']]['content']    = (array_key_exists('value', $tag)) ? $tag['value'] : NULL;
          if($tag['type'] == 'open') {
            $elements[$tag['tag']]['children'] = array();
            $stack[count($stack)] = &$elements;
            $elements = &$elements[$tag['tag']]['children'];
          }
        }
        if($tag['type'] == 'close') {
          $elements = &$stack[count($stack) - 1];
          unset($stack[count($stack) - 1]);
        }
      }
      $return_data = $elements;
	  } else {
	    // not valid xml data
	    $return_data = FALSE;
	  }
	  xml_parser_free($parser);
    return $return_data;
  }
}