Class: ENUtils::Core

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token, production = true) ⇒ Core

Returns a new instance of Core.

Raises:



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/evernote_utils.rb', line 16

def initialize(token, production=true)

  userStoreUrl = "https://#{production ? 'www' : 'sandbox'}.evernote.com/edam/user"
  userStoreTransport = Thrift::HTTPClientTransport.new(userStoreUrl)
  userStoreProtocol = Thrift::BinaryProtocol.new(userStoreTransport)
  userStore = Evernote::EDAM::UserStore::UserStore::Client.new(userStoreProtocol)

  versionOK = userStore.checkVersion("Evernote EDAMTest (Ruby)",
                                     Evernote::EDAM::UserStore::EDAM_VERSION_MAJOR,
                                     Evernote::EDAM::UserStore::EDAM_VERSION_MINOR)
  raise InvalidVersion unless versionOK

  noteStoreUrl = userStore.getNoteStoreUrl(token)

  noteStoreTransport = Thrift::HTTPClientTransport.new(noteStoreUrl)
  noteStoreProtocol = Thrift::BinaryProtocol.new(noteStoreTransport)
  @notestore = Evernote::EDAM::NoteStore::NoteStore::Client.new(noteStoreProtocol)

  @token = token
end

Instance Attribute Details

#notestoreObject

Returns the value of attribute notestore.



14
15
16
# File 'lib/evernote_utils.rb', line 14

def notestore
  @notestore
end

#tokenObject

Returns the value of attribute token.



14
15
16
# File 'lib/evernote_utils.rb', line 14

def token
  @token
end

Instance Method Details

#create_note(attrs) ⇒ Object



53
54
55
# File 'lib/evernote_utils.rb', line 53

def create_note(attrs)
  Note.create(self, attrs)
end

#create_tag(attrs) ⇒ Object



72
73
74
# File 'lib/evernote_utils.rb', line 72

def create_tag(attrs)
  Tag.create(self, attrs)
end

#delete_note(guid) ⇒ Object



57
58
59
# File 'lib/evernote_utils.rb', line 57

def delete_note(guid)
  Note.delete(self, guid)
end

#find_note(guid, with_content: false, with_resources_data: false, with_resources_recognition: false, with_resources_alternate_data: false) ⇒ Object Also known as: note



42
43
44
45
46
47
48
49
50
# File 'lib/evernote_utils.rb', line 42

def find_note(guid, with_content: false,
                    with_resources_data: false,
                    with_resources_recognition: false,
                    with_resources_alternate_data: false)
  self.notestore.getNote(self.token, guid, with_content,
                                           with_resources_data,
                                           with_resources_recognition,
                                           with_resources_alternate_data)
end

#find_notebook(name = nil) ⇒ Object Also known as: notebook



61
62
63
64
# File 'lib/evernote_utils.rb', line 61

def find_notebook(name=nil)
  return nil unless name
  Notebook.find_by_name(self, name)
end

#find_notebooks(options = {}) ⇒ Object Also known as: notebooks



67
68
69
# File 'lib/evernote_utils.rb', line 67

def find_notebooks(options={})
  Notebook.where(self, options)
end

#find_notes(options = {}) ⇒ Object Also known as: notes



37
38
39
# File 'lib/evernote_utils.rb', line 37

def find_notes(options={})
  Note.where(self, options.reverse_merge(order: :updated))
end

#find_tag(name = nil) ⇒ Object Also known as: tag



76
77
78
79
# File 'lib/evernote_utils.rb', line 76

def find_tag(name=nil)
  return nil unless name
  Tag.find_by_name(self, name)
end

#find_tags(options = {}) ⇒ Object Also known as: tags



82
83
84
# File 'lib/evernote_utils.rb', line 82

def find_tags(options={})
  Tag.where(self, options)
end