class EvernoteOAuth::Client
Public Class Methods
new(options={})
click to toggle source
# 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
Public Instance Methods
request_token(options={})
click to toggle source
# File lib/evernote_oauth/client.rb, line 41 def request_token(options={}) consumer.options[:authorize_path] = '/OAuth.action' consumer.get_request_token(options) end
Private Instance Methods
access_token()
click to toggle source
# File lib/evernote_oauth/client.rb, line 63 def access_token @access_token ||= OAuth::AccessToken.new(consumer, @token, @secret) end
consumer()
click to toggle source
# File lib/evernote_oauth/client.rb, line 47 def consumer @consumer ||= OAuth::Consumer.new( @consumer_key, @consumer_secret, {site: endpoint, request_token_path: "/oauth", access_token_path: "/oauth"} ) end
endpoint(path=nil)
click to toggle source
# File lib/evernote_oauth/client.rb, line 57 def endpoint(path=nil) url = "https://#{@service_host}" url += "/#{path}" if path url end
thrift_client(client_class, url)
click to toggle source
# File lib/evernote_oauth/client.rb, line 67 def thrift_client(client_class, url) if m = /:A=([^:]+):/.match(@token) key_id = m[1] else key_id = @consumer_key || 'nil' end transport = Thrift::HTTPClientTransport.new(url) transport.add_headers( 'User-Agent' => "#{key_id} / #{::EvernoteOAuth::VERSION}; Ruby / #{RUBY_VERSION};" ) transport.add_headers(@additional_headers) if @additional_headers protocol = Thrift::BinaryProtocol.new(transport) client_class.new(protocol) end