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