-
-
Notifications
You must be signed in to change notification settings - Fork 598
Add support for asset creation #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -41,6 +43,52 @@ public function show($username, $repository, $id) | |||
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/assets/'.rawurlencode($id)); | |||
} | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blank line should be removed
Please use 4-spaces indentation for methods bodies instead of 2-spaces |
@@ -43,6 +43,25 @@ public function shouldGetSingleReleaseAsset() | |||
/** | |||
* @test | |||
*/ | |||
public function shouldCreateReleaseAsset() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://travis-ci.org/KnpLabs/php-github-api/jobs/13906045 skip it for 5.3.3
Thanks for the comments @cursedcoder. I have fixed the broken test and the code style issues. I am still unable to actually upload an asset using the new method. Uploading with cURL works fine. |
@kasperg that because body is posted as json hash, you will need to define new method like |
Thank you for the suggestion. I will look into that. |
When receiving a validation error (as in KnpLabs#86) there is no `X-RateLimit-Remaining` header included with the response. That is quite confusing. Here `$remaining` when cast to a string is set to "" (empty string). This does not strictly equal null and thus a `ApiLimitExceedException` is thrown. This change fixes this behavior. cURL requests/responses: ``` # Request: POST /repos/kasperg/release-asset-test/releases/92217/assets?name=test2.txt HTTP/1.1 Host: uploads.github.com 0: Accept: application/vnd.github.v3+json 1: User-Agent: php-github-api (http://github.com/KnpLabs/php-github-api) Content-Type: text/plain, text/plain User-Agent: Guzzle/3.7.4 curl/7.30.0 PHP/5.3.27 Authorization: Basic a2FzcGVyZzpwaW5rbW9ucw== Content-Length: 14 {"body":"122"} # Response: HTTP/1.1 422 status code 422 Cache-Control: no-cache Content-Length: 214 Content-Type: application/json; charset=utf-8 X-Content-Type-Options: nosniff X-Github-Media-Type: github.beta; format=json X-Github-Request-Id: a6633df9-4dff-11e3-800a-0be28f962e12 Date: Fri, 15 Nov 2013 14:10:15 GMT {"message":"Validation Failed","request_id":"a6633df9-4dff-11e3-800a-0be28f962e12","documentation_url":"http://developer.github.com/v3","errors":[{"resource":"ReleaseAsset","code":"already_exists","field":"name"}]} ```
@kasperg please try this patch https://gist.github.com/cursedcoder/7506314 |
When receiving a validation error (as in KnpLabs#86) there is no `X-RateLimit-Remaining` header included with the response. That is quite confusing. Here `$remaining` when cast to a string is set to "" (empty string). This does not strictly equal null and thus a `ApiLimitExceedException` is thrown. This change fixes this behavior. cURL requests/responses: ``` # Request: POST /repos/kasperg/release-asset-test/releases/92217/assets?name=test2.txt HTTP/1.1 Host: uploads.github.com 0: Accept: application/vnd.github.v3+json 1: User-Agent: php-github-api (http://github.com/KnpLabs/php-github-api) Content-Type: text/plain, text/plain User-Agent: Guzzle/3.7.4 curl/7.30.0 PHP/5.3.27 Authorization: Basic a2FzcGVyZzpwaW5rbW9ucw== Content-Length: 14 {"body":"122"} # Response: HTTP/1.1 422 status code 422 Cache-Control: no-cache Content-Length: 214 Content-Type: application/json; charset=utf-8 X-Content-Type-Options: nosniff X-Github-Media-Type: github.beta; format=json X-Github-Request-Id: a6633df9-4dff-11e3-800a-0be28f962e12 Date: Fri, 15 Nov 2013 14:10:15 GMT {"message":"Validation Failed","request_id":"a6633df9-4dff-11e3-800a-0be28f962e12","documentation_url":"http://developer.github.com/v3","errors":[{"resource":"ReleaseAsset","code":"already_exists","field":"name"}]} ```
@cursedcoder Thanks for the suggestion. It's a simple solution which should would work. Before I saw this I started working on some a more serious refactoring which moves JSON encoding from Let me know what you think goes best with the structure of the project. |
* @param $parameters Request parameters | ||
* @return null|string | ||
*/ | ||
protected function createJsonBody(array $parameters) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curly brace should be on next line
@kasperg PR looks good |
Great! I'll clean up the commit history a bit and then it should be good to go. |
… encoded parameters. This is needed to support Asset creation where the request body must be the content of the asset. This involves the following changes - Updated HttpClient methods to accept an untyped body instead of an array of parameters - Moved JSON encoding to AbstractApi and updated documentation accordingly - Updated test cases
Added coresponding unit test for PHP 5.3.4 or newer. SSL extensions are not fully working for 5.3.3. See travis-ci/travis-ci#1385. Updated documentation to show that Asset creation is now supported.
Add support for asset creation
merged, thanks @kasperg |
Based on #85 I have taken a first stab at support for creating assets.
I do not have that much experience using this library or its code style so feedback would be much appreciated.
The related test case passes but I have tried to create an actual asset using the following code:
This fails with the following exception. I am unsure why.
Github\Exception\RuntimeException: You have reached GitHub hour limit! Actual limit is: 5000 in /Users/kasper/Code/php-github-api/lib/Github/HttpClient/HttpClient.php on line 138
The corresponding cURL request works fine:
curl --user "kasperg" -H "Content-Type: text/plain" --data-binary test.txt "https://uploads.github.com/repos/kasperg/release-asset-test/releases/92217/assets?name=test1.txt"
If we at some point decide to merge this, the documentation will have to be updated as well.