Version Notes
- Moved Laposta library into Laposta Connect module root
Download this release
Release Info
Developer | Merten van Gerven |
Extension | Mage_Laposta_Connect |
Version | 1.0.10 |
Comparing to | |
See all releases |
Code changes from version 1.0.9 to 1.0.10
- app/code/community/Laposta/Connect/Helper/Laposta.php +1 -1
- app/code/community/Laposta/Connect/etc/config.xml +1 -1
- app/code/community/Laposta/Connect/lib/Laposta/Laposta.php +56 -0
- app/code/community/Laposta/Connect/lib/Laposta/Laposta/Error.php +28 -0
- app/code/community/Laposta/Connect/lib/Laposta/Laposta/Field.php +74 -0
- app/code/community/Laposta/Connect/lib/Laposta/Laposta/List.php +58 -0
- app/code/community/Laposta/Connect/lib/Laposta/Laposta/Login.php +20 -0
- app/code/community/Laposta/Connect/lib/Laposta/Laposta/Member.php +74 -0
- app/code/community/Laposta/Connect/lib/Laposta/Laposta/Request.php +63 -0
- app/code/community/Laposta/Connect/lib/Laposta/Laposta/Resource.php +68 -0
- app/code/community/Laposta/Connect/lib/Laposta/Laposta/Util.php +68 -0
- app/code/community/Laposta/Connect/lib/Laposta/Laposta/Webhook.php +74 -0
- package.xml +5 -4
app/code/community/Laposta/Connect/Helper/Laposta.php
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
require_once
|
4 |
|
5 |
class Laposta_Connect_Helper_Laposta extends Mage_Core_Helper_Abstract
|
6 |
{
|
1 |
<?php
|
2 |
|
3 |
+
require_once dirname(dirname(__FILE__)) . '/lib/Laposta/Laposta.php';
|
4 |
|
5 |
class Laposta_Connect_Helper_Laposta extends Mage_Core_Helper_Abstract
|
6 |
{
|
app/code/community/Laposta/Connect/etc/config.xml
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
<config>
|
3 |
<modules>
|
4 |
<Laposta_Connect>
|
5 |
-
<version>1.0.
|
6 |
</Laposta_Connect>
|
7 |
</modules>
|
8 |
<frontend>
|
2 |
<config>
|
3 |
<modules>
|
4 |
<Laposta_Connect>
|
5 |
+
<version>1.0.10</version>
|
6 |
</Laposta_Connect>
|
7 |
</modules>
|
8 |
<frontend>
|
app/code/community/Laposta/Connect/lib/Laposta/Laposta.php
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// Tested on PHP 5.2, 5.3, 5.4
|
3 |
+
|
4 |
+
if (!function_exists('curl_init')) {
|
5 |
+
throw new Exception('Laposta needs the CURL PHP extension.');
|
6 |
+
}
|
7 |
+
|
8 |
+
if (!function_exists('json_decode')) {
|
9 |
+
throw new Exception('Laposta needs the JSON PHP extension.');
|
10 |
+
}
|
11 |
+
|
12 |
+
class Laposta
|
13 |
+
{
|
14 |
+
public static $apiKey;
|
15 |
+
|
16 |
+
public static $https = true;
|
17 |
+
|
18 |
+
public static $apiBase = 'api.laposta.nl/v2';
|
19 |
+
|
20 |
+
const VERSION = '1.2.0';
|
21 |
+
|
22 |
+
public static function getApiKey()
|
23 |
+
{
|
24 |
+
return self::$apiKey;
|
25 |
+
}
|
26 |
+
|
27 |
+
public static function setApiKey($apiKey)
|
28 |
+
{
|
29 |
+
self::$apiKey = $apiKey;
|
30 |
+
}
|
31 |
+
|
32 |
+
public static function getProtocol()
|
33 |
+
{
|
34 |
+
return self::$https ? 'https' : 'http';
|
35 |
+
}
|
36 |
+
|
37 |
+
public static function setHttps($https)
|
38 |
+
{
|
39 |
+
self::$https = $https;
|
40 |
+
}
|
41 |
+
|
42 |
+
public static function getApiBase()
|
43 |
+
{
|
44 |
+
return self::getProtocol() . '://' . self::$apiBase;
|
45 |
+
}
|
46 |
+
}
|
47 |
+
|
48 |
+
require(dirname(__FILE__) . '/Laposta/Util.php');
|
49 |
+
require(dirname(__FILE__) . '/Laposta/Error.php');
|
50 |
+
require(dirname(__FILE__) . '/Laposta/Resource.php');
|
51 |
+
require(dirname(__FILE__) . '/Laposta/Request.php');
|
52 |
+
require(dirname(__FILE__) . '/Laposta/Member.php');
|
53 |
+
require(dirname(__FILE__) . '/Laposta/List.php');
|
54 |
+
require(dirname(__FILE__) . '/Laposta/Field.php');
|
55 |
+
require(dirname(__FILE__) . '/Laposta/Webhook.php');
|
56 |
+
require(dirname(__FILE__) . '/Laposta/Login.php');
|
app/code/community/Laposta/Connect/lib/Laposta/Laposta/Error.php
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Laposta_Error extends Exception
|
3 |
+
{
|
4 |
+
|
5 |
+
public function __construct($message = null, $http_status = null, $http_body = null, $json_body = null)
|
6 |
+
{
|
7 |
+
|
8 |
+
parent::__construct($message);
|
9 |
+
$this->http_status = $http_status;
|
10 |
+
$this->http_body = $http_body;
|
11 |
+
$this->json_body = $json_body;
|
12 |
+
}
|
13 |
+
|
14 |
+
public function getHttpStatus()
|
15 |
+
{
|
16 |
+
return $this->http_status;
|
17 |
+
}
|
18 |
+
|
19 |
+
public function getHttpBody()
|
20 |
+
{
|
21 |
+
return $this->http_body;
|
22 |
+
}
|
23 |
+
|
24 |
+
public function getJsonBody()
|
25 |
+
{
|
26 |
+
return $this->json_body;
|
27 |
+
}
|
28 |
+
}
|
app/code/community/Laposta/Connect/lib/Laposta/Laposta/Field.php
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Laposta_Field extends Laposta_Resource
|
3 |
+
{
|
4 |
+
|
5 |
+
private $list_id;
|
6 |
+
|
7 |
+
public function __construct($list_id)
|
8 |
+
{
|
9 |
+
|
10 |
+
// we need the list_id for each call
|
11 |
+
$this->list_id = $list_id;
|
12 |
+
parent::__construct(get_class());
|
13 |
+
}
|
14 |
+
|
15 |
+
public function get($field_id)
|
16 |
+
{
|
17 |
+
|
18 |
+
return parent::connect(
|
19 |
+
array(
|
20 |
+
'path' => array($field_id),
|
21 |
+
'parameters' => array('list_id' => $this->list_id)
|
22 |
+
)
|
23 |
+
);
|
24 |
+
}
|
25 |
+
|
26 |
+
public function create($data)
|
27 |
+
{
|
28 |
+
|
29 |
+
// add list_id to data
|
30 |
+
$data['list_id'] = $this->list_id;
|
31 |
+
|
32 |
+
return parent::connect(
|
33 |
+
array(
|
34 |
+
'post' => $data
|
35 |
+
)
|
36 |
+
);
|
37 |
+
}
|
38 |
+
|
39 |
+
public function update($field_id, $data)
|
40 |
+
{
|
41 |
+
|
42 |
+
// add list_id to data
|
43 |
+
$data['list_id'] = $this->list_id;
|
44 |
+
|
45 |
+
return parent::connect(
|
46 |
+
array(
|
47 |
+
'path' => array($field_id),
|
48 |
+
'post' => $data
|
49 |
+
)
|
50 |
+
);
|
51 |
+
}
|
52 |
+
|
53 |
+
public function delete($field_id)
|
54 |
+
{
|
55 |
+
|
56 |
+
return parent::connect(
|
57 |
+
array(
|
58 |
+
'path' => array($field_id),
|
59 |
+
'parameters' => array('list_id' => $this->list_id),
|
60 |
+
'method' => 'DELETE'
|
61 |
+
)
|
62 |
+
);
|
63 |
+
}
|
64 |
+
|
65 |
+
public function all()
|
66 |
+
{
|
67 |
+
|
68 |
+
return parent::connect(
|
69 |
+
array(
|
70 |
+
'parameters' => array('list_id' => $this->list_id)
|
71 |
+
)
|
72 |
+
);
|
73 |
+
}
|
74 |
+
}
|
app/code/community/Laposta/Connect/lib/Laposta/Laposta/List.php
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Laposta_List extends Laposta_Resource
|
3 |
+
{
|
4 |
+
|
5 |
+
public function __construct()
|
6 |
+
{
|
7 |
+
|
8 |
+
parent::__construct(get_class());
|
9 |
+
}
|
10 |
+
|
11 |
+
public function get($list_id)
|
12 |
+
{
|
13 |
+
|
14 |
+
return parent::connect(
|
15 |
+
array(
|
16 |
+
'path' => array($list_id)
|
17 |
+
)
|
18 |
+
);
|
19 |
+
}
|
20 |
+
|
21 |
+
public function create($data)
|
22 |
+
{
|
23 |
+
|
24 |
+
return parent::connect(
|
25 |
+
array(
|
26 |
+
'post' => $data
|
27 |
+
)
|
28 |
+
);
|
29 |
+
}
|
30 |
+
|
31 |
+
public function update($list_id, $data)
|
32 |
+
{
|
33 |
+
|
34 |
+
return parent::connect(
|
35 |
+
array(
|
36 |
+
'path' => array($list_id),
|
37 |
+
'post' => $data
|
38 |
+
)
|
39 |
+
);
|
40 |
+
}
|
41 |
+
|
42 |
+
public function delete($list_id)
|
43 |
+
{
|
44 |
+
|
45 |
+
return parent::connect(
|
46 |
+
array(
|
47 |
+
'path' => array($list_id),
|
48 |
+
'method' => 'DELETE'
|
49 |
+
)
|
50 |
+
);
|
51 |
+
}
|
52 |
+
|
53 |
+
public function all()
|
54 |
+
{
|
55 |
+
|
56 |
+
return parent::connect();
|
57 |
+
}
|
58 |
+
}
|
app/code/community/Laposta/Connect/lib/Laposta/Laposta/Login.php
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Laposta_Login extends Laposta_Resource
|
3 |
+
{
|
4 |
+
|
5 |
+
public function __construct()
|
6 |
+
{
|
7 |
+
|
8 |
+
parent::__construct(get_class());
|
9 |
+
}
|
10 |
+
|
11 |
+
public function get($login, $password)
|
12 |
+
{
|
13 |
+
|
14 |
+
return parent::connect(
|
15 |
+
array(
|
16 |
+
'parameters' => array('login' => $login, 'password' => $password)
|
17 |
+
)
|
18 |
+
);
|
19 |
+
}
|
20 |
+
}
|
app/code/community/Laposta/Connect/lib/Laposta/Laposta/Member.php
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Laposta_Member extends Laposta_Resource
|
3 |
+
{
|
4 |
+
|
5 |
+
private $list_id;
|
6 |
+
|
7 |
+
public function __construct($list_id)
|
8 |
+
{
|
9 |
+
|
10 |
+
// we need the list_id for each call
|
11 |
+
$this->list_id = $list_id;
|
12 |
+
parent::__construct(get_class());
|
13 |
+
}
|
14 |
+
|
15 |
+
public function get($member_id)
|
16 |
+
{
|
17 |
+
|
18 |
+
return parent::connect(
|
19 |
+
array(
|
20 |
+
'path' => array($member_id),
|
21 |
+
'parameters' => array('list_id' => $this->list_id)
|
22 |
+
)
|
23 |
+
);
|
24 |
+
}
|
25 |
+
|
26 |
+
public function create($data)
|
27 |
+
{
|
28 |
+
|
29 |
+
// add list_id to data
|
30 |
+
$data['list_id'] = $this->list_id;
|
31 |
+
|
32 |
+
return parent::connect(
|
33 |
+
array(
|
34 |
+
'post' => $data
|
35 |
+
)
|
36 |
+
);
|
37 |
+
}
|
38 |
+
|
39 |
+
public function update($member_id, $data)
|
40 |
+
{
|
41 |
+
|
42 |
+
// add list_id to data
|
43 |
+
$data['list_id'] = $this->list_id;
|
44 |
+
|
45 |
+
return parent::connect(
|
46 |
+
array(
|
47 |
+
'path' => array($member_id),
|
48 |
+
'post' => $data
|
49 |
+
)
|
50 |
+
);
|
51 |
+
}
|
52 |
+
|
53 |
+
public function delete($member_id)
|
54 |
+
{
|
55 |
+
|
56 |
+
return parent::connect(
|
57 |
+
array(
|
58 |
+
'path' => array($member_id),
|
59 |
+
'parameters' => array('list_id' => $this->list_id),
|
60 |
+
'method' => 'DELETE'
|
61 |
+
)
|
62 |
+
);
|
63 |
+
}
|
64 |
+
|
65 |
+
public function all()
|
66 |
+
{
|
67 |
+
|
68 |
+
return parent::connect(
|
69 |
+
array(
|
70 |
+
'parameters' => array('list_id' => $this->list_id)
|
71 |
+
)
|
72 |
+
);
|
73 |
+
}
|
74 |
+
}
|
app/code/community/Laposta/Connect/lib/Laposta/Laposta/Request.php
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Laposta_Request
|
3 |
+
{
|
4 |
+
|
5 |
+
public static function connect($data)
|
6 |
+
{
|
7 |
+
|
8 |
+
// result from server
|
9 |
+
$response = Laposta_Util::connect(
|
10 |
+
$data['url'],
|
11 |
+
self::getHeaders(),
|
12 |
+
Laposta::getApiKey(),
|
13 |
+
$data['post'],
|
14 |
+
$data['method']
|
15 |
+
);
|
16 |
+
|
17 |
+
// check for CURL error
|
18 |
+
if ($response['error']) {
|
19 |
+
throw new Laposta_Error('Connection error: ' . $response['error_msg'], $response['status'], $response['body']);
|
20 |
+
}
|
21 |
+
|
22 |
+
// decode JSON
|
23 |
+
$result = self::decode($response);
|
24 |
+
|
25 |
+
// check for API errors
|
26 |
+
if ($response['status'] < 200 || $response['status'] >= 300) {
|
27 |
+
throw new Laposta_Error('API error: ' . $result['error']['message'], $response['status'], $response['body'], $result);
|
28 |
+
}
|
29 |
+
|
30 |
+
return $result;
|
31 |
+
}
|
32 |
+
|
33 |
+
private static function getHeaders()
|
34 |
+
{
|
35 |
+
|
36 |
+
$ua = array(
|
37 |
+
'bindings_version' => Laposta::VERSION,
|
38 |
+
'lang' => 'php',
|
39 |
+
'lang_version' => phpversion(),
|
40 |
+
'uname' => php_uname()
|
41 |
+
);
|
42 |
+
|
43 |
+
$headers = array(
|
44 |
+
'X-Laposta-Client-User-Agent: ' . json_encode($ua),
|
45 |
+
'User-Agent: laposta-php-' . Laposta::VERSION
|
46 |
+
);
|
47 |
+
|
48 |
+
return $headers;
|
49 |
+
}
|
50 |
+
|
51 |
+
private static function decode($response)
|
52 |
+
{
|
53 |
+
|
54 |
+
$result = json_decode($response['body'], true);
|
55 |
+
|
56 |
+
// no problems decoding?
|
57 |
+
if (empty($result) || !is_array($result)) {
|
58 |
+
throw new Laposta_Error('Invalid response body from API', $response['status'], $response['body']);
|
59 |
+
}
|
60 |
+
|
61 |
+
return $result;
|
62 |
+
}
|
63 |
+
}
|
app/code/community/Laposta/Connect/lib/Laposta/Laposta/Resource.php
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Laposta_Resource
|
3 |
+
{
|
4 |
+
|
5 |
+
protected $result;
|
6 |
+
|
7 |
+
private $classname;
|
8 |
+
|
9 |
+
public function __construct($classname)
|
10 |
+
{
|
11 |
+
|
12 |
+
$this->classname = $classname;
|
13 |
+
}
|
14 |
+
|
15 |
+
protected function connect($data = array())
|
16 |
+
{
|
17 |
+
|
18 |
+
// request parts
|
19 |
+
$path = is_array($data['path']) ? $data['path'] : array();
|
20 |
+
$parameters = is_array($data['parameters']) ? $data['parameters'] : array();
|
21 |
+
$post = is_array($data['post']) ? $data['post'] : array();
|
22 |
+
$method = $data['method'];
|
23 |
+
|
24 |
+
// start with base url
|
25 |
+
$url = $this->formatBaseUrl();
|
26 |
+
|
27 |
+
// add path
|
28 |
+
if (count($path)) {
|
29 |
+
foreach ($path as $item) {
|
30 |
+
$url .= '/' . $item;
|
31 |
+
}
|
32 |
+
}
|
33 |
+
|
34 |
+
// add parameters to querystring
|
35 |
+
if (count($parameters)) {
|
36 |
+
$url .= '?' . http_build_query($parameters);
|
37 |
+
}
|
38 |
+
|
39 |
+
// build query for post
|
40 |
+
if (count($post)) {
|
41 |
+
$post = http_build_query($post);
|
42 |
+
}
|
43 |
+
|
44 |
+
return Laposta_Request::connect(
|
45 |
+
array(
|
46 |
+
'url' => $url,
|
47 |
+
'post' => $post,
|
48 |
+
'method' => $method
|
49 |
+
)
|
50 |
+
);
|
51 |
+
}
|
52 |
+
|
53 |
+
private function formatBaseUrl()
|
54 |
+
{
|
55 |
+
|
56 |
+
$url = Laposta::getApiBase() . '/' . $this->getResource();
|
57 |
+
|
58 |
+
return $url;
|
59 |
+
}
|
60 |
+
|
61 |
+
private function getResource()
|
62 |
+
{
|
63 |
+
|
64 |
+
$resource = strtolower(substr($this->classname, strpos($this->classname, '_') + 1));
|
65 |
+
|
66 |
+
return $resource;
|
67 |
+
}
|
68 |
+
}
|
app/code/community/Laposta/Connect/lib/Laposta/Laposta/Util.php
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Laposta_Util
|
3 |
+
{
|
4 |
+
|
5 |
+
public static function connect($url, $headers, $api_key, $post = null, $method = null, $timeout = 15)
|
6 |
+
{
|
7 |
+
|
8 |
+
$error = false;
|
9 |
+
|
10 |
+
$ch = curl_init();
|
11 |
+
curl_setopt($ch, CURLOPT_URL, $url);
|
12 |
+
curl_setopt($ch, CURLOPT_HEADER, false);
|
13 |
+
curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
|
14 |
+
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
|
15 |
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
16 |
+
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
|
17 |
+
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
18 |
+
curl_setopt($ch, CURLOPT_FORBID_REUSE, true);
|
19 |
+
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
|
20 |
+
curl_setopt($ch, CURLOPT_USERPWD, $api_key . ':');
|
21 |
+
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
22 |
+
|
23 |
+
if ($post) {
|
24 |
+
curl_setopt($ch, CURLOPT_POST, true);
|
25 |
+
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
|
26 |
+
}
|
27 |
+
|
28 |
+
if ($method == 'DELETE') {
|
29 |
+
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
|
30 |
+
}
|
31 |
+
|
32 |
+
$body = curl_exec($ch);
|
33 |
+
$info = curl_getinfo($ch);
|
34 |
+
|
35 |
+
// controleer op fouten
|
36 |
+
$error = false;
|
37 |
+
if (curl_errno($ch)) {
|
38 |
+
$error = true;
|
39 |
+
$error_msg = curl_error($ch);
|
40 |
+
}
|
41 |
+
curl_close($ch);
|
42 |
+
|
43 |
+
return array('error' => $error,
|
44 |
+
'error_msg' => $error_msg,
|
45 |
+
'status' => $info['http_code'],
|
46 |
+
'body' => $body,
|
47 |
+
'info' => $info
|
48 |
+
);
|
49 |
+
}
|
50 |
+
|
51 |
+
public static function utf8($value)
|
52 |
+
{
|
53 |
+
|
54 |
+
if (is_string($value)) {
|
55 |
+
return utf8_encode($value);
|
56 |
+
}
|
57 |
+
else if (is_array($value)) {
|
58 |
+
function encode_items(&$item, $key)
|
59 |
+
{
|
60 |
+
$item = utf8_encode($item);
|
61 |
+
}
|
62 |
+
|
63 |
+
array_walk_recursive($value, 'encode_items');
|
64 |
+
}
|
65 |
+
|
66 |
+
return $value;
|
67 |
+
}
|
68 |
+
}
|
app/code/community/Laposta/Connect/lib/Laposta/Laposta/Webhook.php
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class Laposta_Webhook extends Laposta_Resource
|
3 |
+
{
|
4 |
+
|
5 |
+
private $list_id;
|
6 |
+
|
7 |
+
public function __construct($list_id)
|
8 |
+
{
|
9 |
+
|
10 |
+
// we need the list_id for each call
|
11 |
+
$this->list_id = $list_id;
|
12 |
+
parent::__construct(get_class());
|
13 |
+
}
|
14 |
+
|
15 |
+
public function get($webhook_id)
|
16 |
+
{
|
17 |
+
|
18 |
+
return parent::connect(
|
19 |
+
array(
|
20 |
+
'path' => array($webhook_id),
|
21 |
+
'parameters' => array('list_id' => $this->list_id)
|
22 |
+
)
|
23 |
+
);
|
24 |
+
}
|
25 |
+
|
26 |
+
public function create($data)
|
27 |
+
{
|
28 |
+
|
29 |
+
// add list_id to data
|
30 |
+
$data['list_id'] = $this->list_id;
|
31 |
+
|
32 |
+
return parent::connect(
|
33 |
+
array(
|
34 |
+
'post' => $data
|
35 |
+
)
|
36 |
+
);
|
37 |
+
}
|
38 |
+
|
39 |
+
public function update($webhook_id, $data)
|
40 |
+
{
|
41 |
+
|
42 |
+
// add list_id to data
|
43 |
+
$data['list_id'] = $this->list_id;
|
44 |
+
|
45 |
+
return parent::connect(
|
46 |
+
array(
|
47 |
+
'path' => array($webhook_id),
|
48 |
+
'post' => $data
|
49 |
+
)
|
50 |
+
);
|
51 |
+
}
|
52 |
+
|
53 |
+
public function delete($webhook_id)
|
54 |
+
{
|
55 |
+
|
56 |
+
return parent::connect(
|
57 |
+
array(
|
58 |
+
'path' => array($webhook_id),
|
59 |
+
'parameters' => array('list_id' => $this->list_id),
|
60 |
+
'method' => 'DELETE'
|
61 |
+
)
|
62 |
+
);
|
63 |
+
}
|
64 |
+
|
65 |
+
public function all()
|
66 |
+
{
|
67 |
+
|
68 |
+
return parent::connect(
|
69 |
+
array(
|
70 |
+
'parameters' => array('list_id' => $this->list_id)
|
71 |
+
)
|
72 |
+
);
|
73 |
+
}
|
74 |
+
}
|
package.xml
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Mage_Laposta_Connect</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>
|
@@ -24,11 +24,12 @@
|
|
24 |

|
25 |
<h2>Questions</h2>
|
26 |
<p>Please see the FAQ section for questions.</p></description>
|
27 |
-
<notes>-
|
|
|
28 |
<authors><author><name>Merten van Gerven</name><user>mertenvg</user><email>merten@codeblanche.com</email></author></authors>
|
29 |
<date>2014-06-03</date>
|
30 |
-
<time>
|
31 |
-
<contents><target name="magecommunity"><dir name="Laposta"><dir name="Connect"><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Form"><dir name="Field"><file name="Mapfields.php" hash="2c88b8a08121c09ba5748f631205a282"/></dir></dir></dir></dir></dir></dir><dir name="Helper"><file name="Customer.php" hash="ef0a5dff85fd77de92a0fefe06fddc60"/><file name="Data.php" hash="8f9e28d0f28f9375385432d227ec1d06"/><file name="Fields.php" hash="51bc0aa26167219b038c04b3babb19af"/><file name="Laposta.php" hash="
|
32 |
<compatible/>
|
33 |
<dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
|
34 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Mage_Laposta_Connect</name>
|
4 |
+
<version>1.0.10</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>
|
24 |

|
25 |
<h2>Questions</h2>
|
26 |
<p>Please see the FAQ section for questions.</p></description>
|
27 |
+
<notes>- Moved Laposta library into Laposta Connect module root
|
28 |
+
</notes>
|
29 |
<authors><author><name>Merten van Gerven</name><user>mertenvg</user><email>merten@codeblanche.com</email></author></authors>
|
30 |
<date>2014-06-03</date>
|
31 |
+
<time>15:04:34</time>
|
32 |
+
<contents><target name="magecommunity"><dir name="Laposta"><dir name="Connect"><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Form"><dir name="Field"><file name="Mapfields.php" hash="2c88b8a08121c09ba5748f631205a282"/></dir></dir></dir></dir></dir></dir><dir name="Helper"><file name="Customer.php" hash="ef0a5dff85fd77de92a0fefe06fddc60"/><file name="Data.php" hash="8f9e28d0f28f9375385432d227ec1d06"/><file name="Fields.php" hash="51bc0aa26167219b038c04b3babb19af"/><file name="Laposta.php" hash="e3e752e09512b9a3317ead8a0ca68eba"/><file name="Subscribe.php" hash="f58bc248ee3b4d229b58de8b4efbccf3"/><file name="Sync.php" hash="ad94bd49cf666fb99fa043bef1ba8bcf"/></dir><dir name="Model"><file name="Cron.php" hash="270a2289a1de1bc678dfc4e6264c095b"/><file name="Field.php" hash="42e1857bdb7d90b31be189e2921ac8fd"/><file name="List.php" hash="99f590a5e5ea3b1a14869c641f49eaed"/><dir name="Mysql4"><dir name="Field"><file name="Collection.php" hash="f8133202231937b1ec14d8cdc39903fe"/></dir><file name="Field.php" hash="c49743d6acd1d4ce2b69aadf22838839"/><dir name="List"><file name="Collection.php" hash="fcc556452fff91bb3e9f933c68fff630"/></dir><file name="List.php" hash="6fef1b36f5d3a5560f83bafe205be614"/><dir name="Subscriber"><file name="Collection.php" hash="05db928eb656f132e4fa16ac740ce3c5"/></dir><file name="Subscriber.php" hash="9f73d39e97d4a19f8d8ad3c19f83a699"/></dir><file name="Observer.php" hash="1f22b2201a11543b725bc76f133b803d"/><file name="Subscriber.php" hash="cba5176e53a7dcab9b9014190f13485d"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="LapostaController.php" hash="cc2a0d62caf63469258042e3b29616e4"/></dir><file name="IndexController.php" hash="7577e30abee9624d59901edb5cecd3e9"/><file name="SubscribeAllController.php" hash="160ac8e5229bb1003d7220116a9b06f7"/><file name="WebhookController.php" hash="0526b02b319fc31cd8c8a3e9789ba358"/></dir><dir name="etc"><file name="adminhtml.xml" hash="71f985837d4b79e3db94c529bfee1e47"/><file name="config.xml" hash="e0f0be6791cbcdb6bf2f129eaa02feb2"/><file name="system.xml" hash="6ee7d5de56541573f16a2caf94dc0418"/></dir><dir name="lib"><dir name="Laposta"><dir name="Laposta"><file name="Error.php" hash="46e746b650bbb5df1ec51f4c530d5f35"/><file name="Field.php" hash="99bc22f997692ff648cb660330552a94"/><file name="List.php" hash="f3b8a716c1d9fd11828f980445dd6d5b"/><file name="Login.php" hash="dc11941e5ca3a404005730843c74e8b3"/><file name="Member.php" hash="cae2b3f6b23ee44e9246a8d33d2ddd46"/><file name="Request.php" hash="66bc536b8b9ce443c3ae0917bdd472ed"/><file name="Resource.php" hash="c2ca77821136b798b526b5dc41659054"/><file name="Util.php" hash="d6760d2d5ddb6f4de6aff185fd432a91"/><file name="Webhook.php" hash="e06b2e711c348af1df425b7faaa5c33e"/></dir><file name="Laposta.php" hash="c99f38dcfef24df38a5a921360356381"/></dir></dir><dir name="sql"><dir name="lapostaconnect_setup"><file name="mysql4-install-1.0.0.php" hash="a1b0319b992b9effe6aa2712031e8701"/><file name="mysql4-upgrade-1.0.7-1.0.8.php" hash="a1b0319b992b9effe6aa2712031e8701"/></dir></dir></dir></dir></target><target name="magelocal"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="lapostaconnect.xml" hash=""/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Laposta_Connect.xml" hash="ab7675e19ea96d39c5980bee835f0e76"/></dir></target><target name="magelocale"><dir name="en_US"><file name="Laposta_Connect.csv" hash="4f8f28790602cdd01633c0bb00f70585"/></dir></target></contents>
|
33 |
<compatible/>
|
34 |
<dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php></required></dependencies>
|
35 |
</package>
|