Adding optional SSL support
This commit is contained in:
parent
eaa6be4f81
commit
2a44dea3ed
2 changed files with 15 additions and 5 deletions
|
@ -116,18 +116,23 @@ class OpenPhotoOAuth
|
|||
return $resp;
|
||||
}
|
||||
|
||||
public function useSSL($bool)
|
||||
{
|
||||
$this->protocol = $bool ? 'https' : 'http';
|
||||
}
|
||||
|
||||
private function constructEndpoint($endpoint, $includeConsumerKey = false)
|
||||
{
|
||||
if($includeConsumerKey)
|
||||
{
|
||||
if(stristr($endpoint, '?') === false)
|
||||
return sprintf('http://%s%s?oauth_consumer_key=%s', $this->host, $endpoint, $this->consumerKey);
|
||||
return sprintf('%s://%s%s?oauth_consumer_key=%s', $this->protocol, $this->host, $endpoint, $this->consumerKey);
|
||||
else
|
||||
return sprintf('http://%s%s&oauth_consumer_key=%s', $this->host, $endpoint, $this->consumerKey);
|
||||
return sprintf('%s://%s%s&oauth_consumer_key=%s', $this->protocol, $this->host, $endpoint, $this->consumerKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
return sprintf('http://%s%s', $this->host, $endpoint);
|
||||
return sprintf('%s://%s%s', $this->protocol, $this->host, $endpoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,10 @@ $consumerSecret = getenv('consumerSecret');
|
|||
$token = getenv('token');
|
||||
$tokenSecret = getenv('tokenSecret');
|
||||
|
||||
$arguments = getopt('F:X:h:e:pv', array('encode::'));
|
||||
$arguments = getopt('F:X:h:e:pvs', array('encode::'));
|
||||
$host = 'localhost';
|
||||
$useSSL = false;
|
||||
|
||||
if(isset($arguments['h']))
|
||||
$host = $arguments['h'];
|
||||
$method = 'get';
|
||||
|
@ -21,6 +23,8 @@ if(isset($arguments['p']))
|
|||
$verbose = false;
|
||||
if(isset($arguments['v']))
|
||||
$verbose = true;
|
||||
if(isset($arguments['s']))
|
||||
$useSSL = true;
|
||||
$encode = false;
|
||||
if(isset($arguments['encode']))
|
||||
$encode = true;
|
||||
|
@ -40,13 +44,14 @@ if(isset($arguments['F']))
|
|||
|
||||
include 'OpenPhotoOAuth.php';
|
||||
$client = new OpenPhotoOAuth($host, $consumerKey, $consumerSecret, $token, $tokenSecret);
|
||||
$client->useSSL($useSSL);
|
||||
if($method == 'get')
|
||||
$resp = $client->get($endpoint, $fields);
|
||||
elseif($method == 'post')
|
||||
$resp = $client->post($endpoint, $fields);
|
||||
|
||||
if($verbose)
|
||||
echo sprintf("==========\nMethod: %s\nHost: %s\nEndpoint: %s\n==========\n\n", $method, $host, $endpoint);
|
||||
echo sprintf("==========\nMethod: %s\nHost: %s\nEndpoint: %s\nSSL: %s\n==========\n\n", $method, $host, $endpoint, $useSSL ? 'Yes' : 'No');
|
||||
|
||||
if($pretty)
|
||||
echo indent($resp);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue