Upload files to 'src'
This commit is contained in:
parent
a87e69d3b0
commit
01f23590e4
8
src/Error.php
Normal file
8
src/Error.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Postman;
|
||||
|
||||
class Error extends \Exception
|
||||
{
|
||||
//
|
||||
}
|
21
src/Message.php
Normal file
21
src/Message.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
namespace Postman;
|
||||
|
||||
class Message
|
||||
{
|
||||
public function __construct($client, $attributes)
|
||||
{
|
||||
$this->client = $client;
|
||||
$this->attributes = $attributes;
|
||||
}
|
||||
|
||||
public function id()
|
||||
{
|
||||
return $this->attributes->id;
|
||||
}
|
||||
|
||||
public function token()
|
||||
{
|
||||
return $this->attributes->token;
|
||||
}
|
||||
}
|
93
src/SendMessage.php
Normal file
93
src/SendMessage.php
Normal file
@ -0,0 +1,93 @@
|
||||
<?php
|
||||
namespace Postman;
|
||||
|
||||
class SendMessage
|
||||
{
|
||||
protected $client;
|
||||
|
||||
public $attributes = [];
|
||||
|
||||
public function __construct($client)
|
||||
{
|
||||
$this->client = $client;
|
||||
$this->attributes['to'] = [];
|
||||
$this->attributes['cc'] = [];
|
||||
$this->attributes['bcc'] = [];
|
||||
$this->attributes['headers'] = null;
|
||||
$this->attributes['attachments'] = [];
|
||||
}
|
||||
|
||||
public function to($address)
|
||||
{
|
||||
$this->attributes['to'][] = $address;
|
||||
}
|
||||
|
||||
public function cc($address)
|
||||
{
|
||||
$this->attributes['cc'][] = $address;
|
||||
}
|
||||
|
||||
public function bcc($address)
|
||||
{
|
||||
$this->attributes['bcc'][] = $address;
|
||||
}
|
||||
|
||||
public function from($address)
|
||||
{
|
||||
$this->attributes['from'] = $address;
|
||||
}
|
||||
|
||||
public function sender($address)
|
||||
{
|
||||
$this->attributes['sender'] = $address;
|
||||
}
|
||||
|
||||
public function subject($subject)
|
||||
{
|
||||
$this->attributes['subject'] = $subject;
|
||||
}
|
||||
|
||||
public function tag($tag)
|
||||
{
|
||||
$this->attributes['tag'] = $tag;
|
||||
}
|
||||
|
||||
public function replyTo($replyTo)
|
||||
{
|
||||
$this->attributes['reply_to'] = $replyTo;
|
||||
}
|
||||
|
||||
public function plainBody($content)
|
||||
{
|
||||
$this->attributes['plain_body'] = $content;
|
||||
}
|
||||
|
||||
public function htmlBody($content)
|
||||
{
|
||||
$this->attributes['html_body'] = $content;
|
||||
}
|
||||
|
||||
public function header($key, $value)
|
||||
{
|
||||
$this->attributes['headers'][$key] = $value;
|
||||
}
|
||||
|
||||
public function attach($filename, $content_type, $data)
|
||||
{
|
||||
$attachment = [
|
||||
'name' => $filename,
|
||||
'content_type' => $content_type,
|
||||
'data' => base64_encode($data),
|
||||
];
|
||||
|
||||
$this->attributes['attachments'][] = $attachment;
|
||||
}
|
||||
|
||||
|
||||
public function send()
|
||||
{
|
||||
$result = $this->client->makeRequest('send', 'message', $this->attributes);
|
||||
|
||||
return new SendResult($this->client, $result);
|
||||
}
|
||||
}
|
38
src/SendRawMessage.php
Normal file
38
src/SendRawMessage.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Postman;
|
||||
|
||||
class SendRawMessage
|
||||
{
|
||||
protected $client;
|
||||
|
||||
public $attributes = [];
|
||||
|
||||
public function __construct($client)
|
||||
{
|
||||
$this->client = $client;
|
||||
$this->attributes['rcpt_to'] = [];
|
||||
}
|
||||
|
||||
public function mailFrom($address)
|
||||
{
|
||||
$this->attributes['mail_from'] = $address;
|
||||
}
|
||||
|
||||
public function rcptTo($address)
|
||||
{
|
||||
$this->attributes['rcpt_to'][] = $address;
|
||||
}
|
||||
|
||||
public function data($data)
|
||||
{
|
||||
$this->attributes['data'] = base64_encode($data);
|
||||
}
|
||||
|
||||
public function send()
|
||||
{
|
||||
$result = $this->client->makeRequest('send', 'raw', $this->attributes);
|
||||
|
||||
return new SendResult($this->client, $result);
|
||||
}
|
||||
}
|
34
src/SendResult.php
Normal file
34
src/SendResult.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Postman;
|
||||
|
||||
class SendResult
|
||||
{
|
||||
protected $recipients;
|
||||
|
||||
public function __construct($client, $result)
|
||||
{
|
||||
$this->client = $client;
|
||||
$this->result = $result;
|
||||
}
|
||||
|
||||
public function recipients()
|
||||
{
|
||||
if ($this->recipients != null) {
|
||||
return $this->recipients;
|
||||
} else {
|
||||
$this->recipients = [];
|
||||
|
||||
foreach ($this->result->messages as $key => $value) {
|
||||
$this->recipients[strtolower($key)] = new Message($this->client, $value);
|
||||
}
|
||||
|
||||
return $this->recipients;
|
||||
}
|
||||
}
|
||||
|
||||
public function size()
|
||||
{
|
||||
return count($this->recipients());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user