Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add an option to override SendGrid Client path version #850

Merged
merged 4 commits into from
Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
7 changes: 5 additions & 2 deletions lib/SendGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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'];
}
Expand All @@ -57,7 +60,7 @@ public function __construct($apiKey, $options = array())
$this->client = new \SendGrid\Client(
$host,
$headers,
'/v3',
$path,
null,
$curlOptions
);
Expand Down
22 changes: 22 additions & 0 deletions test/unit/SendGridTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
}
}