Skip to content

peter279k/serviceBundle

Repository files navigation

serviceBundle

Build Status Latest Stable Version Total Downloads Latest Unstable Version License codecov Gitter

SensioLabsInsight

Integrating with mailing service, uploading image service and so on.

It's based on Guzzle,HTTP client.

Following service table is about supporting status

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

Usage

Install Package

We strongly recommended using composer

Getting composer

curl -sS https://getcomposer.org/installer | php

Using this command

php composer.phar require lee/service-bundle

Sample code

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());

Run TestCase

composer test

Changelog

2016/07/20

  • version: v1.2.7
  • Using the new version of Guzzle 5 and avoid the Httpoxy vulnerability.

2016/07/21

  • version: v1.2.8
  • Fix the uploading image via imgur service bug.

2016/07/21

  • version: v1.2.9
  • adding some information images

2016/07/21

  • version: v1.3.1
  • supporting the Imageshack API

2017/11/11

  • 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 Guidance

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

serviceBundle-1-repo

serviceBundle-2-repo(deprecated)