Source for file milestones.php

Documentation is available at milestones.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 Milestones class for the Joomla Platform.
  14.  *
  15.  * @package     Joomla.Platform
  16.  * @subpackage  GitHub
  17.  * @since       12.3
  18.  */
  19. {
  20.     /**
  21.      * Method to get the list of milestones for a repo.
  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   $state      The milestone state to retrieved.  Open (default) or closed.
  26.      * @param   string   $sort       Sort can be due_date (default) or completeness.
  27.      * @param   string   $direction  Direction is asc or desc (default).
  28.      * @param   integer  $page       The page number from which to get items.
  29.      * @param   integer  $limit      The number of items on a page.
  30.      *
  31.      * @return  array 
  32.      *
  33.      * @since   12.3
  34.      */
  35.     public function getList($user$repo$state 'open'$sort 'due_date'$direction 'desc'$page 0$limit 0)
  36.     {
  37.         // Build the request path.
  38.         $path '/repos/' $user '/' $repo '/milestones?';
  39.  
  40.         $path .= 'state=' $state;
  41.         $path .= '&sort=' $sort;
  42.         $path .= '&direction=' $direction;
  43.  
  44.         // Send the request.
  45.         $response $this->client->get($this->fetchUrl($path$page$limit));
  46.  
  47.         // Validate the response code.
  48.         if ($response->code != 200)
  49.         {
  50.             // Decode the error response and throw an exception.
  51.             $error json_decode($response->body);
  52.             throw new DomainException($error->message$response->code);
  53.         }
  54.  
  55.         return json_decode($response->body);
  56.     }
  57.  
  58.     /**
  59.      * Method to get a specific milestone.
  60.      *
  61.      * @param   string   $user         The name of the owner of the GitHub repository.
  62.      * @param   string   $repo         The name of the GitHub repository.
  63.      * @param   integer  $milestoneId  The milestone id to get.
  64.      *
  65.      * @return  object 
  66.      *
  67.      * @since   12.3
  68.      */
  69.     public function get($user$repo$milestoneId)
  70.     {
  71.         // Build the request path.
  72.         $path '/repos/' $user '/' $repo '/milestones/' . (int) $milestoneId;
  73.  
  74.         // Send the request.
  75.         $response $this->client->get($this->fetchUrl($path));
  76.  
  77.         // Validate the response code.
  78.         if ($response->code != 200)
  79.         {
  80.             // Decode the error response and throw an exception.
  81.             $error json_decode($response->body);
  82.             throw new DomainException($error->message$response->code);
  83.         }
  84.  
  85.         return json_decode($response->body);
  86.     }
  87.  
  88.     /**
  89.      * Method to create a milestone for a repository.
  90.      *
  91.      * @param   string   $user         The name of the owner of the GitHub repository.
  92.      * @param   string   $repo         The name of the GitHub repository.
  93.      * @param   integer  $title        The title of the milestone.
  94.      * @param   string   $state        Can be open (default) or closed.
  95.      * @param   string   $description  Optional description for milestone.
  96.      * @param   string   $due_on       Optional ISO 8601 time.
  97.      *
  98.      * @return  object 
  99.      *
  100.      * @since   12.3
  101.      */
  102.     public function create($user$repo$title$state null$description null$due_on null)
  103.     {
  104.         // Build the request path.
  105.         $path '/repos/' $user '/' $repo '/milestones';
  106.  
  107.         // Build the request data.
  108.         $data array(
  109.             'title' => $title
  110.         );
  111.  
  112.         if (!is_null($state))
  113.         {
  114.             $data['state'$state;
  115.         }
  116.  
  117.         if (!is_null($description))
  118.         {
  119.             $data['description'$description;
  120.         }
  121.  
  122.         if (!is_null($due_on))
  123.         {
  124.             $data['due_on'$due_on;
  125.         }
  126.  
  127.         $data json_encode($data);
  128.  
  129.         // Send the request.
  130.         $response $this->client->post($this->fetchUrl($path)$data);
  131.  
  132.         // Validate the response code.
  133.         if ($response->code != 201)
  134.         {
  135.             // Decode the error response and throw an exception.
  136.             $error json_decode($response->body);
  137.             throw new DomainException($error->message$response->code);
  138.         }
  139.  
  140.         return json_decode($response->body);
  141.     }
  142.  
  143.     /**
  144.      * Method to update a milestone.
  145.      *
  146.      * @param   string   $user         The name of the owner of the GitHub repository.
  147.      * @param   string   $repo         The name of the GitHub repository.
  148.      * @param   integer  $milestoneId  The id of the comment to update.
  149.      * @param   integer  $title        Optional title of the milestone.
  150.      * @param   string   $state        Can be open (default) or closed.
  151.      * @param   string   $description  Optional description for milestone.
  152.      * @param   string   $due_on       Optional ISO 8601 time.
  153.      *
  154.      * @return  object 
  155.      *
  156.      * @since   12.3
  157.      */
  158.     public function edit($user$repo$milestoneId$title null$state null$description null$due_on null)
  159.     {
  160.         // Build the request path.
  161.         $path '/repos/' $user '/' $repo '/milestones/' . (int) $milestoneId;
  162.  
  163.         // Build the request data.
  164.         $data array();
  165.  
  166.         if (!is_null($title))
  167.         {
  168.             $data['title'$title;
  169.         }
  170.  
  171.         if (!is_null($state))
  172.         {
  173.             $data['state'$state;
  174.         }
  175.  
  176.         if (!is_null($description))
  177.         {
  178.             $data['description'$description;
  179.         }
  180.  
  181.         if (!is_null($due_on))
  182.         {
  183.             $data['due_on'$due_on;
  184.         }
  185.  
  186.         $data json_encode($data);
  187.  
  188.         // Send the request.
  189.         $response $this->client->patch($this->fetchUrl($path)$data);
  190.  
  191.         // Validate the response code.
  192.         if ($response->code != 200)
  193.         {
  194.             // Decode the error response and throw an exception.
  195.             $error json_decode($response->body);
  196.             throw new DomainException($error->message$response->code);
  197.         }
  198.  
  199.         return json_decode($response->body);
  200.     }
  201.  
  202.     /**
  203.      * Method to delete a milestone.
  204.      *
  205.      * @param   string   $user         The name of the owner of the GitHub repository.
  206.      * @param   string   $repo         The name of the GitHub repository.
  207.      * @param   integer  $milestoneId  The id of the milestone to delete.
  208.      *
  209.      * @return  void 
  210.      *
  211.      * @since   12.3
  212.      */
  213.     public function delete($user$repo$milestoneId)
  214.     {
  215.         // Build the request path.
  216.         $path '/repos/' $user '/' $repo '/milestones/' . (int) $milestoneId;
  217.  
  218.         // Send the request.
  219.         $response $this->client->delete($this->fetchUrl($path));
  220.  
  221.         // Validate the response code.
  222.         if ($response->code != 204)
  223.         {
  224.             // Decode the error response and throw an exception.
  225.             $error json_decode($response->body);
  226.             throw new DomainException($error->message$response->code);
  227.         }
  228.     }
  229. }

Documentation generated on Tue, 19 Nov 2013 15:08:13 +0100 by phpDocumentor 1.4.3