mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2025-02-06 08:19:25 +03:00
* #276 additional method to get an attachment * #276 fix code style * Add Mailgun::getAttachment + test * code style fix
This commit is contained in:
parent
74929b6518
commit
718547a273
@ -108,6 +108,26 @@ class RestClient
|
|||||||
return $this->responseHandler($response);
|
return $this->responseHandler($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $url
|
||||||
|
*
|
||||||
|
* @throws GenericHTTPError
|
||||||
|
* @throws InvalidCredentials
|
||||||
|
* @throws MissingEndpoint
|
||||||
|
* @throws MissingRequiredParameters
|
||||||
|
*
|
||||||
|
* @return \stdClass
|
||||||
|
*/
|
||||||
|
public function getAttachment($url)
|
||||||
|
{
|
||||||
|
$headers['User-Agent'] = Api::SDK_USER_AGENT.'/'.Api::SDK_VERSION;
|
||||||
|
$headers['Authorization'] = 'Basic '.base64_encode(sprintf('%s:%s', Api::API_USER, $this->apiKey));
|
||||||
|
$request = MessageFactoryDiscovery::find()->createRequest('get', $url, $headers);
|
||||||
|
$response = HttpClientDiscovery::find()->sendRequest($request);
|
||||||
|
|
||||||
|
return $this->responseHandler($response);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $endpointUrl
|
* @param string $endpointUrl
|
||||||
* @param array $postData
|
* @param array $postData
|
||||||
|
@ -179,6 +179,16 @@ class Mailgun
|
|||||||
return $this->restClient->get($endpointUrl, $queryString);
|
return $this->restClient->get($endpointUrl, $queryString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $url
|
||||||
|
*
|
||||||
|
* @return \stdClass
|
||||||
|
*/
|
||||||
|
public function getAttachment($url)
|
||||||
|
{
|
||||||
|
return $this->restClient->getAttachment($url);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $endpointUrl
|
* @param string $endpointUrl
|
||||||
*
|
*
|
||||||
|
@ -49,4 +49,22 @@ class MailgunTest extends \Mailgun\Tests\MailgunTestCase
|
|||||||
$postData = [];
|
$postData = [];
|
||||||
assert(!$client->verifyWebhookSignature($postData));
|
assert(!$client->verifyWebhookSignature($postData));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetAttachmentOk()
|
||||||
|
{
|
||||||
|
$attachmentUrl = 'http://example.com';
|
||||||
|
$client = new Mailgun('key-3ax6xnjp29jd6fds4gc373sgvjxteol0');
|
||||||
|
$response = $client->getAttachment($attachmentUrl);
|
||||||
|
|
||||||
|
$this->assertInstanceOf('stdClass', $response);
|
||||||
|
$this->assertEquals($response->http_response_code, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetAttachmentFail()
|
||||||
|
{
|
||||||
|
$this->setExpectedException('\\Mailgun\\Connection\\Exceptions\\GenericHTTPError');
|
||||||
|
$attachmentUrl = 'https://api.mailgun.net/non.existing.uri/1/2/3';
|
||||||
|
$client = new Mailgun('key-3ax6xnjp29jd6fds4gc373sgvjxteol0');
|
||||||
|
$client->getAttachment($attachmentUrl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user