Skip to content

Commit

Permalink
add evernote authorization url
Browse files Browse the repository at this point in the history
  • Loading branch information
ishanjayamanne authored and ishanjayamanne committed Aug 16, 2016
1 parent be3cb74 commit ea3cb8c
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .scrutinizer.yml
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/*]
36 changes: 36 additions & 0 deletions .travis.yml
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
29 changes: 29 additions & 0 deletions README.md
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
3 changes: 3 additions & 0 deletions _config/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Director:
rules:
'evernote-auth': 'EvernoteAuthController'
18 changes: 18 additions & 0 deletions code/controller/EvernoteAuthController.php
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();
}

}
84 changes: 84 additions & 0 deletions code/model/Evernote.php
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;
}

}

0 comments on commit ea3cb8c

Please sign in to comment.