Source for file statuses.php

Documentation is available at statuses.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. {
  20.     /**
  21.      * Method to create a status.
  22.      *
  23.      * @param   string  $user         The name of the owner of the GitHub repository.
  24.      * @param   string  $repo         The name of the GitHub repository.
  25.      * @param   string  $sha          The SHA1 value for which to set the status.
  26.      * @param   string  $state        The state (pending, success, error or failure).
  27.      * @param   string  $targetUrl    Optional target URL.
  28.      * @param   string  $description  Optional description for the status.
  29.      *
  30.      * @return  object 
  31.      *
  32.      * @since   12.3
  33.      */
  34.     public function create($user$repo$sha$state$targetUrl null$description null)
  35.     {
  36.         // Build the request path.
  37.         $path '/repos/' $user '/' $repo '/statuses/' $sha;
  38.  
  39.         if (!in_array($statearray('pending''success''error''failure')))
  40.         {
  41.             throw new InvalidArgumentException('State must be one of pending, success, error or failure.');
  42.         }
  43.  
  44.         // Build the request data.
  45.         $data array(
  46.             'state' => $state
  47.         );
  48.  
  49.         if (!is_null($targetUrl))
  50.         {
  51.             $data['target_url'$targetUrl;
  52.         }
  53.  
  54.         if (!is_null($description))
  55.         {
  56.             $data['description'$description;
  57.         }
  58.  
  59.         // Send the request.
  60.         $response $this->client->post($this->fetchUrl($path)json_encode($data));
  61.  
  62.         // Validate the response code.
  63.         if ($response->code != 201)
  64.         {
  65.             // Decode the error response and throw an exception.
  66.             $error json_decode($response->body);
  67.             throw new DomainException($error->message$response->code);
  68.         }
  69.  
  70.         return json_decode($response->body);
  71.     }
  72.  
  73.     /**
  74.      * Method to list statuses for an SHA.
  75.      *
  76.      * @param   string  $user  The name of the owner of the GitHub repository.
  77.      * @param   string  $repo  The name of the GitHub repository.
  78.      * @param   string  $sha   SHA1 for which to get the statuses.
  79.      *
  80.      * @return  array 
  81.      *
  82.      * @since   12.3
  83.      */
  84.     public function getList($user$repo$sha)
  85.     {
  86.         // Build the request path.
  87.         $path '/repos/' $user '/' $repo '/statuses/' $sha;
  88.  
  89.         // Send the request.
  90.         $response $this->client->get($this->fetchUrl($path));
  91.  
  92.         // Validate the response code.
  93.         if ($response->code != 200)
  94.         {
  95.             // Decode the error response and throw an exception.
  96.             $error json_decode($response->body);
  97.             throw new DomainException($error->message$response->code);
  98.         }
  99.  
  100.         return json_decode($response->body);
  101.     }
  102. }

Documentation generated on Tue, 19 Nov 2013 15:14:21 +0100 by phpDocumentor 1.4.3