@@ -3,9 +3,9 @@ |
||
3 | 3 | |
4 | 4 | class ParaleTest extends PHPUnit_Framework_TestCase { |
5 | 5 | |
6 | - public function testParale() { |
|
7 | - /* todo */ |
|
8 | - $this->assertTrue(true); |
|
9 | - } |
|
6 | + public function testParale() { |
|
7 | + /* todo */ |
|
8 | + $this->assertTrue(true); |
|
9 | + } |
|
10 | 10 | |
11 | 11 | } |
12 | 12 | \ No newline at end of file |
@@ -42,14 +42,14 @@ discard block |
||
42 | 42 | */ |
43 | 43 | private function makeRequest($method, $args = array()) { |
44 | 44 | |
45 | - $url = $this->api_endpoint . '/' . $method . '.json'; |
|
45 | + $url = $this->api_endpoint.'/'.$method.'.json'; |
|
46 | 46 | |
47 | 47 | if (function_exists('curl_init') && function_exists('curl_setopt')) { |
48 | 48 | $ch = curl_init(); |
49 | 49 | curl_setopt($ch, CURLOPT_URL, $url); |
50 | - curl_setopt($ch, CURLOPT_USERPWD, $this->username . ":" . $this->password); |
|
50 | + curl_setopt($ch, CURLOPT_USERPWD, $this->username.":".$this->password); |
|
51 | 51 | curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); |
52 | - curl_setopt($ch, CURLOPT_USERAGENT, "2Parale-" . $this->api_version); |
|
52 | + curl_setopt($ch, CURLOPT_USERAGENT, "2Parale-".$this->api_version); |
|
53 | 53 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
54 | 54 | curl_setopt($ch, CURLOPT_TIMEOUT, 10); |
55 | 55 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->verify_ssl); |
@@ -64,12 +64,12 @@ discard block |
||
64 | 64 | $result = file_get_contents($url, null, stream_context_create(array( |
65 | 65 | 'http' => array( |
66 | 66 | 'protocol_version' => 1.1, |
67 | - 'user_agent' => "2Parale-" . $this->api_version, |
|
67 | + 'user_agent' => "2Parale-".$this->api_version, |
|
68 | 68 | 'method' => 'POST', |
69 | - 'header' => "Authorization: Basic " . base64_encode($this->username . ':' . $this->password) . "\r\n" . |
|
70 | - "Content-type: application/json\r\n" . |
|
71 | - "Connection: close\r\n" . |
|
72 | - "Content-length: " . strlen($json_data) . "\r\n", |
|
69 | + 'header' => "Authorization: Basic ".base64_encode($this->username.':'.$this->password)."\r\n". |
|
70 | + "Content-type: application/json\r\n". |
|
71 | + "Connection: close\r\n". |
|
72 | + "Content-length: ".strlen($json_data)."\r\n", |
|
73 | 73 | 'content' => $json_data, |
74 | 74 | ), |
75 | 75 | ))); |
@@ -10,70 +10,70 @@ |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | class Parale { |
13 | - private $username; |
|
14 | - private $password; |
|
15 | - private $api_endpoint = "https://api.2parale.ro"; |
|
16 | - private $verify_ssl = false; |
|
17 | - private $api_version = "0.1"; |
|
13 | + private $username; |
|
14 | + private $password; |
|
15 | + private $api_endpoint = "https://api.2parale.ro"; |
|
16 | + private $verify_ssl = false; |
|
17 | + private $api_version = "0.1"; |
|
18 | 18 | |
19 | - /** |
|
20 | - * Create a new instance |
|
21 | - * @param string $username Your username |
|
22 | - * @param string $password Your password |
|
23 | - */ |
|
24 | - function __construct($username, $password) { |
|
25 | - $this->username = $username; |
|
26 | - $this->password = $password; |
|
27 | - } |
|
19 | + /** |
|
20 | + * Create a new instance |
|
21 | + * @param string $username Your username |
|
22 | + * @param string $password Your password |
|
23 | + */ |
|
24 | + function __construct($username, $password) { |
|
25 | + $this->username = $username; |
|
26 | + $this->password = $password; |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * Call method, just call me maybe |
|
31 | - * @param string $method The API method to call, e.g. 'campaigns/listforaffiliate' |
|
32 | - * @param array $args An array of arguments to pass to the method e.g. page=2 Will be json-encoded for you. |
|
33 | - * @return array Associative array of json decoded API response. |
|
34 | - */ |
|
35 | - public function call($method, $args = array()) { |
|
36 | - return $this->makeRequest($method, $args); |
|
37 | - } |
|
29 | + /** |
|
30 | + * Call method, just call me maybe |
|
31 | + * @param string $method The API method to call, e.g. 'campaigns/listforaffiliate' |
|
32 | + * @param array $args An array of arguments to pass to the method e.g. page=2 Will be json-encoded for you. |
|
33 | + * @return array Associative array of json decoded API response. |
|
34 | + */ |
|
35 | + public function call($method, $args = array()) { |
|
36 | + return $this->makeRequest($method, $args); |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param string $method |
|
41 | - */ |
|
42 | - private function makeRequest($method, $args = array()) { |
|
39 | + /** |
|
40 | + * @param string $method |
|
41 | + */ |
|
42 | + private function makeRequest($method, $args = array()) { |
|
43 | 43 | |
44 | - $url = $this->api_endpoint . '/' . $method . '.json'; |
|
44 | + $url = $this->api_endpoint . '/' . $method . '.json'; |
|
45 | 45 | |
46 | - if (function_exists('curl_init') && function_exists('curl_setopt')) { |
|
47 | - $ch = curl_init(); |
|
48 | - curl_setopt($ch, CURLOPT_URL, $url); |
|
49 | - curl_setopt($ch, CURLOPT_USERPWD, $this->username . ":" . $this->password); |
|
50 | - curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); |
|
51 | - curl_setopt($ch, CURLOPT_USERAGENT, "2Parale-" . $this->api_version); |
|
52 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
53 | - curl_setopt($ch, CURLOPT_TIMEOUT, 10); |
|
54 | - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->verify_ssl); |
|
55 | - if (!empty($args)) { |
|
56 | - curl_setopt($ch, CURLOPT_POST, true); |
|
57 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($args)); |
|
58 | - } |
|
59 | - $result = curl_exec($ch); |
|
60 | - curl_close($ch); |
|
61 | - } else { |
|
62 | - $json_data = json_encode($args); |
|
63 | - $result = file_get_contents($url, null, stream_context_create(array( |
|
64 | - 'http' => array( |
|
65 | - 'protocol_version' => 1.1, |
|
66 | - 'user_agent' => "2Parale-" . $this->api_version, |
|
67 | - 'method' => 'POST', |
|
68 | - 'header' => "Authorization: Basic " . base64_encode($this->username . ':' . $this->password) . "\r\n" . |
|
69 | - "Content-type: application/json\r\n" . |
|
70 | - "Connection: close\r\n" . |
|
71 | - "Content-length: " . strlen($json_data) . "\r\n", |
|
72 | - 'content' => $json_data, |
|
73 | - ), |
|
74 | - ))); |
|
75 | - } |
|
76 | - return $result ? json_decode($result, true) : false; |
|
77 | - } |
|
46 | + if (function_exists('curl_init') && function_exists('curl_setopt')) { |
|
47 | + $ch = curl_init(); |
|
48 | + curl_setopt($ch, CURLOPT_URL, $url); |
|
49 | + curl_setopt($ch, CURLOPT_USERPWD, $this->username . ":" . $this->password); |
|
50 | + curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); |
|
51 | + curl_setopt($ch, CURLOPT_USERAGENT, "2Parale-" . $this->api_version); |
|
52 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
53 | + curl_setopt($ch, CURLOPT_TIMEOUT, 10); |
|
54 | + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->verify_ssl); |
|
55 | + if (!empty($args)) { |
|
56 | + curl_setopt($ch, CURLOPT_POST, true); |
|
57 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($args)); |
|
58 | + } |
|
59 | + $result = curl_exec($ch); |
|
60 | + curl_close($ch); |
|
61 | + } else { |
|
62 | + $json_data = json_encode($args); |
|
63 | + $result = file_get_contents($url, null, stream_context_create(array( |
|
64 | + 'http' => array( |
|
65 | + 'protocol_version' => 1.1, |
|
66 | + 'user_agent' => "2Parale-" . $this->api_version, |
|
67 | + 'method' => 'POST', |
|
68 | + 'header' => "Authorization: Basic " . base64_encode($this->username . ':' . $this->password) . "\r\n" . |
|
69 | + "Content-type: application/json\r\n" . |
|
70 | + "Connection: close\r\n" . |
|
71 | + "Content-length: " . strlen($json_data) . "\r\n", |
|
72 | + 'content' => $json_data, |
|
73 | + ), |
|
74 | + ))); |
|
75 | + } |
|
76 | + return $result ? json_decode($result, true) : false; |
|
77 | + } |
|
78 | 78 | |
79 | 79 | } |
@@ -14,8 +14,8 @@ |
||
14 | 14 | |
15 | 15 | /* Campaigns */ |
16 | 16 | $campaigns = $parale->call( |
17 | - 'campaigns/listforaffiliate', |
|
18 | - array("page" => "1") |
|
17 | + 'campaigns/listforaffiliate', |
|
18 | + array("page" => "1") |
|
19 | 19 | ); |
20 | 20 | |
21 | 21 | /* do some stuff with $campaigns; */ |