Api/Odr.php
/**
     * Login procedure
     * At first, script tries to find out how signature is generated and after that actually tries to login
     * Is first step necessary? No. There is pretty slim chances that signature generation method will be changed in the future, but still, it wouldn't hurt
     *
     * @param string|null $apiKey    User's API Key
     * @param string|null $apiSecret User's API Secret
     *
     * @return Api_Odr
     *
     * @throws Api_Odr_Exception
     */
Login procedure
At first, script tries to find out how signature is generated and after that actually tries to login
Is first step necessary. No. There is pretty slim chances that signature generation method will be changed in the future, but still, it wouldn't hurt

@param string|null $apiKey    User's API Key
@param string|null $apiSecret User's API Secret




Login procedure At first script tries to find out how signature is generated and after that actually tries to login Is first step necessary . No . There is pretty slim chances that signature generation method will be changed in the future but still it wouldn ' t hurt @param string|null $apiKey User ' s API Key @param string|null $apiSecret User ' s API Secret
public function login($apiKey = null, $apiSecret = null)
    {
        $this->_execute('/info/user/login', self::METHOD_POST);
        if (!empty($this->_error)) {
            throw new Api_Odr_Exception($this->_error);
        }
        $result = $this->_resultBody;
        if (!is_string($apiKey) || $apiKey === '') {
            $apiKey = $this->_config['api_key'];
        }
        if (!is_string($apiSecret) || $apiSecret === '') {
            $apiSecret = $this->_config['api_secret'];
        }
        $apiKey    = trim($apiKey);
        $apiSecret = trim($apiSecret);
        if ($apiKey === '' || $apiSecret === '') {
            throw new Api_Odr_Exception('You should defined `api_key` and `api_secret`');
        }
        $signatureRuleWrapper = $result['response']['fields']['signature']['signature_rule'];
        $signatureRule = $result['response']['fields']['signature']['signature_rule_clear'];
        $wrapper = 'sha1';
        if (strpos($signatureRuleWrapper, '#SHA1(') === 0) {
            $wrapper = 'sha1';
        } elseif (strpos($signatureRuleWrapper, '#MD5(') === 0) {
            $wrapper = 'md5';
        }
        $timestamp = time();
        $r = array(
            '#API_KEY#'          => $apiKey,
            '#MD5(API_KEY)#'     => md5($apiKey),
            '#SHA1(API_KEY)#'    => sha1($apiKey),
            '#TIMESTAMP#'        => $timestamp,
            '#API_SECRET#'       => $apiSecret,
            '#MD5(API_SECRET)#'  => md5($apiSecret),
            '#SHA1(API_SECRET)#' => sha1($apiSecret),
        );
        $signature = str_replace(array_keys($r), array_values($r), $signatureRule);
        switch ($wrapper) {
            case 'sha1':
                    $signature = sha1($signature);
                break;
            case 'md5':
                    $signature = md5($signature);
                break;
            default:
                break;
        }
        $data = array(
            'timestamp' => $timestamp,
            'api_key'   => $apiKey,
            'signature' => 'token$' . $signature,
        );
        $this->_execute('/user/login/', self::METHOD_POST, $data);
        $result = $this->_resultBody;
        if ($result['status'] === self::STATUS_ERROR) {
            throw new Api_Odr_Exception($result['response']['message']);
        }
        $this->setHeader($result['response']['as_header'], $result['response']['token']);
        return $this;
    }
public function login ( $ apiKey = null , $ apiSecret = null ) { $ this -> _execute ( '/info/user/login' , self :: METHOD_POST ) ; if ( ! empty ( $ this -> _error ) ) { throw new Api_Odr_Exception ( $ this -> _error ) ; } $ result = $ this -> _resultBody ; if ( ! is_string ( $ apiKey ) || $ apiKey === '' ) { $ apiKey = $ this -> _config [ 'api_key' ] ; } if ( ! is_string ( $ apiSecret ) || $ apiSecret === '' ) { $ apiSecret = $ this -> _config [ 'api_secret' ] ; } $ apiKey = trim ( $ apiKey ) ; $ apiSecret = trim ( $ apiSecret ) ; if ( $ apiKey === '' || $ apiSecret === '' ) { throw new Api_Odr_Exception ( 'You should defined `api_key` and `api_secret`' ) ; } $ signatureRuleWrapper = $ result [ 'response' ] [ 'fields' ] [ 'signature' ] [ 'signature_rule' ] ; $ signatureRule = $ result [ 'response' ] [ 'fields' ] [ 'signature' ] [ 'signature_rule_clear' ] ; $ wrapper = 'sha1' ; if ( strpos ( $ signatureRuleWrapper , '#SHA1(' ) === 0 ) { $ wrapper = 'sha1' ; } elseif ( strpos ( $ signatureRuleWrapper , '#MD5(' ) === 0 ) { $ wrapper = 'md5' ; } $ timestamp = time ( ) ; $ r = array ( '#API_KEY#' => $ apiKey , '#MD5(API_KEY)#' => md5 ( $ apiKey ) , '#SHA1(API_KEY)#' => sha1 ( $ apiKey ) , '#TIMESTAMP#' => $ timestamp , '#API_SECRET#' => $ apiSecret , '#MD5(API_SECRET)#' => md5 ( $ apiSecret ) , '#SHA1(API_SECRET)#' => sha1 ( $ apiSecret ) , ) ; $ signature = str_replace ( array_keys ( $ r ) , array_values ( $ r ) , $ signatureRule ) ; switch ( $ wrapper ) { case 'sha1' : $ signature = sha1 ( $ signature ) ; break ; case 'md5' : $ signature = md5 ( $ signature ) ; break ; default : break ; } $ data = array ( 'timestamp' => $ timestamp , 'api_key' => $ apiKey , 'signature' => 'token$' . $ signature , ) ; $ this -> _execute ( '/user/login/' , self :: METHOD_POST , $ data ) ; $ result = $ this -> _resultBody ; if ( $ result [ 'status' ] === self :: STATUS_ERROR ) { throw new Api_Odr_Exception ( $ result [ 'response' ] [ 'message' ] ) ; } $ this -> setHeader ( $ result [ 'response' ] [ 'as_header' ] , $ result [ 'response' ] [ 'token' ] ) ; return $ this ; }
Login procedure
 At first, script tries to find out how signature is generated and after that actually tries to login
 Is first step necessary?
Login procedure At first script tries to find out how signature is generated and after that actually tries to login Is first step necessary?