summaryrefslogtreecommitdiffstats
path: root/lib/MessageSystems
diff options
context:
space:
mode:
Diffstat (limited to 'lib/MessageSystems')
-rw-r--r--lib/MessageSystems/Configuration.php39
-rw-r--r--lib/MessageSystems/Transmission.php85
2 files changed, 124 insertions, 0 deletions
diff --git a/lib/MessageSystems/Configuration.php b/lib/MessageSystems/Configuration.php
new file mode 100644
index 0000000..9f7c4ea
--- /dev/null
+++ b/lib/MessageSystems/Configuration.php
@@ -0,0 +1,39 @@
+<?php
+namespace MessageSystems;
+
+class Configuration {
+
+ private static $config;
+ private static $defaults = [
+ 'host'=>'app.cloudplaceholder.com',
+ 'protocol'=>'https',
+ 'port'=>443,
+ 'strictSSL'=>true,
+ 'key'=>'',
+ 'version'=>'v1'
+ ];
+
+
+ private function __constructor(){
+ }
+
+ public static function setConfig($configMap) {
+ //check for API key because its required
+ if (!isset($configMap['key']) || empty(trim($configMap['key']))){
+ throw new \Exception('You must provide an API key');
+ }
+ self::$config = self::$defaults;
+ foreach ($configMap as $configOption => $configValue) {
+ self::$config[$configOption] = $configValue;
+ }
+ }
+
+ public static function getConfig() {
+ if (self::$config === null) {
+ throw new \Exception('No configuration has been provided');
+ }
+ return self::$config;
+ }
+}
+
+?> \ No newline at end of file
diff --git a/lib/MessageSystems/Transmission.php b/lib/MessageSystems/Transmission.php
new file mode 100644
index 0000000..3039270
--- /dev/null
+++ b/lib/MessageSystems/Transmission.php
@@ -0,0 +1,85 @@
+<?php
+namespace MessageSystems;
+use GuzzleHttp\Client;
+use GuzzleHttp\Exception\RequestException;
+
+class Transmission {
+ private $model;
+ private $config;
+ private $request;
+
+ /**
+ *
+ */
+ public function __construct() {
+ $this->config = Configuration::getConfig();
+ $this->request = new Client();
+ $this->model = [
+ 'campaign_id'=>null,
+ 'metadata'=>null,
+ 'substitution_data'=>null,
+ 'description'=>null,
+ 'return_path'=>null,
+ 'content' => [
+ 'reply_to'=>null,
+ 'subject'=>null,
+ 'from'=>null,
+ 'html'=>null,
+ 'text'=>null,
+ 'email_rfc822'=>null,
+ 'headers'=>null
+ ],
+ 'recipients'=>null
+ ];
+ }
+
+
+ private function getBaseUrl() {
+ return $this->config['protocol'] . '://' . $this->config['host'] . ($this->config['port'] ? ':' . $this->config['port'] : '') . $this->config['baseUrl'];
+ }
+
+ /**
+ *
+ * @param unknown $config
+ * @param string $transmissionID
+ * @param string $callback
+ * @return multitype:multitype:string
+ */
+ private function fetch ($transmissionID = null) {
+ //figure out the url
+ $url = $this->getBaseUrl();
+ if (!is_null($transmissionID)){
+ $url .= '/'.$transmissionID;
+ }
+
+ //make request
+ try {
+ $response = $this->request->get($url, [
+ "headers"=>['authorization' => $this->config['key']]
+ "verify"=>$this->config['strictSSL']
+ ]);
+
+ if($response->getStatusCode() === 404) {
+ throw new \Exception("The specified Transmission ID does not exist", 404);
+ } else if ($response->getStatusCode() !== 200) {
+ throw new \Exception("Received bad response from Transmission API: ". $response->getStatusCode());
+ } else {
+ $results = $response->json();
+ }
+
+ } catch (RequestException $exception) {
+ throw new \Exception('Unable to contact Transmissions API: '. $exception->getMessage());
+ }
+ return $results;
+ }
+
+ public function all() {
+ return $this->fetch();
+ }
+
+ public function find($transmissionID) {
+ $this->fetch($transmissionID);
+ }
+}
+
+?> \ No newline at end of file