lee/service-bundle

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

v1.4.1 2018-10-08 04:45 UTC

This package is auto-updated.

Last update: 2024-11-07 19:08:44 UTC


README

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

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' => 'peter279k@gmail.com',
    'to' => 'peter279k@gmail.com',
    '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' => 'john.doe@gmail.com',
    'to-name' => 'John Doe',
    'to-email' => 'john.doe@gmail.com',
    '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' => 'john.doe@gmail.com',
    'to-name' => 'John Doe',
    'to-email' => 'john.doe@gmail.com',
    '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

serviceBundle-1-repo

serviceBundle-2-repo(deprecated)