From 1de141702724373f2f36e21ceec500526bfd125c Mon Sep 17 00:00:00 2001 From: Martin van de Belt Date: Wed, 25 Mar 2015 21:52:34 +0100 Subject: [PATCH] Cleanup of code --- src/Vdbelt/InmobileSmsApi/Connector.php | 150 ++++++++++++------------ src/Vdbelt/InmobileSmsApi/Message.php | 66 +++++------ 2 files changed, 108 insertions(+), 108 deletions(-) diff --git a/src/Vdbelt/InmobileSmsApi/Connector.php b/src/Vdbelt/InmobileSmsApi/Connector.php index 3dc8acb..3bc64f0 100644 --- a/src/Vdbelt/InmobileSmsApi/Connector.php +++ b/src/Vdbelt/InmobileSmsApi/Connector.php @@ -32,12 +32,12 @@ class Connector * @param null $endpoint */ public function __construct($api_key, $endpoint = null) - { - $this->api_key = $api_key; + { + $this->api_key = $api_key; - if(!is_null($endpoint)) - $this->setEndpoint($endpoint); - } + if(!is_null($endpoint)) + $this->setEndpoint($endpoint); + } /** * Get the current endpoint @@ -45,27 +45,27 @@ public function __construct($api_key, $endpoint = null) * @return string */ public function getEndpoint() - { - return $this->endpoint; - } + { + return $this->endpoint; + } /** * Get the current API key * @return string */ public function getApiKey() - { - return $this->api_key; - } + { + return $this->api_key; + } /** * Get an array with the current message objects * @return array */ public function getMessages() - { - return $this->messages; - } + { + return $this->messages; + } /** * Set the endpoint @@ -73,11 +73,11 @@ public function getMessages() * @return $this */ public function setEndpoint($endpoint) - { - $this->endpoint = $endpoint; + { + $this->endpoint = $endpoint; - return $this; - } + return $this; + } /** * Set the API key @@ -85,11 +85,11 @@ public function setEndpoint($endpoint) * @return $this */ public function setApiKey($api_key) - { - $this->api_key = $api_key; + { + $this->api_key = $api_key; - return $this; - } + return $this; + } /** * Add a message to the payload @@ -97,11 +97,11 @@ public function setApiKey($api_key) * @return $this */ public function addMessage(Message $Message) - { - $this->messages[] = $Message; + { + $this->messages[] = $Message; - return $this; - } + return $this; + } /** * Send the actual payload to the endpoint @@ -109,20 +109,20 @@ public function addMessage(Message $Message) * @throws \Exception */ public function send() - { - if(count($this->messages) < 1) - throw new \Exception('No messages to send'); + { + if(count($this->messages) < 1) + throw new \Exception('No messages to send'); - $builder = new XML_Payload_Builder($this); - $client = $this->getHttpClient(); + $builder = new XML_Payload_Builder($this); + $client = $this->getHttpClient(); - $client->post($this->endpoint.'/Api/V2/SendMessages', [ - 'body' => [ - 'xml' => $builder->getXML() - ]]); + $client->post($this->endpoint.'/Api/V2/SendMessages', [ + 'body' => [ + 'xml' => $builder->getXML() + ]]); - return true; - } + return true; + } /** * Get the http client using @@ -159,70 +159,70 @@ class XML_Payload_Builder * @param Connector $Connector */ public function __construct(Connector $Connector) - { - $this->connector = $Connector; - $this->dom = new \DomDocument('1.0', 'UTF-8'); + { + $this->connector = $Connector; + $this->dom = new \DomDocument('1.0', 'UTF-8'); - $request = $this->dom->createElement('request'); + $request = $this->dom->createElement('request'); - $request->appendChild($this->buildAuthenticationHeader()); - $request->appendChild($this->buildMessages()); + $request->appendChild($this->buildAuthenticationHeader()); + $request->appendChild($this->buildMessages()); - $this->dom->appendChild($request); - } + $this->dom->appendChild($request); + } /** * Returns the XML payload * @return mixed */ public function getXML() - { - return $this->dom->saveXML(); - } + { + return $this->dom->saveXML(); + } /** * Builds the authentication header to add * @return mixed */ protected function buildAuthenticationHeader() - { - $authentication = $this->dom->createElement('authentication'); - $authentication->setAttribute('apikey', $this->connector->getApiKey()); - - return $authentication; - } + { + $authentication = $this->dom->createElement('authentication'); + $authentication->setAttribute('apikey', $this->connector->getApiKey()); + + return $authentication; + } /** * Transforms Message objects into XML * @return mixed */ protected function buildMessages() - { - $data = $this->dom->createElement('data'); + { + $data = $this->dom->createElement('data'); - foreach($this->connector->getMessages() as $Message) - { - $element = $this->dom->createElement('message'); - $sendername = $this->dom->createElement('sendername', $Message->getSenderName()); - $text = $this->dom->createElement('text'); - $recipients = $this->dom->createElement('recipients'); + foreach($this->connector->getMessages() as $Message) + { + $element = $this->dom->createElement('message'); + $sendername = $this->dom->createElement('sendername', $Message->getSenderName()); + $text = $this->dom->createElement('text'); + $recipients = $this->dom->createElement('recipients'); - foreach($Message->getRecipients() as $Recipient) - { - $msisdn = $this->dom->createElement('msisdn', $Recipient); - $recipients->appendChild($msisdn); - } + foreach($Message->getRecipients() as $Recipient) + { + $msisdn = $this->dom->createElement('msisdn', $Recipient); + $recipients->appendChild($msisdn); + } - $text->appendChild($this->dom->createCDATASection($Message->getContent())); + $text->appendChild($this->dom->createCDATASection($Message->getContent())); - $element->appendChild($sendername); - $element->appendChild($text); - $element->appendChild($recipients); + $element->appendChild($sendername); + $element->appendChild($text); + $element->appendChild($recipients); - $data->appendChild($element); - } + $data->appendChild($element); + } - return $data; - } + return $data; + } } \ No newline at end of file diff --git a/src/Vdbelt/InmobileSmsApi/Message.php b/src/Vdbelt/InmobileSmsApi/Message.php index 6517044..d600ad0 100644 --- a/src/Vdbelt/InmobileSmsApi/Message.php +++ b/src/Vdbelt/InmobileSmsApi/Message.php @@ -31,38 +31,38 @@ class Message * @param $sendername */ public function __construct($content, array $recipients, $sendername) - { - $this->setContent($content); - $this->setRecipients($recipients); - $this->setSenderName($sendername); - } + { + $this->setContent($content); + $this->setRecipients($recipients); + $this->setSenderName($sendername); + } /** * Get array with msisdns of recipients * @return array */ public function getRecipients() - { - return $this->recipients; - } + { + return $this->recipients; + } /** * Get string containing the sendername * @return string */ public function getSenderName() - { - return $this->sendername; - } + { + return $this->sendername; + } /** * Get string containing the content * @return string */ public function getContent() - { - return $this->content; - } + { + return $this->content; + } /** * Set array with msisdns of the recipients @@ -70,12 +70,12 @@ public function getContent() * @return $this */ public function setRecipients(array $recipients) - { - foreach($recipients as $recipient) - $this->addRecipient($recipient); + { + foreach($recipients as $recipient) + $this->addRecipient($recipient); - return $this; - } + return $this; + } /** * Add a recipient to the array with msisdn @@ -83,11 +83,11 @@ public function setRecipients(array $recipients) * @return $this */ public function addRecipient($recipient) - { - $this->recipients[] = $recipient; + { + $this->recipients[] = $recipient; - return $this; - } + return $this; + } /** * Set the sendername and throw an exception if invalid @@ -96,14 +96,14 @@ public function addRecipient($recipient) * @throws \Exception */ public function setSenderName($sendername) - { - if(strlen($sendername) > 16 OR strlen($sendername) < 4) - throw new \Exception('Invalid sendername'); + { + if(strlen($sendername) > 16 OR strlen($sendername) < 4) + throw new \Exception('Invalid sendername'); - $this->sendername = $sendername; + $this->sendername = $sendername; - return $this; - } + return $this; + } /** * Set the content of the message @@ -111,10 +111,10 @@ public function setSenderName($sendername) * @return $this */ public function setContent($content) - { - $this->content = $content; + { + $this->content = $content; - return $this; - } + return $this; + } } \ No newline at end of file