Skip to content

Commit

Permalink
Merge pull request huginn#1032 from bencornelis/evernote_agent
Browse files Browse the repository at this point in the history
Evernote agent
  • Loading branch information
cantino committed Sep 23, 2015
2 parents 5fa1824 + a05ef9e commit 9c58474
Show file tree
Hide file tree
Showing 9 changed files with 1,041 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ DROPBOX_OAUTH_SECRET=
WUNDERLIST_OAUTH_KEY=
WUNDERLIST_OAUTH_SECRET=

EVERNOTE_OAUTH_KEY=
EVERNOTE_OAUTH_SECRET=
# Set to true in development, false in production
USE_EVERNOTE_SANDBOX=true

#############################
# AWS and Mechanical Turk #
#############################
Expand Down
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ gem 'omniauth-dropbox'
# UserLocationAgent
gem 'haversine'

# EvernoteAgent
gem 'omniauth-evernote'
gem 'evernote_oauth'

# Optional Services.
gem 'omniauth-37signals' # BasecampAgent
gem 'omniauth-wunderlist', github: 'wunderlist/omniauth-wunderlist', ref: 'd0910d0396107b9302aa1bc50e74bb140990ccb8'
Expand Down
10 changes: 10 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ GEM
ethon (0.7.1)
ffi (>= 1.3.0)
eventmachine (1.0.7)
evernote-thrift (1.25.1)
evernote_oauth (0.2.3)
evernote-thrift
oauth (>= 0.4.1)
execjs (2.3.0)
extlib (0.9.16)
faraday (0.9.1)
Expand Down Expand Up @@ -318,6 +322,10 @@ GEM
omniauth-oauth2 (~> 1.0)
omniauth-dropbox (0.2.0)
omniauth-oauth (~> 1.0)
omniauth-evernote (1.2.1)
evernote-thrift
multi_json (~> 1.0)
omniauth-oauth (~> 1.0)
omniauth-oauth (1.0.1)
oauth
omniauth (~> 1.0)
Expand Down Expand Up @@ -543,6 +551,7 @@ DEPENDENCIES
dotenv-rails (~> 2.0.1)
dropbox-api
em-http-request (~> 1.1.2)
evernote_oauth
faraday (~> 0.9.0)
faraday_middleware (>= 0.10.0)
feed-normalizer
Expand Down Expand Up @@ -576,6 +585,7 @@ DEPENDENCIES
omniauth
omniauth-37signals
omniauth-dropbox
omniauth-evernote
omniauth-tumblr
omniauth-twitter
omniauth-wunderlist!
Expand Down
48 changes: 48 additions & 0 deletions app/concerns/evernote_concern.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module EvernoteConcern
extend ActiveSupport::Concern

included do
include Oauthable

validate :validate_evernote_options

valid_oauth_providers :evernote

gem_dependency_check { defined?(EvernoteOAuth) && Devise.omniauth_providers.include?(:evernote) }
end

def evernote_client
EvernoteOAuth::Client.new(
token: evernote_oauth_token,
consumer_key: evernote_consumer_key,
consumer_secret: evernote_consumer_secret,
sandbox: use_sandbox?
)
end

private

def use_sandbox?
ENV["USE_EVERNOTE_SANDBOX"] == "true"
end

def validate_evernote_options
unless evernote_consumer_key.present? &&
evernote_consumer_secret.present? &&
evernote_oauth_token.present?
errors.add(:base, "Evernote ENV variables and a Service are required")
end
end

def evernote_consumer_key
(config = Devise.omniauth_configs[:evernote]) && config.strategy.consumer_key
end

def evernote_consumer_secret
(config = Devise.omniauth_configs[:evernote]) && config.strategy.consumer_secret
end

def evernote_oauth_token
service && service.token
end
end
Loading

0 comments on commit 9c58474

Please sign in to comment.