From 935ab9e4e11dbbc4caa520bd491dbfdde65624b9 Mon Sep 17 00:00:00 2001 From: David Schneider Date: Thu, 12 Nov 2015 21:46:09 +0100 Subject: [PATCH] Initial commit --- composer.json | 21 +++++++++++++++++++ src/Mailtrapper.php | 49 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 composer.json create mode 100644 src/Mailtrapper.php diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..2299586 --- /dev/null +++ b/composer.json @@ -0,0 +1,21 @@ +{ + "name": "crazyinventor/mailtrapper", + "description": "A mailtrap.io wrapper class", + "license": "MIT", + "authors": [ + { + "name": "David Schneider", + "email": "david@crazyinventor.net", + "homepage": "http://www.crazyinventor.net", + "role": "Developer" + } + ], + "require": { + "php": ">=5.4.0" + }, + "autoload": { + "psr-4": { + "CrazyInventor\\": "src/" + } + } +} diff --git a/src/Mailtrapper.php b/src/Mailtrapper.php new file mode 100644 index 0000000..d0e6d45 --- /dev/null +++ b/src/Mailtrapper.php @@ -0,0 +1,49 @@ +token=$api_token; + if($format && in_array($format, ['json', 'xml'])) { + $this->format = '.' . $format; + } + } + + public function getInboxes() + { + $url = $this->buildUrl('inboxes'); + return $this->process($url); + } + + public function getMails($inbox_id) + { + $path = 'inboxes/'.$inbox_id.'/messages'; + $url = $this->buildUrl($path); + return $this->process($url); + } + + protected function buildUrl($path) + { + return $this->url + . $path + . $this->format + . '?api_token=' + . $this->token; + } + + protected function process($url) + { + return json_decode( + file_get_contents($url), + true + ); + } + +}