Skip to content

Commit 8190bad

Browse files
author
Chris Park
committed
Merge branch 'develop'
2 parents 1595b96 + a641109 commit 8190bad

File tree

12 files changed

+83
-154
lines changed

12 files changed

+83
-154
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rosette/api",
3-
"version": "1.1.2",
3+
"version": "1.2.0",
44
"description": "Rosette API PHP client SDK",
55
"license": "Apache",
66
"keywords": [

docker/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ RUN apt-get -y update && apt-get install -y \
1717
php5-dev \
1818
php5-cli \
1919
php5-curl \
20-
php5-xsl \
2120
libapache2-mod-php5
2221

2322

docker/Dockerfile-php7

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ RUN apt-get -y update && apt-get install -y \
1717
php7.0-dev \
1818
php7.0-cli \
1919
php7.0-curl \
20-
php7.0-xsl \
2120
libapache2-mod-php7.0
2221

2322

docker/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ Build the docker image, e.g. `docker build -t basistech/php:1.1 .`
99

1010
Run an example as `docker run -e API_KEY=api-key -v "path-to-php-dir:/source" basistech/php:1.1`
1111

12-
To test against a specific source file, add `-e FILENAME=filename` before the `-v`, to test against an alternate url, add `-e ALT_URL=alternate_url`, and optionally if you would like to regenerate gh-pages from the changes made to the development source you can add `-e GIT_USERNAME=git-username -e VERSION=version` before the `-v`. In order to push the gh-pages to git remember to mount .ssh and .gitconfig to the root dir `-v path-to-.ssh-dir:/root/.ssh -v path-to-.gitconfig:/root/.gitconfig`.
12+
To test against a specific source file, add `-e FILENAME=filename` before the `-v`, to test against an alternate url, add `-e ALT_URL=alternate_url`.

docker/composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
],
1818
"require-dev": {
1919
"phpspec/phpspec": "~2.5",
20-
"fabpot/php-cs-fixer": ">=1.9",
21-
"phpdocumentor/phpdocumentor": "~2.8"
20+
"friendsofphp/php-cs-fixer": ">=1.9"
2221
},
2322
"config": {
2423
"bin-dir": "bin"

docker/run_php.sh

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
retcode=0
44
ping_url="https://api.rosette.com/rest/v1"
5+
errors=( "Exception" "processingFailure" "badRequest" "ParseError" "ValueError" "SyntaxError" "AttributeError" "ImportError" )
56

67
#------------------ Functions ----------------------------------------------------
78

@@ -11,12 +12,14 @@ function HELP {
1112
echo " API_KEY - Rosette API key (required)"
1213
echo " FILENAME - PHP source file (optional)"
1314
echo " ALT_URL - Alternate service URL (optional)"
14-
echo " GIT_USERNAME - Git username where you would like to push regenerated gh-pages (optional)"
15-
echo " VERSION - Build version (optional)"
1615
echo "Compiles and runs the source file(s) using the local development source."
1716
exit 1
1817
}
1918

19+
if [ ! -z ${ALT_URL} ]; then
20+
ping_url=${ALT_URL}
21+
fi
22+
2023
#Checks if Rosette API key is valid
2124
function checkAPI {
2225
match=$(curl "${ping_url}/ping" -H "X-RosetteAPI-Key: ${API_KEY}" | grep -o "forbidden")
@@ -36,6 +39,7 @@ function cleanURL() {
3639
esac
3740
ping_url=${ALT_URL}
3841
fi
42+
echo "Calling URL: ${ping_url}"
3943
}
4044

4145
function validateURL() {
@@ -56,16 +60,11 @@ function runExample() {
5660
fi
5761
echo "${result}"
5862
echo -e "\n---------- ${1} end -------------"
59-
if [[ "${result}" == *"Exception"* ]]; then
60-
echo "Exception found"
61-
retcode=1
62-
elif [[ "$result" == *"processingFailure"* ]]; then
63-
retcode=1
64-
elif [[ "$result" == *"AttributeError"* ]]; then
65-
retcode=1
66-
elif [[ "$result" == *"ImportError"* ]]; then
67-
retcode=1
68-
fi
63+
for err in "${errors[@]}"; do
64+
if [[ ${result} == *"${err}"* ]]; then
65+
retcode=1
66+
fi
67+
done
6968
}
7069
#------------------ Functions End ------------------------------------------------
7170

@@ -84,14 +83,6 @@ while getopts ":API_KEY:FILENAME:ALT_URL" arg; do
8483
FILENAME=${OPTARG}
8584
usage
8685
;;
87-
GIT_USERNAME)
88-
GIT_USERNAME=${OPTARG}
89-
usage
90-
;;
91-
VERSION)
92-
VERSION={OPTARG}
93-
usage
94-
;;
9586
esac
9687
done
9788

@@ -108,8 +99,10 @@ if [ ! -z ${API_KEY} ]; then
10899
checkAPI
109100
cd /php-dev/examples
110101
if [ ! -z ${FILENAME} ]; then
102+
echo -e "\nRunning example against: ${ping_url}\n"
111103
runExample ${FILENAME}
112104
else
105+
echo -e "\nRunning examples against: ${ping_url}\n"
113106
for file in *.php; do
114107
runExample ${file}
115108
done
@@ -125,22 +118,4 @@ cd /php-dev && ./bin/phpspec run --config=phpspec.yml --bootstrap=./vendor/autol
125118
#Run php-cs-fixer
126119
./bin/php-cs-fixer fix . --dry-run --diff --level=psr2
127120

128-
#Generate gh-pages and push them to git account (if git username is provided)
129-
if [ ! -z ${GIT_USERNAME} ] && [ ! -z ${VERSION} ]; then
130-
#clone php git repo to the root dir
131-
cd /
132-
git clone [email protected]:${GIT_USERNAME}/php.git
133-
cd php
134-
git checkout origin/gh-pages -b gh-pages
135-
git branch -d develop
136-
#generate gh-pages from development source and output the contents to php repo
137-
cd /php-dev
138-
./bin/phpdoc -d ./source/rosette/api -t /php
139-
cd /php
140-
find -name 'phpdoc-cache-*' -exec rm -rf {} \;
141-
git add .
142-
git commit -a -m "publish php apidocs ${VERSION}"
143-
git push
144-
fi
145-
146121
exit ${retcode}

examples/docker/run_php.sh

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
retcode=0
44
ping_url="https://api.rosette.com/rest/v1"
5+
errors=( "Exception" "processingFailure" "badRequest" "ParseError" "ValueError" "SyntaxError" "AttributeError" "ImportError" )
56

67
#------------------ Functions ----------------------------------------------------
78

@@ -15,6 +16,10 @@ function HELP {
1516
exit 1
1617
}
1718

19+
if [ ! -z ${ALT_URL} ]; then
20+
ping_url=${ALT_URL}
21+
fi
22+
1823
#Checks if Rosette API key is valid
1924
function checkAPI {
2025
match=$(curl "${ping_url}/ping" -H "X-RosetteAPI-Key: ${API_KEY}" | grep -o "forbidden")
@@ -54,16 +59,11 @@ function runExample() {
5459
fi
5560
echo "${result}"
5661
echo -e "\n---------- ${1} end -------------"
57-
if [[ "${result}" == *"Exception"* ]]; then
58-
echo "Exception found"
59-
retcode=1
60-
elif [[ "$result" == *"processingFailure"* ]]; then
61-
retcode=1
62-
elif [[ "$result" == *"AttributeError"* ]]; then
63-
retcode=1
64-
elif [[ "$result" == *"ImportError"* ]]; then
65-
retcode=1
66-
fi
62+
for err in "${errors[@]}"; do
63+
if [[ ${result} == *"${err}"* ]]; then
64+
retcode=1
65+
fi
66+
done
6767
}
6868
#------------------ Functions End ------------------------------------------------
6969

@@ -73,15 +73,12 @@ while getopts ":API_KEY:FILENAME:ALT_URL" arg; do
7373
case "${arg}" in
7474
API_KEY)
7575
API_KEY=${OPTARG}
76-
usage
7776
;;
7877
FILENAME)
7978
FILENAME=${OPTARG}
80-
usage
8179
;;
8280
ALT_URL)
8381
ALT_URL=${OPTARG}
84-
usage
8582
;;
8683
esac
8784
done
@@ -97,8 +94,10 @@ cp /source/examples/*.* .
9794
if [ ! -z ${API_KEY} ]; then
9895
checkAPI
9996
if [ ! -z ${FILENAME} ]; then
97+
echo -e "\nRunning example against: ${ping_url}\n"
10098
runExample ${FILENAME}
10199
else
100+
echo -e "\nRunning examples against: ${ping_url}\n"
102101
for file in *.php; do
103102
runExample ${file}
104103
done

examples/entities.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
$params = new DocumentParameters();
1919
$content = $entities_text_data;
2020
$params->set('content', $content);
21+
$params->set('genre', 'social-media');
2122

2223
try {
23-
$result = $api->entities($params);
24+
$result = $api->entities($params, false);
2425
var_dump($result);
2526
} catch (RosetteException $e) {
2627
error_log($e);

source/rosette/api/Api.php

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__DIR__));
2222
spl_autoload_register(function ($class) {
2323
$class = preg_replace('/.+\\\\/', '', $class);
24-
require_once $class . '.php';
24+
require_once ucfirst($class) . '.php';
2525
});
2626

2727
/**
@@ -45,7 +45,7 @@ class Api
4545
*
4646
* @var string
4747
*/
48-
private static $binding_version = '1.1.2';
48+
private static $binding_version = '1.2.0';
4949

5050
/**
5151
* User key (required for Rosette API).
@@ -329,8 +329,8 @@ public function getCustomHeaders()
329329
public function setCustomHeaders($header)
330330
{
331331
$this->clearCustomHeaders();
332-
if($header != null){
333-
if(preg_match("/^X-RosetteAPI-/", $header)){
332+
if ($header != null) {
333+
if (preg_match("/^X-RosetteAPI-/", $header)) {
334334
array_push($this->customHeaders, $header);
335335
} else {
336336
throw new RosetteException("Custom headers must start with \"X-\"");
@@ -347,17 +347,16 @@ public function setCustomHeaders($header)
347347
**/
348348
private function addHeaders($headers)
349349
{
350-
$customHeaders = $this->getCustomHeaders();
350+
$customHeaders = $this->getCustomHeaders();
351351

352-
if(sizeof($customHeaders) > 0){
353-
foreach($customHeaders as $value)
354-
{
352+
if (sizeof($customHeaders) > 0) {
353+
foreach ($customHeaders as $value) {
355354
array_push($headers, $value);
356355
}
357356
return $headers;
358-
} else {
359-
return $headers;
360-
}
357+
} else {
358+
return $headers;
359+
}
361360
}
362361

363362
/**
@@ -402,7 +401,7 @@ private function callEndpoint($parameters, $subUrl)
402401

403402
if (strlen($parameters->getMultiPartContent()) > 0) {
404403
$content = $parameters->getMultiPartContent();
405-
$filename = $parameters->fileName;
404+
$filename = $parameters->getFileName();
406405

407406
json_encode($content, JSON_FORCE_OBJECT);
408407

@@ -426,7 +425,6 @@ private function callEndpoint($parameters, $subUrl)
426425

427426
$resultObject = $this->postHttp($url, $this->headers, $multi);
428427
} else {
429-
430428
$url = $this->service_url . $this->subUrl;
431429
$resultObject = $this->postHttp($url, $this->headers, $parameters->serialize($this->options));
432430
}
@@ -609,20 +607,25 @@ public function morphology($params, $facet = null)
609607
return $this->callEndpoint($params, 'morphology/' . $facet);
610608
}
611609

612-
/**
613-
* Calls the entities endpoint.
614-
*
615-
* @param $params
616-
* @param $resolve_entities
617-
*
618-
* @return mixed
619-
*
620-
* @throws RosetteException
621-
*/
622-
public function entities($params, $resolve_entities = false)
623-
{
624-
return $resolve_entities ? $this->callEndpoint($params, 'entities/linked') : $this->callEndpoint($params, 'entities');
625-
}
610+
/* Calls the entities endpoint.
611+
*
612+
* @param $params
613+
* @param $resolve_entities
614+
*
615+
* @return mixed
616+
*
617+
* @throws RosetteException
618+
*/
619+
public function entities($params, $resolve_entities = false)
620+
{
621+
if ($resolve_entities == true) {
622+
error_reporting(E_DEPRECATED);
623+
return $this->callEndpoint($params, 'entities/linked');
624+
} else {
625+
return $this->callEndpoint($params, 'entities');
626+
}
627+
}
628+
626629

627630
/**
628631
* Calls the categories endpoint.

source/rosette/api/DocumentParameters.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class DocumentParameters extends RosetteParamsSetBase
4646
/**
4747
* @var string fileName is the name of the file containing content to be analyzed
4848
*/
49-
public $fileName;
49+
private $fileName;
5050

5151
/**
5252
* @var string genre to categorize the input data
@@ -92,6 +92,16 @@ public function getMultiPartContent()
9292
return $this->multiPartContent;
9393
}
9494

95+
/**
96+
* Getter for fileName
97+
*
98+
* @return string
99+
*/
100+
public function getFileName()
101+
{
102+
return $this->fileName;
103+
}
104+
95105
/**
96106
* Validates parameters.
97107
*

0 commit comments

Comments
 (0)