Last active
August 29, 2015 14:09
-
-
Save eddiezane/69f8ee3ed9da20c4e3a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function send(SendGrid\Email $email) { | |
$form = $email->toWebFormat(); | |
$form['api_user'] = $this->api_user; | |
$form['api_key'] = $this->api_key; | |
$response = $this->makeRequest($form); | |
if ($response->code != 200) { | |
throw new SendGrid\Exception($response->raw_body); | |
} | |
return $response->body; | |
} | |
public function makeRequest($form) { | |
return \Unirest::post($this->url, array('User-Agent' => 'sendgrid/' . $this->version . ';php'), $form); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @expectedException SendGrid\Exception | |
*/ | |
public function testSendGridExceptionThrownWhenNot200() { | |
$mockResponse = (object)array("code" => 400, "raw_body" => '{"message": "error", "errors": ["Bad username / password"]}'); | |
$sendgrid = m::mock("SendGrid[makeRequest]", array("foo", "bar")); | |
$sendgrid->shouldReceive('makeRequest')->once()->andReturn($mockResponse); | |
$email = new SendGrid\Email(); | |
$email->setFrom("bar@foo.com")-> | |
setSubject("foobar subject")-> | |
setText("foobar text")-> | |
addTo("foo@bar.com"); | |
$response = $sendgrid->send($email); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment