From 3f27fdaa5a1c743380254dd5bab0f4105cecedd5 Mon Sep 17 00:00:00 2001 From: Denny Swindle Date: Thu, 29 May 2014 19:39:15 -0400 Subject: [PATCH 01/14] initial check-in --- .../src/HelpScoutApp/ClassLoader.php | 39 ++++++ .../src/HelpScoutApp/DynamicApp.php | 113 ++++++++++++++++++ .../src/HelpScoutApp/model/Customer.php | 40 +++++++ .../src/HelpScoutApp/model/Ticket.php | 28 +++++ .../src/HelpScoutApp/model/User.php | 49 ++++++++ 5 files changed, 269 insertions(+) create mode 100644 helpscout-apps-php/src/HelpScoutApp/ClassLoader.php create mode 100644 helpscout-apps-php/src/HelpScoutApp/DynamicApp.php create mode 100644 helpscout-apps-php/src/HelpScoutApp/model/Customer.php create mode 100644 helpscout-apps-php/src/HelpScoutApp/model/Ticket.php create mode 100644 helpscout-apps-php/src/HelpScoutApp/model/User.php diff --git a/helpscout-apps-php/src/HelpScoutApp/ClassLoader.php b/helpscout-apps-php/src/HelpScoutApp/ClassLoader.php new file mode 100644 index 0000000..557ec8a --- /dev/null +++ b/helpscout-apps-php/src/HelpScoutApp/ClassLoader.php @@ -0,0 +1,39 @@ +baseDir = dirname(__FILE__) . DIRECTORY_SEPARATOR; + } + + public function __destruct() { + spl_autoload_unregister(array($this, 'autoload')); + } + + public function autoload($className) { + if (strpos($className, 'HelpScoutApp') === false) { + return false; + } + $className = str_replace( + array(self::NAMESPACE_SEPARATOR . 'HelpScoutApp' . self::NAMESPACE_SEPARATOR, 'HelpScoutApp' . self::NAMESPACE_SEPARATOR), '', $className + ); + require_once ($this->baseDir . str_replace(self::NAMESPACE_SEPARATOR, DIRECTORY_SEPARATOR, $className) . '.php'); + return true; + } + + public static function register() { + if (self::$instance === false) { + self::$instance = new ClassLoader(); + } + } +} diff --git a/helpscout-apps-php/src/HelpScoutApp/DynamicApp.php b/helpscout-apps-php/src/HelpScoutApp/DynamicApp.php new file mode 100644 index 0000000..cfeb3c9 --- /dev/null +++ b/helpscout-apps-php/src/HelpScoutApp/DynamicApp.php @@ -0,0 +1,113 @@ +secretKey = $key; + } + + private function getHeader($header) { + if (isset($_SERVER[$header])) { + return $_SERVER[$header]; + } + return false; + } + + private function getJsonString() { + if ($this->input === false) { + $this->input = @file_get_contents('php://input'); + } + return $this->input; + } + + private function generateSignature() { + $str = $this->getJsonString(); + if ($str) { + return base64_encode(hash_hmac('sha1', $str, $this->secretKey, true)); + } + return false; + } + + private function initData() { + if ($this->customer === false) { + $data = $this->getHelpScoutData(); + if ($data) { + if (isset($data['customer'])) { + $this->customer = new Customer($data['customer']); + } + if (isset($data['ticket'])) { + $this->ticket = new Ticket($data['ticket']); + } + if (isset($data['user'])) { + $this->user = new User($data['user']); + } + } + } + } + + /** + * @return \HelpScoutApp\model\Customer + */ + public function getCustomer() { + $this->initData(); + return $this->customer; + } + + /** + * @return \HelpScoutApp\model\Ticket + */ + public function getTicket() { + $this->initData(); + return $this->ticket; + } + + /** + * @return \HelpScoutApp\model\User + */ + public function getUser() { + $this->initData(); + return $this->user; + } + + /** + * Returns true if the current request is a valid webhook issued from Help Scout, false otherwise. + * @return boolean + */ + public function isSignatureValid() { + $signature = $this->generateSignature(); + if ($signature) { + return $signature === $this->getHeader('HTTP_X_HELPSCOUT_SIGNATURE'); + } + return false; + } + + private function getHelpScoutData() { + $this->getJsonString(); //ensure data has been loaded from input + return json_decode($this->input, true); + } + + public function getResponse($html) { + return json_encode(array('html' => $html)); + } +} \ No newline at end of file diff --git a/helpscout-apps-php/src/HelpScoutApp/model/Customer.php b/helpscout-apps-php/src/HelpScoutApp/model/Customer.php new file mode 100644 index 0000000..040de21 --- /dev/null +++ b/helpscout-apps-php/src/HelpScoutApp/model/Customer.php @@ -0,0 +1,40 @@ +id = isset($data->id) ? $data->id : null; + $this->fname = isset($data->fname) ? $data->fname : null; + $this->lname = isset($data->lname) ? $data->lname : null; + $this->email = isset($data->email) ? $data->email : null; + $this->emails= isset($data->emails)? $data->emails: null; + } + } + + public function getId() { + return $this->id; + } + + public function getFname() { + return $this->fname; + } + + public function getLame() { + return $this->lame; + } + + public function getEmail() { + return $this->email; + } + + public function getEmails() { + return $this->emails; + } +} \ No newline at end of file diff --git a/helpscout-apps-php/src/HelpScoutApp/model/Ticket.php b/helpscout-apps-php/src/HelpScoutApp/model/Ticket.php new file mode 100644 index 0000000..12716cb --- /dev/null +++ b/helpscout-apps-php/src/HelpScoutApp/model/Ticket.php @@ -0,0 +1,28 @@ +id = isset($data->id) ? $data->id : §null; + $this->number = isset($data->number) ? $data->number : null; + $this->subject= isset($data->subject)? $data->subject : null; + } + } + + public function getId() { + return $this->id; + } + + public function getNumber() { + return $this->number; + } + + public function getSubject() { + return $this->subject; + } +} \ No newline at end of file diff --git a/helpscout-apps-php/src/HelpScoutApp/model/User.php b/helpscout-apps-php/src/HelpScoutApp/model/User.php new file mode 100644 index 0000000..87352b2 --- /dev/null +++ b/helpscout-apps-php/src/HelpScoutApp/model/User.php @@ -0,0 +1,49 @@ +id = isset($data->id) ? $data->id : null; + $this->fname = isset($data->fname) ? $data->fname : null; + $this->lname = isset($data->lname) ? $data->lname : null; + $this->role = isset($data->role) ? intval($data->role): null; + } + } + + public function getId() { + return $this->id; + } + + public function getFname() { + return $this->fname; + } + + public function getLame() { + return $this->lame; + } + + public function getRole() { + return $this->role; + } + + public function isOwnerOrAdmin() { + return in_array($this->role, array(self::ROLE_OWNER, self::ROLE_ADMIN)); + } + + public function isOwner() { + return $this->role == self::ROLE_OWNER; + } + public function isAdmin() { + return $this->role == self::ROLE_ADMIN; + } +} \ No newline at end of file From ac08d8a75ced8b48c860cf08813f04021a5e7cd7 Mon Sep 17 00:00:00 2001 From: Denny Swindle Date: Thu, 29 May 2014 20:13:12 -0400 Subject: [PATCH 02/14] moving files around Change-Id: Ib6f3f6ba5eebf7c85e362dfa5b4d36f6108fd198 --- {helpscout-apps-php/src => src}/HelpScoutApp/ClassLoader.php | 0 {helpscout-apps-php/src => src}/HelpScoutApp/DynamicApp.php | 2 +- {helpscout-apps-php/src => src}/HelpScoutApp/model/Customer.php | 0 {helpscout-apps-php/src => src}/HelpScoutApp/model/Ticket.php | 0 {helpscout-apps-php/src => src}/HelpScoutApp/model/User.php | 0 5 files changed, 1 insertion(+), 1 deletion(-) rename {helpscout-apps-php/src => src}/HelpScoutApp/ClassLoader.php (100%) rename {helpscout-apps-php/src => src}/HelpScoutApp/DynamicApp.php (97%) rename {helpscout-apps-php/src => src}/HelpScoutApp/model/Customer.php (100%) rename {helpscout-apps-php/src => src}/HelpScoutApp/model/Ticket.php (100%) rename {helpscout-apps-php/src => src}/HelpScoutApp/model/User.php (100%) diff --git a/helpscout-apps-php/src/HelpScoutApp/ClassLoader.php b/src/HelpScoutApp/ClassLoader.php similarity index 100% rename from helpscout-apps-php/src/HelpScoutApp/ClassLoader.php rename to src/HelpScoutApp/ClassLoader.php diff --git a/helpscout-apps-php/src/HelpScoutApp/DynamicApp.php b/src/HelpScoutApp/DynamicApp.php similarity index 97% rename from helpscout-apps-php/src/HelpScoutApp/DynamicApp.php rename to src/HelpScoutApp/DynamicApp.php index cfeb3c9..4b8cb30 100644 --- a/helpscout-apps-php/src/HelpScoutApp/DynamicApp.php +++ b/src/HelpScoutApp/DynamicApp.php @@ -5,7 +5,7 @@ use HelpScoutApp\model\Ticket; use HelpScoutApp\model\User; -require_once 'ClassLoader.php'; +require_once '../helpscout-apps-php/src/HelpScoutApp/ClassLoader.php'; class DynamicApp { const NAMESPACE_SEPARATOR = '\\'; diff --git a/helpscout-apps-php/src/HelpScoutApp/model/Customer.php b/src/HelpScoutApp/model/Customer.php similarity index 100% rename from helpscout-apps-php/src/HelpScoutApp/model/Customer.php rename to src/HelpScoutApp/model/Customer.php diff --git a/helpscout-apps-php/src/HelpScoutApp/model/Ticket.php b/src/HelpScoutApp/model/Ticket.php similarity index 100% rename from helpscout-apps-php/src/HelpScoutApp/model/Ticket.php rename to src/HelpScoutApp/model/Ticket.php diff --git a/helpscout-apps-php/src/HelpScoutApp/model/User.php b/src/HelpScoutApp/model/User.php similarity index 100% rename from helpscout-apps-php/src/HelpScoutApp/model/User.php rename to src/HelpScoutApp/model/User.php From e0e5ef941475e83c3b00e7b6ac8845b2d5391732 Mon Sep 17 00:00:00 2001 From: Denny Swindle Date: Thu, 29 May 2014 21:02:43 -0400 Subject: [PATCH 03/14] more changes for initial release Change-Id: I80e7180e29ac043c428b57ddd7ef2d9788df19b9 --- README.md | 34 ++++++++++++++++++ src/HelpScoutApp/DynamicApp.php | 36 +++++++++++-------- .../model/{Ticket.php => Conversation.php} | 2 +- src/HelpScoutApp/model/Customer.php | 8 ++--- src/HelpScoutApp/model/User.php | 8 ++--- 5 files changed, 65 insertions(+), 23 deletions(-) rename src/HelpScoutApp/model/{Ticket.php => Conversation.php} (96%) diff --git a/README.md b/README.md index c1b5af5..4f6452e 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,37 @@ helpscout-apps-php ================== Client library to help with building custom apps to integrate with Help Scout + +Example Usage +--------------------- +

+include 'sumo.php';
+use HelpScoutApp\DynamicApp;
+
+include 'lib/src/HelpScoutApp/DynamicApp.php';
+
+$app = new DynamicApp('1234');
+if ($app->isSignatureValid()) {
+        $customer = $app->getCustomer();
+        $user     = $app->getUser();
+        $convo    = $app->getConversation();
+
+        $html = array(
+                '

Convo

', + '
  • Id: ' . $convo->getId() . '
  • ', + '
  • Number: ' . $convo->getNumber() . '
  • ', + '
  • Subject: ' . $convo->getSubject() . '
', + '

Customer

', + '
  • First: ' . $customer->getFirstName() . '
  • ', + '
  • Last: ' . $customer->getLastName() . '
  • ', + '
  • Email: ' . $customer->getEmail() . '
', + '

User

', + '
  • First: ' . $user->getFirstName() . '
  • ', + '
  • Last: ' . $user->getLastName() . '
  • ', + '
  • Id: ' . $user->getId() . '
' + ); + echo $app->getResponse($html); +} else { + echo $app->getResponse('

Invalid Request

'); +} +
\ No newline at end of file diff --git a/src/HelpScoutApp/DynamicApp.php b/src/HelpScoutApp/DynamicApp.php index 4b8cb30..557506a 100644 --- a/src/HelpScoutApp/DynamicApp.php +++ b/src/HelpScoutApp/DynamicApp.php @@ -2,10 +2,10 @@ namespace HelpScoutApp; use HelpScoutApp\model\Customer; -use HelpScoutApp\model\Ticket; +use HelpScoutApp\model\Conversation; use HelpScoutApp\model\User; -require_once '../helpscout-apps-php/src/HelpScoutApp/ClassLoader.php'; +require_once 'ClassLoader.php'; class DynamicApp { const NAMESPACE_SEPARATOR = '\\'; @@ -16,8 +16,8 @@ class DynamicApp { /** @var \HelpScoutApp\model\Customer */ private $customer = false; - /** @var \HelpScoutApp\model\Ticket */ - private $ticket = false; + /** @var \HelpScoutApp\model\Conversation */ + private $convo = false; /** @var \HelpScoutApp\model\User */ private $user = false; @@ -53,16 +53,18 @@ private function initData() { if ($this->customer === false) { $data = $this->getHelpScoutData(); if ($data) { - if (isset($data['customer'])) { - $this->customer = new Customer($data['customer']); + if (isset($data->customer)) { + $this->customer = new Customer($data->customer); } - if (isset($data['ticket'])) { - $this->ticket = new Ticket($data['ticket']); + if (isset($data->ticket)) { + $this->convo = new Conversation($data->ticket); } - if (isset($data['user'])) { - $this->user = new User($data['user']); + if (isset($data->user)) { + $this->user = new User($data->user); } } + unset($data); + $this->input = null; } } @@ -75,11 +77,11 @@ public function getCustomer() { } /** - * @return \HelpScoutApp\model\Ticket + * @return \HelpScoutApp\model\Conversation */ - public function getTicket() { + public function getConversation() { $this->initData(); - return $this->ticket; + return $this->convo; } /** @@ -102,12 +104,18 @@ public function isSignatureValid() { return false; } + /** + * @return array + */ private function getHelpScoutData() { $this->getJsonString(); //ensure data has been loaded from input - return json_decode($this->input, true); + return json_decode($this->input); } public function getResponse($html) { + if (is_array($html)) { + $html = implode('', $html); + } return json_encode(array('html' => $html)); } } \ No newline at end of file diff --git a/src/HelpScoutApp/model/Ticket.php b/src/HelpScoutApp/model/Conversation.php similarity index 96% rename from src/HelpScoutApp/model/Ticket.php rename to src/HelpScoutApp/model/Conversation.php index 12716cb..2d85f60 100644 --- a/src/HelpScoutApp/model/Ticket.php +++ b/src/HelpScoutApp/model/Conversation.php @@ -1,7 +1,7 @@ id; } - public function getFname() { + public function getFirstName() { return $this->fname; } - public function getLame() { - return $this->lame; + public function getLastName() { + return $this->lname; } public function getEmail() { diff --git a/src/HelpScoutApp/model/User.php b/src/HelpScoutApp/model/User.php index 87352b2..29941a4 100644 --- a/src/HelpScoutApp/model/User.php +++ b/src/HelpScoutApp/model/User.php @@ -8,7 +8,7 @@ class User { private $id; private $fname; - private $lame; + private $lname; private $role; public function __construct($data=null) { @@ -24,12 +24,12 @@ public function getId() { return $this->id; } - public function getFname() { + public function getFirstName() { return $this->fname; } - public function getLame() { - return $this->lame; + public function getLastName() { + return $this->lname; } public function getRole() { From 11c7424065faa71e7f464f3dbb3de70ae500b2fb Mon Sep 17 00:00:00 2001 From: Denny Swindle Date: Thu, 29 May 2014 21:07:04 -0400 Subject: [PATCH 04/14] updating example usage Change-Id: I18010a946983bf204154be6a66f2e900a25ea5fc --- README.md | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 4f6452e..5077f56 100644 --- a/README.md +++ b/README.md @@ -18,21 +18,27 @@ if ($app->isSignatureValid()) { $convo = $app->getConversation(); $html = array( - '

Convo

', - '
  • Id: ' . $convo->getId() . '
  • ', - '
  • Number: ' . $convo->getNumber() . '
  • ', - '
  • Subject: ' . $convo->getSubject() . '
', - '

Customer

', - '
  • First: ' . $customer->getFirstName() . '
  • ', - '
  • Last: ' . $customer->getLastName() . '
  • ', - '
  • Email: ' . $customer->getEmail() . '
', - '

User

', - '
  • First: ' . $user->getFirstName() . '
  • ', - '
  • Last: ' . $user->getLastName() . '
  • ', - '
  • Id: ' . $user->getId() . '
' + '<p>ConvogetId() . '</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>' ); echo $app->getResponse($html); } else { - echo $app->getResponse('

Invalid Request

'); + echo $app->getResponse('<p>Invalid Request</p>'); } \ No newline at end of file From 0aadde12439393cff33962ec5c1ea79f0b29bd87 Mon Sep 17 00:00:00 2001 From: Denny Swindle Date: Thu, 29 May 2014 21:08:15 -0400 Subject: [PATCH 05/14] show where secret-key goes Change-Id: Id3adac0c712ac59a9c7dfc31c3db65184406470f --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5077f56..e3d6e2d 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,11 @@ Client library to help with building custom apps to integrate with Help Scout Example Usage ---------------------

-include 'sumo.php';
 use HelpScoutApp\DynamicApp;
 
-include 'lib/src/HelpScoutApp/DynamicApp.php';
+include 'src/HelpScoutApp/DynamicApp.php';
 
-$app = new DynamicApp('1234');
+$app = new DynamicApp('SECRET-KEY-HERE');
 if ($app->isSignatureValid()) {
         $customer = $app->getCustomer();
         $user     = $app->getUser();

From 0a43224003e8bd1b3660f3ce5bbc812d0d23366a Mon Sep 17 00:00:00 2001
From: Denny Swindle 
Date: Thu, 29 May 2014 21:09:33 -0400
Subject: [PATCH 06/14] more example usage tweaks

Change-Id: I0cd919d3d28a9c5e13715a3f84996cf05ea4b294
---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index e3d6e2d..fcef22e 100644
--- a/README.md
+++ b/README.md
@@ -17,7 +17,7 @@ if ($app->isSignatureValid()) {
         $convo    = $app->getConversation();
 
         $html = array(
-			'<p>ConvogetId() . '</li>',
                 '<li>Number: ' . $convo->getNumber() . '</li>',

From d040578d23c60ff00a11701d78b0e80dde4cfd12 Mon Sep 17 00:00:00 2001
From: Denny Swindle 
Date: Thu, 29 May 2014 21:11:55 -0400
Subject: [PATCH 07/14] more pre-release changes

---
 README.md | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index fcef22e..f177421 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,12 @@
 helpscout-apps-php
 ==================
 
-Client library to help with building custom apps to integrate with Help Scout
+Client library to assist with building custom apps that integrate with Help Scout. More inforomation:
+[http://developer.helpscout.net](http://developer.helpscout.net)
+
+Version 1.0 Released
+---------------------
+Please see the [Changelog](https://github.com/helpscout/helpscout-app-php/blob/master/CHANGELOG.md) for details.
 
 Example Usage
 ---------------------

From 9516c23cdddac6960d3e2957e9efd4cb69178a3c Mon Sep 17 00:00:00 2001
From: Denny Swindle 
Date: Thu, 29 May 2014 21:14:28 -0400
Subject: [PATCH 08/14] more updates

---
 CHANGELOG.md | 3 +++
 README.md    | 5 ++---
 2 files changed, 5 insertions(+), 3 deletions(-)
 create mode 100644 CHANGELOG.md

diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 0000000..7f32bc1
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,3 @@
+#### 1.0 (May 29, 2014)
+
+* Initial release
diff --git a/README.md b/README.md
index f177421..6cb31d8 100644
--- a/README.md
+++ b/README.md
@@ -1,12 +1,11 @@
 helpscout-apps-php
 ==================
 
-Client library to assist with building custom apps that integrate with Help Scout. More inforomation:
-[http://developer.helpscout.net](http://developer.helpscout.net)
+Client library to assist with building custom apps that integrate with Help Scout. More inforomation: [http://developer.helpscout.net/custom-apps/](http://developer.helpscout.net/custom-apps/)
 
 Version 1.0 Released
 ---------------------
-Please see the [Changelog](https://github.com/helpscout/helpscout-app-php/blob/master/CHANGELOG.md) for details.
+Please see the [Changelog](https://github.com/helpscout/helpscout-apps-php/blob/master/CHANGELOG.md) for details.
 
 Example Usage
 ---------------------

From b94b2db94b46bd4f0a05fc89c8604c81dbbccd0c Mon Sep 17 00:00:00 2001
From: Denny Swindle 
Date: Thu, 29 May 2014 21:16:30 -0400
Subject: [PATCH 09/14] initial check-in

---
 composer.json | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
 create mode 100644 composer.json

diff --git a/composer.json b/composer.json
new file mode 100644
index 0000000..a0cd7ac
--- /dev/null
+++ b/composer.json
@@ -0,0 +1,15 @@
+{
+    "name": "helpscout/apps",
+    "type": "library",
+    "description": "Client library to assist with building dynamic apps that integrate with the Help Scout UI",
+    "keywords": ["apps", "dynamic-app", "helpscout"],
+    "homepage": "http://www.helpscout.net",
+    "license": "MIT",
+    "require": {
+        "php": ">=5.3.2",
+        "ext-curl": "*"
+    },
+    "autoload": {
+        "psr-0": { "HelpScoutApp\\": "src/" }
+    }
+}

From dc640c61d107fd960af8fd9d762a129e32b407ce Mon Sep 17 00:00:00 2001
From: Denny Swindle 
Date: Thu, 29 May 2014 21:17:28 -0400
Subject: [PATCH 10/14] updating title

---
 README.md | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md
index 6cb31d8..95950d9 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
-helpscout-apps-php
-==================
+Help Scout Dynamic App Client Library
+=====================================
 
 Client library to assist with building custom apps that integrate with Help Scout. More inforomation: [http://developer.helpscout.net/custom-apps/](http://developer.helpscout.net/custom-apps/)
 
@@ -44,4 +44,4 @@ if ($app->isSignatureValid()) {
 } else {
         echo $app->getResponse('<p>Invalid Request</p>');
 }
-
\ No newline at end of file + From 4648907b9f8dcebedb7266567da15d4086cfc398 Mon Sep 17 00:00:00 2001 From: Denny Swindle Date: Thu, 29 May 2014 21:18:45 -0400 Subject: [PATCH 11/14] updating example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 95950d9..1a9094a 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,6 @@ if ($app->isSignatureValid()) { ); echo $app->getResponse($html); } else { - echo $app->getResponse('<p>Invalid Request</p>'); + echo 'Invalid Request'); } From 1e8e89bd61e08ce5ae382b5c84febe5cd33ae3aa Mon Sep 17 00:00:00 2001 From: Denny Swindle Date: Thu, 29 May 2014 21:19:03 -0400 Subject: [PATCH 12/14] updating example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1a9094a..12c80db 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,6 @@ if ($app->isSignatureValid()) { ); echo $app->getResponse($html); } else { - echo 'Invalid Request'); + echo 'Invalid Request'; } From e3787d4065f7cb8e7b2f6f362e86b29aa6998f2f Mon Sep 17 00:00:00 2001 From: Denny Swindle Date: Thu, 29 May 2014 21:20:54 -0400 Subject: [PATCH 13/14] updating example --- README.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 12c80db..ceeee4e 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Version 1.0 Released --------------------- Please see the [Changelog](https://github.com/helpscout/helpscout-apps-php/blob/master/CHANGELOG.md) for details. -Example Usage +Example Usage (1) ---------------------

 use HelpScoutApp\DynamicApp;
@@ -45,3 +45,18 @@ if ($app->isSignatureValid()) {
         echo 'Invalid Request';
 }
 
+ +Example Usage (2) +--------------------- +

+use HelpScoutApp\DynamicApp;
+
+include 'src/HelpScoutApp/DynamicApp.php';
+
+$app = new DynamicApp('SECRET-KEY-HERE');
+if ($app->isSignatureValid()) {               
+        echo $app->getResponse('<p>Hello World</p>');
+} else {
+        echo 'Invalid Request';
+}
+
From 22111388a025d9c5b6346344c3eb964903559b7d Mon Sep 17 00:00:00 2001 From: Denny Swindle Date: Thu, 29 May 2014 21:22:18 -0400 Subject: [PATCH 14/14] updating phpdocs --- src/HelpScoutApp/DynamicApp.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/HelpScoutApp/DynamicApp.php b/src/HelpScoutApp/DynamicApp.php index 557506a..d5cd3ae 100644 --- a/src/HelpScoutApp/DynamicApp.php +++ b/src/HelpScoutApp/DynamicApp.php @@ -112,6 +112,12 @@ private function getHelpScoutData() { return json_decode($this->input); } + /** + * Pass either an array that will be flattened to a string, or a string of HTML. + * + * @param mixed $html + * @return string + */ public function getResponse($html) { if (is_array($html)) { $html = implode('', $html);