Skip to content
This repository was archived by the owner on Oct 30, 2018. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions alchemyapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,22 @@ class AlchemyAPI {

private $_api_key;
private $_ENDPOINTS;
private $_BASE_URL = 'http://access.alchemyapi.com/calls';
private $_base_url;
private $_BASE_HTTP_URL = 'http://access.alchemyapi.com/calls';
private $_BASE_HTTPS_URL = 'https://access.alchemyapi.com/calls';

/**
* Constructor
*
* @param string
* @param boolean
* @return void
*/
public function __construct($key) {
public function __construct($key, $use_https = false) {
$this->_api_key = $key;


$this->_base_url = $use_https ? $this->_BASE_HTTPS_URL : $this->_BASE_HTTP_URL;

//Initialize the API Endpoints
$this->_ENDPOINTS['sentiment']['url'] = '/url/URLGetTextSentiment';
$this->_ENDPOINTS['sentiment']['text'] = '/text/TextGetTextSentiment';
Expand Down Expand Up @@ -698,7 +703,7 @@ public function combined($flavor, $data, $options) {
*/
private function analyze($endpoint, $params) {
//Insert the base URL
$url = $this->_BASE_URL . $endpoint;
$url = $this->_base_url . $endpoint;

//Add the API Key and set the output mode to JSON
$params['apikey'] = $this->_api_key;
Expand Down Expand Up @@ -726,7 +731,7 @@ private function analyzeImage($endpoint, $params, $imageData) {
$params['outputMode'] = 'json';

//Insert the base URL
$url = $this->_BASE_URL . $endpoint . '?' . http_build_query($params);
$url = $this->_base_url . $endpoint . '?' . http_build_query($params);

//Create the HTTP header
$header = array('http' => array('method' => 'POST','header'=>'Content-Type: application/x-www-form-urlencode', 'content'=>$imageData));
Expand Down Expand Up @@ -766,4 +771,3 @@ private function analyzeImage($endpoint, $params, $imageData) {
}

?>