Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
refs.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 11.3
18  */
20 {
21  /**
22  * Method to create an issue.
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 $ref The name of the fully qualified reference.
27  * @param string $sha The SHA1 value to set this reference to.
28  *
29  * @return object
30  *
31  * @since 11.3
32  */
33  public function create($user, $repo, $ref, $sha)
34  {
35  // Build the request path.
36  $path = '/repos/' . $user . '/' . $repo . '/git/refs';
37 
38  // Build the request data.
39  $data = json_encode(
40  array(
41  'ref' => $ref,
42  'sha' => $sha
43  )
44  );
45 
46  // Send the request.
47  $response = $this->client->post($this->fetchUrl($path), $data);
48 
49  // Validate the response code.
50  if ($response->code != 201)
51  {
52  // Decode the error response and throw an exception.
53  $error = json_decode($response->body);
54  throw new DomainException($error->message, $response->code);
55  }
56 
57  return json_decode($response->body);
58  }
59 
60  /**
61  * Method to update a reference.
62  *
63  * @param string $user The name of the owner of the GitHub repository.
64  * @param string $repo The name of the GitHub repository.
65  * @param string $ref The reference to update.
66  * @param string $sha The SHA1 value to set the reference to.
67  * @param string $force Whether the update should be forced. Default to false.
68  *
69  * @return object
70  *
71  * @since 11.3
72  */
73  public function edit($user, $repo, $ref, $sha, $force = false)
74  {
75  // Build the request path.
76  $path = '/repos/' . $user . '/' . $repo . '/git/refs/' . $ref;
77 
78  // Craete the data object.
79  $data = new stdClass;
80 
81  // If a title is set add it to the data object.
82  if ($force)
83  {
84  $data->force = true;
85  }
86 
87  $data->sha = $sha;
88 
89  // Encode the request data.
90  $data = json_encode($data);
91 
92  // Send the request.
93  $response = $this->client->patch($this->fetchUrl($path), $data);
94 
95  // Validate the response code.
96  if ($response->code != 200)
97  {
98  // Decode the error response and throw an exception.
99  $error = json_decode($response->body);
100  throw new DomainException($error->message, $response->code);
101  }
102 
103  return json_decode($response->body);
104  }
105 
106  /**
107  * Method to get a reference.
108  *
109  * @param string $user The name of the owner of the GitHub repository.
110  * @param string $repo The name of the GitHub repository.
111  * @param string $ref The reference to get.
112  *
113  * @return object
114  *
115  * @since 11.3
116  */
117  public function get($user, $repo, $ref)
118  {
119  // Build the request path.
120  $path = '/repos/' . $user . '/' . $repo . '/git/refs/' . $ref;
121 
122  // Send the request.
123  $response = $this->client->get($this->fetchUrl($path));
124 
125  // Validate the response code.
126  if ($response->code != 200)
127  {
128  // Decode the error response and throw an exception.
129  $error = json_decode($response->body);
130  throw new DomainException($error->message, $response->code);
131  }
132 
133  return json_decode($response->body);
134  }
135 
136  /**
137  * Method to list references for a repository.
138  *
139  * @param string $user The name of the owner of the GitHub repository.
140  * @param string $repo The name of the GitHub repository.
141  * @param string $namespace Optional sub-namespace to limit the returned references.
142  * @param integer $page Page to request
143  * @param integer $limit Number of results to return per page
144  *
145  * @return array
146  *
147  * @since 11.3
148  */
149  public function getList($user, $repo, $namespace = '', $page = 0, $limit = 0)
150  {
151  // Build the request path.
152  $path = '/repos/' . $user . '/' . $repo . '/git/refs' . $namespace;
153 
154  // Send the request.
155  $response = $this->client->get($this->fetchUrl($path, $page, $limit));
156 
157  // Validate the response code.
158  if ($response->code != 200)
159  {
160  // Decode the error response and throw an exception.
161  $error = json_decode($response->body);
162  throw new DomainException($error->message, $response->code);
163  }
164 
165  return json_decode($response->body);
166  }
167 }