1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Part of the Joomla Framework Github Package |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved. |
6
|
|
|
* @license GNU General Public License version 2 or later; see LICENSE |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Joomla\Github\Package\Data; |
10
|
|
|
|
11
|
|
|
use Joomla\Github\AbstractPackage; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* GitHub API Data Blobs class for the Joomla Framework. |
15
|
|
|
* |
16
|
|
|
* Since blobs can be any arbitrary binary data, the input and responses for the blob API |
17
|
|
|
* takes an encoding parameter that can be either utf-8 or base64. If your data cannot be |
18
|
|
|
* losslessly sent as a UTF-8 string, you can base64 encode it. |
19
|
|
|
* |
20
|
|
|
* @documentation http://developer.github.com/v3/git/blobs/ |
21
|
|
|
* |
22
|
|
|
* @since 1.0 |
23
|
|
|
*/ |
24
|
|
View Code Duplication |
class Blobs extends AbstractPackage |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Get a Blob. |
28
|
|
|
* |
29
|
|
|
* @param string $owner Repository owner. |
30
|
|
|
* @param string $repo Repository name. |
31
|
|
|
* @param string $sha The commit SHA. |
32
|
|
|
* |
33
|
|
|
* @return object |
34
|
|
|
* |
35
|
|
|
* @since 1.0 |
36
|
|
|
*/ |
37
|
|
|
public function get($owner, $repo, $sha) |
38
|
|
|
{ |
39
|
|
|
// Build the request path. |
40
|
|
|
$path = '/repos/' . $owner . '/' . $repo . '/git/blobs/' . $sha; |
41
|
|
|
|
42
|
|
|
return $this->processResponse( |
43
|
|
|
$this->client->get($this->fetchUrl($path)) |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Create a Blob. |
49
|
|
|
* |
50
|
|
|
* @param string $owner Repository owner. |
51
|
|
|
* @param string $repo Repository name. |
52
|
|
|
* @param string $content The content of the blob. |
53
|
|
|
* @param string $encoding The encoding to use. |
54
|
|
|
* |
55
|
|
|
* @return object |
56
|
|
|
* |
57
|
|
|
* @since 1.0 |
58
|
|
|
*/ |
59
|
|
|
public function create($owner, $repo, $content, $encoding = 'utf-8') |
60
|
|
|
{ |
61
|
|
|
// Build the request path. |
62
|
|
|
$path = '/repos/' . $owner . '/' . $repo . '/git/blobs'; |
63
|
|
|
|
64
|
|
|
$data = array( |
65
|
|
|
'content' => $content, |
66
|
|
|
'encoding' => $encoding |
67
|
|
|
); |
68
|
|
|
|
69
|
|
|
return $this->processResponse( |
70
|
|
|
$this->client->post($this->fetchUrl($path), json_encode($data)), |
71
|
|
|
201 |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.