mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2024-11-29 00:25:37 +03:00
parent
09113482ea
commit
c0a386027b
@ -105,7 +105,7 @@ class ShowResponse implements ApiResponse
|
|||||||
/**
|
/**
|
||||||
* @param array $data
|
* @param array $data
|
||||||
*
|
*
|
||||||
* @return SendResponse
|
* @return ShowResponse
|
||||||
*/
|
*/
|
||||||
public static function create(array $data)
|
public static function create(array $data)
|
||||||
{
|
{
|
||||||
|
@ -37,7 +37,7 @@ class Tag
|
|||||||
* @param \DateTime $firstSeen
|
* @param \DateTime $firstSeen
|
||||||
* @param \DateTime $lastSeen
|
* @param \DateTime $lastSeen
|
||||||
*/
|
*/
|
||||||
public function __construct($tag, $description, \DateTime $firstSeen, \DateTime $lastSeen)
|
public function __construct($tag, $description, \DateTime $firstSeen = null, \DateTime $lastSeen = null)
|
||||||
{
|
{
|
||||||
$this->tag = $tag;
|
$this->tag = $tag;
|
||||||
$this->description = $description;
|
$this->description = $description;
|
||||||
@ -52,7 +52,10 @@ class Tag
|
|||||||
*/
|
*/
|
||||||
public static function create(array $data)
|
public static function create(array $data)
|
||||||
{
|
{
|
||||||
return new self($data['tag'], $data['description'], new \DateTime($data['first-seen']), new \DateTime($data['last-seen']));
|
$firstSeen = isset($data['first-seen']) ? new \DateTime($data['first-seen']) : null;
|
||||||
|
$lastSeen = isset($data['last-seen']) ? new \DateTime($data['last-seen']) : null;
|
||||||
|
|
||||||
|
return new self($data['tag'], $data['description'], $firstSeen, $lastSeen);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
71
tests/Model/Event/EventResponseTest.php
Normal file
71
tests/Model/Event/EventResponseTest.php
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Mailgun\Tests\Model\Event;
|
||||||
|
|
||||||
|
use Mailgun\Model\Event\EventResponse;
|
||||||
|
use Mailgun\Tests\Model\BaseModelTest;
|
||||||
|
|
||||||
|
class EventResponseTest extends BaseModelTest
|
||||||
|
{
|
||||||
|
public function testCreate()
|
||||||
|
{
|
||||||
|
$json =
|
||||||
|
<<<'JSON'
|
||||||
|
{
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"tags": [],
|
||||||
|
"id": "czsjqFATSlC3QtAK-C80nw",
|
||||||
|
"timestamp": 1376325780.160809,
|
||||||
|
"envelope": {
|
||||||
|
"sender": "me@samples.mailgun.org",
|
||||||
|
"transport": ""
|
||||||
|
},
|
||||||
|
"event": "accepted",
|
||||||
|
"campaigns": [],
|
||||||
|
"user-variables": {},
|
||||||
|
"flags": {
|
||||||
|
"is-authenticated": true,
|
||||||
|
"is-test-mode": false
|
||||||
|
},
|
||||||
|
"message": {
|
||||||
|
"headers": {
|
||||||
|
"to": "foo@example.com",
|
||||||
|
"message-id": "20130812164300.28108.52546@samples.mailgun.org",
|
||||||
|
"from": "Excited User <me@samples.mailgun.org>",
|
||||||
|
"subject": "Hello"
|
||||||
|
},
|
||||||
|
"attachments": [],
|
||||||
|
"recipients": [
|
||||||
|
"foo@example.com",
|
||||||
|
"baz@example.com",
|
||||||
|
"bar@example.com"
|
||||||
|
],
|
||||||
|
"size": 69
|
||||||
|
},
|
||||||
|
"recipient": "baz@example.com",
|
||||||
|
"method": "http"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"paging": {
|
||||||
|
"next":
|
||||||
|
"https://api.mailgun.net/v3/samples.mailgun.org/events/W3siY",
|
||||||
|
"previous":
|
||||||
|
"https://api.mailgun.net/v3/samples.mailgun.org/events/Lkawm"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
JSON;
|
||||||
|
$model = EventResponse::create(json_decode($json, true));
|
||||||
|
$events = $model->getItems();
|
||||||
|
$this->assertCount(1, $events);
|
||||||
|
$event = $events[0];
|
||||||
|
$this->assertEquals('czsjqFATSlC3QtAK-C80nw', $event->getId());
|
||||||
|
}
|
||||||
|
}
|
30
tests/Model/Message/SendResponseTest.php
Normal file
30
tests/Model/Message/SendResponseTest.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Mailgun\Tests\Model\Message;
|
||||||
|
|
||||||
|
use Mailgun\Model\Message\SendResponse;
|
||||||
|
use Mailgun\Tests\Model\BaseModelTest;
|
||||||
|
|
||||||
|
class SendResponseTest extends BaseModelTest
|
||||||
|
{
|
||||||
|
public function testCreate()
|
||||||
|
{
|
||||||
|
$json =
|
||||||
|
<<<'JSON'
|
||||||
|
{
|
||||||
|
"message": "Queued. Thank you.",
|
||||||
|
"id": "<20111114174239.25659.5817@samples.mailgun.org>"
|
||||||
|
}
|
||||||
|
JSON;
|
||||||
|
$model = SendResponse::create(json_decode($json, true));
|
||||||
|
$this->assertEquals('<20111114174239.25659.5817@samples.mailgun.org>', $model->getId());
|
||||||
|
$this->assertEquals('Queued. Thank you.', $model->getMessage());
|
||||||
|
}
|
||||||
|
}
|
42
tests/Model/Route/CreateResponseTest.php
Normal file
42
tests/Model/Route/CreateResponseTest.php
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Mailgun\Tests\Model\Route;
|
||||||
|
|
||||||
|
use Mailgun\Model\Route\Response\CreateResponse;
|
||||||
|
use Mailgun\Tests\Model\BaseModelTest;
|
||||||
|
|
||||||
|
class CreateResponseTest extends BaseModelTest
|
||||||
|
{
|
||||||
|
public function testCreate()
|
||||||
|
{
|
||||||
|
$json =
|
||||||
|
<<<'JSON'
|
||||||
|
{
|
||||||
|
"message": "Route has been created",
|
||||||
|
"route": {
|
||||||
|
"description": "Sample route",
|
||||||
|
"created_at": "Wed, 15 Feb 2012 13:03:31 GMT",
|
||||||
|
"actions": [
|
||||||
|
"forward(\"http://myhost.com/messages/\")",
|
||||||
|
"stop()"
|
||||||
|
],
|
||||||
|
"priority": 0,
|
||||||
|
"expression": "match_recipient(\".*@samples.mailgun.org\")",
|
||||||
|
"id": "4f3bad2335335426750048c6"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
JSON;
|
||||||
|
$model = CreateResponse::create(json_decode($json, true));
|
||||||
|
|
||||||
|
$this->assertEquals('Route has been created', $model->getMessage());
|
||||||
|
$route = $model->getRoute();
|
||||||
|
$this->assertEquals('Sample route', $route->getDescription());
|
||||||
|
}
|
||||||
|
}
|
46
tests/Model/Route/IndexResponseTest.php
Normal file
46
tests/Model/Route/IndexResponseTest.php
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Mailgun\Tests\Model\Route;
|
||||||
|
|
||||||
|
use Mailgun\Model\Route\Response\IndexResponse;
|
||||||
|
use Mailgun\Tests\Model\BaseModelTest;
|
||||||
|
|
||||||
|
class IndexResponseTest extends BaseModelTest
|
||||||
|
{
|
||||||
|
public function testCreate()
|
||||||
|
{
|
||||||
|
$json =
|
||||||
|
<<<'JSON'
|
||||||
|
{
|
||||||
|
"total_count": 266,
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"description": "Sample route",
|
||||||
|
"created_at": "Wed, 15 Feb 2012 12:58:12 GMT",
|
||||||
|
"actions": [
|
||||||
|
"forward(\"http://myhost.com/messages/\")",
|
||||||
|
"stop()"
|
||||||
|
],
|
||||||
|
"priority": 0,
|
||||||
|
"expression": "match_recipient(\".*@samples.mailgun.org\")",
|
||||||
|
"id": "4f3babe4ba8a481c6400476a"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
JSON;
|
||||||
|
$model = IndexResponse::create(json_decode($json, true));
|
||||||
|
|
||||||
|
$this->assertEquals('266', $model->getTotalCount());
|
||||||
|
$routes = $model->getRoutes();
|
||||||
|
$this->assertCount(1, $routes);
|
||||||
|
$route = $routes[0];
|
||||||
|
$this->assertEquals('Sample route', $route->getDescription());
|
||||||
|
}
|
||||||
|
}
|
38
tests/Model/Route/ShowResponseTest.php
Normal file
38
tests/Model/Route/ShowResponseTest.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Mailgun\Tests\Model\Route;
|
||||||
|
|
||||||
|
use Mailgun\Model\Route\Response\ShowResponse;
|
||||||
|
use Mailgun\Tests\Model\BaseModelTest;
|
||||||
|
|
||||||
|
class ShowResponseTest extends BaseModelTest
|
||||||
|
{
|
||||||
|
public function testCreate()
|
||||||
|
{
|
||||||
|
$json =
|
||||||
|
<<<'JSON'
|
||||||
|
{
|
||||||
|
"route": {
|
||||||
|
"description": "Sample route",
|
||||||
|
"created_at": "Wed, 15 Feb 2012 13:03:31 GMT",
|
||||||
|
"actions": [
|
||||||
|
"forward(\"http://myhost.com/messages/\")",
|
||||||
|
"stop()"
|
||||||
|
],
|
||||||
|
"priority": 0,
|
||||||
|
"expression": "match_recipient(\".*@samples.mailgun.org\")",
|
||||||
|
"id": "4f3bad2335335426750048c6"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
JSON;
|
||||||
|
$model = ShowResponse::create(json_decode($json, true));
|
||||||
|
$this->assertEquals('Sample route', $model->getRoute()->getDescription());
|
||||||
|
}
|
||||||
|
}
|
51
tests/Model/Tag/IndexResponseTest.php
Normal file
51
tests/Model/Tag/IndexResponseTest.php
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Mailgun\Tests\Model\Tag;
|
||||||
|
|
||||||
|
use Mailgun\Model\Tag\IndexResponse;
|
||||||
|
use Mailgun\Tests\Model\BaseModelTest;
|
||||||
|
|
||||||
|
class IndexResponseTest extends BaseModelTest
|
||||||
|
{
|
||||||
|
public function testCreate()
|
||||||
|
{
|
||||||
|
$json =
|
||||||
|
<<<'JSON'
|
||||||
|
{
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"tag": "red",
|
||||||
|
"description": "red signup button"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tag": "green",
|
||||||
|
"description": "green signup button"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"paging": {
|
||||||
|
"next":
|
||||||
|
"https://url_to_next_page",
|
||||||
|
"previous":
|
||||||
|
"https://url_to_previous_page",
|
||||||
|
"first":
|
||||||
|
"https://url_to_first_page",
|
||||||
|
"last":
|
||||||
|
"https://url_to_last_page"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
JSON;
|
||||||
|
$model = IndexResponse::create(json_decode($json, true));
|
||||||
|
|
||||||
|
$tags = $model->getItems();
|
||||||
|
$this->assertCount(2, $tags);
|
||||||
|
$tag = $tags[0];
|
||||||
|
$this->assertEquals('red', $tag->getTag());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user