Skip to content

feat: Add init with sdk key #189

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

Merged
merged 5 commits into from
Apr 3, 2020
Merged

feat: Add init with sdk key #189

merged 5 commits into from
Apr 3, 2020

Conversation

oakbani
Copy link
Contributor

@oakbani oakbani commented Jan 24, 2020

Summary

  • This adds sdk key param to Optimizely constructor. The user can now create an Optimizely instance only using sdk key. Previously he was required to create a HTTPProjectConfigManager, and pass it as a config manager in the constructor.
  • The sdk key param in constructor params sequence has been set as last item as to not break.
  • Made configManager inside Optimizely class public so that the user is able to call fetch() which is a public method defined over HTTPProjectConfigManager.
  • Adds a factory method to create a client with sdk key and datafile.

todo
Update readme accordingly.

Test plan

  • Added unit tests to verify init with sdk key.

Issues

  • OASIS-5770

@coveralls
Copy link

coveralls commented Jan 24, 2020

Coverage Status

Coverage increased (+0.4%) to 98.239% when pulling 829a1d8 on oakbani/init-with-sdk-key into d5c038f on master.

@@ -122,6 +124,7 @@ public function __construct(
ErrorHandlerInterface $errorHandler = null,
$skipJsonValidation = false,
UserProfileServiceInterface $userProfileService = null,
$sdkKey = null,
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't this break previous versions since the order changed? Shouldn't this become the last parameter?

Also ok if we file this as a breaking change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just tried to be consistent with python and ruby sdks. I would recommend to go for a breaking change and make sdkKey the first param of constructor. What do you suggest?

@@ -96,7 +97,7 @@ class Optimizely
/**
* @var ProjectConfigManagerInterface
*/
private $_projectConfigManager;
public $configManager;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this have to be public now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

HTTPProjectConfigManager exposes a public method fetch, which the user can use to get the latest datafile from cdn. Previously, we were expecting the user to create it's own config manager and pass. Now, we will be creating httpconfigmanager given the sdk key so the user must be able to access it to fetch the latest datafile.

@oakbani oakbani requested a review from aliabbasrizvi March 10, 2020 04:55
@oakbani
Copy link
Contributor Author

oakbani commented Mar 20, 2020

@aliabbasrizvi and @msohailhussain Added a default instance method in OptimizelyFactory.


// client hasn't been mocked yet. Hence, config manager should return config of hardcoded
// datafile.
$this->assertEquals('15', $optimizelyClient->configManager->getConfig()->getRevision());
Copy link

Choose a reason for hiding this comment

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

We should mock it anyway, to prevent it from ever making a real HTTP request. Even if it won't because of hard coded datafile.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Given the way PHP Unit allows to use doubles, I don't think we can mock the first http call that a config manager makes when it's initialized inside Optly client. I can only mock and set a double, after the Optimizely client has been created and in that case, it has already made a real HTTP request.

@mjc1283 mjc1283 merged commit 0be9ae0 into master Apr 3, 2020
@oakbani oakbani deleted the oakbani/init-with-sdk-key branch April 6, 2020 14:21
jaeopt pushed a commit that referenced this pull request May 28, 2020
Summary:

- This adds sdk key param to Optimizely constructor. The user can now create an Optimizely instance only using sdk key. Previously he was required to create a HTTPProjectConfigManager, and pass it as a config manager in the constructor.
- The sdk key param in constructor params sequence has been set as last item as to not break. 
- Made configManager inside Optimizely class **public** so that the user is able to call fetch() which is a public method defined over HTTPProjectConfigManager.
- Adds a factory method to create a client with sdk key and datafile.  

**todo**
Update readme accordingly.

Test plan:

- Added unit tests to verify init with sdk key.

Issues:

- OASIS-5770
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants