├── .gitignore ├── LICENSE ├── README.md ├── composer.json ├── composer.lock └── src ├── Client.php ├── Helpers.php └── Validator.php /.gitignore: -------------------------------------------------------------------------------- 1 | composer.phar 2 | vendor/ 3 | .idea/ 4 | index.php 5 | php-recommenderir.iml -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 evandhq 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## php-recommenderir 2 | A simple Object Oriented wrapper for [Recommender.ir](http://recommender.ir/) API, written with PHP5. 3 | 4 | ## Installation 5 | ``` 6 | composer require evandhq/php-recommenderir 7 | ``` 8 | or add this line to your composer.json file 9 | ``` 10 | "evandhq/php-recommenderir" : "dev-master" 11 | ``` 12 | 13 | ## Basic usage 14 | ```php 15 | require_once 'vendor/autoload.php'; 16 | 17 | $client = new Evand\Recommenderir\Client(['base_uri' => 'http://example.com']); 18 | $client->ingest(12345, 'product1', 200); 19 | ``` 20 | 21 | ## Available methods 22 | 23 | * ingest 24 | * forgetItems 25 | * forgetItemsList 26 | * rememberItems 27 | * addTerms 28 | * removeTerms 29 | * termsList 30 | * itemLocationAdd 31 | * itemLocationList 32 | * recommend 33 | * termRecommend 34 | * spectrometer 35 | * spotlight 36 | * recommendToGroup 37 | * similarity 38 | * similarityToItem 39 | * because 40 | * mostPopularItems 41 | * termMostPopularItems 42 | * termSimilarity 43 | * termBasedRecommend 44 | * termBasedRecommendInclusive 45 | * termBasedMostPopularItems 46 | * termBasedSimilarity 47 | * termBasedSimilarityInclusive 48 | * termNeighborhood 49 | * latestTouchedItems 50 | * latestTouchedTerms 51 | * userFrequentlyTouchedItems 52 | * itemFrequentlyVisitors 53 | * currentMood 54 | * setUserProfile 55 | * getUserProfile 56 | * guessUserProfile 57 | * luckyUser 58 | * getTrends 59 | 60 | Feel free to open an issue and send a pull request. 61 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "evandhq/php-recommenderir", 3 | "type": "library", 4 | "description": "Recommender.ir API PHP client", 5 | "homepage": "https://github.com/evandhq/php-recommenderir", 6 | "keywords": ["recommender", "api", "gist", "api-wrapper"], 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "Evand Team", 11 | "homepage": "https://evand.ir" 12 | } 13 | ], 14 | "require": { 15 | "php": ">=5.5.0", 16 | "ext-curl": "*", 17 | "guzzlehttp/guzzle": "^6.2" 18 | }, 19 | "require-dev": { 20 | "phpunit/phpunit": "~4.0" 21 | }, 22 | "autoload": { 23 | "psr-4": { 24 | "Evand\\Recommenderir\\": "src/" 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", 5 | "This file is @generated automatically" 6 | ], 7 | "hash": "fd9828c75ce3ddea97c79a0551d6466c", 8 | "content-hash": "3ff94588be5be32ee378879e3d21022f", 9 | "packages": [ 10 | { 11 | "name": "guzzlehttp/guzzle", 12 | "version": "6.2.0", 13 | "source": { 14 | "type": "git", 15 | "url": "https://github.com/guzzle/guzzle.git", 16 | "reference": "d094e337976dff9d8e2424e8485872194e768662" 17 | }, 18 | "dist": { 19 | "type": "zip", 20 | "url": "https://api.github.com/repos/guzzle/guzzle/zipball/d094e337976dff9d8e2424e8485872194e768662", 21 | "reference": "d094e337976dff9d8e2424e8485872194e768662", 22 | "shasum": "" 23 | }, 24 | "require": { 25 | "guzzlehttp/promises": "~1.0", 26 | "guzzlehttp/psr7": "~1.1", 27 | "php": ">=5.5.0" 28 | }, 29 | "require-dev": { 30 | "ext-curl": "*", 31 | "phpunit/phpunit": "~4.0", 32 | "psr/log": "~1.0" 33 | }, 34 | "type": "library", 35 | "extra": { 36 | "branch-alias": { 37 | "dev-master": "6.2-dev" 38 | } 39 | }, 40 | "autoload": { 41 | "files": [ 42 | "src/functions_include.php" 43 | ], 44 | "psr-4": { 45 | "GuzzleHttp\\": "src/" 46 | } 47 | }, 48 | "notification-url": "https://packagist.org/downloads/", 49 | "license": [ 50 | "MIT" 51 | ], 52 | "authors": [ 53 | { 54 | "name": "Michael Dowling", 55 | "email": "mtdowling@gmail.com", 56 | "homepage": "https://github.com/mtdowling" 57 | } 58 | ], 59 | "description": "Guzzle is a PHP HTTP client library", 60 | "homepage": "http://guzzlephp.org/", 61 | "keywords": [ 62 | "client", 63 | "curl", 64 | "framework", 65 | "http", 66 | "http client", 67 | "rest", 68 | "web service" 69 | ], 70 | "time": "2016-03-21 20:02:09" 71 | }, 72 | { 73 | "name": "guzzlehttp/promises", 74 | "version": "1.1.0", 75 | "source": { 76 | "type": "git", 77 | "url": "https://github.com/guzzle/promises.git", 78 | "reference": "bb9024c526b22f3fe6ae55a561fd70653d470aa8" 79 | }, 80 | "dist": { 81 | "type": "zip", 82 | "url": "https://api.github.com/repos/guzzle/promises/zipball/bb9024c526b22f3fe6ae55a561fd70653d470aa8", 83 | "reference": "bb9024c526b22f3fe6ae55a561fd70653d470aa8", 84 | "shasum": "" 85 | }, 86 | "require": { 87 | "php": ">=5.5.0" 88 | }, 89 | "require-dev": { 90 | "phpunit/phpunit": "~4.0" 91 | }, 92 | "type": "library", 93 | "extra": { 94 | "branch-alias": { 95 | "dev-master": "1.0-dev" 96 | } 97 | }, 98 | "autoload": { 99 | "psr-4": { 100 | "GuzzleHttp\\Promise\\": "src/" 101 | }, 102 | "files": [ 103 | "src/functions_include.php" 104 | ] 105 | }, 106 | "notification-url": "https://packagist.org/downloads/", 107 | "license": [ 108 | "MIT" 109 | ], 110 | "authors": [ 111 | { 112 | "name": "Michael Dowling", 113 | "email": "mtdowling@gmail.com", 114 | "homepage": "https://github.com/mtdowling" 115 | } 116 | ], 117 | "description": "Guzzle promises library", 118 | "keywords": [ 119 | "promise" 120 | ], 121 | "time": "2016-03-08 01:15:46" 122 | }, 123 | { 124 | "name": "guzzlehttp/psr7", 125 | "version": "1.2.3", 126 | "source": { 127 | "type": "git", 128 | "url": "https://github.com/guzzle/psr7.git", 129 | "reference": "2e89629ff057ebb49492ba08e6995d3a6a80021b" 130 | }, 131 | "dist": { 132 | "type": "zip", 133 | "url": "https://api.github.com/repos/guzzle/psr7/zipball/2e89629ff057ebb49492ba08e6995d3a6a80021b", 134 | "reference": "2e89629ff057ebb49492ba08e6995d3a6a80021b", 135 | "shasum": "" 136 | }, 137 | "require": { 138 | "php": ">=5.4.0", 139 | "psr/http-message": "~1.0" 140 | }, 141 | "provide": { 142 | "psr/http-message-implementation": "1.0" 143 | }, 144 | "require-dev": { 145 | "phpunit/phpunit": "~4.0" 146 | }, 147 | "type": "library", 148 | "extra": { 149 | "branch-alias": { 150 | "dev-master": "1.0-dev" 151 | } 152 | }, 153 | "autoload": { 154 | "psr-4": { 155 | "GuzzleHttp\\Psr7\\": "src/" 156 | }, 157 | "files": [ 158 | "src/functions_include.php" 159 | ] 160 | }, 161 | "notification-url": "https://packagist.org/downloads/", 162 | "license": [ 163 | "MIT" 164 | ], 165 | "authors": [ 166 | { 167 | "name": "Michael Dowling", 168 | "email": "mtdowling@gmail.com", 169 | "homepage": "https://github.com/mtdowling" 170 | } 171 | ], 172 | "description": "PSR-7 message implementation", 173 | "keywords": [ 174 | "http", 175 | "message", 176 | "stream", 177 | "uri" 178 | ], 179 | "time": "2016-02-18 21:54:00" 180 | }, 181 | { 182 | "name": "psr/http-message", 183 | "version": "1.0", 184 | "source": { 185 | "type": "git", 186 | "url": "https://github.com/php-fig/http-message.git", 187 | "reference": "85d63699f0dbedb190bbd4b0d2b9dc707ea4c298" 188 | }, 189 | "dist": { 190 | "type": "zip", 191 | "url": "https://api.github.com/repos/php-fig/http-message/zipball/85d63699f0dbedb190bbd4b0d2b9dc707ea4c298", 192 | "reference": "85d63699f0dbedb190bbd4b0d2b9dc707ea4c298", 193 | "shasum": "" 194 | }, 195 | "require": { 196 | "php": ">=5.3.0" 197 | }, 198 | "type": "library", 199 | "extra": { 200 | "branch-alias": { 201 | "dev-master": "1.0.x-dev" 202 | } 203 | }, 204 | "autoload": { 205 | "psr-4": { 206 | "Psr\\Http\\Message\\": "src/" 207 | } 208 | }, 209 | "notification-url": "https://packagist.org/downloads/", 210 | "license": [ 211 | "MIT" 212 | ], 213 | "authors": [ 214 | { 215 | "name": "PHP-FIG", 216 | "homepage": "http://www.php-fig.org/" 217 | } 218 | ], 219 | "description": "Common interface for HTTP messages", 220 | "keywords": [ 221 | "http", 222 | "http-message", 223 | "psr", 224 | "psr-7", 225 | "request", 226 | "response" 227 | ], 228 | "time": "2015-05-04 20:22:00" 229 | } 230 | ], 231 | "packages-dev": [ 232 | { 233 | "name": "doctrine/instantiator", 234 | "version": "1.0.5", 235 | "source": { 236 | "type": "git", 237 | "url": "https://github.com/doctrine/instantiator.git", 238 | "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d" 239 | }, 240 | "dist": { 241 | "type": "zip", 242 | "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d", 243 | "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d", 244 | "shasum": "" 245 | }, 246 | "require": { 247 | "php": ">=5.3,<8.0-DEV" 248 | }, 249 | "require-dev": { 250 | "athletic/athletic": "~0.1.8", 251 | "ext-pdo": "*", 252 | "ext-phar": "*", 253 | "phpunit/phpunit": "~4.0", 254 | "squizlabs/php_codesniffer": "~2.0" 255 | }, 256 | "type": "library", 257 | "extra": { 258 | "branch-alias": { 259 | "dev-master": "1.0.x-dev" 260 | } 261 | }, 262 | "autoload": { 263 | "psr-4": { 264 | "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" 265 | } 266 | }, 267 | "notification-url": "https://packagist.org/downloads/", 268 | "license": [ 269 | "MIT" 270 | ], 271 | "authors": [ 272 | { 273 | "name": "Marco Pivetta", 274 | "email": "ocramius@gmail.com", 275 | "homepage": "http://ocramius.github.com/" 276 | } 277 | ], 278 | "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", 279 | "homepage": "https://github.com/doctrine/instantiator", 280 | "keywords": [ 281 | "constructor", 282 | "instantiate" 283 | ], 284 | "time": "2015-06-14 21:17:01" 285 | }, 286 | { 287 | "name": "phpdocumentor/reflection-docblock", 288 | "version": "2.0.4", 289 | "source": { 290 | "type": "git", 291 | "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", 292 | "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8" 293 | }, 294 | "dist": { 295 | "type": "zip", 296 | "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/d68dbdc53dc358a816f00b300704702b2eaff7b8", 297 | "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8", 298 | "shasum": "" 299 | }, 300 | "require": { 301 | "php": ">=5.3.3" 302 | }, 303 | "require-dev": { 304 | "phpunit/phpunit": "~4.0" 305 | }, 306 | "suggest": { 307 | "dflydev/markdown": "~1.0", 308 | "erusev/parsedown": "~1.0" 309 | }, 310 | "type": "library", 311 | "extra": { 312 | "branch-alias": { 313 | "dev-master": "2.0.x-dev" 314 | } 315 | }, 316 | "autoload": { 317 | "psr-0": { 318 | "phpDocumentor": [ 319 | "src/" 320 | ] 321 | } 322 | }, 323 | "notification-url": "https://packagist.org/downloads/", 324 | "license": [ 325 | "MIT" 326 | ], 327 | "authors": [ 328 | { 329 | "name": "Mike van Riel", 330 | "email": "mike.vanriel@naenius.com" 331 | } 332 | ], 333 | "time": "2015-02-03 12:10:50" 334 | }, 335 | { 336 | "name": "phpspec/prophecy", 337 | "version": "v1.6.0", 338 | "source": { 339 | "type": "git", 340 | "url": "https://github.com/phpspec/prophecy.git", 341 | "reference": "3c91bdf81797d725b14cb62906f9a4ce44235972" 342 | }, 343 | "dist": { 344 | "type": "zip", 345 | "url": "https://api.github.com/repos/phpspec/prophecy/zipball/3c91bdf81797d725b14cb62906f9a4ce44235972", 346 | "reference": "3c91bdf81797d725b14cb62906f9a4ce44235972", 347 | "shasum": "" 348 | }, 349 | "require": { 350 | "doctrine/instantiator": "^1.0.2", 351 | "php": "^5.3|^7.0", 352 | "phpdocumentor/reflection-docblock": "~2.0", 353 | "sebastian/comparator": "~1.1", 354 | "sebastian/recursion-context": "~1.0" 355 | }, 356 | "require-dev": { 357 | "phpspec/phpspec": "~2.0" 358 | }, 359 | "type": "library", 360 | "extra": { 361 | "branch-alias": { 362 | "dev-master": "1.5.x-dev" 363 | } 364 | }, 365 | "autoload": { 366 | "psr-0": { 367 | "Prophecy\\": "src/" 368 | } 369 | }, 370 | "notification-url": "https://packagist.org/downloads/", 371 | "license": [ 372 | "MIT" 373 | ], 374 | "authors": [ 375 | { 376 | "name": "Konstantin Kudryashov", 377 | "email": "ever.zet@gmail.com", 378 | "homepage": "http://everzet.com" 379 | }, 380 | { 381 | "name": "Marcello Duarte", 382 | "email": "marcello.duarte@gmail.com" 383 | } 384 | ], 385 | "description": "Highly opinionated mocking framework for PHP 5.3+", 386 | "homepage": "https://github.com/phpspec/prophecy", 387 | "keywords": [ 388 | "Double", 389 | "Dummy", 390 | "fake", 391 | "mock", 392 | "spy", 393 | "stub" 394 | ], 395 | "time": "2016-02-15 07:46:21" 396 | }, 397 | { 398 | "name": "phpunit/php-code-coverage", 399 | "version": "2.2.4", 400 | "source": { 401 | "type": "git", 402 | "url": "https://github.com/sebastianbergmann/php-code-coverage.git", 403 | "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979" 404 | }, 405 | "dist": { 406 | "type": "zip", 407 | "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/eabf68b476ac7d0f73793aada060f1c1a9bf8979", 408 | "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979", 409 | "shasum": "" 410 | }, 411 | "require": { 412 | "php": ">=5.3.3", 413 | "phpunit/php-file-iterator": "~1.3", 414 | "phpunit/php-text-template": "~1.2", 415 | "phpunit/php-token-stream": "~1.3", 416 | "sebastian/environment": "^1.3.2", 417 | "sebastian/version": "~1.0" 418 | }, 419 | "require-dev": { 420 | "ext-xdebug": ">=2.1.4", 421 | "phpunit/phpunit": "~4" 422 | }, 423 | "suggest": { 424 | "ext-dom": "*", 425 | "ext-xdebug": ">=2.2.1", 426 | "ext-xmlwriter": "*" 427 | }, 428 | "type": "library", 429 | "extra": { 430 | "branch-alias": { 431 | "dev-master": "2.2.x-dev" 432 | } 433 | }, 434 | "autoload": { 435 | "classmap": [ 436 | "src/" 437 | ] 438 | }, 439 | "notification-url": "https://packagist.org/downloads/", 440 | "license": [ 441 | "BSD-3-Clause" 442 | ], 443 | "authors": [ 444 | { 445 | "name": "Sebastian Bergmann", 446 | "email": "sb@sebastian-bergmann.de", 447 | "role": "lead" 448 | } 449 | ], 450 | "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", 451 | "homepage": "https://github.com/sebastianbergmann/php-code-coverage", 452 | "keywords": [ 453 | "coverage", 454 | "testing", 455 | "xunit" 456 | ], 457 | "time": "2015-10-06 15:47:00" 458 | }, 459 | { 460 | "name": "phpunit/php-file-iterator", 461 | "version": "1.4.1", 462 | "source": { 463 | "type": "git", 464 | "url": "https://github.com/sebastianbergmann/php-file-iterator.git", 465 | "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0" 466 | }, 467 | "dist": { 468 | "type": "zip", 469 | "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/6150bf2c35d3fc379e50c7602b75caceaa39dbf0", 470 | "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0", 471 | "shasum": "" 472 | }, 473 | "require": { 474 | "php": ">=5.3.3" 475 | }, 476 | "type": "library", 477 | "extra": { 478 | "branch-alias": { 479 | "dev-master": "1.4.x-dev" 480 | } 481 | }, 482 | "autoload": { 483 | "classmap": [ 484 | "src/" 485 | ] 486 | }, 487 | "notification-url": "https://packagist.org/downloads/", 488 | "license": [ 489 | "BSD-3-Clause" 490 | ], 491 | "authors": [ 492 | { 493 | "name": "Sebastian Bergmann", 494 | "email": "sb@sebastian-bergmann.de", 495 | "role": "lead" 496 | } 497 | ], 498 | "description": "FilterIterator implementation that filters files based on a list of suffixes.", 499 | "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", 500 | "keywords": [ 501 | "filesystem", 502 | "iterator" 503 | ], 504 | "time": "2015-06-21 13:08:43" 505 | }, 506 | { 507 | "name": "phpunit/php-text-template", 508 | "version": "1.2.1", 509 | "source": { 510 | "type": "git", 511 | "url": "https://github.com/sebastianbergmann/php-text-template.git", 512 | "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" 513 | }, 514 | "dist": { 515 | "type": "zip", 516 | "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", 517 | "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", 518 | "shasum": "" 519 | }, 520 | "require": { 521 | "php": ">=5.3.3" 522 | }, 523 | "type": "library", 524 | "autoload": { 525 | "classmap": [ 526 | "src/" 527 | ] 528 | }, 529 | "notification-url": "https://packagist.org/downloads/", 530 | "license": [ 531 | "BSD-3-Clause" 532 | ], 533 | "authors": [ 534 | { 535 | "name": "Sebastian Bergmann", 536 | "email": "sebastian@phpunit.de", 537 | "role": "lead" 538 | } 539 | ], 540 | "description": "Simple template engine.", 541 | "homepage": "https://github.com/sebastianbergmann/php-text-template/", 542 | "keywords": [ 543 | "template" 544 | ], 545 | "time": "2015-06-21 13:50:34" 546 | }, 547 | { 548 | "name": "phpunit/php-timer", 549 | "version": "1.0.7", 550 | "source": { 551 | "type": "git", 552 | "url": "https://github.com/sebastianbergmann/php-timer.git", 553 | "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b" 554 | }, 555 | "dist": { 556 | "type": "zip", 557 | "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3e82f4e9fc92665fafd9157568e4dcb01d014e5b", 558 | "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b", 559 | "shasum": "" 560 | }, 561 | "require": { 562 | "php": ">=5.3.3" 563 | }, 564 | "type": "library", 565 | "autoload": { 566 | "classmap": [ 567 | "src/" 568 | ] 569 | }, 570 | "notification-url": "https://packagist.org/downloads/", 571 | "license": [ 572 | "BSD-3-Clause" 573 | ], 574 | "authors": [ 575 | { 576 | "name": "Sebastian Bergmann", 577 | "email": "sb@sebastian-bergmann.de", 578 | "role": "lead" 579 | } 580 | ], 581 | "description": "Utility class for timing", 582 | "homepage": "https://github.com/sebastianbergmann/php-timer/", 583 | "keywords": [ 584 | "timer" 585 | ], 586 | "time": "2015-06-21 08:01:12" 587 | }, 588 | { 589 | "name": "phpunit/php-token-stream", 590 | "version": "1.4.8", 591 | "source": { 592 | "type": "git", 593 | "url": "https://github.com/sebastianbergmann/php-token-stream.git", 594 | "reference": "3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da" 595 | }, 596 | "dist": { 597 | "type": "zip", 598 | "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da", 599 | "reference": "3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da", 600 | "shasum": "" 601 | }, 602 | "require": { 603 | "ext-tokenizer": "*", 604 | "php": ">=5.3.3" 605 | }, 606 | "require-dev": { 607 | "phpunit/phpunit": "~4.2" 608 | }, 609 | "type": "library", 610 | "extra": { 611 | "branch-alias": { 612 | "dev-master": "1.4-dev" 613 | } 614 | }, 615 | "autoload": { 616 | "classmap": [ 617 | "src/" 618 | ] 619 | }, 620 | "notification-url": "https://packagist.org/downloads/", 621 | "license": [ 622 | "BSD-3-Clause" 623 | ], 624 | "authors": [ 625 | { 626 | "name": "Sebastian Bergmann", 627 | "email": "sebastian@phpunit.de" 628 | } 629 | ], 630 | "description": "Wrapper around PHP's tokenizer extension.", 631 | "homepage": "https://github.com/sebastianbergmann/php-token-stream/", 632 | "keywords": [ 633 | "tokenizer" 634 | ], 635 | "time": "2015-09-15 10:49:45" 636 | }, 637 | { 638 | "name": "phpunit/phpunit", 639 | "version": "4.8.24", 640 | "source": { 641 | "type": "git", 642 | "url": "https://github.com/sebastianbergmann/phpunit.git", 643 | "reference": "a1066c562c52900a142a0e2bbf0582994671385e" 644 | }, 645 | "dist": { 646 | "type": "zip", 647 | "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a1066c562c52900a142a0e2bbf0582994671385e", 648 | "reference": "a1066c562c52900a142a0e2bbf0582994671385e", 649 | "shasum": "" 650 | }, 651 | "require": { 652 | "ext-dom": "*", 653 | "ext-json": "*", 654 | "ext-pcre": "*", 655 | "ext-reflection": "*", 656 | "ext-spl": "*", 657 | "php": ">=5.3.3", 658 | "phpspec/prophecy": "^1.3.1", 659 | "phpunit/php-code-coverage": "~2.1", 660 | "phpunit/php-file-iterator": "~1.4", 661 | "phpunit/php-text-template": "~1.2", 662 | "phpunit/php-timer": ">=1.0.6", 663 | "phpunit/phpunit-mock-objects": "~2.3", 664 | "sebastian/comparator": "~1.1", 665 | "sebastian/diff": "~1.2", 666 | "sebastian/environment": "~1.3", 667 | "sebastian/exporter": "~1.2", 668 | "sebastian/global-state": "~1.0", 669 | "sebastian/version": "~1.0", 670 | "symfony/yaml": "~2.1|~3.0" 671 | }, 672 | "suggest": { 673 | "phpunit/php-invoker": "~1.1" 674 | }, 675 | "bin": [ 676 | "phpunit" 677 | ], 678 | "type": "library", 679 | "extra": { 680 | "branch-alias": { 681 | "dev-master": "4.8.x-dev" 682 | } 683 | }, 684 | "autoload": { 685 | "classmap": [ 686 | "src/" 687 | ] 688 | }, 689 | "notification-url": "https://packagist.org/downloads/", 690 | "license": [ 691 | "BSD-3-Clause" 692 | ], 693 | "authors": [ 694 | { 695 | "name": "Sebastian Bergmann", 696 | "email": "sebastian@phpunit.de", 697 | "role": "lead" 698 | } 699 | ], 700 | "description": "The PHP Unit Testing framework.", 701 | "homepage": "https://phpunit.de/", 702 | "keywords": [ 703 | "phpunit", 704 | "testing", 705 | "xunit" 706 | ], 707 | "time": "2016-03-14 06:16:08" 708 | }, 709 | { 710 | "name": "phpunit/phpunit-mock-objects", 711 | "version": "2.3.8", 712 | "source": { 713 | "type": "git", 714 | "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", 715 | "reference": "ac8e7a3db35738d56ee9a76e78a4e03d97628983" 716 | }, 717 | "dist": { 718 | "type": "zip", 719 | "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/ac8e7a3db35738d56ee9a76e78a4e03d97628983", 720 | "reference": "ac8e7a3db35738d56ee9a76e78a4e03d97628983", 721 | "shasum": "" 722 | }, 723 | "require": { 724 | "doctrine/instantiator": "^1.0.2", 725 | "php": ">=5.3.3", 726 | "phpunit/php-text-template": "~1.2", 727 | "sebastian/exporter": "~1.2" 728 | }, 729 | "require-dev": { 730 | "phpunit/phpunit": "~4.4" 731 | }, 732 | "suggest": { 733 | "ext-soap": "*" 734 | }, 735 | "type": "library", 736 | "extra": { 737 | "branch-alias": { 738 | "dev-master": "2.3.x-dev" 739 | } 740 | }, 741 | "autoload": { 742 | "classmap": [ 743 | "src/" 744 | ] 745 | }, 746 | "notification-url": "https://packagist.org/downloads/", 747 | "license": [ 748 | "BSD-3-Clause" 749 | ], 750 | "authors": [ 751 | { 752 | "name": "Sebastian Bergmann", 753 | "email": "sb@sebastian-bergmann.de", 754 | "role": "lead" 755 | } 756 | ], 757 | "description": "Mock Object library for PHPUnit", 758 | "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", 759 | "keywords": [ 760 | "mock", 761 | "xunit" 762 | ], 763 | "time": "2015-10-02 06:51:40" 764 | }, 765 | { 766 | "name": "sebastian/comparator", 767 | "version": "1.2.0", 768 | "source": { 769 | "type": "git", 770 | "url": "https://github.com/sebastianbergmann/comparator.git", 771 | "reference": "937efb279bd37a375bcadf584dec0726f84dbf22" 772 | }, 773 | "dist": { 774 | "type": "zip", 775 | "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/937efb279bd37a375bcadf584dec0726f84dbf22", 776 | "reference": "937efb279bd37a375bcadf584dec0726f84dbf22", 777 | "shasum": "" 778 | }, 779 | "require": { 780 | "php": ">=5.3.3", 781 | "sebastian/diff": "~1.2", 782 | "sebastian/exporter": "~1.2" 783 | }, 784 | "require-dev": { 785 | "phpunit/phpunit": "~4.4" 786 | }, 787 | "type": "library", 788 | "extra": { 789 | "branch-alias": { 790 | "dev-master": "1.2.x-dev" 791 | } 792 | }, 793 | "autoload": { 794 | "classmap": [ 795 | "src/" 796 | ] 797 | }, 798 | "notification-url": "https://packagist.org/downloads/", 799 | "license": [ 800 | "BSD-3-Clause" 801 | ], 802 | "authors": [ 803 | { 804 | "name": "Jeff Welch", 805 | "email": "whatthejeff@gmail.com" 806 | }, 807 | { 808 | "name": "Volker Dusch", 809 | "email": "github@wallbash.com" 810 | }, 811 | { 812 | "name": "Bernhard Schussek", 813 | "email": "bschussek@2bepublished.at" 814 | }, 815 | { 816 | "name": "Sebastian Bergmann", 817 | "email": "sebastian@phpunit.de" 818 | } 819 | ], 820 | "description": "Provides the functionality to compare PHP values for equality", 821 | "homepage": "http://www.github.com/sebastianbergmann/comparator", 822 | "keywords": [ 823 | "comparator", 824 | "compare", 825 | "equality" 826 | ], 827 | "time": "2015-07-26 15:48:44" 828 | }, 829 | { 830 | "name": "sebastian/diff", 831 | "version": "1.4.1", 832 | "source": { 833 | "type": "git", 834 | "url": "https://github.com/sebastianbergmann/diff.git", 835 | "reference": "13edfd8706462032c2f52b4b862974dd46b71c9e" 836 | }, 837 | "dist": { 838 | "type": "zip", 839 | "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/13edfd8706462032c2f52b4b862974dd46b71c9e", 840 | "reference": "13edfd8706462032c2f52b4b862974dd46b71c9e", 841 | "shasum": "" 842 | }, 843 | "require": { 844 | "php": ">=5.3.3" 845 | }, 846 | "require-dev": { 847 | "phpunit/phpunit": "~4.8" 848 | }, 849 | "type": "library", 850 | "extra": { 851 | "branch-alias": { 852 | "dev-master": "1.4-dev" 853 | } 854 | }, 855 | "autoload": { 856 | "classmap": [ 857 | "src/" 858 | ] 859 | }, 860 | "notification-url": "https://packagist.org/downloads/", 861 | "license": [ 862 | "BSD-3-Clause" 863 | ], 864 | "authors": [ 865 | { 866 | "name": "Kore Nordmann", 867 | "email": "mail@kore-nordmann.de" 868 | }, 869 | { 870 | "name": "Sebastian Bergmann", 871 | "email": "sebastian@phpunit.de" 872 | } 873 | ], 874 | "description": "Diff implementation", 875 | "homepage": "https://github.com/sebastianbergmann/diff", 876 | "keywords": [ 877 | "diff" 878 | ], 879 | "time": "2015-12-08 07:14:41" 880 | }, 881 | { 882 | "name": "sebastian/environment", 883 | "version": "1.3.5", 884 | "source": { 885 | "type": "git", 886 | "url": "https://github.com/sebastianbergmann/environment.git", 887 | "reference": "dc7a29032cf72b54f36dac15a1ca5b3a1b6029bf" 888 | }, 889 | "dist": { 890 | "type": "zip", 891 | "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/dc7a29032cf72b54f36dac15a1ca5b3a1b6029bf", 892 | "reference": "dc7a29032cf72b54f36dac15a1ca5b3a1b6029bf", 893 | "shasum": "" 894 | }, 895 | "require": { 896 | "php": ">=5.3.3" 897 | }, 898 | "require-dev": { 899 | "phpunit/phpunit": "~4.4" 900 | }, 901 | "type": "library", 902 | "extra": { 903 | "branch-alias": { 904 | "dev-master": "1.3.x-dev" 905 | } 906 | }, 907 | "autoload": { 908 | "classmap": [ 909 | "src/" 910 | ] 911 | }, 912 | "notification-url": "https://packagist.org/downloads/", 913 | "license": [ 914 | "BSD-3-Clause" 915 | ], 916 | "authors": [ 917 | { 918 | "name": "Sebastian Bergmann", 919 | "email": "sebastian@phpunit.de" 920 | } 921 | ], 922 | "description": "Provides functionality to handle HHVM/PHP environments", 923 | "homepage": "http://www.github.com/sebastianbergmann/environment", 924 | "keywords": [ 925 | "Xdebug", 926 | "environment", 927 | "hhvm" 928 | ], 929 | "time": "2016-02-26 18:40:46" 930 | }, 931 | { 932 | "name": "sebastian/exporter", 933 | "version": "1.2.1", 934 | "source": { 935 | "type": "git", 936 | "url": "https://github.com/sebastianbergmann/exporter.git", 937 | "reference": "7ae5513327cb536431847bcc0c10edba2701064e" 938 | }, 939 | "dist": { 940 | "type": "zip", 941 | "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/7ae5513327cb536431847bcc0c10edba2701064e", 942 | "reference": "7ae5513327cb536431847bcc0c10edba2701064e", 943 | "shasum": "" 944 | }, 945 | "require": { 946 | "php": ">=5.3.3", 947 | "sebastian/recursion-context": "~1.0" 948 | }, 949 | "require-dev": { 950 | "phpunit/phpunit": "~4.4" 951 | }, 952 | "type": "library", 953 | "extra": { 954 | "branch-alias": { 955 | "dev-master": "1.2.x-dev" 956 | } 957 | }, 958 | "autoload": { 959 | "classmap": [ 960 | "src/" 961 | ] 962 | }, 963 | "notification-url": "https://packagist.org/downloads/", 964 | "license": [ 965 | "BSD-3-Clause" 966 | ], 967 | "authors": [ 968 | { 969 | "name": "Jeff Welch", 970 | "email": "whatthejeff@gmail.com" 971 | }, 972 | { 973 | "name": "Volker Dusch", 974 | "email": "github@wallbash.com" 975 | }, 976 | { 977 | "name": "Bernhard Schussek", 978 | "email": "bschussek@2bepublished.at" 979 | }, 980 | { 981 | "name": "Sebastian Bergmann", 982 | "email": "sebastian@phpunit.de" 983 | }, 984 | { 985 | "name": "Adam Harvey", 986 | "email": "aharvey@php.net" 987 | } 988 | ], 989 | "description": "Provides the functionality to export PHP variables for visualization", 990 | "homepage": "http://www.github.com/sebastianbergmann/exporter", 991 | "keywords": [ 992 | "export", 993 | "exporter" 994 | ], 995 | "time": "2015-06-21 07:55:53" 996 | }, 997 | { 998 | "name": "sebastian/global-state", 999 | "version": "1.1.1", 1000 | "source": { 1001 | "type": "git", 1002 | "url": "https://github.com/sebastianbergmann/global-state.git", 1003 | "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4" 1004 | }, 1005 | "dist": { 1006 | "type": "zip", 1007 | "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bc37d50fea7d017d3d340f230811c9f1d7280af4", 1008 | "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4", 1009 | "shasum": "" 1010 | }, 1011 | "require": { 1012 | "php": ">=5.3.3" 1013 | }, 1014 | "require-dev": { 1015 | "phpunit/phpunit": "~4.2" 1016 | }, 1017 | "suggest": { 1018 | "ext-uopz": "*" 1019 | }, 1020 | "type": "library", 1021 | "extra": { 1022 | "branch-alias": { 1023 | "dev-master": "1.0-dev" 1024 | } 1025 | }, 1026 | "autoload": { 1027 | "classmap": [ 1028 | "src/" 1029 | ] 1030 | }, 1031 | "notification-url": "https://packagist.org/downloads/", 1032 | "license": [ 1033 | "BSD-3-Clause" 1034 | ], 1035 | "authors": [ 1036 | { 1037 | "name": "Sebastian Bergmann", 1038 | "email": "sebastian@phpunit.de" 1039 | } 1040 | ], 1041 | "description": "Snapshotting of global state", 1042 | "homepage": "http://www.github.com/sebastianbergmann/global-state", 1043 | "keywords": [ 1044 | "global state" 1045 | ], 1046 | "time": "2015-10-12 03:26:01" 1047 | }, 1048 | { 1049 | "name": "sebastian/recursion-context", 1050 | "version": "1.0.2", 1051 | "source": { 1052 | "type": "git", 1053 | "url": "https://github.com/sebastianbergmann/recursion-context.git", 1054 | "reference": "913401df809e99e4f47b27cdd781f4a258d58791" 1055 | }, 1056 | "dist": { 1057 | "type": "zip", 1058 | "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/913401df809e99e4f47b27cdd781f4a258d58791", 1059 | "reference": "913401df809e99e4f47b27cdd781f4a258d58791", 1060 | "shasum": "" 1061 | }, 1062 | "require": { 1063 | "php": ">=5.3.3" 1064 | }, 1065 | "require-dev": { 1066 | "phpunit/phpunit": "~4.4" 1067 | }, 1068 | "type": "library", 1069 | "extra": { 1070 | "branch-alias": { 1071 | "dev-master": "1.0.x-dev" 1072 | } 1073 | }, 1074 | "autoload": { 1075 | "classmap": [ 1076 | "src/" 1077 | ] 1078 | }, 1079 | "notification-url": "https://packagist.org/downloads/", 1080 | "license": [ 1081 | "BSD-3-Clause" 1082 | ], 1083 | "authors": [ 1084 | { 1085 | "name": "Jeff Welch", 1086 | "email": "whatthejeff@gmail.com" 1087 | }, 1088 | { 1089 | "name": "Sebastian Bergmann", 1090 | "email": "sebastian@phpunit.de" 1091 | }, 1092 | { 1093 | "name": "Adam Harvey", 1094 | "email": "aharvey@php.net" 1095 | } 1096 | ], 1097 | "description": "Provides functionality to recursively process PHP variables", 1098 | "homepage": "http://www.github.com/sebastianbergmann/recursion-context", 1099 | "time": "2015-11-11 19:50:13" 1100 | }, 1101 | { 1102 | "name": "sebastian/version", 1103 | "version": "1.0.6", 1104 | "source": { 1105 | "type": "git", 1106 | "url": "https://github.com/sebastianbergmann/version.git", 1107 | "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6" 1108 | }, 1109 | "dist": { 1110 | "type": "zip", 1111 | "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", 1112 | "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", 1113 | "shasum": "" 1114 | }, 1115 | "type": "library", 1116 | "autoload": { 1117 | "classmap": [ 1118 | "src/" 1119 | ] 1120 | }, 1121 | "notification-url": "https://packagist.org/downloads/", 1122 | "license": [ 1123 | "BSD-3-Clause" 1124 | ], 1125 | "authors": [ 1126 | { 1127 | "name": "Sebastian Bergmann", 1128 | "email": "sebastian@phpunit.de", 1129 | "role": "lead" 1130 | } 1131 | ], 1132 | "description": "Library that helps with managing the version number of Git-hosted PHP projects", 1133 | "homepage": "https://github.com/sebastianbergmann/version", 1134 | "time": "2015-06-21 13:59:46" 1135 | }, 1136 | { 1137 | "name": "symfony/yaml", 1138 | "version": "v3.0.4", 1139 | "source": { 1140 | "type": "git", 1141 | "url": "https://github.com/symfony/yaml.git", 1142 | "reference": "0047c8366744a16de7516622c5b7355336afae96" 1143 | }, 1144 | "dist": { 1145 | "type": "zip", 1146 | "url": "https://api.github.com/repos/symfony/yaml/zipball/0047c8366744a16de7516622c5b7355336afae96", 1147 | "reference": "0047c8366744a16de7516622c5b7355336afae96", 1148 | "shasum": "" 1149 | }, 1150 | "require": { 1151 | "php": ">=5.5.9" 1152 | }, 1153 | "type": "library", 1154 | "extra": { 1155 | "branch-alias": { 1156 | "dev-master": "3.0-dev" 1157 | } 1158 | }, 1159 | "autoload": { 1160 | "psr-4": { 1161 | "Symfony\\Component\\Yaml\\": "" 1162 | }, 1163 | "exclude-from-classmap": [ 1164 | "/Tests/" 1165 | ] 1166 | }, 1167 | "notification-url": "https://packagist.org/downloads/", 1168 | "license": [ 1169 | "MIT" 1170 | ], 1171 | "authors": [ 1172 | { 1173 | "name": "Fabien Potencier", 1174 | "email": "fabien@symfony.com" 1175 | }, 1176 | { 1177 | "name": "Symfony Community", 1178 | "homepage": "https://symfony.com/contributors" 1179 | } 1180 | ], 1181 | "description": "Symfony Yaml Component", 1182 | "homepage": "https://symfony.com", 1183 | "time": "2016-03-04 07:55:57" 1184 | } 1185 | ], 1186 | "aliases": [], 1187 | "minimum-stability": "stable", 1188 | "stability-flags": [], 1189 | "prefer-stable": false, 1190 | "prefer-lowest": false, 1191 | "platform": { 1192 | "php": ">=5.5.0", 1193 | "ext-curl": "*" 1194 | }, 1195 | "platform-dev": [] 1196 | } 1197 | -------------------------------------------------------------------------------- /src/Client.php: -------------------------------------------------------------------------------- 1 | 'http://example.com', 23 | 'user_agent' => 'php-recommenderir (https://github.com/evandhq/php-recommenderir)', 24 | 'connect_timeout' => 30, 25 | 'timeout' => 30 26 | ); 27 | 28 | /** 29 | * @var GuzzleClient 30 | */ 31 | protected $client; 32 | 33 | /** 34 | * @param array $options 35 | */ 36 | public function __construct(array $options = []) 37 | { 38 | $this->client = new GuzzleClient(array_merge($this->options, $options)); 39 | } 40 | 41 | /** 42 | * @param int $userId 43 | * @param string $item 44 | * @param int $value 45 | * 46 | * @return bool 47 | */ 48 | public function ingest($userId, $item, $value = 0) 49 | { 50 | 51 | $this->isInt($userId, 'userId'); 52 | $this->haveString($item, 'item'); 53 | $this->validateValue($value); 54 | 55 | try { 56 | $this->client->get('/ingest', [ 57 | 'query' => [ 58 | 'id' => $userId, 59 | 'url' => "'" . $item . "'", 60 | 'value' => $value 61 | ] 62 | ]); 63 | } catch (ClientException $e) { 64 | return false; 65 | } 66 | 67 | return true; 68 | } 69 | 70 | /** 71 | * @param array $items 72 | * 73 | * @return bool 74 | */ 75 | public function forgetItems(array $items) 76 | { 77 | if (empty($items)) { 78 | throw new InvalidArgumentException('items is empty!'); 79 | } 80 | 81 | $this->validateArray($items, 'haveString', 'items'); 82 | 83 | try { 84 | $this->client->get('/forget/' . implode('/', $items)); 85 | } catch (ClientException $e) { 86 | return false; 87 | } 88 | 89 | return true; 90 | } 91 | 92 | /** 93 | * @return array 94 | */ 95 | public function forgetItemsList() 96 | { 97 | try { 98 | $response = $this->client->get('/forget?list'); 99 | $itemsString = $response->getBody()->getContents(); 100 | 101 | if (empty($itemsString)) { 102 | return []; 103 | } 104 | 105 | $items = explode(PHP_EOL, $itemsString); 106 | $items = array_filter($items); 107 | $items = array_unique($items); 108 | } catch (ClientException $e) { 109 | return []; 110 | } 111 | 112 | return $items; 113 | } 114 | 115 | /** 116 | * @param array $items 117 | * 118 | * @return bool 119 | */ 120 | public function rememberItems(array $items) 121 | { 122 | if (empty($items)) { 123 | throw new InvalidArgumentException('items is empty!'); 124 | } 125 | 126 | $this->validateArray($items, 'haveString', 'items'); 127 | 128 | try { 129 | $this->client->get('/forget/' . implode('/', $items) . '?remember=1'); 130 | } catch (ClientException $e) { 131 | return false; 132 | } 133 | 134 | return true; 135 | } 136 | 137 | /** 138 | * @param $item 139 | * @param array $terms 140 | * @param bool $overwrite 141 | * 142 | * @param bool $nocheck 143 | * @return bool 144 | */ 145 | public function addTerms($item, array $terms, $overwrite = true, $nocheck = true) 146 | { 147 | 148 | if (empty($terms)) { 149 | throw new InvalidArgumentException('terms is empty!'); 150 | } 151 | 152 | $this->validateArray($terms, 'haveString', 'terms'); 153 | $this->haveString($item, 'item'); 154 | 155 | try { 156 | $queryString = []; 157 | if ($overwrite === true) { 158 | $queryString['query']['overwrite'] = ''; 159 | } 160 | 161 | if ($nocheck === true) { 162 | $queryString['query']['nocheck'] = ''; 163 | } 164 | 165 | $this->client->get('/termItemAdd/' . $item . '/' . implode('/', $terms), $queryString); 166 | } catch (ClientException $e) { 167 | return false; 168 | } 169 | 170 | return true; 171 | } 172 | 173 | /** 174 | * @param $item 175 | * @param array $terms 176 | * 177 | * @return bool 178 | */ 179 | public function removeTerms($item, array $terms) 180 | { 181 | if (empty($terms)) { 182 | throw new InvalidArgumentException('terms is empty!'); 183 | } 184 | 185 | $this->validateArray($terms, 'haveString', 'terms'); 186 | $this->haveString($item, 'item'); 187 | 188 | try { 189 | $this->client->get('/termItemRemove/' . $item . '/' . implode('/', $terms)); 190 | } catch (ClientException $e) { 191 | return false; 192 | } 193 | 194 | return true; 195 | } 196 | 197 | /** 198 | * @param $item 199 | * 200 | * @return array 201 | */ 202 | public function termsList($item) 203 | { 204 | $this->haveString($item, 'item'); 205 | 206 | try { 207 | $response = $this->client->get('/termItemList/' . $item); 208 | 209 | $terms = $this->json_decode_recommender($response->getBody()->getContents()); 210 | if ($terms === null) { 211 | return []; 212 | } 213 | } catch (ClientException $e) { 214 | return []; 215 | } 216 | 217 | return $terms->$item; 218 | } 219 | 220 | /** 221 | * @param $item 222 | * @param array $locations 223 | * @param bool $overwrite 224 | * @param bool $nocheck 225 | * @return bool 226 | */ 227 | public function itemLocationAdd($item, array $locations, $overwrite = true, $nocheck = true) 228 | { 229 | 230 | if (empty($locations)) { 231 | throw new InvalidArgumentException('locations is empty!'); 232 | } 233 | 234 | $this->haveString($item, 'item'); 235 | 236 | try { 237 | $queryString = []; 238 | if ($overwrite === true) { 239 | $queryString['query']['overwrite'] = ''; 240 | } 241 | 242 | if ($nocheck === true) { 243 | $queryString['query']['nocheck'] = ''; 244 | } 245 | 246 | $this->client->get('/itemLocationAdd/' . $item . '/' . implode('/', $locations), $queryString); 247 | } catch (ClientException $e) { 248 | return false; 249 | } 250 | 251 | return true; 252 | } 253 | 254 | /** 255 | * @param $item 256 | * @return array 257 | */ 258 | public function itemLocationList($item) 259 | { 260 | $this->haveString($item, 'item'); 261 | 262 | try { 263 | $response = $this->client->get('/itemLocationList/' . $item); 264 | $terms = $this->json_decode_recommender($response->getBody()->getContents()); 265 | if ($terms === null) { 266 | return []; 267 | } 268 | } catch (ClientException $e) { 269 | return []; 270 | } 271 | 272 | return $terms->$item; 273 | } 274 | 275 | /** 276 | * @param $userId 277 | * @param null $howMany 278 | * @param bool|false $dither 279 | * 280 | * @param null $radius 281 | * @return array|mixed 282 | */ 283 | public function recommend($userId, $howMany = null, $dither = false, $radius = null) 284 | { 285 | $this->isInt($userId, 'userId'); 286 | 287 | try { 288 | 289 | $queryString = []; 290 | if (is_numeric($howMany) and $howMany > 0) { 291 | $queryString['query']['howMany'] = $howMany; 292 | } 293 | 294 | if ($dither === true) { 295 | $queryString['query']['dither'] = ''; 296 | } 297 | 298 | if (is_numeric($radius) and $radius > 0) { 299 | $queryString['query']['radius'] = $radius; 300 | } 301 | 302 | $response = $this->client->get('/recommend/' . $userId, $queryString); 303 | return json_decode($response->getBody()->getContents()); 304 | } catch (ClientException $e) { 305 | return []; 306 | } 307 | } 308 | 309 | /** 310 | * @param $userId 311 | * @param null $howMany 312 | * @param bool $fresh 313 | * @return array|mixed 314 | */ 315 | public function termRecommend($userId, $howMany = null, $fresh = false) 316 | { 317 | $this->isInt($userId, 'userId'); 318 | 319 | try { 320 | 321 | $queryString = []; 322 | if (is_numeric($howMany) and $howMany > 0) { 323 | $queryString['query']['howMany'] = $howMany; 324 | } 325 | 326 | if ($fresh === true) { 327 | $queryString['query']['fresh'] = ''; 328 | } 329 | 330 | $response = $this->client->get('/termRecommend/' . $userId, $queryString); 331 | return json_decode($response->getBody()->getContents()); 332 | } catch (ClientException $e) { 333 | return []; 334 | } 335 | } 336 | 337 | /** 338 | * @param $userId 339 | * @param null $howMany 340 | * @param bool $fresh 341 | * @return array|mixed 342 | */ 343 | public function spectrometer($userId, $howMany = null, $fresh = false) 344 | { 345 | $this->isInt($userId, 'userId'); 346 | 347 | try { 348 | 349 | $queryString = []; 350 | if (is_numeric($howMany) and $howMany > 0) { 351 | $queryString['query']['howMany'] = $howMany; 352 | } 353 | 354 | if ($fresh === true) { 355 | $queryString['query']['fresh'] = ''; 356 | } 357 | 358 | $response = $this->client->get('/spectrometer/' . $userId, $queryString); 359 | return json_decode($response->getBody()->getContents()); 360 | } catch (ClientException $e) { 361 | return []; 362 | } 363 | } 364 | 365 | /** 366 | * @param $userId 367 | * @param null $howMany 368 | * @param bool $fresh 369 | * @return array|mixed 370 | */ 371 | public function spotlight($userId, $howMany = null, $fresh = false) 372 | { 373 | $this->isInt($userId, 'userId'); 374 | 375 | try { 376 | 377 | $queryString = []; 378 | if (is_numeric($howMany) and $howMany > 0) { 379 | $queryString['query']['howMany'] = $howMany; 380 | } 381 | 382 | if ($fresh === true) { 383 | $queryString['query']['fresh'] = ''; 384 | } 385 | 386 | $response = $this->client->get('/spotlight/' . $userId, $queryString); 387 | return json_decode($response->getBody()->getContents()); 388 | } catch (ClientException $e) { 389 | return []; 390 | } 391 | } 392 | 393 | /** 394 | * @param array $userIds 395 | * @param null $howMany 396 | * @param bool|false $dither 397 | * 398 | * @return array|mixed 399 | */ 400 | public function recommendToGroup(array $userIds, $howMany = null, $dither = false) 401 | { 402 | if (empty($userIds)) { 403 | throw new InvalidArgumentException('userIds is empty!'); 404 | } 405 | 406 | $this->validateArray($userIds, 'isInt', 'userIds'); 407 | 408 | try { 409 | 410 | $queryString = []; 411 | if (is_numeric($howMany) and $howMany > 0) { 412 | $queryString['query']['howMany'] = $howMany; 413 | } 414 | 415 | if ($dither === true) { 416 | $queryString['query']['dither'] = ''; 417 | } 418 | 419 | $response = $this->client->get('/recommendToGroup/' . implode('/', $userIds), $queryString); 420 | return json_decode($response->getBody()->getContents()); 421 | } catch (ClientException $e) { 422 | return []; 423 | } 424 | } 425 | 426 | 427 | /** 428 | * @param array $items 429 | * @param null $howMany 430 | * @return array|mixed 431 | */ 432 | public function recommendToNewcomer(array $items, $howMany = null) 433 | { 434 | if (empty($items)) { 435 | throw new InvalidArgumentException('items is empty!'); 436 | } 437 | 438 | $this->validateArray($items, 'haveString', 'items'); 439 | 440 | try { 441 | 442 | $queryString = []; 443 | if (is_numeric($howMany) and $howMany > 0) { 444 | $queryString['query']['howMany'] = $howMany; 445 | } 446 | 447 | $response = $this->client->get('/recommendToNewcomer/' . implode('/', $items), $queryString); 448 | return json_decode($response->getBody()->getContents()); 449 | } catch (ClientException $e) { 450 | return []; 451 | } 452 | } 453 | 454 | 455 | /** 456 | * @param array $items 457 | * @param null $howMany 458 | * 459 | * @return array|mixed 460 | */ 461 | public function similarity(array $items, $howMany = null) 462 | { 463 | if (empty($items)) { 464 | throw new InvalidArgumentException('items is empty!'); 465 | } 466 | 467 | $this->validateArray($items, 'haveString', 'items'); 468 | 469 | try { 470 | 471 | $queryString = []; 472 | if (is_numeric($howMany) and $howMany > 0) { 473 | $queryString['query']['howMany'] = $howMany; 474 | } 475 | 476 | $response = $this->client->get('/similarity/' . implode('/', $items), $queryString); 477 | return json_decode($response->getBody()->getContents()); 478 | } catch (ClientException $e) { 479 | return []; 480 | } 481 | } 482 | 483 | /** 484 | * @param $item 485 | * @param array $items 486 | * 487 | * @return array 488 | */ 489 | public function similarityToItem($item, array $items) 490 | { 491 | $this->haveString($item); 492 | 493 | if (empty($items)) { 494 | throw new InvalidArgumentException('items is empty!'); 495 | } 496 | 497 | $this->validateArray($items, 'haveString', 'items'); 498 | 499 | try { 500 | $response = $this->client->get('/similarityToItem/' . $item . '/' . implode('/', $items)); 501 | 502 | $similarityString = $response->getBody()->getContents(); 503 | 504 | if (empty($similarityString)) { 505 | return []; 506 | } 507 | 508 | $similarities = explode(PHP_EOL, $similarityString); 509 | $similarities = array_filter($similarities); 510 | 511 | $results = []; 512 | $index = 0; 513 | foreach ($items as $item) { 514 | $results[$item] = $similarities[$index]; 515 | $index++; 516 | } 517 | 518 | return $results; 519 | } catch (ClientException $e) { 520 | return []; 521 | } 522 | } 523 | 524 | /** 525 | * @param $userId 526 | * @param $item 527 | * @param null $howMany 528 | * 529 | * @return array|mixed 530 | */ 531 | public function because($userId, $item, $howMany = null) 532 | { 533 | $this->isInt($userId); 534 | $this->haveString($item); 535 | 536 | try { 537 | 538 | $queryString = []; 539 | if (is_numeric($howMany) and $howMany > 0) { 540 | $queryString['query']['howMany'] = $howMany; 541 | } 542 | 543 | $response = $this->client->get('/because/' . $userId . '/' . $item, $queryString); 544 | 545 | return json_decode($response->getBody()->getContents()); 546 | } catch (ClientException $e) { 547 | return []; 548 | } 549 | } 550 | 551 | /** 552 | * @param null $howMany 553 | * 554 | * @return array|mixed 555 | */ 556 | public function mostPopularItems($howMany = null) 557 | { 558 | try { 559 | 560 | $queryString = []; 561 | if (is_numeric($howMany) and $howMany > 0) { 562 | $queryString['query']['howMany'] = $howMany; 563 | } 564 | 565 | $response = $this->client->get('/mostPopularItems', $queryString); 566 | return json_decode($response->getBody()->getContents()); 567 | } catch (ClientException $e) { 568 | return []; 569 | } 570 | } 571 | 572 | /** 573 | * @param null $howMany 574 | * 575 | * @return array|mixed 576 | */ 577 | public function termMostPopularItems($howMany = null) 578 | { 579 | try { 580 | 581 | $queryString = []; 582 | if (is_numeric($howMany) and $howMany > 0) { 583 | $queryString['query']['howMany'] = $howMany; 584 | } 585 | 586 | $response = $this->client->get('/termMostPopularItems', $queryString); 587 | return json_decode($response->getBody()->getContents()); 588 | } catch (ClientException $e) { 589 | return []; 590 | } 591 | } 592 | 593 | /** 594 | * @param array $items 595 | * @param null $howMany 596 | * @param bool|false $guess 597 | * 598 | * @return array|mixed 599 | */ 600 | public function termSimilarity(array $items, $howMany = null, $guess = false) 601 | { 602 | if (empty($items)) { 603 | throw new InvalidArgumentException('items is empty!'); 604 | } 605 | 606 | $this->validateArray($items, 'haveString', 'items'); 607 | 608 | try { 609 | 610 | $queryString = []; 611 | if (is_numeric($howMany) and $howMany > 0) { 612 | $queryString['query']['howMany'] = $howMany; 613 | } 614 | 615 | if ($guess === true) { 616 | $queryString['query']['guess'] = ''; 617 | } 618 | 619 | $response = $this->client->get('/termSimilarity/' . implode('/', $items), $queryString); 620 | return json_decode($response->getBody()->getContents()); 621 | } catch (ClientException $e) { 622 | return []; 623 | } 624 | } 625 | 626 | /** 627 | * @param $userId 628 | * @param array $terms 629 | * @param null $howMany 630 | * @param bool $fresh 631 | * @param bool $profileBased 632 | * @param null $radius 633 | * @param bool $dither 634 | * @return array|mixed 635 | */ 636 | public function termBasedRecommend( 637 | $userId, 638 | array $terms, 639 | $howMany = null, 640 | $fresh = false, 641 | $profileBased = false, 642 | $radius = null, 643 | $dither = false 644 | ) 645 | { 646 | $this->isInt($userId); 647 | 648 | 649 | if (empty($terms) and $profileBased == false) { 650 | throw new InvalidArgumentException('terms is empty!'); 651 | } 652 | 653 | $queryStringTerms = ''; 654 | if (!empty($terms)) { 655 | $this->validateArray($terms, 'haveString', 'terms'); 656 | $queryStringTerms = implode('/', $terms); 657 | } 658 | 659 | try { 660 | 661 | $queryString = []; 662 | if (is_numeric($howMany) and $howMany > 0) { 663 | $queryString['query']['howMany'] = $howMany; 664 | } 665 | 666 | if (is_numeric($radius) and $radius > 0) { 667 | $queryString['query']['radius'] = $radius; 668 | } 669 | 670 | if ($fresh === true) { 671 | $queryString['query']['fresh'] = ''; 672 | } 673 | 674 | if ($profileBased === true) { 675 | $queryString['query']['profileBased'] = ''; 676 | } 677 | 678 | if ($dither === true) { 679 | $queryString['query']['dither'] = ''; 680 | } 681 | 682 | 683 | $response = $this->client->get('/termBasedRecommend/' . $userId . '/' . $queryStringTerms, $queryString); 684 | return json_decode($response->getBody()->getContents()); 685 | } catch (ClientException $e) { 686 | return []; 687 | } 688 | } 689 | 690 | /** 691 | * @param $userId 692 | * @param array $terms 693 | * @param null $howMany 694 | * @param bool $fresh 695 | * @param bool $profileBased 696 | * @param null $radius 697 | * @param bool $dither 698 | * @return array|mixed 699 | */ 700 | public function termBasedRecommendInclusive( 701 | $userId, 702 | array $terms, 703 | $howMany = null, 704 | $fresh = false, 705 | $profileBased = false, 706 | $radius = null, 707 | $dither = false 708 | ) 709 | { 710 | $this->isInt($userId); 711 | 712 | 713 | if (empty($terms) and $profileBased == false) { 714 | throw new InvalidArgumentException('terms is empty!'); 715 | } 716 | 717 | $queryStringTerms = ''; 718 | if (!empty($terms)) { 719 | $this->validateArray($terms, 'haveString', 'terms'); 720 | $queryStringTerms = implode('/', $terms); 721 | } 722 | 723 | try { 724 | 725 | $queryString = []; 726 | if (is_numeric($howMany) and $howMany > 0) { 727 | $queryString['query']['howMany'] = $howMany; 728 | } 729 | 730 | if (is_numeric($radius) and $radius > 0) { 731 | $queryString['query']['radius'] = $radius; 732 | } 733 | 734 | if ($fresh === true) { 735 | $queryString['query']['fresh'] = ''; 736 | } 737 | 738 | if ($profileBased === true) { 739 | $queryString['query']['profileBased'] = ''; 740 | } 741 | 742 | if ($dither === true) { 743 | $queryString['query']['dither'] = ''; 744 | } 745 | 746 | 747 | $response = $this->client->get('/termBasedRecommendInclusive/' . $userId . '/' . $queryStringTerms, 748 | $queryString); 749 | return json_decode($response->getBody()->getContents()); 750 | } catch (ClientException $e) { 751 | return []; 752 | } 753 | } 754 | 755 | 756 | /** 757 | * @param array $terms 758 | * @param null $howMany 759 | * 760 | * @return array|mixed 761 | */ 762 | public function termBasedMostPopularItems(array $terms, $howMany = null) 763 | { 764 | 765 | if (empty($terms)) { 766 | throw new InvalidArgumentException('terms is empty!'); 767 | } 768 | 769 | $this->validateArray($terms, 'haveString', 'terms'); 770 | 771 | try { 772 | 773 | $queryString = []; 774 | if (is_numeric($howMany) and $howMany > 0) { 775 | $queryString['query']['howMany'] = $howMany; 776 | } 777 | 778 | $response = $this->client->get('/termBasedMostPopularItems/' . implode('/', $terms), $queryString); 779 | return json_decode($response->getBody()->getContents()); 780 | } catch (ClientException $e) { 781 | return []; 782 | } 783 | } 784 | 785 | /** 786 | * @param $item 787 | * @param array $terms 788 | * @param null $howMany 789 | * 790 | * @param bool $fresh 791 | * @return array|mixed 792 | */ 793 | public function termBasedSimilarity($item, array $terms, $howMany = null, $fresh = false) 794 | { 795 | $this->haveString($item); 796 | 797 | if (empty($terms)) { 798 | throw new InvalidArgumentException('terms is empty!'); 799 | } 800 | 801 | $this->validateArray($terms, 'haveString', 'terms'); 802 | 803 | try { 804 | 805 | $queryString = []; 806 | if (is_numeric($howMany) and $howMany > 0) { 807 | $queryString['query']['howMany'] = $howMany; 808 | } 809 | 810 | if ($fresh === true) { 811 | $queryString['query']['fresh'] = ''; 812 | } 813 | 814 | $response = $this->client->get('/termBasedSimilarity/' . $item . '/' . implode('/', $terms), $queryString); 815 | return json_decode($response->getBody()->getContents()); 816 | } catch (ClientException $e) { 817 | return []; 818 | } 819 | } 820 | 821 | /** 822 | * @param $item 823 | * @param array $terms 824 | * @param null $howMany 825 | * @param bool $fresh 826 | * @return array|mixed 827 | */ 828 | public function termBasedSimilarityInclusive($item, array $terms, $howMany = null, $fresh = false) 829 | { 830 | $this->haveString($item); 831 | 832 | if (empty($terms)) { 833 | throw new InvalidArgumentException('terms is empty!'); 834 | } 835 | 836 | $this->validateArray($terms, 'haveString', 'terms'); 837 | 838 | try { 839 | 840 | $queryString = []; 841 | if (is_numeric($howMany) and $howMany > 0) { 842 | $queryString['query']['howMany'] = $howMany; 843 | } 844 | 845 | if ($fresh === true) { 846 | $queryString['query']['fresh'] = ''; 847 | } 848 | 849 | $response = $this->client->get('/termBasedSimilarity/' . $item . '/' . implode('/', $terms), $queryString); 850 | return json_decode($response->getBody()->getContents()); 851 | } catch (ClientException $e) { 852 | return []; 853 | } 854 | } 855 | 856 | /** 857 | * @param array $terms 858 | * 859 | * @return array|mixed 860 | */ 861 | public function termNeighborhood(array $terms) 862 | { 863 | 864 | if (empty($terms)) { 865 | throw new InvalidArgumentException('terms is empty!'); 866 | } 867 | 868 | $this->validateArray($terms, 'haveString', 'terms'); 869 | 870 | try { 871 | $response = $this->client->get('/termNeighborhood/' . implode('/', $terms)); 872 | return json_decode($response->getBody()->getContents()); 873 | } catch (ClientException $e) { 874 | return []; 875 | } 876 | } 877 | 878 | /** 879 | * @param $userId 880 | * 881 | * @return array|mixed 882 | */ 883 | public function latestTouchedItems($userId) 884 | { 885 | $this->isInt($userId); 886 | 887 | try { 888 | $response = $this->client->get('/latestTouchedItems/' . $userId); 889 | return json_decode($response->getBody()->getContents()); 890 | } catch (ClientException $e) { 891 | return []; 892 | } 893 | } 894 | 895 | /** 896 | * @param $userId 897 | * 898 | * @return array|mixed 899 | */ 900 | public function latestTouchedTerms($userId) 901 | { 902 | $this->isInt($userId); 903 | 904 | try { 905 | $response = $this->client->get('/latestTouchedTerms/' . $userId); 906 | return json_decode($response->getBody()->getContents()); 907 | } catch (ClientException $e) { 908 | return []; 909 | } 910 | } 911 | 912 | /** 913 | * @param $userId 914 | * 915 | * @return array|mixed 916 | */ 917 | public function userFrequentlyTouchedItems($userId) 918 | { 919 | $this->isInt($userId); 920 | 921 | try { 922 | $response = $this->client->get('/userFrequentlyTouchedItems/' . $userId); 923 | return json_decode($response->getBody()->getContents()); 924 | } catch (ClientException $e) { 925 | return []; 926 | } 927 | } 928 | 929 | /** 930 | * @param $item 931 | * 932 | * @return array 933 | */ 934 | public function itemFrequentlyVisitors($item) 935 | { 936 | $this->haveString($item, 'item'); 937 | 938 | try { 939 | $response = $this->client->get('/itemFrequentlyVisitors/' . $item); 940 | 941 | $users = $this->json_decode_recommender($response->getBody()->getContents()); 942 | if ($users === null) { 943 | return []; 944 | } 945 | } catch (ClientException $e) { 946 | return []; 947 | } 948 | 949 | return $users->$item; 950 | } 951 | 952 | /** 953 | * @param $userId 954 | * 955 | * @return array|mixed 956 | */ 957 | public function currentMood($userId) 958 | { 959 | $this->isInt($userId); 960 | 961 | try { 962 | $response = $this->client->get('/currentMood/' . $userId); 963 | return json_decode($response->getBody()->getContents()); 964 | } catch (ClientException $e) { 965 | return []; 966 | } 967 | } 968 | 969 | /** 970 | * @param $userId 971 | * @param null $gender 972 | * @param null $birthYear 973 | * @param null $homeLocation 974 | * @param null $workLocation 975 | * @param null $currentLocation 976 | * @param array $priorities 977 | * @param bool $overwrite 978 | * @return bool 979 | */ 980 | public function setUserProfile( 981 | $userId, 982 | $gender = null, 983 | $birthYear = null, 984 | $homeLocation = null, 985 | $workLocation = null, 986 | $currentLocation = null, 987 | array $priorities = [], 988 | $overwrite = true 989 | ) 990 | { 991 | try { 992 | $this->isInt($userId, 'userId'); 993 | 994 | $queryString = []; 995 | if ($birthYear !== null and $birthYear > 0) { 996 | $queryString['query']['birthYear'] = $birthYear; 997 | } 998 | 999 | if ($gender !== null) { 1000 | $queryString['query']['gender'] = $gender; 1001 | } 1002 | 1003 | if ($overwrite === true) { 1004 | $queryString['query']['overwrite'] = ''; 1005 | } 1006 | 1007 | if ($homeLocation !== null) { 1008 | $queryString['query']['homeLocation'] = $homeLocation; 1009 | } 1010 | 1011 | if ($workLocation !== null) { 1012 | $queryString['query']['workLocation'] = $workLocation; 1013 | } 1014 | 1015 | if ($currentLocation !== null) { 1016 | $queryString['query']['currentLocation'] = $currentLocation; 1017 | } 1018 | 1019 | if (!empty($priorities)) { 1020 | $queryString['query']['priorities'] = implode(',', $priorities); 1021 | } 1022 | 1023 | $this->client->get('/setUserProfile/' . $userId, $queryString); 1024 | } catch (ClientException $e) { 1025 | return false; 1026 | } 1027 | 1028 | return true; 1029 | } 1030 | 1031 | /** 1032 | * @param $userId 1033 | * @return mixed|null 1034 | */ 1035 | public function getUserProfile($userId) 1036 | { 1037 | $this->isInt($userId); 1038 | 1039 | try { 1040 | $response = $this->client->get('/getUserProfile/' . $userId); 1041 | return json_decode($response->getBody()->getContents()); 1042 | } catch (ClientException $e) { 1043 | return null; 1044 | } 1045 | } 1046 | 1047 | /** 1048 | * @param $userId 1049 | * @return mixed|null 1050 | */ 1051 | public function guessUserProfile($userId) 1052 | { 1053 | $this->isInt($userId); 1054 | 1055 | try { 1056 | $response = $this->client->get('/guessUserProfiles/' . $userId); 1057 | return json_decode($response->getBody()->getContents()); 1058 | } catch (ClientException $e) { 1059 | return null; 1060 | } 1061 | } 1062 | 1063 | /** 1064 | * @param $userId 1065 | * @param $item 1066 | * @param null $howMany 1067 | * @param bool $fresh 1068 | * @return array|mixed 1069 | */ 1070 | public function luckyUser($userId, $item, $howMany = null, $fresh = false) 1071 | { 1072 | $this->isInt($userId, 'userId'); 1073 | $this->haveString($item, 'item'); 1074 | 1075 | try { 1076 | 1077 | $queryString = []; 1078 | if (is_numeric($howMany) and $howMany > 0) { 1079 | $queryString['query']['howMany'] = $howMany; 1080 | } 1081 | 1082 | if ($fresh === true) { 1083 | $queryString['query']['dither'] = ''; 1084 | } 1085 | 1086 | $response = $this->client->get('/luckyUser/' . $userId . '/' . $item, $queryString); 1087 | return json_decode($response->getBody()->getContents()); 1088 | } catch (ClientException $e) { 1089 | return []; 1090 | } 1091 | } 1092 | 1093 | /** 1094 | * @param $frequency 1095 | * @param null $howMany 1096 | * @return mixed 1097 | */ 1098 | public function getTrends($frequency = 'trendMidTime', $howMany = null) 1099 | { 1100 | try { 1101 | if (!in_array($frequency, ['trendMidTime', 'trendShortTime', 'trendLongTime'])) { 1102 | throw new InvalidArgumentException; 1103 | } 1104 | 1105 | $queryString = []; 1106 | if (is_numeric($howMany) and $howMany > 0) { 1107 | $queryString['query']['howMany'] = $howMany; 1108 | } 1109 | 1110 | $response = $this->client->get("/{$frequency}", $queryString); 1111 | return json_decode($response->getBody()); 1112 | } catch (ClientException $e) { 1113 | return []; 1114 | } 1115 | } 1116 | 1117 | 1118 | /** 1119 | * @param $user_id 1120 | * @param array $items 1121 | * @return array|mixed 1122 | */ 1123 | public function interest($user_id, array $items) 1124 | { 1125 | $this->isInt($user_id, 'userId'); 1126 | $this->validateArray($items, 'haveString'); 1127 | 1128 | try { 1129 | $response = $this->client->get('/interest/'. "{$user_id}/". implode('/', $items)); 1130 | return json_decode($response->getBody()); 1131 | } catch (ClientException $e) { 1132 | return []; 1133 | } 1134 | } 1135 | 1136 | /** 1137 | * @param $user_id 1138 | * @param array $items 1139 | * @return array|mixed 1140 | */ 1141 | public function sort($user_id, array $items) 1142 | { 1143 | $this->isInt($user_id, 'userId'); 1144 | $this->validateArray($items, 'haveString'); 1145 | 1146 | try { 1147 | $response = $this->client->get('/genericSort/interest/'. "{$user_id}/". implode('/', $items)); 1148 | return json_decode($response->getBody()); 1149 | } catch (ClientException $e) { 1150 | return []; 1151 | } 1152 | } 1153 | } 1154 | -------------------------------------------------------------------------------- /src/Helpers.php: -------------------------------------------------------------------------------- 1 | str_replace_last(']', '}', $string); 10 | $json = $this->str_replace_first('[', '{', $string); 11 | 12 | return json_decode($json); 13 | } 14 | 15 | protected function str_replace_last($search, $replace, $subject) 16 | { 17 | 18 | if (($pos = strrpos($subject, $search)) !== false) { 19 | $search_length = strlen($search); 20 | $subject = substr_replace($subject, $replace, $pos, $search_length); 21 | } 22 | return $subject; 23 | } 24 | 25 | protected function str_replace_first($search, $replace, $subject) 26 | { 27 | $search = '/' . preg_quote($search, '/') . '/'; 28 | return preg_replace($search, $replace, $subject, 1); 29 | } 30 | } -------------------------------------------------------------------------------- /src/Validator.php: -------------------------------------------------------------------------------- 1 | {$functionName}($ar, $key); 25 | } 26 | return true; 27 | } 28 | 29 | /** 30 | * @param $var 31 | * @param string $key 32 | * 33 | * @return bool 34 | */ 35 | protected function haveString($var, $key = 'item') 36 | { 37 | if (!preg_match('/[a-zA-Z]/', $var)) { 38 | throw new InvalidArgumentException($key.' must be string and contains at least one character!'); 39 | } 40 | 41 | return true; 42 | } 43 | 44 | /** 45 | * @param $var 46 | * @param string $key 47 | * 48 | * @return bool 49 | */ 50 | protected function isInt($var, $key = 'item') 51 | { 52 | if (!is_numeric($var)) { 53 | throw new InvalidArgumentException($key.' must be integer!'); 54 | } 55 | 56 | return true; 57 | } 58 | 59 | /** 60 | * @param $value 61 | * 62 | * @return bool 63 | */ 64 | protected function validateValue($value) 65 | { 66 | if ($value < -255 and $value > 255) { 67 | throw new InvalidArgumentException('value must be between -255 and 255'); 68 | } 69 | 70 | return true; 71 | } 72 | } --------------------------------------------------------------------------------