Skip to content

Commit

Permalink
add evernote agent and specs
Browse files Browse the repository at this point in the history
  • Loading branch information
bencornelis committed Sep 14, 2015
1 parent d94a1ef commit 2fd8283
Show file tree
Hide file tree
Showing 8 changed files with 746 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ DROPBOX_OAUTH_SECRET=
WUNDERLIST_OAUTH_KEY=
WUNDERLIST_OAUTH_SECRET=

EVERNOTE_OAUTH_KEY=
EVERNOTE_OAUTH_SECRET=

#############################
# 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: false
)
end

private

def validate_evernote_options
unless evernote_consumer_key.present? &&
evernote_consumer_secret.present? &&
evernote_oauth_token.present?
errors.add(:base, "Evernote consumer_key, consumer_secret, oauth_token, and oauth_token_secret are required to authenticate with the Twitter API. You can provide these as options to this Agent, or as Credentials with the same names, but starting with 'evernote_'.")
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

def evernote_oauth_token_secret
service && service.secret
end
end
Loading

0 comments on commit 2fd8283

Please sign in to comment.