Skip to content
This repository was archived by the owner on May 18, 2020. It is now read-only.

Commit c8ff14a

Browse files
committed
simplify do_request
1 parent ffe797a commit c8ff14a

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

Wrapper/Mailin.php

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,18 @@ public function __construct($parameters)
3434
*/
3535
private function do_request($resource, $method, $input)
3636
{
37-
$called_url = self::ENDPOINT.$resource;
38-
$ch = curl_init($called_url);
39-
$auth_header = 'api-key:'.$this->api_key;
40-
$content_header = 'Content-Type:application/json';
41-
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
42-
// Windows only over-ride
43-
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
44-
}
45-
curl_setopt($ch, CURLOPT_HTTPHEADER, array($auth_header, $content_header));
46-
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
47-
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
48-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
49-
curl_setopt($ch, CURLOPT_TIMEOUT_MS, $this->timeout);
50-
curl_setopt($ch, CURLOPT_HEADER, 0);
51-
curl_setopt($ch, CURLOPT_POSTFIELDS, $input);
37+
$ch = curl_init(self::ENDPOINT.$resource);
38+
curl_setopt_array($ch, array(
39+
CURLOPT_CUSTOMREQUEST => $method,
40+
CURLOPT_FOLLOWLOCATION => true,
41+
CURLOPT_HTTPHEADER => array(
42+
'api-key' => $this->api_key,
43+
'Content-Type' => 'application/json',
44+
),
45+
CURLOPT_POSTFIELDS => $input,
46+
CURLOPT_RETURNTRANSFER => true,
47+
CURLOPT_TIMEOUT_MS => $this->timeout,
48+
));
5249

5350
$data = curl_exec($ch);
5451
if (curl_errno($ch)) {

0 commit comments

Comments
 (0)