Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
d3rd4v1d committed Nov 12, 2015
0 parents commit 935ab9e
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
21 changes: 21 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "crazyinventor/mailtrapper",
"description": "A mailtrap.io wrapper class",
"license": "MIT",
"authors": [
{
"name": "David Schneider",
"email": "[email protected]",
"homepage": "http://www.crazyinventor.net",
"role": "Developer"
}
],
"require": {
"php": ">=5.4.0"
},
"autoload": {
"psr-4": {
"CrazyInventor\\": "src/"
}
}
}
49 changes: 49 additions & 0 deletions src/Mailtrapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace CrazyInventor;

class Mailtrapper {

protected $token;
protected $url = 'https://mailtrap.io/api/v1/';
protected $format = '';

public function __construct($api_token, $format = false)
{
$this->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
);
}

}

0 comments on commit 935ab9e

Please sign in to comment.