Class: Everton::Remote

Inherits:
Object
  • Object
show all
Defined in:
lib/everton.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.access_tokenObject

Returns the value of attribute access_token.



26
27
28
# File 'lib/everton.rb', line 26

def access_token
  @access_token
end

.note_storeObject (readonly)

Returns the value of attribute note_store.



25
26
27
# File 'lib/everton.rb', line 25

def note_store
  @note_store
end

.shard_idObject (readonly)

Returns the value of attribute shard_id.



25
26
27
# File 'lib/everton.rb', line 25

def shard_id
  @shard_id
end

.user_storeObject (readonly)

Returns the value of attribute user_store.



25
26
27
# File 'lib/everton.rb', line 25

def user_store
  @user_store
end

Class Method Details

.authenticate(config, force = false) ⇒ Object

:username :password :access_token :user_store_url

if @force is true, authenticate even if access_token found



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/everton.rb', line 38

def self.authenticate config, force=false
  if config.is_a? Hash
    cfg = config
  else
    cfg = YAML.load_file config
  end
  @user_store = Evernote::UserStore.new(cfg[:user_store_url], cfg)
  # We have a token, assume it's valid
  if not force and not config[:access_token].nil? and not config[:username].nil?
    @user = config[:username]
    @access_token = config[:access_token]
    @shard_id = @access_token.split(':').first.split('=').last
  else
    auth_result = user_store.authenticate
    @user = auth_result.user
    @access_token = auth_result.authenticationToken
    @shard_id = @user.shardId
  end
  uri = URI.parse cfg[:user_store_url]
  host = uri.host
  scheme = uri.scheme
  @note_store_url = "#{scheme}://#{host}/edam/note/#{@shard_id}"
  @note_store = Evernote::NoteStore.new(@note_store_url)
end