diff --git a/docker/Dockerfile b/docker/Dockerfile index 125579ebd..2062fb35d 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -7,16 +7,20 @@ ENV SENDGRID_API_KEY $SENDGRID_API_KEY WORKDIR /root # install Prism -ADD https://raw.githubusercontent.com/stoplightio/prism/master/install.sh install.sh +ADD https://raw.githubusercontent.com/stoplightio/prism/master/install install.sh +RUN apt-get update && apt-get install dos2unix RUN chmod +x ./install.sh && sync && \ + dos2unix ./install.sh && \ ./install.sh && \ rm ./install.sh + # set up default Twilio SendGrid env WORKDIR /root RUN mkdir sendgrid-php COPY entrypoint.sh entrypoint.sh RUN chmod +x entrypoint.sh +RUN dos2unix ./entrypoint.sh ENTRYPOINT ["./entrypoint.sh"] CMD ["--mock"] diff --git a/lib/SendGrid.php b/lib/SendGrid.php index 08ee1d6e8..8ccf10011 100644 --- a/lib/SendGrid.php +++ b/lib/SendGrid.php @@ -34,7 +34,7 @@ class SendGrid * Setup the HTTP Client * * @param string $apiKey Your Twilio SendGrid API Key. - * @param array $options An array of options, currently only "host", "curl" and + * @param array $options An array of options, currently only "host", "curl", "path" and * "impersonateSubuser" are implemented. */ public function __construct($apiKey, $options = array()) @@ -48,6 +48,9 @@ public function __construct($apiKey, $options = array()) $host = isset($options['host']) ? $options['host'] : 'https://api.sendgrid.com'; + $path = isset($options['path']) ? $options['path'] : + '/v3'; + if (!empty($options['impersonateSubuser'])) { $headers[] = 'On-Behalf-Of: '. $options['impersonateSubuser']; } @@ -57,7 +60,7 @@ public function __construct($apiKey, $options = array()) $this->client = new \SendGrid\Client( $host, $headers, - '/v3', + $path, null, $curlOptions ); diff --git a/test/unit/SendGridTest.php b/test/unit/SendGridTest.php index 274e7aa4e..9221a2889 100644 --- a/test/unit/SendGridTest.php +++ b/test/unit/SendGridTest.php @@ -85,4 +85,26 @@ public function testCanConnectToSendGridApi() $sg5->client->getHeaders() ); } + + + /** + * Test that user can override the path when instantiating a new SendGrid client + */ + public function testCanOverridePath() + { + $opts['path'] = 'v4'; + + $sg = new \SendGrid(self::$apiKey, $opts); + $headers = [ + 'Authorization: Bearer ' . self::$apiKey, + 'User-Agent: sendgrid/' . $sg->version . ';php', + 'Accept: application/json' + ]; + + $this->assertEquals( + $sg->client->getHost(), + 'https://api.sendgrid.com', + '/v4' + ); + } }