Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
seth-mg committed Jan 17, 2018
2 parents 5fd814b + 6119aa0 commit 57586ae
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 13 deletions.
4 changes: 3 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Expand Down
6 changes: 4 additions & 2 deletions Jenkinsfile.examples
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rosette/api",
"version": "1.8.0",
"version": "1.9.0",
"description": "Rosette API PHP client SDK",
"license": "Apache",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion examples/entities.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
echo 'Usage: php ' . __FILE__ . " --key <api_key> --url=<alternate_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;
Expand Down
29 changes: 29 additions & 0 deletions examples/language_multilingual.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/**
* Example code to call Rosette API to detect possible languages for a piece of text.
**/
require_once dirname(__FILE__) . '/../vendor/autoload.php';
use rosette\api\Api;
use rosette\api\DocumentParameters;
use rosette\api\RosetteException;

$options = getopt(null, array('key:', 'url::'));
if (!isset($options['key'])) {
echo 'Usage: php ' . __FILE__ . " --key <api_key> --url=<alternate_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);
}
2 changes: 1 addition & 1 deletion examples/morphology_complete.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
echo 'Usage: php ' . __FILE__ . " --key <api_key> --url=<alternate_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);
Expand Down
2 changes: 1 addition & 1 deletion examples/name_deduplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
echo 'Usage: php ' . __FILE__ . " --key <api_key> --url=<alternate_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;
Expand Down
2 changes: 1 addition & 1 deletion examples/relationships.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
echo 'Usage: php ' . __FILE__ . " --key <api_key> --url=<alternate_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);
Expand Down
2 changes: 1 addition & 1 deletion examples/sentences.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
echo 'Usage: php ' . __FILE__ . " --key <api_key> --url=<alternate_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;
Expand Down
2 changes: 1 addition & 1 deletion examples/transliteration.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
echo 'Usage: php ' . __FILE__ . " --key <api_key> --url=<alternate_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);
Expand Down
22 changes: 19 additions & 3 deletions source/rosette/api/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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);
Expand All @@ -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
*
Expand Down
6 changes: 6 additions & 0 deletions spec/rosette/api/ApiSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 57586ae

Please sign in to comment.