Skip to content

Commit

Permalink
Merged develop into master and fixed merge conflicts.
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenwadejr committed Jun 26, 2015
2 parents 2a2e4a9 + 49a7fec commit 0e18ec0
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#### 1.1 (June 25, 2015)

- Added support for Mailbox information now being passed to the Dynamic App.

#### 1.0 (May 29, 2014)

* Initial release
66 changes: 38 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Dynamic Apps Client Library

Client library to assist with building custom apps that integrate with [Help Scout](https://www.helpscout.net/). More inforomation: [http://developer.helpscout.net/custom-apps/](http://developer.helpscout.net/custom-apps/)

Version 1.0 Released
Version 1.1 Released
---------------------
Please see the [Changelog](https://github.com/helpscout/helpscout-apps-php/blob/master/CHANGELOG.md) for details.

Expand All @@ -18,13 +18,15 @@ Inside of composer.json specify the following:
````
{
"require": {
"helpscout/apps": "1.0.1"
"helpscout/apps": "1.1.*"
}
}
````
## Example Usage 1

<pre><code>
Example Usage (1)
---------------------

```
use HelpScoutApp\DynamicApp;
include 'src/HelpScoutApp/DynamicApp.php';
Expand All @@ -34,43 +36,51 @@ if ($app->isSignatureValid()) {
$customer = $app->getCustomer();
$user = $app->getUser();
$convo = $app->getConversation();
$mailbox = $app->getMailbox();
$html = array(
'&lt;p&gt;Convo&lt;/p&gt;',
'&lt;ul&gt;',
'&lt;li&gt;Id: ' . $convo->getId() . '&lt;/li&gt;',
'&lt;li&gt;Number: ' . $convo->getNumber() . '&lt;/li&gt;',
'&lt;li&gt;Subject: ' . $convo->getSubject() . '&lt;/li&gt;',
'&lt;/ul&gt;',
'&lt;p&gt;Customer&lt;/p&gt;',
'&lt;ul&gt;',
'&lt;li&gt;First: ' . $customer->getFirstName() . '&lt;/li&gt;',
'&lt;li&gt;Last: ' . $customer->getLastName() . '&lt;/li&gt;',
'&lt;li&gt;Email: ' . $customer->getEmail() . '&lt;/li&gt;',
'&lt;/ul&gt;',
'&lt;p&gt;User&lt;/p&gt;',
'&lt;ul&gt;',
'&lt;li&gt;First: ' . $user->getFirstName() . '&lt;/li&gt;',
'&lt;li&gt;Last: ' . $user->getLastName() . '&lt;/li&gt;',
'&lt;li&gt;Id: ' . $user->getId() . '&lt;/li&gt;',
'&lt;/ul&gt;'
'<p>Convo</p>',
'<ul>',
'<li>Id: ' . $convo->getId() . '</li>',
'<li>Number: ' . $convo->getNumber() . '</li>',
'<li>Subject: ' . $convo->getSubject() . '</li>',
'</ul>',
'<p>Customer</p>',
'<ul>',
'<li>First: ' . $customer->getFirstName() . '</li>',
'<li>Last: ' . $customer->getLastName() . '</li>',
'<li>Email: ' . $customer->getEmail() . '</li>',
'</ul>',
'<p>User</p>',
'<ul>',
'<li>First: ' . $user->getFirstName() . '</li>',
'<li>Last: ' . $user->getLastName() . '</li>',
'<li>Id: ' . $user->getId() . '</li>',
'</ul>',
'<p>Mailbox</p>',
'<ul>',
'<li>ID: ' . $mailbox->getId() . '</li>',
'<li>Email: ' . $mailbox->getEmail() . '</li>',
'</ul>'
);
echo $app->getResponse($html);
} else {
echo 'Invalid Request';
}
</code></pre>
```

## Example Usage 2
<pre><code>
Example Usage (2)
---------------------

```
use HelpScoutApp\DynamicApp;
include 'src/HelpScoutApp/DynamicApp.php';
$app = new DynamicApp('SECRET-KEY-HERE');
if ($app->isSignatureValid()) {
echo $app->getResponse('&lt;p&gt;Hello World&lt;/p&gt;');
echo $app->getResponse('<p>Hello World</p>');
} else {
echo 'Invalid Request';
echo 'Invalid Request';
}
</code></pre>
```
17 changes: 16 additions & 1 deletion src/HelpScoutApp/DynamicApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use HelpScoutApp\model\Customer;
use HelpScoutApp\model\Conversation;
use HelpScoutApp\model\User;
use HelpScoutApp\model\Mailbox;

require_once 'ClassLoader.php';

Expand All @@ -22,6 +23,9 @@ class DynamicApp {
/** @var \HelpScoutApp\model\User */
private $user = false;

/** @var \HelpScoutApp\model\Mailbox */
private $mailbox = false;

public function __construct($key) {
ClassLoader::register();
$this->secretKey = $key;
Expand Down Expand Up @@ -62,6 +66,9 @@ private function initData() {
if (isset($data->user)) {
$this->user = new User($data->user);
}
if (isset($data->mailbox)) {
$this->mailbox = new Mailbox($data->mailbox);
}
}
unset($data);
$this->input = null;
Expand Down Expand Up @@ -92,6 +99,14 @@ public function getUser() {
return $this->user;
}

/**
* @return \HelpScoutApp\model\Mailbox
*/
public function getMailbox() {
$this->initData();
return $this->mailbox;
}

/**
* Returns true if the current request is a valid webhook issued from Help Scout, false otherwise.
* @return boolean
Expand Down Expand Up @@ -124,4 +139,4 @@ public function getResponse($html) {
}
return json_encode(array('html' => $html));
}
}
}
30 changes: 30 additions & 0 deletions src/HelpScoutApp/model/Mailbox.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
namespace HelpScoutApp\model;

class Mailbox {

private $id;
private $email;

public function __construct($data = null) {
if ($data) {
$this->id = isset($data->id) ? $data->id : null;
$this->email = isset($data->email) ? $data->email : null;
}
}

/**
* @return int The ID of the Mailbox
*/
public function getId() {
return $this->id;
}

/**
* @return string|null The Mailbox email
*/
public function getEmail() {
return $this->email;
}

}

0 comments on commit 0e18ec0

Please sign in to comment.