Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Remove default Graph API version fallback #643

Merged
merged 14 commits into from
Dec 23, 2016

Conversation

SammyK
Copy link
Contributor

@SammyK SammyK commented Aug 29, 2016

This is a first step to knock out #608. I think in order to close that issue, we'll need to rethink how we're passing around the required vars. You can see I added a hard-coded fallback (temporarily) in FacebookRequest since the $graphVersion can be null and it's at the end of a long list of optional params.

Perhaps we could add a GraphEnvironment entity that would include the Graph version, FacebookApp, access token, etc. Then we could just pass around the GraphEnvironment entity instead of all these individual params. What do you think? :)

@SammyK SammyK added this to the 6.0.0 milestone Aug 29, 2016
@ghost ghost added the CLA Signed label Aug 29, 2016
Copy link
Contributor

@yguedidi yguedidi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @SammyK for this PR

@@ -74,13 +74,13 @@ class OAuth2Client
/**
* @param FacebookApp $app
* @param FacebookClient $client
* @param string|null $graphVersion The version of the Graph API to use.
* @param string $graphVersion The version of the Graph API to use.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong indentation :)

@@ -127,7 +122,6 @@ public function __construct(array $config = [])
$config = array_merge([
'app_id' => getenv(static::APP_ID_ENV_NAME),
'app_secret' => getenv(static::APP_SECRET_ENV_NAME),
'default_graph_version' => static::DEFAULT_GRAPH_VERSION,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd keep this with a null value, as this list of keys is like a doc of available options

@@ -141,6 +135,9 @@ public function __construct(array $config = [])
if (!$config['app_secret']) {
throw new FacebookSDKException('Required "app_secret" key not supplied in config and could not find fallback environment variable "' . static::APP_SECRET_ENV_NAME . '"');
}
if (empty($config['default_graph_version'])) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you keep the key above, then I'll check here like above, if (!$config['default_graph_version']) {, for consistency

@@ -102,7 +102,8 @@ public function __construct(FacebookApp $app = null, $accessToken = null, $metho
$this->setEndpoint($endpoint);
$this->setParams($params);
$this->setETag($eTag);
$this->graphVersion = $graphVersion ?: Facebook::DEFAULT_GRAPH_VERSION;
// @TODO Remove this fall-back
$this->graphVersion = $graphVersion ?: 'v2.7';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the way to handle this case is to allow null graph version in requests. This parameter is here to override the version given in the client, so it can be null, we just have to take care of this value when sending the request, falling back to the client version when this is null :)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello yguedidi! I have no certainties about this case version 2.8 yet and icoguinita for me, but I resolve to be with this team for sure has brilhates minds, we try faser tests, for and studying the case to come to perfection. I trust you guys the importate and not waste time, bad weather do quick pass worth every second. with an impeccable work. ok let's see what happens reversing from 2.7 to 2.8 ok

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -36,6 +36,8 @@

class FacebookTest extends \PHPUnit_Framework_TestCase
{
const DEFAULT_GRAPH_VERSION = 'v2.7';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be changed to 2.8 :)

@SammyK
Copy link
Contributor Author

SammyK commented Dec 16, 2016

Sorry for the delay @yguedidi! I've made the changes you requested and also updated the tests. :) Do you have any other thoughts on this one?

Copy link
Contributor

@yguedidi yguedidi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just two last comments, otherwise it looks good to me


$this->assertEquals($expectedUrl, $getUrl);

$postRequest = new FacebookRequest($app, 'foo_token', 'POST', '/bar', ['foo' => 'bar']);

$postUrl = $postRequest->getUrl();
$expectedUrl = '/' . Facebook::DEFAULT_GRAPH_VERSION . '/bar';
$expectedUrl = '/bar';

$this->assertEquals($expectedUrl, $postUrl);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add a case for a versionned request, as it useful in the case of batched request to use a different version than the one of the master request :)

@@ -36,9 +36,12 @@

class FacebookTest extends \PHPUnit_Framework_TestCase
{
const DEFAULT_GRAPH_VERSION = 'v2.8';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd remove this constant and hardcode it's value everywhere it's used. In tests, we do not need to maintain a consistent value across all tests.
BTW, that why I'd change the value to vX.X or v4.2 (haha), remember to change the value each time the Graph API gets updated is a pain.

@SammyK SammyK merged commit 0b076fb into facebookarchive:master Dec 23, 2016
@SammyK
Copy link
Contributor Author

SammyK commented Dec 23, 2016

Thanks as always @yguedidi! :)

@SammyK SammyK deleted the patch-608-force-graph-version branch December 23, 2016 15:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants