Integrating with mailing service, uploading image service and so on.
It's based on Guzzle,HTTP client.
service-name | support | service-type |
---|---|---|
mailgun | Yes | mailing service |
mailjet | No | mailing service |
sendgrid | Yes | mailing service |
Imgur | Yes | uploading images service |
Imageshack | Yes | uploading images service |
bit.ly | Yes | shorten url service |
McAf.ee | Yes | shorten url service |
We strongly recommended using composer
Getting composer
curl -sS https://getcomposer.org/installer | php
Using this command
php composer.phar require lee/service-bundle
Mailgun: a sending mail service
require 'vendor/autoload.php';
$config = [
'service-name' => 'Mailgun',
//e.g. key-98dXXXXXXX
'api-key' => 'mailgun-api-key',
//e.g. sandbox5099cXXXXXXXXXXXXXXXXXXX
'domain-name' => 'mailgun-domain-name',
'from' => '[email protected]',
'to' => '[email protected]',
'subject' => 'Hello',
//contents supported only plain text now.
'contents' => 'Mailgun is awesome !'
];
$bundle = new \peter\components\serviceBundle\ServiceBundle($config);
//return json format (mailgun standard api response via cURL)
var_dump($bundle->sendReq());
SendGrid: a sending mail service
require 'vendor/autoload.php';
$config = [
'api-key' => 'sendgrid-api-key',
'from-name' => 'John Doe',
'from-email' => '[email protected]',
'to-name' => 'John Doe',
'to-email' => '[email protected]',
'subject' => 'SendGrid Test',
'contents' => 'Sendgrid is awesome!',
];
$service = (new peter\components\serviceBundle\Services\ServiceFactory)->create('SendGrid');
$service->setConfig($config);
//return json format (SendGrid standard api response via cURL)
var_dump($service->sendReq());
Mailjet: a sending mail service
require 'vendor/autoload.php';
$config = [
'api-key-public' => 'mailjet-public-api-key',
'api-key-private' => 'mailjet-privave-api-key',
'from-name' => 'John Doe',
'from-email' => '[email protected]',
'to-name' => 'John Doe',
'to-email' => '[email protected]',
'subject' => 'Mailjet Test',
'contents' => 'Mailjet is awesome!',
];
$service = (new peter\components\serviceBundle\Services\ServiceFactory)->create('Mailjet');
$service->setConfig($config);
//return json format (Mailjet standard api response via cURL)
var_dump($service->sendReq());
Imgur: an uploading images service
require 'vendor/autoload.php';
$config = [
'service-name' => 'Imgur',
'clientID' => 'imgur-client-id',
'filePath' => '/path/to/image.png'
];
$bundle = new \peter\components\serviceBundle\ServiceBundle($config);
//return json format (Imgur standard api response via cURL)
var_dump($bundle -> sendReq());
ImageShack: an uploading images service
require 'vendor/autoload.php';
$config = [
'service-name' => 'ImageShack',
'key' => 'your-Imageshack-api-key',
//specify the image max file size
'maxFileSize' => '5242880'
'filePath' => '/path/to/image.png'
];
$bundle = new \peter\components\serviceBundle\ServiceBundle($config);
//return json format (Imgur standard api response via cURL)
var_dump($bundle -> sendReq());
McAfee: a shorten url service
require 'vendor/autoload.php';
$config = [
'service-name' => 'McAfee',
'longUrl' => 'your-long-url'
];
$bundle = new \peter\components\serviceBundle\ServiceBundle($config);
//return json format (McAf standard api response via cURL)
var_dump($bundle->sendReq());
Bitly: a shorten url service
require 'vendor/autoload.php';
$config = [
'service-name' => 'Bitly',
'login' => 'your-login',
'apiKey' => 'your-api-key',
'longUrl' => 'your-long-url'
];
$bundle = new \peter\components\serviceBundle\ServiceBundle($config);
//return json format (bit.ly standard api response via cURL)
var_dump($bundle -> sendReq());
composer test
- version: v1.2.7
- Using the new version of Guzzle 5 and avoid the Httpoxy vulnerability.
- version: v1.2.8
- Fix the uploading image via imgur service bug.
- version: v1.2.9
- adding some information images
- version: v1.3.1
- supporting the Imageshack API
- version: v1.4.0
- Change the namespace and see the sample code to know this.
- Change the source code(code refactoring)
- Using the PHPUnit
Mock
to test the HTTP API requests. - The version 2.x is deprecated.
- Update the Guzzle version to 6.2
- Change the
service-name
value in$config
array.
Version | Status | Packagist | Namespace | PSR-7 |
---|---|---|---|---|
1.x | Maintained | lee/service-bundle |
peter\components\serviceBundle |
No |
2.x | **Deprecated | lee/service-bundle |
peter\components\ServiceBundle |
No |