Skip to content

Commit

Permalink
Merge branch 'trunk'
Browse files Browse the repository at this point in the history
  • Loading branch information
lafin committed Jan 15, 2018
2 parents 273d3ac + 1bf0b62 commit 55f9b17
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 113 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/docs/phpdoc-cache*
/vendor
/cache
/cache
composer.phar
phpunit.phar
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ For more info read [API reference](http://public.innomdc.com/inno-helper/)

### [0.0.9] - 2017-11-20
- Added method getting list of tasks

### [0.0.10] - 2017-12-5
- Has add support a new segment evaluation
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "library",
"description": "Innometrics helper",
"homepage": "http://www.innometrics.com",
"version": "0.0.9",
"version": "0.0.10",
"require": {
"php": ">=5.3.2",
"illuminate/container": "v5.0.33",
Expand Down
55 changes: 41 additions & 14 deletions lib/Innometrics/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ class Helper {
*/
protected $apiUrl = null;

/**
* Evaluation API url
* @var string
*/
protected $evaluationApiUrl = null;

/**
* No cache flag
* @var bool
Expand Down Expand Up @@ -73,6 +79,7 @@ public function __construct($config = array()) {
$this->validateConfig($config);
$this->groupId = $config['groupId'];
$this->apiUrl = $config['apiUrl'];
$this->evaluationApiUrl = $config['evaluationApiUrl'];
$this->bucketName = $config['bucketName'];
$this->appName = $config['appName'];
$this->appKey = $config['appKey'];
Expand Down Expand Up @@ -281,6 +288,14 @@ public function getApiHost () {
return $this->apiUrl;
}

/**
* Get evaluation Api url
* @return string
*/
public function getEvaluationApiHost () {
return $this->evaluationApiUrl;
}

/**
* Build Url for API request to work with certain Profile
*
Expand Down Expand Up @@ -346,13 +361,18 @@ protected function getSegmentsUrl () {
* @return string
*/
public function getSegmentEvaluationUrl ($params = array()) {
$typeSegmentEvaluation = $params['typeSegmentEvaluation'];
unset($params['typeSegmentEvaluation']);
$params = preg_replace('/%5B\d+%5D/i', '$1$2', http_build_query($params));

return sprintf(
'%s/v1/companies/%s/buckets/%s/segment-evaluation?app_key=%s&%s',
$this->getApiHost(),
'%s/companies/%s/buckets/%s/%s?app_key=%s&%s',
$this->getEvaluationApiHost(),
$this->getCompany(),
$this->getBucket(),
$typeSegmentEvaluation,
$this->getAppKey(),
http_build_query($params)
$params
);
}

Expand Down Expand Up @@ -566,24 +586,28 @@ public function evaluateProfileBySegment (Profile $profile, Segment $segment) {
/**
* Evaluate profile by segment's id
* @param Profile $profile
* @param string $segmentId
* @return bool
* @param string|array $segmentIds
* @return bool|array
*/
public function evaluateProfileBySegmentId (Profile $profile, $segmentId) {
public function evaluateProfileBySegmentId (Profile $profile, $segmentIds) {
$segmentIds = is_array($segmentIds) ? $segmentIds : array($segmentIds);
return $this->_evaluateProfileByParams($profile, array(
'segment_id' => $segmentId
'segment_id' => $segmentIds,
'typeSegmentEvaluation' => 'segment-id-evaluation'
));
}

/**
* Evaluate profile by IQL expression
* @param Profile $profile
* @param string $iql
* @param string|array $iqls
* @return bool
*/
public function evaluateProfileByIql ($profile, $iql) {
public function evaluateProfileByIql ($profile, $iqls) {
$iqls = is_array($iqls) ? $iqls : array($iqls);
return $this->_evaluateProfileByParams($profile, array(
'iql' => $iql
'iql' => $iqls,
'typeSegmentEvaluation' => 'iql-evaluation'
));
}

Expand Down Expand Up @@ -792,7 +816,7 @@ protected function checkErrors ($response, $successCode = 200) {
* @return bool
*/
protected function _evaluateProfileByParams (Profile $profile, $params) {
$result = null;
$results = null;
$defParams = array(
'profile_id' => $profile->getId()
);
Expand All @@ -808,11 +832,14 @@ protected function _evaluateProfileByParams (Profile $profile, $params) {
$this->checkErrors($response);

$body = $response['body'];
if (isset($body['segmentEvaluation']) && isset($body['segmentEvaluation']['result'])) {
$result = $body['segmentEvaluation']['result'];
if (isset($body['segmentEvaluation']) && isset($body['segmentEvaluation']['results'])) {
$results = $body['segmentEvaluation']['results'];
if (count($results) === 1) {
$results = $results[0];
}
}

return $result;
return $results;
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/Helper/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Base extends \PHPUnit_Framework_TestCase {
'appName' => 'appName',
'appKey' => 'appKey',
'apiUrl' => 'apiUrl',
'evaluationApiUrl' => 'evaluationApiUrl',
'groupId' => 4,
'schedulerApiHost' => 'schedulerApiHost'
);
Expand Down
6 changes: 4 additions & 2 deletions tests/Helper/HelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public function testShouldNotThrowErrorOnCorrectConfig () {
'appName' => 'appName',
'appKey' => 'appKey',
'apiUrl' => 'apiUrl',
'evaluationApiUrl' => 'evaluationApiUrl',
'groupId' => 4,
'schedulerApiHost' => 'schedulerApiHost'
));
Expand All @@ -89,6 +90,7 @@ public function testShouldNotThrowErrorOnCorrectConfig () {
'appName' => 'appName',
'appKey' => 'appKey',
'apiUrl' => 'apiUrl',
'evaluationApiUrl' => 'evaluationApiUrl',
'groupId' => '42',
'schedulerApiHost' => 'schedulerApiHost'
));
Expand Down Expand Up @@ -144,8 +146,8 @@ public function testShouldGenerateUrlsCorrectly () {
),
array(
'method' => 'getSegmentEvaluationUrl',
'arg' => array('param1' => 'value1'),
'res' => 'apiUrl/v1/companies/4/buckets/bucketName/segment-evaluation?app_key=appKey&param1=value1'
'arg' => array('param1' => 'value1', 'typeSegmentEvaluation' => 'segment-id-evaluation'),
'res' => 'evaluationApiUrl/companies/4/buckets/bucketName/segment-id-evaluation?app_key=appKey&param1=value1'
),
);

Expand Down
Loading

0 comments on commit 55f9b17

Please sign in to comment.