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