Skip to content

Commit

Permalink
add possibility to use a user in other methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Metrakit committed Jun 22, 2016
1 parent cbaac46 commit 97737ff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
9 changes: 1 addition & 8 deletions src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,7 @@ public function send($message)
$parameters->senderForResponse = true;
}

$uri = "/sms/".$this->Sms->getAccount();

// Specify user if not null
if (!is_null($this->Sms->getUser())) {
$uri .= '/users/' . $this->Sms->getUser();
}

return $this->Sms->getConnection()->post("$uri/jobs", $parameters);
return $this->Sms->getConnection()->post($this->Sms->getUri() . "jobs", $parameters);
}

/**
Expand Down
21 changes: 17 additions & 4 deletions src/SmsApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,20 @@ public function checkUser($user)
}


/**
* Get the URI to use
* @return string
*/
public function getUri()
{
$uri = '/sms/' . $this->account . '/';
if (is_null($this->getUser())) {
return $uri;
}
return $uri . 'users/' . $this->getUser() . '/';
}


/**
* Get an instance of \Ovh\Sms\Message
* to create a new message to send
Expand Down Expand Up @@ -351,7 +365,7 @@ public function getIncomingMessages($startDateTime = null, $endDateTime = null,


// Get messages
$messages = $this->conn->get("/sms/".$this->account."/incoming", (object) $parameters);
$messages = $this->conn->get($this->getUri() . "incoming", (object) $parameters);

foreach ($messages as $id => $message) {
$messages[$id] = new Sms($this, "incoming", $message);
Expand Down Expand Up @@ -408,7 +422,7 @@ public function getOutgoingMessages($dateStart = null, $dateEnd = null, $sender
}

// Get messages
$messages = $this->conn->get("/sms/".$this->account."/outgoing", (object) $parameters);
$messages = $this->conn->get($this->getUri() . "outgoing", (object) $parameters);

foreach ($messages as $id => $message) {
$messages[$id] = new Sms($this, "outgoing", $message);
Expand All @@ -417,7 +431,6 @@ public function getOutgoingMessages($dateStart = null, $dateEnd = null, $sender
return $messages;
}


/**
* Get planned
*
Expand All @@ -432,7 +445,7 @@ public function getPlannedMessages()
}

// Get messages
$messages = $this->conn->get("/sms/".$this->account."/jobs");
$messages = $this->conn->get($this->getUri() . "jobs");

foreach ($messages as $id => $message) {
$messages[$id] = new Sms($this, "jobs", $message);
Expand Down

0 comments on commit 97737ff

Please sign in to comment.