@@ -19,20 +19,23 @@ class Client{
1919    protected  $ account
2020    protected  $ token
2121    protected  $ request
22+     protected  $ protocol
2223
2324    /** 
2425     * @ignore 
2526     */ 
26-     const  BASE_URI  = 'https:// rapi.recombee.com ;
27+     const  BASE_URI  = 'rapi.recombee.com ' ;
2728
2829    /** 
2930     * Create the client 
3031     * @param string $account Name of your account at Recombee 
3132     * @param string $token Secret token 
33+      * @param string $protocol Default protocol for sending requests. Possible values: 'http', 'https'. 
3234     */ 
33-     public  function  __construct ($ account$ token
35+     public  function  __construct ($ account$ token,  $ protocol  =  ' http ' 
3436        $ this account  = $ account
3537        $ this token  = $ token
38+         $ this protocol  = $ protocol
3639    }
3740
3841    /** 
@@ -44,27 +47,30 @@ public function __construct($account, $token) {
4447    public  function  send (Requests \Request $ request
4548        $ this request  = $ request
4649        $ pathsliceDbName ($ requestgetPath ());
47-         $ uri$ path$ this paramsToStr ($ requestgetQueryParameters ());
50+         $ request_url$ path$ this paramsToStr ($ requestgetQueryParameters ());
51+         $ signed_url$ this signUrl ($ request_url
52+         $ protocol$ requestgetEnsureHttps ()) ? 'https '  : $ this protocol ;
53+         $ uri$ protocol':// '  . Client::BASE_URI  . $ signed_url
4854        $ timeout$ requestgetTimeout () / 1000 ;
4955        $ resultnull ;
5056
5157        try  {
5258            switch  ($ requestgetMethod ()) {
5359                case  Requests \Request::HTTP_GET :
54-                     $ result$ this hmacGet ($ uri$ timeout
60+                     $ result$ this get ($ uri$ timeout
5561                    break ;
5662
5763                case  Requests \Request::HTTP_PUT :
58-                     $ result$ this hmacPut ($ uri$ timeout
64+                     $ result$ this put ($ uri$ timeout
5965                    break ;
6066
6167                case  Requests \Request::HTTP_DELETE :
62-                     $ result$ this hmacDelete ($ uri$ timeout
68+                     $ result$ this delete ($ uri$ timeout
6369                    break ;
6470
6571                case  Requests \Request::HTTP_POST :
6672                    $ jsonjson_encode ($ requestgetBodyParameters (), JSON_UNESCAPED_UNICODE  | JSON_UNESCAPED_SLASHES );
67-                     $ result$ this hmacPost ($ uri$ timeout$ json
73+                     $ result$ this post ($ uri$ timeout$ json
6874                    break ;
6975            }
7076        }
@@ -80,31 +86,27 @@ public function send(Requests\Request $request) {
8086
8187    /* ----------------------- Send requests -----------------------  */ 
8288    //TODO remove ceils when Requests 1.7 is released as it support timeout in milliseconds 
83-     protected  function  hmacPut ($ uri$ timeout
84-         $ signed_url$ this signUrl ($ uri
85-         $ responseput ($ signed_urlarray (), ['timeout '  => ceil ($ timeout
89+     protected  function  put ($ uri$ timeout
90+         $ responseput ($ uriarray (), ['timeout '  => ceil ($ timeout
8691        $ this checkErrors ($ response
8792        return  $ responsebody ;
8893    }
8994
90-     protected  function  hmacGet ($ uri$ timeout
91-         $ signed_url$ this signUrl ($ uri
92-         $ responseget ($ signed_urlarray (), ['timeout '  => ceil ($ timeout
95+     protected  function  get ($ uri$ timeout
96+         $ responseget ($ uriarray (), ['timeout '  => ceil ($ timeout
9397        $ this checkErrors ($ response
9498        return  json_decode ($ responsebody , true );
9599    }
96100
97-     protected  function  hmacDelete ($ uri$ timeout
98-         $ signed_url$ this signUrl ($ uri
99-         $ responsedelete ($ signed_urlarray (), ['timeout '  => ceil ($ timeout
101+     protected  function  delete ($ uri$ timeout
102+         $ responsedelete ($ uriarray (), ['timeout '  => ceil ($ timeout
100103        $ this checkErrors ($ response
101104        return  $ responsebody ;
102105    }
103106
104-     protected  function  hmacPost ($ uri$ timeout$ body
105-         $ signed_url$ this signUrl ($ uri
107+     protected  function  post ($ uri$ timeout$ body
106108        $ headersarray ('Content-Type '  => 'application/json ' );
107-         $ responsepost ($ signed_url $ headers$ body'timeout '  => ceil ($ timeout
109+         $ responsepost ($ uri $ headers$ body'timeout '  => ceil ($ timeout
108110        $ this checkErrors ($ response
109111
110112        $ jsonjson_decode ($ responsebody , true );
@@ -126,7 +128,7 @@ protected function signUrl($uri) {
126128        $ uri'/ '  . $ this account  . '/ '  . $ uri
127129        $ time_str$ this hmacTime ($ uri
128130        $ sign$ this hmacSign ($ uri$ time_str
129-         return  Client:: BASE_URI  .  $ uri$ time_str'&hmac_sign= '  . $ sign
131+         return  $ uri$ time_str'&hmac_sign= '  . $ sign
130132    }
131133
132134    protected  function  hmacTime ($ uri
0 commit comments