Skip to content

Commit

Permalink
SSL is now the only way to consume the REST API
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier Sirven committed Sep 9, 2014
1 parent c49a976 commit 08a46b6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 75 deletions.
31 changes: 3 additions & 28 deletions java/org/webservice/fotolia/FotoliaApi.java
Expand Up @@ -31,7 +31,7 @@

public class FotoliaApi
{
public static String REST_URI = "api.fotolia.com/Rest";
public static String REST_URI = "https://api.fotolia.com/Rest";

public static String REST_VERSION = "1";

Expand Down Expand Up @@ -68,11 +68,6 @@ public class FotoliaApi
*/
private final String _api_key;

/**
* HTTPs mode flag
*/
private boolean _use_https;

/**
* Current session ID
*/
Expand All @@ -98,12 +93,10 @@ public FotoliaApi(final String api_key)
* Constructor
*
* @param api_key
* @param use_https
*/
public FotoliaApi(final String api_key, final boolean use_https)
public FotoliaApi(final String api_key)
{
this._api_key = api_key;
this.setHttpsMode(use_https);
}

/**
Expand All @@ -116,18 +109,6 @@ public String getApiKey()
return this._api_key;
}

/**
* Sets the HTTPs mode flag
*
* @param flag
* @return FotoliaApi
*/
public FotoliaApi setHttpsMode(final boolean flag)
{
this._use_https = flag;
return this;
}

/**
* Fotolia API test mode
*
Expand Down Expand Up @@ -1431,13 +1412,7 @@ private String _getUri(final String method_name, final FotoliaApiArgs args)
namespace += "/";
}

uri = "http";

if (this._use_https) {
uri += 's';
}

uri += "://" + FotoliaApi.REST_URI + "/" + FotoliaApi.REST_VERSION + "/" + namespace + method_name;
uri = FotoliaApi.REST_URI + "/" + FotoliaApi.REST_VERSION + "/" + namespace + method_name;

if (args != null) {
uri += "?" + args;
Expand Down
32 changes: 3 additions & 29 deletions php/fotolia-api.php
Expand Up @@ -22,7 +22,7 @@ class Fotolia_Api
/**
* Fotolia REST uri
*/
const FOTOLIA_REST_URI = 'api.fotolia.com/Rest';
const FOTOLIA_REST_URI = 'https://api.fotolia.com/Rest';

/**
* Fotolia REST API version
Expand Down Expand Up @@ -65,11 +65,6 @@ class Fotolia_Api
*/
private $_api_key;

/**
* HTTPs mode flag
*/
private $_use_https;

/**
* Current session id
*
Expand All @@ -89,12 +84,11 @@ class Fotolia_Api
*
* @param string $api_key
*/
public function __construct($api_key, $use_https = FALSE)
public function __construct($api_key)
{
$this->_api_key = $api_key;
$this->_session_id = NULL;
$this->_session_id_timestamp = NULL;
$this->_use_https = $use_https;
}

/**
Expand All @@ -107,15 +101,6 @@ public function getApiKey()
return $this->_api_key;
}

/**
* Toggle HTTPS
*/
public function setHttpsMode($flag)
{
$this->_use_https = $flag;
return $this;
}

/**
* This method makes possible to search media in fotolia image bank.
* Full search capabilities are available through the API
Expand Down Expand Up @@ -434,21 +419,12 @@ public function getMediaComp($id)
*/
public function loginUser($login, $pass)
{
$old_https_flag = $this->_use_https;
if (!$old_https_flag) {
$this->setHttpsMode(true);
}

$res = $this->_api('loginUser',
array(
'login' => $login,
'pass' => $pass,
));

if (!$old_https_flag) {
$this->setHttpsMode(false);
}

$this->_session_id = $res['session_token'];
$this->_session_id_timestamp = time();
}
Expand Down Expand Up @@ -1042,14 +1018,12 @@ protected function _getSessionId($auto_refresh_token = TRUE)
*/
private function _getFullURI($method, array $query = NULL)
{
$scheme = $this->_use_https ? 'https' : 'http';

$namespace = $this->_getNamespace($method);
if (!empty($namespace)) {
$namespace .= '/';
}

$uri = $scheme . '://' . Fotolia_Api::FOTOLIA_REST_URI . '/'
$uri = Fotolia_Api::FOTOLIA_REST_URI . '/'
. Fotolia_Api::FOTOLIA_REST_VERSION . '/' . $namespace . $method;

if ($query !== NULL) {
Expand Down
2 changes: 1 addition & 1 deletion python/fotolia_api/__init__.py
@@ -1,4 +1,4 @@
REST_URI = "api.fotolia.com/Rest"
REST_URI = "https://api.fotolia.com/Rest"
REST_VERSION = "1"

LANGUAGE_ID_FR_FR = 1
Expand Down
19 changes: 2 additions & 17 deletions python/fotolia_api/rest.py
Expand Up @@ -15,22 +15,18 @@ class Rest:
# api key
_api_key = None

# https toggle flag
_use_https = False

# session ID if any
_session_id = None

# session ID timestamp if any
_session_id_timestamp = None

def __init__(self, api_key, use_https = False):
def __init__(self, api_key):
"""
Constructor
"""

self._api_key = api_key
self._use_https = use_https
self._session_id = None
self._session_id_timestamp = None

Expand All @@ -41,13 +37,6 @@ def get_api_key(self):

return self._api_key

def set_https_mode(self, flag):
"""
Toggle HTTPS
"""

self._use_https = flag

def get_search_results(self, search_params, result_columns = []):
"""
This method makes possible to search media in fotolia image bank.
Expand Down Expand Up @@ -722,17 +711,13 @@ def _get_full_uri(self, method, query = None):
Generate the full URI to use for API calls
"""

scheme = 'http'
if self._use_https:
scheme += 's'

namespace = self._get_namespace(method)
if namespace != None:
namespace += '/'
else:
namespace = ''

uri = scheme + '://' + fotolia_api.REST_URI + '/' + fotolia_api.REST_VERSION + '/' + namespace + method
uri = fotolia_api.REST_URI + '/' + fotolia_api.REST_VERSION + '/' + namespace + method

if query != None:
uri += '?' + self._recursive_urlencode(query)
Expand Down

0 comments on commit 08a46b6

Please sign in to comment.