summaryrefslogtreecommitdiff
path: root/Postman/PostmanOAuthToken.php
diff options
context:
space:
mode:
authoryehudah <yehudah@b8457f37-d9ea-0310-8a92-e5e31aec5664>2017-10-15 06:46:12 +0000
committeryehudah <yehudah@b8457f37-d9ea-0310-8a92-e5e31aec5664>2017-10-15 06:46:12 +0000
commitca6c8f41c1a2b9a4b5acae91419a6a114e1c77c6 (patch)
tree40ff112761d82af1d8c1c89d30ede8206502e17b /Postman/PostmanOAuthToken.php
parent8812fbf61bde539d1599e239044595ccb8a2c3a5 (diff)
downloadPost-SMTP-ca6c8f41c1a2b9a4b5acae91419a6a114e1c77c6.zip
release
Diffstat (limited to 'Postman/PostmanOAuthToken.php')
-rw-r--r--Postman/PostmanOAuthToken.php86
1 files changed, 86 insertions, 0 deletions
diff --git a/Postman/PostmanOAuthToken.php b/Postman/PostmanOAuthToken.php
new file mode 100644
index 0000000..1f4de78
--- /dev/null
+++ b/Postman/PostmanOAuthToken.php
@@ -0,0 +1,86 @@
+<?php
+if (! class_exists ( 'PostmanOAuthToken.php' )) {
+
+ class PostmanOAuthToken {
+ const OPTIONS_NAME = 'postman_auth_token';
+ //
+ const REFRESH_TOKEN = 'refresh_token';
+ const EXPIRY_TIME = 'auth_token_expires';
+ const ACCESS_TOKEN = 'access_token';
+ const VENDOR_NAME = 'vendor_name';
+ //
+ private $vendorName;
+ private $accessToken;
+ private $refreshToken;
+ private $expiryTime;
+
+ // singleton instance
+ public static function getInstance() {
+ static $inst = null;
+ if ($inst === null) {
+ $inst = new PostmanOAuthToken ();
+ }
+ return $inst;
+ }
+
+ // private constructor
+ private function __construct() {
+ $this->load ();
+ }
+
+ /**
+ * Is there a valid access token and refresh token
+ */
+ public function isValid() {
+ $accessToken = $this->getAccessToken ();
+ $refreshToken = $this->getRefreshToken ();
+ return ! (empty ( $accessToken ) || empty ( $refreshToken ));
+ }
+
+ /**
+ * Load the Postman OAuth token properties to the database
+ */
+ private function load() {
+ $a = get_option ( PostmanOAuthToken::OPTIONS_NAME );
+ $this->setAccessToken ( $a [PostmanOAuthToken::ACCESS_TOKEN] );
+ $this->setRefreshToken ( $a [PostmanOAuthToken::REFRESH_TOKEN] );
+ $this->setExpiryTime ( $a [PostmanOAuthToken::EXPIRY_TIME] );
+ $this->setVendorName ( $a [PostmanOAuthToken::VENDOR_NAME] );
+ }
+
+ /**
+ * Save the Postman OAuth token properties to the database
+ */
+ public function save() {
+ $a [PostmanOAuthToken::ACCESS_TOKEN] = $this->getAccessToken ();
+ $a [PostmanOAuthToken::REFRESH_TOKEN] = $this->getRefreshToken ();
+ $a [PostmanOAuthToken::EXPIRY_TIME] = $this->getExpiryTime ();
+ $a [PostmanOAuthToken::VENDOR_NAME] = $this->getVendorName ();
+ update_option ( PostmanOAuthToken::OPTIONS_NAME, $a );
+ }
+ public function getVendorName() {
+ return $this->vendorName;
+ }
+ public function getExpiryTime() {
+ return $this->expiryTime;
+ }
+ public function getAccessToken() {
+ return $this->accessToken;
+ }
+ public function getRefreshToken() {
+ return $this->refreshToken;
+ }
+ public function setVendorName($name) {
+ $this->vendorName = sanitize_text_field ( $name );
+ }
+ public function setExpiryTime($time) {
+ $this->expiryTime = sanitize_text_field ( $time );
+ }
+ public function setAccessToken($token) {
+ $this->accessToken = sanitize_text_field ( $token );
+ }
+ public function setRefreshToken($token) {
+ $this->refreshToken = sanitize_text_field ( $token );
+ }
+ }
+} \ No newline at end of file