Exemplo n.º 1
0
 /**
  * Retrieve a SessionAuthentication instance
  *
  * @param string $accountRef
  * @param string $username
  * @param string $password
  * @return SessionAuthentication
  */
 function startSession($accountRef, $username, $password)
 {
     $login = new Authentication\LoginAuthentication($accountRef, $username, $password);
     $uri = Http\UriBuilder::serviceUri(self::SERVICE_VERSION, self::SERVICE, array("constructor"), $this->httpUtil->isSecure());
     $result = $this->httpUtil->post($uri, $login, '');
     $session = simplexml_load_string($result);
     return new Authentication\SessionAuthentication($accountRef, $session->id);
 }
 /**
  * @param array $options
  * @return Model\SentMessagesPage
  */
 public function loadMessages(array $options)
 {
     $uri = Http\UriBuilder::serviceUri(self::SENT_MESSAGES_SERVICE_VERSION, self::SENT_MESSAGES_SERVICE, null, $this->httpClient->isSecure());
     $options['accountreference'] = $this->authentication->accountReference();
     $uri .= "?" . Http\UriBuilder::buildQuery($options);
     $data = $this->httpClient->get($uri, $this->authentication);
     return $this->parser->parse($data);
 }
Exemplo n.º 3
0
 /**
  * @param $messageId
  * @return string
  * @throws Exceptions\ArgumentException
  */
 public function getMessageBodyById($messageId)
 {
     if ($messageId == null) {
         throw new Exceptions\ArgumentException("messageId is null");
     }
     if (!is_string($messageId)) {
         throw new Exceptions\ArgumentException("messageId is not a string");
     }
     $uri = Http\UriBuilder::serviceUri(self::SERVICE_VERSION, self::SERVICE, array($messageId, "body"), $this->httpClient->isSecure());
     return $this->loadMessageBody($uri);
 }
 /**
  * Get the number of remaining credits for your account
  *
  * @return int
  */
 public function getCredits()
 {
     try {
         $uri = Http\UriBuilder::serviceUri(self::ACCOUNTS_SERVICE_VERSION, self::ACCOUNTS_SERVICE, null, $this->httpClient->isSecure());
         $xml = $this->httpClient->get($uri, $this->authentication);
         $accounts = new \SimpleXMLElement($xml);
         foreach ($accounts->account as $account) {
             if (strcasecmp($account->reference, $this->authentication->accountReference()) == 0) {
                 return intval($account->messagesremaining, 10);
             }
         }
         return 0;
     } catch (\Exception $e) {
         return 0;
     }
 }
 /**
  * Check that any authentication is valid
  *
  * @param Authentication\IAuthentication $authentication
  * @return bool
  */
 public function checkAuthenticationAccess(Authentication\IAuthentication $authentication)
 {
     try {
         $uri = Http\UriBuilder::serviceUri(self::SERVICE_VERSION, self::SERVICE, null, $this->httpClient->isSecure());
         $xml = $this->httpClient->get($uri, $authentication);
         $accounts = new \SimpleXMLElement($xml);
         foreach ($accounts->account as $account) {
             if (strcasecmp($account->reference, $authentication->accountReference()) == 0) {
                 return true;
             }
         }
         return false;
     } catch (\Exception $e) {
         return false;
     }
 }
 /**
  * Get detailed information about a message from it's messageId.
  *
  * @param $messageId
  * @return Model\InboxMessage|Model\SentMessage
  */
 public function message($messageId)
 {
     $uri = Http\UriBuilder::serviceUri(self::SERVICE_VERSION, self::SERVICE, array($messageId), $this->httpClient->isSecure());
     $result = $this->httpClient->get($uri, $this->authentication);
     return $this->parser->parse($result);
 }
Exemplo n.º 7
0
 /**
  * @return Model\Account[]
  */
 public function getAccounts()
 {
     $uri = Http\UriBuilder::serviceUri(self::ACCOUNT_SERVICE_VERSION, self::ACCOUNT_SERVICE, null, $this->httpClient->isSecure());
     $data = $this->httpClient->get($uri, $this->authentication);
     return $this->parser->parse($data);
 }
Exemplo n.º 8
0
 /**
  * Delete an inbox message using it's messageId
  *
  * @param string $messageId
  * @return bool
  */
 function deleteInboxMessage($messageId)
 {
     $uri = Http\UriBuilder::serviceUri(self::INBOX_SERVICE_VERSION, self::INBOX_SERVICE, array("messages", $messageId), $this->httpClient->isSecure());
     return $this->httpClient->delete($uri, $this->authentication) == 200;
 }