From e25c7ae0104f54b5cbf5c143cac3b7693c08d78a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1ndor?= Date: Fri, 5 Apr 2019 18:59:23 +0000 Subject: [PATCH] client api --- ninjamail.class.php | 136 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 ninjamail.class.php diff --git a/ninjamail.class.php b/ninjamail.class.php new file mode 100644 index 0000000..b5473d9 --- /dev/null +++ b/ninjamail.class.php @@ -0,0 +1,136 @@ +host = $host; + if ($key) $this->key = $key; + } + + public function check() + { + if (!$this->host || !$this->key) + return false; + return true; + } + + public function process($f, $data, $post_method = true) + { + $ch = curl_init($this->host.'/a/'.$f.'/?key='.$this->key); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $post); + $data = curl_exec($ch); + curl_close($ch); + + $data = @(object)json_decode($response); + $this->data = $data; + return $data; + } + + public function login() + { + return $this->process('login', ['rkey' => md5(time().rand(0,65500).rand(0,10))]); + } + +} + +// Send Email +class ninjaMailSend extends ninjaMail +{ + + private $to; + private $subject; + private $message; + private $message_text; + + public function to($to) + { + $this->to = $to; + return true; + } + + public function subject($s) + { + $this->subject = $s; + return true; + } + + public function message($m, $t = false) + { + $this->message = $m; + if (!$t) $this->message_text = trim(strip_tags($m)); + else $this->message_text = $t; + return true; + } + + public function send() + { + $post = [ + 'to' => $this->to, + 'subject' => $this->subject, + 'message' => $this->message, + 'message_text' => $this->message_text + ]; + return $this->process('send', $post, true)->status == 'message_queued' ? true : false; + } +} + +// Subscribe +class ninjaMailSubscription extends ninjaMail +{ + + private $list; + private $activated = false; + + public function list($id) + { + if (is_numeric($id)) + { + $this->list = $id; + return true; + } + return false; + } + + public function activated($s) + { + if ($s) $this->activated = 1; + else $this->activated = 0; + return true; + } + + public function subscribe($email, $name = '') + { + if (!$this->list || !is_numeric($this->activated)) + return false; + + $post = [ + 'list' => $this->list, + 'name' => $name, + 'email' => $email, + 'activated' => $this->activated + ]; + return $this->process('subscribe', $post, true)->status == 'success' ? true : false; + } + + public function unsubscribe($email) + { + if (!$this->list) + return false; + + $post = [ + 'list' => $this->list, + 'email' => $email + ]; + return $this->process('unsubscribe', $post, true)->status == 'success' ? true : false; + } +} + + +