1 <?php
2 /**
3 * @package Joomla.Platform
4 * @subpackage GitHub
5 *
6 * @copyright Copyright (C) 2005 - 2017 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 Gitignore class for the Joomla Platform.
14 *
15 * The .gitignore Templates API lists and fetches templates from the GitHub .gitignore repository.
16 *
17 * @documentation https://developer.github.com/v3/gitignore/
18 * @documentation https://github.com/github/gitignore
19 *
20 * @since 12.4
21 * @deprecated 4.0 Use the `joomla/github` package via Composer instead
22 */
23 class JGithubPackageGitignore extends JGithubPackage
24 {
25 /**
26 * Listing available templates
27 *
28 * List all templates available to pass as an option when creating a repository.
29 *
30 * @since 3.3 (CMS)
31 *
32 * @return object
33 */
34 public function getList()
35 {
36 // Build the request path.
37 $path = '/gitignore/templates';
38
39 return $this->processResponse(
40 $this->client->get($this->fetchUrl($path))
41 );
42 }
43
44 /**
45 * Get a single template
46 *
47 * @param string $name The name of the template
48 * @param boolean $raw Raw output
49 *
50 * @throws DomainException
51 * @since 3.3 (CMS)
52 *
53 * @return mixed|string
54 */
55 public function get($name, $raw = false)
56 {
57 // Build the request path.
58 $path = '/gitignore/templates/' . $name;
59
60 $headers = array();
61
62 if ($raw)
63 {
64 $headers['Accept'] = 'application/vnd.github.raw+json';
65 }
66
67 $response = $this->client->get($this->fetchUrl($path), $headers);
68
69 // Validate the response code.
70 if ($response->code != 200)
71 {
72 // Decode the error response and throw an exception.
73 $error = json_decode($response->body);
74 $message = (isset($error->message)) ? $error->message : 'Invalid response';
75
76 throw new DomainException($message, $response->code);
77 }
78
79 return ($raw) ? $response->body : json_decode($response->body);
80 }
81 }
82