diff --git a/Jenkinsfile b/Jenkinsfile index 4267d6e..26d0ffb 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,7 +8,9 @@ node { checkout scm } stage("Test with Docker") { - withEnv(["API_KEY=${env.ROSETTE_API_KEY}", "ALT_URL=${env.BINDING_TEST_URL}"]) { + echo "${env.ALT_URL}" + def useUrl = ("${env.ALT_URL}" == "null") ? "${env.BINDING_TEST_URL}" : "${env.ALT_URL}" + withEnv(["API_KEY=${env.ROSETTE_API_KEY}", "ALT_URL=${useUrl}"]) { sh "docker run --rm -e API_KEY=${API_KEY} -e ALT_URL=${ALT_URL} -v ${SOURCEDIR}:/source rosetteapi/docker-php" } } diff --git a/Jenkinsfile.examples b/Jenkinsfile.examples index 2727fbc..2fbe64f 100644 --- a/Jenkinsfile.examples +++ b/Jenkinsfile.examples @@ -11,11 +11,13 @@ node { } stage("Build Dockerfile") { dir ("${DOCKERFILE_DIR}") { - docker.build("${TEST_CONTAINER}") + sh "docker build --no-cache -t ${TEST_CONTAINER} ." } } stage("Run Examples") { - withEnv(["API_KEY=${env.ROSETTE_API_KEY}", "ALT_URL=${env.BINDING_TEST_URL}"]) { + echo "${env.ALT_URL}" + def useUrl = ("${env.ALT_URL}" == "null") ? "${env.BINDING_TEST_URL}" : "${env.ALT_URL}" + withEnv(["API_KEY=${env.ROSETTE_API_KEY}", "ALT_URL=${useUrl}"]) { sh "docker run --rm -e API_KEY=${API_KEY} -e ALT_URL=${ALT_URL} -v ${SOURCEDIR}:/source ${TEST_CONTAINER}" } } diff --git a/composer.json b/composer.json index 0bf9ab5..edcd26c 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "rosette/api", - "version": "1.8.0", + "version": "1.9.0", "description": "Rosette API PHP client SDK", "license": "Apache", "keywords": [ diff --git a/examples/entities.php b/examples/entities.php index b54e803..d1866db 100644 --- a/examples/entities.php +++ b/examples/entities.php @@ -13,7 +13,7 @@ echo 'Usage: php ' . __FILE__ . " --key --url=\n"; exit(); } -$entities_text_data = "Bill Murray will appear in new Ghostbusters film: Dr. Peter Venkman was spotted filming a cameo in Boston this… http://dlvr.it/BnsFfS"; +$entities_text_data = "The Securities and Exchange Commission today announced the leadership of the agency’s trial unit. Bridget Fitzpatrick has been named Chief Litigation Counsel of the SEC and David Gottesman will continue to serve as the agency’s Deputy Chief Litigation Counsel. Since December 2016, Ms. Fitzpatrick and Mr. Gottesman have served as Co-Acting Chief Litigation Counsel. In that role, they were jointly responsible for supervising the trial unit at the agency’s Washington D.C. headquarters as well as coordinating with litigators in the SEC’s 11 regional offices around the country."; $api = isset($options['url']) ? new Api($options['key'], $options['url']) : new Api($options['key']); $params = new DocumentParameters(); $content = $entities_text_data; diff --git a/examples/language_multilingual.php b/examples/language_multilingual.php new file mode 100644 index 0000000..d0f5c4d --- /dev/null +++ b/examples/language_multilingual.php @@ -0,0 +1,29 @@ + --url=\n"; + exit(); +} +$language_multilingual_data = "On Thursday, as protesters gathered in Washington D.C., the United States Federal Communications Commission under Chairman Ajit Pai voted 3-2 to overturn a 2015 decision, commonly called Net Neutrality, that forbade Internet service providers (ISPs) such as Verizon, Comcast, and AT&T from blocking individual websites or charging websites or customers more for faster load times. Quatre femmes ont été nommées au Conseil de rédaction de la loi du Qatar. Jeudi, le décret royal du Qatar a annoncé que 28 nouveaux membres ont été nommés pour le Conseil de la Choura du pays. ذكرت مصادر أمنية يونانية، أن 9 موقوفين من منظمة \"د هـ ك ب ج\" الذين كانت قد أوقفتهم الشرطة اليونانية في وقت سابق كانوا يخططون لاغتيال الرئيس التركي رجب طيب أردوغان."; +$api = isset($options['url']) ? new Api($options['key'], $options['url']) : new Api($options['key']); +$params = new DocumentParameters(); +$content = $language_multilingual_data; +$params->set('content', $content); +$api->setCustomHeader('X-RosetteAPI-App', 'php-app'); +$api->setOption('multilingual', 'true'); + +try { + $result = $api->language($params); + var_dump($result); +} catch (RosetteException $e) { + error_log($e); +} diff --git a/examples/morphology_complete.php b/examples/morphology_complete.php index 9f8c4d8..ed3ddd2 100644 --- a/examples/morphology_complete.php +++ b/examples/morphology_complete.php @@ -15,7 +15,7 @@ echo 'Usage: php ' . __FILE__ . " --key --url=\n"; exit(); } -$morphology_complete_data = "The quick brown fox jumped over the lazy dog. Yes he did."; +$morphology_complete_data = "The quick brown fox jumped over the lazy dog. 👍🏾 Yes he did. B)"; $api = isset($options['url']) ? new Api($options['key'], $options['url']) : new Api($options['key']); $params = new DocumentParameters(); $params->set('content', $morphology_complete_data); diff --git a/examples/name_deduplication.php b/examples/name_deduplication.php index 1907d96..03e35dc 100644 --- a/examples/name_deduplication.php +++ b/examples/name_deduplication.php @@ -14,7 +14,7 @@ echo 'Usage: php ' . __FILE__ . " --key --url=\n"; exit(); } -$name_dedupe_data = "John Smith,Johnathon Smith,Fred Jones"; +$name_dedupe_data = "Alice Terry,Alice Thierry,Betty Grable,Betty Gable,Norma Shearer,Norm Shearer,Brigitte Helm,Bridget Helem,Judy Holliday,Julie Halliday"; $dedup_array = array(); $threshold = 0.75; diff --git a/examples/relationships.php b/examples/relationships.php index 73451d6..23634d9 100644 --- a/examples/relationships.php +++ b/examples/relationships.php @@ -13,7 +13,7 @@ echo 'Usage: php ' . __FILE__ . " --key --url=\n"; exit(); } -$relationships_text_data = "Bill Gates, Microsoft's former CEO, is a philanthropist."; +$relationships_text_data = "FLIR Systems is headquartered in Oregon and produces thermal imaging, night vision, and infrared cameras and sensor systems. According to the SEC’s order instituting a settled administrative proceeding, FLIR entered into a multi-million dollar contract to provide thermal binoculars to the Saudi government in November 2008. Timms and Ramahi were the primary sales employees responsible for the contract, and also were involved in negotiations to sell FLIR’s security cameras to the same government officials. At the time, Timms was the head of FLIR’s Middle East office in Dubai."; $api = isset($options['url']) ? new Api($options['key'], $options['url']) : new Api($options['key']); $params = new DocumentParameters(); $params->set('content', $relationships_text_data); diff --git a/examples/sentences.php b/examples/sentences.php index 266cfd4..b846a9a 100644 --- a/examples/sentences.php +++ b/examples/sentences.php @@ -13,7 +13,7 @@ echo 'Usage: php ' . __FILE__ . " --key --url=\n"; exit(); } -$sentences_data = "This land is your land. This land is my land\nFrom California to the New York island;\nFrom the red wood forest to the Gulf Stream waters\n\nThis land was made for you and Me.\n\nAs I was walking that ribbon of highway,\nI saw above me that endless skyway:\nI saw below me that golden valley:\nThis land was made for you and me."; +$sentences_data = "This land is your land. This land is my land, from California to the New York island; from the red wood forest to the Gulf Stream waters. This land was made for you and Me. As I was walking that ribbon of highway, I saw above me that endless skyway: I saw below me that golden valley: This land was made for you and me."; $api = isset($options['url']) ? new Api($options['key'], $options['url']) : new Api($options['key']); $params = new DocumentParameters(); $content = $sentences_data; diff --git a/examples/transliteration.php b/examples/transliteration.php index 3d52c78..b7a8a00 100644 --- a/examples/transliteration.php +++ b/examples/transliteration.php @@ -13,7 +13,7 @@ echo 'Usage: php ' . __FILE__ . " --key --url=\n"; exit(); } -$transliteration_data = "معمر محمد أبو منيار القذاف"; +$transliteration_data = "ana r2ye7 el gam3a el sa3a 3 el 3asr"; $api = isset($options['url']) ? new Api($options['key'], $options['url']) : new Api($options['key']); $params = new DocumentParameters(); $params->set('content', $transliteration_data); diff --git a/source/rosette/api/Api.php b/source/rosette/api/Api.php index dcb3d7d..c667b80 100644 --- a/source/rosette/api/Api.php +++ b/source/rosette/api/Api.php @@ -38,7 +38,7 @@ class Api * * @var string */ - private static $binding_version = '1.8.0'; + private static $binding_version = '1.9.0'; /** * User key (required for Rosette API). @@ -114,9 +114,9 @@ public function __construct($user_key, $service_url = 'https://api.rosette.com/r $this->headers = array('X-RosetteAPI-Key' => $user_key, 'Content-Type' => 'application/json', 'Accept-Encoding' => 'gzip', - 'User-Agent' => 'RosetteAPIPHP/' . self::$binding_version, + 'User-Agent' => $this->getUserAgent(), 'X-RosetteApi-Binding' => 'php', - 'X-RosetteAPI-Binding-Version' => self::$binding_version); + 'X-RosetteAPI-Binding-Version' => $this->getBindingVersion()); $this->setServiceUrl($service_url); $this->setDebug(false); @@ -127,6 +127,22 @@ public function __construct($user_key, $service_url = 'https://api.rosette.com/r $this->customHeaders = array(); } + /** + * Returns the binding version + */ + public function getBindingVersion() + { + return self::$binding_version; + } + + /** + * Returns the string used for User-Agent + */ + public function getUserAgent() + { + return 'RosetteAPIPHP/' . $this->getBindingVersion() . '/' . phpversion(); + } + /** * Sets on override Request for mocking purposes * diff --git a/spec/rosette/api/ApiSpec.php b/spec/rosette/api/ApiSpec.php index 09fe596..b26114b 100644 --- a/spec/rosette/api/ApiSpec.php +++ b/spec/rosette/api/ApiSpec.php @@ -24,6 +24,12 @@ public function it_sets_gets_response_code() $this->setResponseCode($responseCode); $this->getResponseCode()->shouldBe($responseCode); } + public function it_constructs_user_agent() + { + $version = $this->getWrappedObject()->getBindingVersion(); + $uaString = 'RosetteAPIPHP/' . $version . '/' . phpversion(); + $this->getUserAgent()->shouldBe($uaString); + } public function it_sets_gets_clears_url_params() { $this->setUrlParam("output", "Rosette");