| @@ 24-74 (lines=51) @@ | ||
| 21 | * |
|
| 22 | * @since 1.0 |
|
| 23 | */ |
|
| 24 | 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 | ||
| @@ 20-72 (lines=53) @@ | ||
| 17 | * |
|
| 18 | * @since 1.0 |
|
| 19 | */ |
|
| 20 | class Commits extends AbstractPackage |
|
| 21 | { |
|
| 22 | /** |
|
| 23 | * Get a Commit. |
|
| 24 | * |
|
| 25 | * @param string $owner The name of the owner of the GitHub repository. |
|
| 26 | * @param string $repo The name of the GitHub repository. |
|
| 27 | * @param string $sha The commit SHA. |
|
| 28 | * |
|
| 29 | * @return object |
|
| 30 | */ |
|
| 31 | public function get($owner, $repo, $sha) |
|
| 32 | { |
|
| 33 | // Build the request path. |
|
| 34 | $path = '/repos/' . $owner . '/' . $repo . '/git/commits/' . $sha; |
|
| 35 | ||
| 36 | return $this->processResponse( |
|
| 37 | $this->client->get($this->fetchUrl($path)) |
|
| 38 | ); |
|
| 39 | } |
|
| 40 | ||
| 41 | /** |
|
| 42 | * Create a Commit. |
|
| 43 | * |
|
| 44 | * @param string $owner The name of the owner of the GitHub repository. |
|
| 45 | * @param string $repo The name of the GitHub repository. |
|
| 46 | * @param string $message The commit message. |
|
| 47 | * @param string $tree SHA of the tree object this commit points to. |
|
| 48 | * @param array $parents Array of the SHAs of the commits that were the parents of this commit. |
|
| 49 | * If omitted or empty, the commit will be written as a root commit. |
|
| 50 | * For a single parent, an array of one SHA should be provided. |
|
| 51 | * For a merge commit, an array of more than one should be provided. |
|
| 52 | * |
|
| 53 | * @since 1.0 |
|
| 54 | * |
|
| 55 | * @return object |
|
| 56 | */ |
|
| 57 | public function create($owner, $repo, $message, $tree, array $parents = array()) |
|
| 58 | { |
|
| 59 | // Build the request path. |
|
| 60 | $path = '/repos/' . $owner . '/' . $repo . '/git/commits'; |
|
| 61 | ||
| 62 | $data = json_encode( |
|
| 63 | array('message' => $message, 'tree' => $tree, 'parents' => $parents) |
|
| 64 | ); |
|
| 65 | ||
| 66 | // Send the request. |
|
| 67 | return $this->processResponse( |
|
| 68 | $response = $this->client->post($this->fetchUrl($path), $data), |
|
| 69 | 201 |
|
| 70 | ); |
|
| 71 | } |
|
| 72 | } |
|
| 73 | ||