@@ -41,7 +41,7 @@ around the GitHub API v3. This is achieved using a number of methods:
4141The following resources for the API are covered:
4242
4343 * [ Users API] ( http://developer.github.com/v3/users/ )
44-
44+
4545### Requirements
4646
4747 * PHP5+
@@ -50,7 +50,7 @@ The following resources for the API are covered:
5050### Dependancies
5151
5252 * [ curl-php] ( https://github.com/dsyph3r/curl-php )
53-
53+
5454### Installation
5555
5656```` bash
@@ -208,4 +208,373 @@ Unfollow a user for the authenticated user. Returns `TRUE` if user was unfollowe
208208
209209``` php
210210 $response = $user->unfollow('octocat');
211- ```
211+ ```
212+
213+ ### Access user related API's
214+
215+ Each API can be used independent of other API's. However, proxy methods can be used
216+ to access related API's such as ` Emails ` for a ` User ` . The ` User ` API provides the following
217+ proxies.
218+
219+ ``` php
220+ // Access email API
221+ $user->emails();
222+
223+ // Access keys API
224+ $user->keys();
225+
226+ // Access repos API
227+ $user->repos();
228+
229+ // Access gists API
230+ $user->gists();
231+ ```
232+
233+ ## User Emails
234+
235+ Perform operations on authenticated users emails.
236+
237+ GitHub API Documentation - [ User Email API] ( http://developer.github.com/v3/users/emails/ ) .
238+
239+ The email API can be used independently of the other API's as follows:
240+
241+ ``` php
242+ $email = new Email();
243+ $response = $email->all();
244+ ```
245+
246+ However, as emails are related to the user you can also access the email API via the
247+ user as follows:
248+
249+ ``` php
250+ $user = new User();
251+ $response = $user->emails()->all();
252+ ```
253+
254+ There are a number of benefits to this approach including increased readability, and
255+ authentication being carried across from each independent API, i.e. you don't
256+ have to authenticated the user and the email API.
257+
258+ ### List emails
259+
260+ List all email addresses for authenticated user.
261+
262+ ``` php
263+ $response = $user->emails()->all();
264+ ```
265+
266+ ### Add email address(es)
267+
268+ Adds single or multiple address(es) for the authenticated user. On success returns
269+ list of all email address for user. On failure returns ` FALSE ` . This operation
270+ can fail if email addresses already exist for the user.
271+
272+ ``` php
273+ // Add single
274+ $response = $user->emails()->create('dsyph3r@gmail.com');
275+ // Add multiple
276+ $response = $user->emails()->create(array('dsyph3r@gmail.com', 'octocat@github.com'));
277+ ```
278+
279+ ### Delete email address(es)
280+
281+ Deletes single or multiple address(es) for the authenticated user. On success returns
282+ ` TRUE ` .
283+
284+ ``` php
285+ // Delete single
286+ $response = $user->emails()->delete('dsyph3r@gmail.com');
287+ // Delete multiple
288+ $response = $user->emails()->delete(array('dsyph3r@gmail.com', 'octocat@github.com'));
289+ ```
290+
291+ ## User Keys
292+
293+ Perform operations on authenticated users keys.
294+
295+ GitHub API Documentation - [ User Keys API] ( http://developer.github.com/v3/users/keys/ ) .
296+
297+ The keys API can be used independently of the other API's as follows:
298+
299+ ``` php
300+ $key = new Keys();
301+ $response = $key->all();
302+ ```
303+
304+ However, as keys are related to the user you can also access the keys API via the
305+ user as follows:
306+
307+ ``` php
308+ $user = new User();
309+ $response = $user->keys()->all();
310+ ```
311+
312+ ### List keys
313+
314+ List all keys for authenticated user.
315+
316+ ``` php
317+ $response = $user->keys()->all();
318+ ```
319+
320+ ### Get key
321+
322+ Get a key for authenticated user by key ID.
323+
324+ ``` php
325+ $response = $user->keys()->get(1);
326+ ```
327+
328+ ### Add key
329+
330+ Adds a key for authenticated user. On success returns the created key.
331+ On failure returns ` FALSE ` . This operation can fail if the key is invalid.
332+
333+ ``` php
334+ $response = $user->keys()->create('desktop@dsyph3r', 'ssh-rsa ABCDEF');
335+ ```
336+
337+ ### Update key
338+
339+ Update a key for authenticated user by key ID. On success returns the updated key.
340+ On failure returns ` FALSE ` . This operation can fail if the key is invalid.
341+
342+ ``` php
343+ $response = $user->keys()->update(1, 'desktop@dsyph3r', 'ssh-rsa FEDCBA');
344+ ```
345+
346+ ### Delete key
347+
348+ Delete a key for authenticated user by ID. On success returns ` TRUE ` .
349+
350+ ``` php
351+ $response = $user->keys()->delete(1);
352+ ```
353+
354+ ## Gists
355+
356+ Perform operations on gists.
357+
358+ GitHub API Documentation - [ Gists API] ( http://developer.github.com/v3/gists/ ) .
359+
360+ The gists API can be used independently of the other API's as follows:
361+
362+ ``` php
363+ $gist = new Gist();
364+ $response = $gist->all();
365+ ```
366+
367+ ### List gists
368+
369+ List all public gists. No authentication required.
370+
371+ ``` php
372+ $response = $gist->all();
373+ ```
374+
375+ List all public gists for a user
376+
377+ ``` php
378+ $response = $gist->all('dsph3r');
379+ ```
380+
381+ List all public gists for authenticated user.
382+
383+ ``` php
384+ $gist->login();
385+ $response = $gist->all();
386+ ```
387+
388+ List all starred gists for authenticated user.
389+
390+ ``` php
391+ $gist->login();
392+ $response = $gist->all(null, Api::GIST_TYPE_STARRED);
393+ ```
394+
395+ All above operations return paginated results. Accessing paginated results is as follows.
396+
397+ ``` php
398+ $response = $gist->all('dsyph3r', Api::GIST_TYPE_PUBLIC, 2, 50); // Get page 2, 50 results per page
399+ ```
400+
401+ ### Get gist
402+
403+ Get a gist. Authentication maybe required depending on the gist permissions, ie. Private gist
404+
405+ ``` php
406+ $response = $gist->get(1);
407+ ```
408+
409+ ### Create gist
410+
411+ Creates a gist for authenticated user. On success returns the created gist.
412+ On failure returns ` FALSE ` .
413+
414+ Gists contain files and should be passed in as an array.
415+
416+ ``` php
417+ $files = array(
418+ 'file1.txt' => array(
419+ 'content' => 'File 1 contents',
420+ ),
421+ 'file2.txt' => array(
422+ 'content' => 'File 2 contents',
423+ ),
424+ );
425+ $response = $gist->create($files, true, "Gist description");
426+ ```
427+
428+ ### Update gist
429+
430+ Updates a gist for authenticated user. On success returns the updated gist.
431+ On failure returns ` FALSE ` .
432+
433+ Gists contain files and should be passed in as an array. Setting a filename
434+ key value to null will removed the file from the gist. Leaving filename keys
435+ out will cause no update to the gist file.
436+
437+ ``` php
438+ $files = array(
439+ 'file1.txt' => array(
440+ // Update the contents of this file
441+ 'content' => 'File 1 contents update',
442+ ),
443+ // This file will be removed from gist
444+ 'file2.txt' => null,
445+ );
446+ $response = $gist->update(1, $files, "Gist description update");
447+ ```
448+
449+ ### Star gist
450+
451+ Star a gist for the authenticated user. Returns ` TRUE ` if gist was starred.
452+
453+ ``` php
454+ $response = $gist->star(1);
455+ ```
456+
457+ ### Unstar gist
458+
459+ Unstar a gist for the authenticated user. Returns ` TRUE ` if gist was unstarred.
460+
461+ ``` php
462+ $response = $gist->unstar(1);
463+ ```
464+
465+ ### Check gist is starred
466+
467+ Check if gist is starred for the authenticated user. Returns ` TRUE ` if gist is starred.
468+
469+ ``` php
470+ $response = $gist->isStarred(1);
471+ ```
472+
473+ ### Fork gist
474+
475+ Fork a gist for the authenticated user. Returns ` TRUE ` if gist was forked.
476+
477+ ``` php
478+ $response = $gist->fork(1);
479+ ```
480+
481+ ### Delete gist
482+
483+ Delete a gist for the authenticated user. Returns ` TRUE ` if gist was deleted.
484+
485+ ``` php
486+ $response = $gist->delete(1);
487+ ```
488+
489+ ### Access gists related API's
490+
491+ Each API can be used independent of other API's. However, proxy methods can be used
492+ to access related API's such as ` Comments ` for a ` Gist ` . The ` Gist ` API provides the following
493+ proxies.
494+
495+ ``` php
496+ // Access gist comments API
497+ $gist->comments();
498+ ```
499+
500+ ## Gist Comments
501+
502+ Perform operations on gist comments.
503+
504+ GitHub API Documentation - [ Gists Comments API] ( http://developer.github.com/v3/gists/comments/ ) .
505+
506+ The gists comments API can be used independently of the other API's as follows:
507+
508+ ``` php
509+ $comment = new GistComment();
510+ $response = $comment->all();
511+ ```
512+
513+ However, as comments are related to the gists you can also access the comments API via the
514+ gist as follows:
515+
516+ ``` php
517+ $gist = new Gist();
518+ $response = $gist->comments()->all();
519+ ```
520+
521+ ### Custom Mime Types
522+
523+ Gist comments use [ custom mime types] ( http://developer.github.com/v3/gists/comments/#custom-mime-types )
524+ to return formatted results. Custom mime types can be passed in as an argument to most functions.
525+ Available formats are:
526+
527+ ``` php
528+ Api::FORMAT_RAW; // Default
529+ Api::FORMAT_TEXT;
530+ Api::FORMAT_HTML;
531+ Api::FORMAT_FULL;
532+ ```
533+
534+ ### List comments
535+
536+ List all comments for gist. Authentication maybe required depending on the gist permissions, ie. Private gist
537+
538+ ``` php
539+ $response = $gist->comments()->all(1);
540+ ```
541+
542+ Get the results in ` HTML ` format
543+
544+ ``` php
545+ $response = $gist->comments()->all(1, Api::FORMAT_HTML);
546+ ```
547+
548+ ### Get comment
549+
550+ Get a gist comment. Authentication maybe required depending on the gist permissions, ie. Private gist
551+
552+ ``` php
553+ $response = $gist->comments()->get(1);
554+ ```
555+
556+ ### Create comment
557+
558+ Creates a gist comment for authenticated user. On success returns the created comment.
559+ On failure returns ` FALSE ` .
560+
561+ ``` php
562+ $response = $gist->comments()->create(1, "Comment Body");
563+ ```
564+
565+ ### Update comment
566+
567+ Updates a gist comment for authenticated user. On success returns the updated comment.
568+ On failure returns ` FALSE ` .
569+
570+ ``` php
571+ $response = $gist->comments()->update(1, "Comment body update");
572+ ```
573+
574+ ### Delete comment
575+
576+ Delete a gist comment for the authenticated user. Returns ` TRUE ` if gist comment was deleted.
577+
578+ ``` php
579+ $response = $gist->comments()->delete(1);
580+ ```
0 commit comments