Version Notes
REQUIRED FIX - all communication now over https, http is turned off for simplerelevance.com.
Download this release
Release Info
Developer | Eli Albert |
Extension | SimpleRelevance_Integration |
Version | 1.0.4 |
Comparing to | |
See all releases |
Code changes from version 1.0.3 to 1.0.4
app/code/community/SimpleRelevance/Integration/Model/Api.php
CHANGED
@@ -74,7 +74,7 @@ class SimpleRelevance_Integration_Model_Api
|
|
74 |
{
|
75 |
$this->api_key = $key;
|
76 |
|
77 |
-
$this->apiUrl = "
|
78 |
|
79 |
return $this;
|
80 |
}
|
74 |
{
|
75 |
$this->api_key = $key;
|
76 |
|
77 |
+
$this->apiUrl = "https://www.simplerelevance.com/api/v{$this->version}/";
|
78 |
|
79 |
return $this;
|
80 |
}
|
app/code/community/SimpleRelevance/Integration/Model/Api.php~
ADDED
@@ -0,0 +1,256 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Simple Relevance API wrapper
|
5 |
+
*
|
6 |
+
* @category SimpleRelevance
|
7 |
+
* @package SimpleRelevance_Integration
|
8 |
+
*/
|
9 |
+
class SimpleRelevance_Integration_Model_Api
|
10 |
+
{
|
11 |
+
/**
|
12 |
+
* API version number
|
13 |
+
*
|
14 |
+
* @var string
|
15 |
+
*/
|
16 |
+
public $version = '2';
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Error Message storage
|
20 |
+
*
|
21 |
+
* @var string
|
22 |
+
*/
|
23 |
+
public $errorMessage;
|
24 |
+
|
25 |
+
/**
|
26 |
+
* Error Code storage
|
27 |
+
*
|
28 |
+
* @var integer
|
29 |
+
*/
|
30 |
+
public $errorCode;
|
31 |
+
|
32 |
+
/**
|
33 |
+
* Cache the user api_key so we only have to log in once per client instantiation
|
34 |
+
*
|
35 |
+
* @var string SimpleRelevance API key
|
36 |
+
*/
|
37 |
+
public $api_key;
|
38 |
+
|
39 |
+
/**
|
40 |
+
* This decides whether the request will wait for completion or start a task and return immediately.
|
41 |
+
* Can be 0 (wait) or 1 (asynchronous)
|
42 |
+
*
|
43 |
+
* @var int
|
44 |
+
*/
|
45 |
+
public $async = 1;
|
46 |
+
|
47 |
+
/**
|
48 |
+
* STS API URL
|
49 |
+
*
|
50 |
+
* @var string
|
51 |
+
*/
|
52 |
+
public $apiUrl;
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Setup data
|
56 |
+
*
|
57 |
+
* @param string $apikey Your SimpleRelevance apikey
|
58 |
+
* @param string $secure Whether or not this should use a secure connection
|
59 |
+
*/
|
60 |
+
function __construct($apikey = null)
|
61 |
+
{
|
62 |
+
if($apikey){
|
63 |
+
$this->setApiKey($apikey);
|
64 |
+
}
|
65 |
+
}
|
66 |
+
|
67 |
+
/**
|
68 |
+
* Api key setter
|
69 |
+
*
|
70 |
+
* @param string $key API Key
|
71 |
+
* @return SimpleRelevance_Integration_Model_Api
|
72 |
+
*/
|
73 |
+
public function setApiKey($key)
|
74 |
+
{
|
75 |
+
$this->api_key = $key;
|
76 |
+
|
77 |
+
$this->apiUrl = "http://www.simplerelevance.com/api/v{$this->version}/";
|
78 |
+
|
79 |
+
return $this;
|
80 |
+
}
|
81 |
+
|
82 |
+
/**
|
83 |
+
* Action: POST
|
84 |
+
* Parameters:
|
85 |
+
* api_key - email tech@simplerelevance.com if you do not have an api key.
|
86 |
+
* item_id (optional-see below) - ID of the item clicked.
|
87 |
+
* user_id (optional-see below) - ID of the user clicking the item.
|
88 |
+
* timestamp (optional) - UTC Timestamp for the click. If not supplied, the current date/time will be used. Format is like “01/31/2011 14:54:53”.
|
89 |
+
* price (optional) - can be a float
|
90 |
+
* email (optional) - if you do not include a user_id, you can identify a user by email address
|
91 |
+
* item_name (optional) - if you do not include an item_id, you can identify an item by the name with which you input it into SimpleRelevance
|
92 |
+
* item_type (optional) - if you are matching by name and not item_id, supplying the same value here which you used on the inital input into SimpleRelevance will help find your item.
|
93 |
+
* zipcode (optional) - if the user is not yet in the system, this zipcode will help determine the user’s location.
|
94 |
+
* Notes: the timestamp is used to differentiate multiple actions with the same deal and user. If you don’t supply one, the SimpleRelevance system will not create save a new user action, and will simply update the old one with whatever new data you supply (price, for instance).
|
95 |
+
*/
|
96 |
+
public function postClicks()
|
97 |
+
{
|
98 |
+
}
|
99 |
+
|
100 |
+
/**
|
101 |
+
* Action: POST
|
102 |
+
* Parameters:
|
103 |
+
* All parameters and notes from the CLICKS hook apply here.
|
104 |
+
*/
|
105 |
+
public function postPurchases($data = array())
|
106 |
+
{
|
107 |
+
return $this->_callServer('purchases', 'post', $data);
|
108 |
+
}
|
109 |
+
|
110 |
+
/**
|
111 |
+
* Action: POST
|
112 |
+
* Parameters:
|
113 |
+
* api_key
|
114 |
+
* item_name - The item’s name - this should be unique across your database if possible.
|
115 |
+
* item_id - a unique ID for the item from your database.
|
116 |
+
* item_type (optional) - this helps the SimpleRelevance system find semantic data for your item. You can use any string you want here, but ‘business’ should be used for actual, real-world businesses.
|
117 |
+
* data_dict - a json encoded dictionary. This can have any attributes at all that apply to your item; the more the better. See below for the list of reserved attribute names - these help SimpleRelevance create semantic connections about your items. Note that these include ‘starts’ and ‘expires’, in case your items are time sensitive.
|
118 |
+
*/
|
119 |
+
public function postItems($itemData = array())
|
120 |
+
{
|
121 |
+
return $this->_callServer('items', 'post', $itemData);
|
122 |
+
}
|
123 |
+
|
124 |
+
/**
|
125 |
+
* Action: POST
|
126 |
+
*
|
127 |
+
*/
|
128 |
+
public function postUsers($userData = array())
|
129 |
+
{
|
130 |
+
return $this->_callServer('users', 'post', $userData);
|
131 |
+
}
|
132 |
+
|
133 |
+
|
134 |
+
|
135 |
+
/**
|
136 |
+
* Action: GET
|
137 |
+
* Parameters:
|
138 |
+
* api_key
|
139 |
+
* email - The email address of the user to return deals for
|
140 |
+
* market - the general city or location for which you want items returned. Leave this blank for locationless predictions.
|
141 |
+
* num_per (optional) - for business items, the number of items to return per business. For products, the number of products to return per leaf category.
|
142 |
+
* starts (optional) - if you have set it when uploading the item data, then only items with a starts value after the one given here will be included in the prediction.
|
143 |
+
* expires (optional) - if you have set it in the data dict when uploading item data, then only items with an expires value after the one given here will be included in the prediction.
|
144 |
+
* Notes:
|
145 |
+
* all returns have the key "data" unless there has been an error.
|
146 |
+
* data points to a list of recommendation items.
|
147 |
+
* each recommendation item has
|
148 |
+
* position - starting at 0, the lower the position, the more highly recommended the item.
|
149 |
+
* If positions are the same, both items come from the same business! If your items are not related to businesses and you are not using the reserved key "business_name", or if you set parameter num_per=1, this should not happen.
|
150 |
+
* id_type - describes whether the item id number is from our database or yours - if you supply external ids when uploading items, which is currently a requirement, we will always return those same ids
|
151 |
+
* id - the item id, hopefully of type "external" so that you can easily find it in your database*
|
152 |
+
* @return string JSON dictionary
|
153 |
+
*/
|
154 |
+
public function getItems()
|
155 |
+
{
|
156 |
+
}
|
157 |
+
|
158 |
+
/**
|
159 |
+
* Actually connect to the server and call the requested methods
|
160 |
+
*
|
161 |
+
* @param string $method
|
162 |
+
* @param array OPTIONAL $params
|
163 |
+
* @return object|false
|
164 |
+
*/
|
165 |
+
protected function _callServer($method, $call, $params = array())
|
166 |
+
{
|
167 |
+
|
168 |
+
$this->errorMessage = null;
|
169 |
+
$this->errorCode = null;
|
170 |
+
|
171 |
+
$data = array();
|
172 |
+
|
173 |
+
//Add API_KEY to request params
|
174 |
+
$data['api_key'] = $this->api_key;
|
175 |
+
|
176 |
+
//This decides whether the request will wait for completion
|
177 |
+
//or start a task and return immediately. Can be 0 (wait) or 1 (asynchronous)
|
178 |
+
$data['async'] = $this->async;
|
179 |
+
|
180 |
+
//Request data
|
181 |
+
$data['data'] = json_encode(array($params), JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP);
|
182 |
+
|
183 |
+
$url = $this->apiUrl . $method;
|
184 |
+
|
185 |
+
$this->_log($url);
|
186 |
+
$this->_log($data);
|
187 |
+
|
188 |
+
$requestParams = http_build_query($data);
|
189 |
+
|
190 |
+
$curlSession = curl_init();
|
191 |
+
|
192 |
+
if($call == 'post'){
|
193 |
+
curl_setopt($curlSession, CURLOPT_POST, TRUE);
|
194 |
+
curl_setopt($curlSession, CURLOPT_POSTFIELDS, $requestParams);
|
195 |
+
}
|
196 |
+
|
197 |
+
curl_setopt($curlSession, CURLOPT_USERAGENT, Mage::helper('simple_relevance')->getUserAgent());
|
198 |
+
curl_setopt($curlSession, CURLOPT_URL, $url);
|
199 |
+
curl_setopt($curlSession, CURLOPT_HEADER, FALSE);
|
200 |
+
|
201 |
+
curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, TRUE);
|
202 |
+
|
203 |
+
$result = curl_exec($curlSession);
|
204 |
+
|
205 |
+
$this->_log($result);
|
206 |
+
|
207 |
+
if(!$result){
|
208 |
+
$errstr = curl_error($curlSession);
|
209 |
+
$errno = curl_errno($curlSession);
|
210 |
+
|
211 |
+
$this->errorMessage = "Could not connect (ERR $errno: $errstr)";
|
212 |
+
$this->errorCode = "-99";
|
213 |
+
return false;
|
214 |
+
}
|
215 |
+
|
216 |
+
// Check that a connection was made
|
217 |
+
if (curl_error($curlSession)) {
|
218 |
+
$this->errorMessage = curl_error($curlSession);
|
219 |
+
$this->errorCode = "-99";
|
220 |
+
return false;
|
221 |
+
}
|
222 |
+
|
223 |
+
$httpCode = curl_getinfo($curlSession, CURLINFO_HTTP_CODE);
|
224 |
+
|
225 |
+
curl_close($curlSession);
|
226 |
+
|
227 |
+
if($httpCode != 200){
|
228 |
+
|
229 |
+
Mage::log($result, null, 'SimpleRelevance_Erros.log');
|
230 |
+
Mage::log($httpCode, null, 'SimpleRelevance_Erros.log');
|
231 |
+
|
232 |
+
$this->errorMessage = $result;
|
233 |
+
$this->errorCode = "-99";
|
234 |
+
return false;
|
235 |
+
}
|
236 |
+
|
237 |
+
return $result;
|
238 |
+
|
239 |
+
}
|
240 |
+
|
241 |
+
/**
|
242 |
+
* Log data to debug log file
|
243 |
+
*
|
244 |
+
* @param mixed $data
|
245 |
+
* @return void
|
246 |
+
*/
|
247 |
+
protected function _log($text)
|
248 |
+
{
|
249 |
+
if(!Mage::getStoreConfigFlag('simple_relevance/general/debug')){
|
250 |
+
return;
|
251 |
+
}
|
252 |
+
|
253 |
+
Mage::log($text, null, 'SimpleRelevance_Integration.log');
|
254 |
+
}
|
255 |
+
|
256 |
+
}
|
package.xml
CHANGED
@@ -1,18 +1,18 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>SimpleRelevance_Integration</name>
|
4 |
-
<version>1.0.
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
|
7 |
<channel>community</channel>
|
8 |
<extends/>
|
9 |
<summary>SimpleRelevance integration module</summary>
|
10 |
<description>Featuring customers, products and orders.</description>
|
11 |
-
<notes>
|
12 |
-
<authors><author><name>Eli Albert</name><user>
|
13 |
-
<date>2012-
|
14 |
-
<time>20:
|
15 |
-
<contents><target name="magecommunity"><dir name="SimpleRelevance"><dir name="Integration"><dir name="Helper"><file name="Data.php" hash="e2e82d1e985bfd9b03d279d6ad972563"/><file name="Data.php~" hash="233ecf0f4a4ced6fd04e1d9a37e0936c"/></dir><dir name="Model"><file name="Api.php" hash="dadb3d39091ef38b2465c566fcbacb38"/><file name="Observer.php" hash="8a247ca67158af2d63c737bdabac53b4"/><file name="Observer.php~" hash="d495ea4fccaede3fd1d9a83e69327839"/><file name="Prediction.php" hash="09830c9269d4b7b30e4ad37d4e7f6792"/><file name="Prediction.php~" hash="ab5d9acea6e208d0ccc5c62a19215179"/><file name="Purchase.php" hash="dae8d7e715381a9ec160123f27800b15"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="ExportController.php" hash="840104daa154dab436ab043f8ea217af"/><file name="IndexController.php~" hash="968a495beece48514394bd597ee32d83"/><file name="InputController.php~" hash="ab5d9acea6e208d0ccc5c62a19215179"/></dir><file name="IndexController.php" hash="304464e66af0b1aeedd61d98ceb2d9e8"/><file name="IndexController.php~" hash="599e35006f80ffd08201ebb5e921d8d4"/><file name="InputController.php" hash="f5324ef04aa854ef8b4b5edd3063c056"/><file name="InputController.php~" hash="f649b3bbffb2da9a8fd94e0dc7faf594"/></dir><
|
16 |
<compatible/>
|
17 |
-
<dependencies
|
18 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>SimpleRelevance_Integration</name>
|
4 |
+
<version>1.0.4</version>
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
|
7 |
<channel>community</channel>
|
8 |
<extends/>
|
9 |
<summary>SimpleRelevance integration module</summary>
|
10 |
<description>Featuring customers, products and orders.</description>
|
11 |
+
<notes>REQUIRED FIX - all communication now over https, http is turned off for simplerelevance.com. </notes>
|
12 |
+
<authors><author><name>Eli Albert</name><user>elialbert</user><email>eli@simplerelevance.com</email></author></authors>
|
13 |
+
<date>2012-07-19</date>
|
14 |
+
<time>20:52:39</time>
|
15 |
+
<contents><target name="magecommunity"><dir name="SimpleRelevance"><dir name="Integration"><dir name="Helper"><file name="Data.php" hash="e2e82d1e985bfd9b03d279d6ad972563"/><file name="Data.php~" hash="233ecf0f4a4ced6fd04e1d9a37e0936c"/></dir><dir name="Model"><file name="Api.php" hash="3934912a2263bc0ae9f4c0e5d8fbeebd"/><file name="Api.php~" hash="dadb3d39091ef38b2465c566fcbacb38"/><file name="Observer.php" hash="8a247ca67158af2d63c737bdabac53b4"/><file name="Observer.php~" hash="d495ea4fccaede3fd1d9a83e69327839"/><file name="Prediction.php" hash="09830c9269d4b7b30e4ad37d4e7f6792"/><file name="Prediction.php~" hash="ab5d9acea6e208d0ccc5c62a19215179"/><file name="Purchase.php" hash="dae8d7e715381a9ec160123f27800b15"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="ExportController.php" hash="840104daa154dab436ab043f8ea217af"/><file name="IndexController.php~" hash="968a495beece48514394bd597ee32d83"/><file name="InputController.php~" hash="ab5d9acea6e208d0ccc5c62a19215179"/></dir><file name="IndexController.php" hash="304464e66af0b1aeedd61d98ceb2d9e8"/><file name="IndexController.php~" hash="599e35006f80ffd08201ebb5e921d8d4"/><file name="InputController.php" hash="f5324ef04aa854ef8b4b5edd3063c056"/><file name="InputController.php~" hash="f649b3bbffb2da9a8fd94e0dc7faf594"/></dir><file name="demo.phtml" hash="e7c307f0014af936fe8c1a97154e4daa"/><file name="demo.phtml~" hash="9366e20fa2eb6ec04d2e66d9e995caf6"/><dir name="etc"><file name="adminhtml.xml" hash="18e9829f6252920f6bf01a5340377b3a"/><file name="config.xml" hash="3ba8219cb93dba44fb1a1e7bcfadcd49"/><file name="config.xml~" hash="3ba8219cb93dba44fb1a1e7bcfadcd49"/><file name="system.xml" hash="638f6aac1d2d19b8b9d9ca4fed0065f5"/></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="simple_relevance.xml" hash="f0d73f30b7aeff70f63b295327ac906c"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="SimpleRelevance_Integration.xml" hash="6ad0b704a9e62de159f09babfe2482d5"/></dir></target><target name="magelocale"><dir name="en_US"><file name="SimpleRelevance_Integration.csv" hash="05e3ba1c882990c307dbe510bc0bea36"/></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="simple_relevance"><file name="css.css" hash="c354dd9c0e48bdb99089b1756058efc1"/><dir name="images"><file name="box-tab.png" hash="208977131fcbe078f10af53295ac686c"/><file name="simplerelevance-header.png" hash="c25099645618a32b8fdb8d4d7786cf2c"/></dir><file name="js.js" hash="5831e6e503ebd86f93e07230b56a6d2f"/></dir></dir></dir></dir></target></contents>
|
16 |
<compatible/>
|
17 |
+
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
|
18 |
</package>
|