Skip to content

Commit

Permalink
chore: merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
sakshamg1304 committed Oct 3, 2024
2 parents dfdfbb7 + 5387424 commit dd98e08
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 26 deletions.
7 changes: 1 addition & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Redesigned models to use private properties instead of public properties.
- Implemented object notation with getter and setter functions for all models.

<<<<<<< HEAD
- **Unit and E2E Testing**
=======
- **Unit and E2E Testing**
>>>>>>> origin/feat/personalize-meg

- Set up Test framework using `Jest`
- Wrote unit and E2E tests to ensure nothing breaks while pushing new code
- Ensure criticla components are working properly on every build
- Ensure critical components are working properly on every build


[1.0.0] - 2024-06-11
Expand Down
10 changes: 8 additions & 2 deletions src/Api/GetFlag.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function get(
// Evaluate Rollout Rules
$rollOutRules = FunctionUtil::getSpecificRulesBasedOnType($feature, CampaignTypeEnum::ROLLOUT);
if (count($rollOutRules) > 0 && !$isEnabled) {
$megGroupWinnerCampaigns = [];
$megGroupWinnerCampaigns = [];
foreach ($rollOutRules as $rule) {
$evaluateRuleResult = $ruleEvaluationUtil->evaluateRule(
$settings,
Expand All @@ -157,7 +157,10 @@ public function get(
'rolloutKey' => $rule->getKey(),
'rolloutVariationId' => $rule->getVariations()[0]->getId()
];
$ruleStatus[$rule->getRuleKey()] = "Passed";
break;
} else {
$ruleStatus[$rule->getRuleKey()] = "Failed";
}
}

Expand Down Expand Up @@ -191,7 +194,7 @@ public function get(
$experimentRules = FunctionUtil::getAllExperimentRules($feature);
$experimentRulesToEvaluate = [];

$megGroupWinnerCampaigns = [];
$megGroupWinnerCampaigns = [];
foreach ($experimentRules as $rule) {
$evaluateRuleResult = $ruleEvaluationUtil->evaluateRule(
$settings,
Expand All @@ -217,7 +220,10 @@ public function get(
'experimentVariationId' => $evaluateRuleResult['whitelistedObject']['variationId'],
]);
}
$ruleStatus[$rule->getRuleKey()] = "Passed";
break;
} else {
$ruleStatus[$rule->getRuleKey()] = "Failed";
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Api/TrackEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@ private function createImpressionForTrack(SettingsModel $settings, string $event
$networkUtil->sendPostApiRequest($properties, $payload);
}
}
?>
?>
28 changes: 14 additions & 14 deletions src/Packages/SegmentationEvaluator/Evaluators/SegmentEvaluator.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ public function some($dslNodes, $customVariables): bool

if ($key === SegmentOperatorValueEnum::FEATURE_ID) {
$featureIdObject = $dsl->$key;

$featureIdKey = array_key_first(get_object_vars($featureIdObject));
$featureIdValue = $featureIdObject->$featureIdKey;

if (in_array($featureIdValue, ['on', 'off'])) {
$features = $this->settings->getFeatures();
$feature = null;
Expand Down Expand Up @@ -138,19 +138,19 @@ public function every($dslNodes, $customVariables): bool
$locationMap = [];
foreach ($dslNodes as $dsl) {
if (isset($dsl->{SegmentOperatorValueEnum::COUNTRY}) || isset($dsl->{SegmentOperatorValueEnum::REGION}) || isset($dsl->{SegmentOperatorValueEnum::CITY})) {
$this->addLocationValuesToMap($dsl, $locationMap);
$this->addLocationValuesToMap($dsl, $locationMap);
if (count($locationMap) === count($dslNodes)) {
return $this->checkLocationPreSegmentation($locationMap);
}
continue;
}
}
if (!$this->isSegmentationValid($dsl, $customVariables)) {
return false;
}
}
}
return true;
}

public function addLocationValuesToMap($dsl, &$locationMap): void
{
if (isset($dsl->{SegmentOperatorValueEnum::COUNTRY})) {
Expand All @@ -162,12 +162,12 @@ public function addLocationValuesToMap($dsl, &$locationMap): void
if (isset($dsl->{SegmentOperatorValueEnum::CITY})) {
$locationMap[SegmentOperatorValueEnum::CITY] = $dsl->{SegmentOperatorValueEnum::CITY};
}
}
}

public function checkLocationPreSegmentation($locationMap): bool
{
$ipAddress = $this->context->getIpAddress(); // Use the getter method

if (empty($ipAddress)) {
LogManager::instance()->info('To evaluate location pre-segmentation, please pass ipAddress in the context object');
return false;
Expand All @@ -176,19 +176,19 @@ public function checkLocationPreSegmentation($locationMap): bool
if (empty($this->context->getVwo()) || empty($this->context->getVwo()->getLocation())) {
return false;
}

return $this->valuesMatch($locationMap, $this->context->getVwo()->getLocation());
}

public function checkUserAgentParser($uaParserMap): bool
{
$userAgent = $this->context->getUserAgent(); // Use the getter method

if (empty($userAgent)) {
LogManager::instance()->info('To evaluate user agent related segments, please pass userAgent in the context object');
return false;
}
}

if (empty($this->context->getVwo()) || empty($this->context->getVwo()->getUaInfo())) {
return false;
}
Expand Down Expand Up @@ -280,4 +280,4 @@ interface Segmentation
{
public function isSegmentationValid($dsl, $properties);
}
?>
?>
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,4 @@ private function isValidNumericComparison($operandValue, $tagValue, callable $co
}
}

?>
?>
75 changes: 75 additions & 0 deletions src/Utils/VWOGatewayServiceUtil.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

/**
* Copyright 2024 Wingify Software Pvt. Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace vwo\Utils;

use vwo\Packages\NetworkLayer\Manager\NetworkManager;
use vwo\Packages\NetworkLayer\Models\RequestModel;
use vwo\Packages\NetworkLayer\Models\ResponseModel;
use vwo\Enums\UrlEnum;
use vwo\Services\UrlService;
use vwo\Packages\Logger\Core\LogManager;

class VWOGatewayServiceUtil {
public static function getFromVWOGatewayService($queryParams, $endpoint) {

$networkInstance = NetworkManager::Instance();

if (UrlService::getBaseUrl() === UrlEnum::BASE_URL) {
LogManager::instance()->info('Invalid URL. Please provide a valid URL for vwo helper VWOGatewayService');
return false;
}

try {
$request = new RequestModel(
UrlService::getBaseUrl(),
'GET',
$endpoint,
$queryParams,
null,
null,
UrlService::getProtocol(),
UrlService::getPort()
);

$response = $networkInstance->get($request);

if ($response instanceof ResponseModel) {
return $response->getData();
} else {
LogManager::instance()->error('Failed to get a valid response from the network request.');
return false;
}
} catch (\Exception $err) {
LogManager::instance()->error('Error occurred while sending GET request: ' . $err->getMessage());
return false;
}
}

public static function getQueryParamForLocationPreSegment($ipAddress) {
return [
'ipAddress' => $ipAddress
];
}

public static function getQueryParamForUaParser($userAgent) {
return [
'userAgent' => urlencode($userAgent)
];
}
}
3 changes: 1 addition & 2 deletions src/VWO.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ private static function setInstance($options)
// Fetch settings and build VWO instance
$settings = self::$vwoBuilder->getSettings();
}

if ($settings) {
self::$instance = self::$vwoBuilder->build($settings);
}
Expand Down Expand Up @@ -113,7 +112,7 @@ public static function init($options = [])
$instance = new VWO($options);

return self::$instance;
} catch (\Throwable $error) {
} catch (\Throwable $error) {
$msg = sprintf('API - %s failed to execute. Trace: %s. ', $apiName, $error->getMessage());
$logMessage = sprintf('[ERROR]: VWO-SDK %s %s', (new \DateTime())->format(DATE_ISO8601), $msg);
file_put_contents("php://stdout", $logMessage . PHP_EOL);
Expand Down

0 comments on commit dd98e08

Please sign in to comment.