-
Notifications
You must be signed in to change notification settings - Fork 215
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
Add return request object #278
Conversation
@@ -25,7 +25,7 @@ public function testSignup() | |||
$api = new Authentication($env['DOMAIN'], $env['APP_CLIENT_ID']); | |||
|
|||
$email = $this->email; | |||
$password = '123-xxx-23A-bar'; | |||
$password = 'Bqn8LEsu68p38TmFvsWW'; |
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.
Password was not passing the security policy.
@@ -46,7 +51,7 @@ public function testAuthorizeWithRO() | |||
|
|||
$this->assertArrayHasKey('email', $userinfo); | |||
$this->assertArrayHasKey('email_verified', $userinfo); | |||
$this->assertArrayHasKey('user_id', $userinfo); | |||
$this->assertArrayHasKey('sub', $userinfo); |
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.
sub
is a better key to check, will exist whether using Legacy or not.
fa88d71
to
1efe8a3
Compare
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.
Why add so much vs saying just returning the response headers, which is what was asked for?
Does the developer have to make multiple requests to retrieve different pieces of info?
@@ -1,101 +1,133 @@ | |||
<?php | |||
/** |
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.
When you lowkey removing German 😆
src/API/Helpers/RequestBuilder.php
Outdated
* | ||
* @var array | ||
*/ | ||
protected $returnTypes = [ 'body', 'headers', 'object', 'protocolVersion', 'reasonPhrase', 'statusCode' ]; |
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.
Why so many options?
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.
Everything that Guzzle can return, might as well include them since the library is capable.
src/API/Helpers/RequestBuilder.php
Outdated
|
||
case 'body': | ||
default: | ||
$body = (string) $response->getBody(); |
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.
when it is not json?
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.
Not sure but no harm in checking
} | ||
|
||
if (! in_array($type, $this->returnTypes)) { | ||
throw new CoreException('Invalid returnType'); |
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.
How can this be thrown? It looks like type if missing is default to body
in the first check. So it will then pass the in_array check?
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.
You could pass in banana
and it wouldn't know what to return.
1efe8a3
to
6107947
Compare
@joshcanhelp can you please add a snippet showing how a single request would be done after this changes, and how all those "return types" are being accessible now? |
@cocojoe - Removed everything except @lbalmaceda - Added an example 👍 |
Great to see an example in description, we should use that more 👍 |
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.
LGTM
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This PR adds the ability to define a return type other than the data retrieved from the API. Return types supported match what Guzzle can return:
body
- Existing installs that do not define this type will default tobody
, which is an array fromjson_decode
. This preserves backwards-compat.headers
- Just the headers returned by the API call.object
- The complete Guzzle Response objectExample:
Specific changes:
returnType
protected var toApiClient
classreturnType
protected var toRequestBuilder
class along withreturnTypes
to define valid values.Closes #277.