Source for file users.php

Documentation is available at users.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Platform
  4.  * @subpackage  GitHub
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * GitHub API References class for the Joomla Platform.
  14.  *
  15.  * @package     Joomla.Platform
  16.  * @subpackage  GitHub
  17.  * @since       12.3
  18.  */
  19. class JGithubUsers extends JGithubObject
  20. {
  21.     /**
  22.      * Get a single user.
  23.      *
  24.      * @param   string  $user  The users login name.
  25.      *
  26.      * @throws DomainException
  27.      *
  28.      * @return mixed 
  29.      */
  30.     public function getUser($user)
  31.     {
  32.         // Build the request path.
  33.         $path '/users/' $user;
  34.  
  35.         // Send the request.
  36.         $response $this->client->get($this->fetchUrl($path));
  37.  
  38.         // Validate the response code.
  39.         if ($response->code != 200)
  40.         {
  41.             // Decode the error response and throw an exception.
  42.             $error json_decode($response->body);
  43.             throw new DomainException($error->message$response->code);
  44.         }
  45.  
  46.         return json_decode($response->body);
  47.     }
  48.  
  49.     /**
  50.      * Get the current authenticated user.
  51.      *
  52.      * @throws DomainException
  53.      *
  54.      * @return mixed 
  55.      */
  56.     public function getAuthenticatedUser()
  57.     {
  58.         // Build the request path.
  59.         $path '/user';
  60.  
  61.         // Send the request.
  62.         $response $this->client->get($this->fetchUrl($path));
  63.  
  64.         // Validate the response code.
  65.         if ($response->code != 200)
  66.         {
  67.             // Decode the error response and throw an exception.
  68.             $error json_decode($response->body);
  69.             throw new DomainException($error->message$response->code);
  70.         }
  71.  
  72.         return json_decode($response->body);
  73.     }
  74.  
  75.     /**
  76.      * Update a user.
  77.      *
  78.      * @param   string  $name      The full name
  79.      * @param   string  $email     The email
  80.      * @param   string  $blog      The blog
  81.      * @param   string  $company   The company
  82.      * @param   string  $location  The location
  83.      * @param   string  $hireable  If he is unemplayed :P
  84.      * @param   string  $bio       The biometrical DNA fingerprint (or smthng...)
  85.      *
  86.      * @throws DomainException
  87.      *
  88.      * @return mixed 
  89.      */
  90.     public function updateUser($name ''$email ''$blog ''$company ''$location ''$hireable ''$bio '')
  91.     {
  92.         $data array(
  93.             'name'     => $name,
  94.             'email'    => $email,
  95.             'blog'     => $blog,
  96.             'company'  => $company,
  97.             'location' => $location,
  98.             'hireable' => $hireable,
  99.             'bio'      => $bio
  100.         );
  101.  
  102.         // Build the request path.
  103.         $path '/user';
  104.  
  105.         // Send the request.
  106.         $response $this->client->patch($this->fetchUrl($path)json_encode($data));
  107.  
  108.         // Validate the response code.
  109.         if ($response->code != 200)
  110.         {
  111.             // Decode the error response and throw an exception.
  112.             $error json_decode($response->body);
  113.             throw new DomainException($error->message$response->code);
  114.         }
  115.  
  116.         return json_decode($response->body);
  117.     }
  118.  
  119.     /**
  120.      * Get all users.
  121.      *
  122.      * This provides a dump of every user, in the order that they signed up for GitHub.
  123.      *
  124.      * @param   integer  $since  The integer ID of the last User that you’ve seen.
  125.      *
  126.      * @throws DomainException
  127.      * @return mixed 
  128.      */
  129.     public function getUsers($since 0)
  130.     {
  131.         // Build the request path.
  132.         $path '/users';
  133.  
  134.         $path .= ($since'?since=' $since '';
  135.  
  136.         // Send the request.
  137.         $response $this->client->get($this->fetchUrl($path));
  138.  
  139.         // Validate the response code.
  140.         if ($response->code != 200)
  141.         {
  142.             // Decode the error response and throw an exception.
  143.             $error json_decode($response->body);
  144.             throw new DomainException($error->message$response->code);
  145.         }
  146.  
  147.         return json_decode($response->body);
  148.     }
  149.  
  150. }

Documentation generated on Tue, 19 Nov 2013 15:16:42 +0100 by phpDocumentor 1.4.3