-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ishanjayamanne
authored and
ishanjayamanne
committed
Aug 16, 2016
1 parent
be3cb74
commit ea3cb8c
Showing
6 changed files
with
179 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
inherit: true | ||
|
||
checks: | ||
php: | ||
code_rating: true | ||
duplication: true | ||
|
||
filter: | ||
paths: [code/*, tests/*] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# See https://github.com/silverstripe-labs/silverstripe-travis-support for setup details | ||
|
||
sudo: false | ||
|
||
language: php | ||
|
||
php: | ||
- 5.3 | ||
- 5.4 | ||
- 5.5 | ||
- 5.6 | ||
- 7.0 | ||
|
||
env: | ||
- DB=MYSQL CORE_RELEASE=3.2 | ||
|
||
matrix: | ||
include: | ||
- php: 5.6 | ||
env: DB=MYSQL CORE_RELEASE=3 | ||
- php: 5.6 | ||
env: DB=MYSQL CORE_RELEASE=3.1 | ||
- php: 5.6 | ||
env: DB=PGSQL CORE_RELEASE=3.2 | ||
allow_failures: | ||
- php: 7.0 | ||
|
||
before_script: | ||
- composer self-update || true | ||
- git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support | ||
- php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss | ||
- cd ~/builds/ss | ||
- composer install | ||
|
||
script: | ||
- vendor/bin/phpunit silverstripe-evernote/tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
## Installation | ||
|
||
The Evernote cloud Service Provider can be installed via [Composer](http://getcomposer.org) by requiring the | ||
`ishannz/silverstripe-evernote` package and setting the `minimum-stability` to `dev` (required for SilverStripe 3.1) in your | ||
project's `composer.json`. | ||
|
||
```json | ||
{ | ||
"require": { | ||
"ishannz/silverstripe-evernote": "dev-master" | ||
}, | ||
"minimum-stability": "dev" | ||
} | ||
``` | ||
|
||
or | ||
|
||
Require this package with composer: | ||
``` | ||
composer require ishannz/silverstripe-evernote | ||
``` | ||
Update your `composer.json` file to include this package as a dependency | ||
|
||
Update your packages with ```composer update``` or install with ```composer install```. | ||
|
||
In Windows, you'll need to include the GD2 DLL `php_gd2.dll` as an extension in php.ini. | ||
|
||
|
||
## Usage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Director: | ||
rules: | ||
'evernote-auth': 'EvernoteAuthController' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
class EvernoteAuthController extends Controller { | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private static $allowed_actions = array( | ||
'login', | ||
); | ||
|
||
public function login() { | ||
|
||
$Evernote = new Evernote(); | ||
$token = $Evernote->Authorize(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
class Evernote | ||
{ | ||
/** @var string */ | ||
protected $token; | ||
|
||
/** @var boolean */ | ||
protected $sandbox; | ||
|
||
/** @var boolean */ | ||
protected $china; | ||
|
||
/** @var string */ | ||
protected $key; | ||
|
||
/** @var string */ | ||
protected $secret; | ||
|
||
/** @var string */ | ||
protected $callback; | ||
|
||
|
||
|
||
/** | ||
* @param string|null $token | ||
*/ | ||
public function __construct($token = null) | ||
{ | ||
$EvernoteSettings = EvernoteSettings::current_Evernote_settings(); | ||
if(empty($EvernoteSettings)) { | ||
user_error( | ||
_t( | ||
'NO_EVERNOTE_ACTIVE', | ||
'No Evernote Settings Available. Please setup the Evernote configuration.' | ||
), | ||
E_USER_ERROR | ||
); | ||
} | ||
$this->token = $token; | ||
$this->sandbox = ($EvernoteSettings->Sandbox) ?: true; | ||
$this->china = ($EvernoteSettings->China) ?: false; | ||
$this->key = ($EvernoteSettings->APIKey) ?: ''; | ||
$this->secret = ($EvernoteSettings->APISecret) ?: ''; | ||
$this->callback = ($EvernoteSettings->CallbackURL) ?: ''; | ||
} | ||
|
||
public function Authorize() | ||
{ | ||
$oauth_handler = new \Evernote\Auth\OauthHandler($this->sandbox, false, $this->china); | ||
try { | ||
$oauth_data = $oauth_handler->authorize($this->key, $this->secret, $this->getCallbackUrl()); | ||
$this->token = $oauth_data['oauth_token']; | ||
$ret = $this->token; | ||
|
||
} catch (\Evernote\Exception\AuthorizationDeniedException $e) { | ||
//If the user decline the authorization, an exception is thrown. | ||
$ret = null; | ||
} | ||
|
||
return $ret; | ||
} | ||
|
||
public function getCallbackUrl() | ||
{ | ||
$thisUrl = (empty($_SERVER['HTTPS'])) ? "http://" : "https://"; | ||
$thisUrl .= $_SERVER['SERVER_NAME']; | ||
$thisUrl .= ($_SERVER['SERVER_PORT'] == 80 || $_SERVER['SERVER_PORT'] == 443) ? "" : (":" . $_SERVER['SERVER_PORT']); | ||
$thisUrl .= $_SERVER['SCRIPT_NAME']; | ||
$thisUrl .= $this->callback; | ||
return $thisUrl; | ||
} | ||
|
||
public function notebookList($token) | ||
{ | ||
$client = new \Evernote\Client($token, $this->sandbox, null, null, $this->china); | ||
|
||
$notebooks = array(); | ||
|
||
$notebooks = $client->listNotebooks(); | ||
return $notebooks; | ||
} | ||
|
||
} |