Class: EvernoteOAuth::Client

Inherits:
Object
  • Object
show all
Includes:
BusinessNoteStore, BusinessUtils, NoteStore, SharedNoteStore, UserStore
Defined in:
lib/evernote_oauth/client.rb

Instance Method Summary collapse

Methods included from BusinessUtils

#create_business_notebook, #create_note_in_business_notebook, #get_corresponding_notebook, #list_business_notebooks

Methods included from BusinessNoteStore

#business_note_store

Methods included from UserStore

#user_store

Methods included from SharedNoteStore

#shared_note_store

Methods included from NoteStore

#note_store

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/evernote_oauth/client.rb', line 9

def initialize(options={})
  config_file = "config/evernote.yml"
  if File.exist?(config_file)
    require 'erb'
    if defined?(Rails)
      config = YAML.load(ERB.new(File.read(config_file)).result)[Rails.env]
    else
      config = YAML.load(ERB.new(File.read(config_file)).result)
    end
    @consumer_key = config['consumer_key']
    @consumer_secret = config['consumer_secret']
    @sandbox = config['sandbox'] ? true : false
  end

  @consumer_key = options[:consumer_key] || @consumer_key
  @consumer_secret = options[:consumer_secret] || @consumer_secret
  @sandbox = true if @sandbox == nil
  @sandbox = (options[:sandbox] == nil ? @sandbox : options[:sandbox])
  @service_host = options[:service_host] || (@sandbox ? 'sandbox.evernote.com' : 'www.evernote.com')
  @additional_headers = options[:additional_headers]
  @token = options[:token]
  @secret = options[:secret]
end

Instance Method Details

#authorize(token, secret, options = {}) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/evernote_oauth/client.rb', line 33

def authorize(token, secret, options={})
  request_token = OAuth::RequestToken.new(consumer, token, secret)
  @access_token = request_token.get_access_token(options)
  @token = @access_token.token
  @secret = @access_token.secret
  @access_token
end

#request_token(options = {}) ⇒ Object



41
42
43
44
# File 'lib/evernote_oauth/client.rb', line 41

def request_token(options={})
  consumer.options[:authorize_path] = '/OAuth.action'
  consumer.get_request_token(options)
end