@@ 156-195 (lines=40) @@ | ||
153 | * |
|
154 | * @return object |
|
155 | */ |
|
156 | public function create($owner, $repo, $path, $message, $content, $branch = 'master', |
|
157 | $authorName = '', $authorEmail = '', $committerName = '', $committerEmail = '') |
|
158 | { |
|
159 | // Build the request path. |
|
160 | $route = '/repos/' . $owner . '/' . $repo . '/contents/' . $path; |
|
161 | ||
162 | $data = array( |
|
163 | 'message' => $message, |
|
164 | 'content' => $content, |
|
165 | 'branch' => $branch |
|
166 | ); |
|
167 | ||
168 | if ($authorName) |
|
169 | { |
|
170 | if (!$authorEmail) |
|
171 | { |
|
172 | throw new \UnexpectedValueException('You must provide an author e-mail if you supply an author name'); |
|
173 | } |
|
174 | ||
175 | $data['author'] = array( |
|
176 | 'name' => $authorName, |
|
177 | 'email' => $authorEmail |
|
178 | ); |
|
179 | } |
|
180 | ||
181 | if ($committerName) |
|
182 | { |
|
183 | if (!$committerEmail) |
|
184 | { |
|
185 | throw new \UnexpectedValueException('You must provide a committer e-mail if you supply a committer name'); |
|
186 | } |
|
187 | ||
188 | $data['committer'] = array( |
|
189 | 'name' => $committerName, |
|
190 | 'email' => $committerEmail |
|
191 | ); |
|
192 | } |
|
193 | ||
194 | return $this->processResponse($this->client->put($this->fetchUrl($route), json_encode($data)), 201); |
|
195 | } |
|
196 | ||
197 | /** |
|
198 | * Update a file. |
|
@@ 226-266 (lines=41) @@ | ||
223 | * |
|
224 | * @return object |
|
225 | */ |
|
226 | public function update($owner, $repo, $path, $message, $content, $sha, $branch = 'master', |
|
227 | $authorName = '', $authorEmail = '', $committerName = '', $committerEmail = '') |
|
228 | { |
|
229 | // Build the request path. |
|
230 | $route = '/repos/' . $owner . '/' . $repo . '/contents/' . $path; |
|
231 | ||
232 | $data = array( |
|
233 | 'message' => $message, |
|
234 | 'content' => $content, |
|
235 | 'sha' => $sha, |
|
236 | 'branch' => $branch |
|
237 | ); |
|
238 | ||
239 | if ($authorName) |
|
240 | { |
|
241 | if (!$authorEmail) |
|
242 | { |
|
243 | throw new \UnexpectedValueException('You must provide an author e-mail if you supply an author name'); |
|
244 | } |
|
245 | ||
246 | $data['author'] = array( |
|
247 | 'name' => $authorName, |
|
248 | 'email' => $authorEmail |
|
249 | ); |
|
250 | } |
|
251 | ||
252 | if ($committerName) |
|
253 | { |
|
254 | if (!$committerEmail) |
|
255 | { |
|
256 | throw new \UnexpectedValueException('You must provide a committer e-mail if you supply a committer name'); |
|
257 | } |
|
258 | ||
259 | $data['committer'] = array( |
|
260 | 'name' => $committerName, |
|
261 | 'email' => $committerEmail |
|
262 | ); |
|
263 | } |
|
264 | ||
265 | return $this->processResponse($this->client->put($this->fetchUrl($route), json_encode($data))); |
|
266 | } |
|
267 | ||
268 | /** |
|
269 | * Delete a file. |
|
@@ 289-333 (lines=45) @@ | ||
286 | * |
|
287 | * @return object |
|
288 | */ |
|
289 | public function delete($owner, $repo, $path, $message, $sha, $branch = 'master', |
|
290 | $authorName = '', $authorEmail = '', $committerName = '', $committerEmail = '') |
|
291 | { |
|
292 | // Build the request path. |
|
293 | $route = '/repos/' . $owner . '/' . $repo . '/contents/' . $path; |
|
294 | ||
295 | $data = array( |
|
296 | 'message' => $message, |
|
297 | 'sha' => $sha, |
|
298 | 'branch' => $branch |
|
299 | ); |
|
300 | ||
301 | if ($authorName) |
|
302 | { |
|
303 | if (!$authorEmail) |
|
304 | { |
|
305 | throw new \UnexpectedValueException('You must provide an author e-mail if you supply an author name'); |
|
306 | } |
|
307 | ||
308 | $data['author'] = array( |
|
309 | 'name' => $authorName, |
|
310 | 'email' => $authorEmail |
|
311 | ); |
|
312 | } |
|
313 | ||
314 | if ($committerName) |
|
315 | { |
|
316 | if (!$committerEmail) |
|
317 | { |
|
318 | throw new \UnexpectedValueException('You must provide a committer e-mail if you supply a committer name'); |
|
319 | } |
|
320 | ||
321 | $data['committer'] = array( |
|
322 | 'name' => $committerName, |
|
323 | 'email' => $committerEmail |
|
324 | ); |
|
325 | } |
|
326 | ||
327 | return $this->processResponse( |
|
328 | $this->client->delete( |
|
329 | $this->fetchUrl($route), |
|
330 | array(), null, json_encode($data) |
|
331 | ) |
|
332 | ); |
|
333 | } |
|
334 | } |
|
335 |