Skip to content

Commit

Permalink
Merge pull request #3 from GiampaoloFalqui/psr-4-laravel-4.2
Browse files Browse the repository at this point in the history
PSR-0 => PSR-4, adds Laravel 4.2 implementation
  • Loading branch information
jlinn committed Oct 27, 2015
2 parents 424b2c8 + 3d117ad commit cf164ac
Show file tree
Hide file tree
Showing 30 changed files with 222 additions and 73 deletions.
44 changes: 40 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ php composer.phar require jlinn/mandrill-api-php:~1.0

Usage
=====

Sending a Message
-----------------

```php
use Mandrill\Mandrill;
use Mandrill\Struct\Message;
use Mandrill\Struct\Recipient;
use Jlinn\Mandrill\Mandrill;
use Jlinn\Mandrill\Struct\Message;
use Jlinn\Mandrill\Struct\Recipient;

// instantiate a client object
$mandrill = new Mandrill('your_api_key');
Expand All @@ -48,4 +49,39 @@ $message->addRecipient($recipient);

// send the message
$response = $mandrill->messages()->send($message);
```
```

Usage with Laravel 4.x
=====

We have built a factory so that it's easier to use with Laravel 4.x facades.

Configuration
-----------------

In order to publish the package configuration you need to perform the following command:

```
php artisan config:publish jlinn/mandrill-api-php
```

Change then the `secret` variable with your Mandrill secret key.

Sending a Message
-----------------

```php
$api = Mandrill::api();

$message = Mandrill::message([
'text' => 'Hello, *|NAME|*!',
'subject' => 'Test',
'from_email' => '[email protected]',
'from_name' => 'Mandrill API Test'
]);

$recipient = Mandrill::recipient('[email protected]', 'Recipient Name');
$recipient->addMergeVar('NAME', $recipient->name);
$message->addRecipient($recipient);

$response = $api->messages()->send($message);
14 changes: 12 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,18 @@
},
"autoload": {
"psr-0": {
"Mandrill": "src/",
"Mandrill\\Tests": "tests/"
"Jlinn\\": "src/Jlinn/"
},
"psr-4": {
"Jlinn\\": "src/Jlinn/"
}
},
"autoload-dev": {
"psr-0": {
"Jlinn\\": "tests/"
},
"psr-4": {
"Jlinn\\": "tests/"
}
}
}
4 changes: 2 additions & 2 deletions src/Mandrill/Api.php → src/Jlinn/Mandrill/Api.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
* Time: 4:46 PM
*/

namespace Mandrill;
namespace Jlinn\Mandrill;

use Guzzle\Http\Client;
use Guzzle\Http\Exception\ServerErrorResponseException;
use Mandrill\Exception\APIException;
use Jlinn\Mandrill\Exception\APIException;

abstract class Api{
const BASE_URL = 'https://mandrillapp.com/api/1.0/';
Expand Down
5 changes: 2 additions & 3 deletions src/Mandrill/Api/Exports.php → src/Jlinn/Mandrill/Api/Exports.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
* Time: 4:56 PM
*/

namespace Mandrill\Api;
namespace Jlinn\Mandrill\Api;


use Mandrill\Api;
use Jlinn\Mandrill\Api;

/**
* Class Exports
Expand Down
5 changes: 2 additions & 3 deletions src/Mandrill/Api/Inbound.php → src/Jlinn/Mandrill/Api/Inbound.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
* Time: 4:52 PM
*/

namespace Mandrill\Api;
namespace Jlinn\Mandrill\Api;


use Mandrill\Api;
use Jlinn\Mandrill\Api;

/**
* Class Inbound
Expand Down
5 changes: 2 additions & 3 deletions src/Mandrill/Api/Ips.php → src/Jlinn/Mandrill/Api/Ips.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
* Time: 5:04 PM
*/

namespace Mandrill\Api;
namespace Jlinn\Mandrill\Api;


use Mandrill\Api;
use Jlinn\Mandrill\Api;

/**
* Class Ips
Expand Down
6 changes: 3 additions & 3 deletions src/Mandrill/Api/Messages.php → src/Jlinn/Mandrill/Api/Messages.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
* Time: 11:55 AM
*/

namespace Mandrill\Api;
namespace Jlinn\Mandrill\Api;

use Guzzle\Http\Client;
use Mandrill\Api;
use Mandrill\Struct\Message;
use Jlinn\Mandrill\Api;
use Jlinn\Mandrill\Struct\Message;

/**
* Class Messages
Expand Down
5 changes: 2 additions & 3 deletions src/Mandrill/Api/Rejects.php → src/Jlinn/Mandrill/Api/Rejects.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
* Time: 3:37 PM
*/

namespace Mandrill\Api;
namespace Jlinn\Mandrill\Api;


use Mandrill\Api;
use Jlinn\Mandrill\Api;

/**
* Class Rejects
Expand Down
5 changes: 2 additions & 3 deletions src/Mandrill/Api/Senders.php → src/Jlinn/Mandrill/Api/Senders.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
* Time: 3:49 PM
*/

namespace Mandrill\Api;
namespace Jlinn\Mandrill\Api;


use Mandrill\Api;
use Jlinn\Mandrill\Api;

/**
* Class Senders
Expand Down
5 changes: 2 additions & 3 deletions src/Mandrill/Api/Subaccounts.php → src/Jlinn/Mandrill/Api/Subaccounts.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
* Time: 4:41 PM
*/

namespace Mandrill\Api;
namespace Jlinn\Mandrill\Api;


use Mandrill\Api;
use Jlinn\Mandrill\Api;

/**
* Class Subaccounts
Expand Down
5 changes: 2 additions & 3 deletions src/Mandrill/Api/Tags.php → src/Jlinn/Mandrill/Api/Tags.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
* Time: 3:25 PM
*/

namespace Mandrill\Api;
namespace Jlinn\Mandrill\Api;


use Mandrill\Api;
use Jlinn\Mandrill\Api;

/**
* Class Tags
Expand Down
5 changes: 2 additions & 3 deletions src/Mandrill/Api/Templates.php → src/Jlinn/Mandrill/Api/Templates.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
* Time: 4:07 PM
*/

namespace Mandrill\Api;
namespace Jlinn\Mandrill\Api;


use Mandrill\Api;
use Jlinn\Mandrill\Api;

/**
* Class Templates
Expand Down
5 changes: 2 additions & 3 deletions src/Mandrill/Api/Urls.php → src/Jlinn/Mandrill/Api/Urls.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
* Time: 3:56 PM
*/

namespace Mandrill\Api;
namespace Jlinn\Mandrill\Api;


use Mandrill\Api;
use Jlinn\Mandrill\Api;

/**
* Class Urls
Expand Down
5 changes: 2 additions & 3 deletions src/Mandrill/Api/Users.php → src/Jlinn/Mandrill/Api/Users.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
* Time: 5:05 PM
*/

namespace Mandrill\Api;

namespace Jlinn\Mandrill\Api;

use Guzzle\Http\Client;
use Mandrill\Api;
use Jlinn\Mandrill\Api;

/**
* Class Users
Expand Down
5 changes: 2 additions & 3 deletions src/Mandrill/Api/Webhooks.php → src/Jlinn/Mandrill/Api/Webhooks.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
* Time: 4:31 PM
*/

namespace Mandrill\Api;
namespace Jlinn\Mandrill\Api;


use Mandrill\Api;
use Jlinn\Mandrill\Api;

/**
* Class Webhooks
Expand Down
5 changes: 2 additions & 3 deletions src/Mandrill/Api/Whitelists.php → src/Jlinn/Mandrill/Api/Whitelists.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
* Time: 3:43 PM
*/

namespace Mandrill\Api;
namespace Jlinn\Mandrill\Api;


use Mandrill\Api;
use Jlinn\Mandrill\Api;

/**
* Class Whitelists
Expand Down
5 changes: 2 additions & 3 deletions src/Mandrill/Exception.php → src/Jlinn/Mandrill/Exception.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
* Time: 12:23 PM
*/

namespace Mandrill;
namespace Jlinn\Mandrill;


class Exception extends \Exception{
class Exception extends \Exception {

}
5 changes: 2 additions & 3 deletions src/Mandrill/Exception/APIException.php → ...Jlinn/Mandrill/Exception/APIException.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
* Time: 12:24 PM
*/

namespace Mandrill\Exception;
namespace Jlinn\Mandrill\Exception;


use Mandrill\Exception;
use Jlinn\Mandrill\Exception;

class APIException extends Exception{
/**
Expand Down
10 changes: 10 additions & 0 deletions src/Jlinn/Mandrill/Facades/Mandrill.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Jlinn\Mandrill\Facades;

use Illuminate\Support\Facades\Facade;

class Mandrill extends Facade
{
protected static function getFacadeAccessor() { return 'mandrill'; }
}
4 changes: 2 additions & 2 deletions src/Mandrill/Mandrill.php → src/Jlinn/Mandrill/Mandrill.php
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

/**
* User: Joe Linn
* Date: 9/13/13
* Time: 10:07 AM
*/

namespace Mandrill;

namespace Jlinn\Mandrill;

class Mandrill{
/**
Expand Down
57 changes: 57 additions & 0 deletions src/Jlinn/Mandrill/MandrillFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace Jlinn\Mandrill;

use Jlinn\Mandrill\Mandrill;

use Jlinn\Mandrill\Struct\Message;
use Jlinn\Mandrill\Struct\Recipient;
use Jlinn\Mandrill\Struct\Attachment;

class MandrillFactory
{
private $apiKey;

public function __construct($apiKey)
{
$this->apiKey = $apiKey;
}

public function api()
{
return new Mandrill($this->apiKey);
}

public function message(Array $args = [])
{
if (empty($args)) {
return new Message;
}

$message = new Message;
foreach ($args as $key => $value) {
$message->$key = $value;
}

return $message;
}

public function attachment(Array $args = [])
{
if (empty($args)) {
return new Attachment;
}

$attachment = new Attachment;
foreach ($args as $key => $value) {
$attachment->$key = $value;
}

return $attachment;
}

public function recipient($email = NULL, $name = NULL, $type = NULL)
{
return new Recipient($email, $name, $type);
}
}
Loading

0 comments on commit cf164ac

Please sign in to comment.