summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/example.php9
-rw-r--r--php_http_client/client.php1
-rw-r--r--php_http_client/config.php11
3 files changed, 14 insertions, 7 deletions
diff --git a/examples/example.php b/examples/example.php
index 05f0a9a..05fe5eb 100644
--- a/examples/example.php
+++ b/examples/example.php
@@ -1,11 +1,8 @@
<?php
include(dirname(__DIR__).'/php_http_client/client.php');
-
-$myfile = fopen(dirname(__DIR__).'/.env', "r");
-$env = fgets($myfile);
-$env = explode('=', $env);
-$api_key = $env[1];
-$api_key = trim(preg_replace('/\s+/', ' ', $api_key));
+include(dirname(__DIR__).'/php_http_client/config.php');
+$config = new Config(dirname(__DIR__), '.env');
+$api_key = getenv('SENDGRID_API_KEY');
$headers = array(
'Content-Type: application/json',
'Authorization: Bearer '.$api_key
diff --git a/php_http_client/client.php b/php_http_client/client.php
index cc79505..77ca629 100644
--- a/php_http_client/client.php
+++ b/php_http_client/client.php
@@ -129,7 +129,6 @@ class Client {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
break;
case 'post':
- curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
$request_body = json_encode($request_body);
curl_setopt($curl, CURLOPT_POSTFIELDS, $request_body);
diff --git a/php_http_client/config.php b/php_http_client/config.php
index e69de29..ba33bef 100644
--- a/php_http_client/config.php
+++ b/php_http_client/config.php
@@ -0,0 +1,11 @@
+<?php
+class Config{
+ function __construct($base_path, $config_filename){
+ $handle = fopen($base_path.'/'.$config_filename, "r");
+ while (($line = fgets($handle)) !== false) {
+ putenv(trim(preg_replace('/\s+/', ' ', $line)));
+ }
+ fclose($handle);
+ }
+}
+?>