evernote_oauth 0.1.8 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e05aecfeb42b65619eaf227c6f8091d14fcd8a7c
4
- data.tar.gz: 10388538657d7e8bd4291968c9fe956bba778297
3
+ metadata.gz: 3fbf6103919edea4362275f58147a52169f4b656
4
+ data.tar.gz: 9c93337f7fd0c7b69287d9f94290f9585ac977f1
5
5
  SHA512:
6
- metadata.gz: 6a4f69543b2c11dd095b7636a6b878f1db0a88e02c8fa98fcfc438253c28de0fdf87d8a3f032f914089733ccf80c9f5b59e3ec64303ee10a4a9912508cae71fa
7
- data.tar.gz: 7a1933799197fabaa355fc3093a1376ce5daf3fedcb34f295a223f223d9e867ddefbf154053b39439ed6e872892454fac8f28555fcc5b20b8b5103b8f9702057
6
+ metadata.gz: 96fbb98b8228f84ef00188ea5c43072bb957da03f98af730320e92a02946405eb614f7f2901a72c9df94b1dd75a01f3c1eff5bde1cf9daad80865c6520ffe00b
7
+ data.tar.gz: fa4ae85a6559097751d743ad832101c088d82e253c46414180a28a3fb9ac1ed12582708184dff6ca01f82e6d001fbe11bc44636fcca26f8182ac3b899af9dff3
data/README.md CHANGED
@@ -137,6 +137,53 @@ You can use hexdigest within ENXML:
137
137
  <en-media type="image/png" hash="#{hexdigest}"/>
138
138
  ```
139
139
 
140
+ Utility methods for Business
141
+ ----------------------------
142
+ This gem provides some utility methods to deal with Evernote Business.
143
+
144
+ ### List business notebooks ###
145
+ To list all business notebooks the user can access
146
+ ```ruby
147
+ client = EvernoteOAuth::Client.new(token: token)
148
+ client.list_business_notebooks
149
+ ```
150
+
151
+ ### Create a business note ###
152
+ To create a business note in a business notebook
153
+ ```ruby
154
+ note = Evernote::EDAM::Type::Note.new
155
+ business_notebook = client.list_business_notebooks.first
156
+ client.create_note_in_business_notebook(note, business_notebook)
157
+ ```
158
+
159
+ ### Create a business notebook ###
160
+ To create a business notebook
161
+ ```ruby
162
+ notebook = Evernote::EDAM::Type::Notebook.new
163
+ client.create_business_notebook(notebook)
164
+ ```
165
+
166
+ ### Get a notebook corresponding to the given business notebook ###
167
+ ```ruby
168
+ business_notebook = client.list_business_notebooks.first
169
+ client.get_corresponding_notebook(business_notebook)
170
+ ```
171
+
172
+ ### Determine if the user can edit the notebook ###
173
+ ```ruby
174
+ notebook.writable?
175
+ ```
176
+
177
+ ### Determine if the user is a part of a business ###
178
+ ```ruby
179
+ user.belongs_to_business?
180
+ ```
181
+
182
+ ### Get a business name of the user ###
183
+ ```ruby
184
+ user.business_name
185
+ ```
186
+
140
187
  References
141
188
  ----------
142
189
  - Evernote Developers: http://dev.evernote.com/
@@ -28,5 +28,7 @@ Gem::Specification.new do |s|
28
28
  s.add_dependency 'oauth', '>= 0.4.1'
29
29
  s.add_dependency 'evernote-thrift'
30
30
  s.add_development_dependency 'rspec'
31
+ s.add_development_dependency 'yard'
32
+ s.add_development_dependency 'redcarpet'
31
33
  end
32
34
  end
@@ -2,8 +2,8 @@ module Evernote
2
2
  module EDAM
3
3
  module NoteStore
4
4
  class NoteList
5
- extend ::EvernoteOAuth::StoreAttachable
6
- attach_note_store :notes
5
+ extend ::EvernoteOAuth::StoreAttachable
6
+ attach_note_store :notes
7
7
  end
8
8
  end
9
9
  end
@@ -2,9 +2,14 @@ module Evernote
2
2
  module EDAM
3
3
  module NoteStore
4
4
  class NoteMetadata
5
- def tags
6
- @tags ||= (tagGuids || []).map{|guid| note_store.getTag(guid)}
7
- end
5
+
6
+ # Returns the tags that are applied to this note.
7
+ #
8
+ # @return [Array<Evernote::EDAM::Type::Tag>]
9
+ def tags
10
+ @tags ||= (tagGuids || []).map{|guid| note_store.getTag(guid)}
11
+ end
12
+
8
13
  end
9
14
  end
10
15
  end
@@ -2,8 +2,8 @@ module Evernote
2
2
  module EDAM
3
3
  module NoteStore
4
4
  class NotesMetadataList
5
- extend NoteStoreAttachable
6
- attach_note_store :notes
5
+ extend NoteStoreAttachable
6
+ attach_note_store :notes
7
7
  end
8
8
  end
9
9
  end
@@ -2,8 +2,8 @@ module Evernote
2
2
  module EDAM
3
3
  module NoteStore
4
4
  class SyncChunk
5
- extend ::EvernoteOAuth::StoreAttachable
6
- attach_note_store :notes, :notebooks, :tags, :searches, :resources, :linkedNotebooks
5
+ extend ::EvernoteOAuth::StoreAttachable
6
+ attach_note_store :notes, :notebooks, :tags, :searches, :resources, :linkedNotebooks
7
7
  end
8
8
  end
9
9
  end
@@ -2,21 +2,35 @@ module Evernote
2
2
  module EDAM
3
3
  module Type
4
4
  class Note
5
+
6
+ # Returns the notebook that contains this note.
7
+ #
8
+ # @return [Evernote::EDAM::Type::Notebook]
5
9
  def notebook
6
10
  @notebook ||= note_store.getNotebook(notebookGuid)
7
- end
11
+ end
8
12
 
9
- def tags
10
- @tags ||= (tagGuids || []).map{|guid| note_store.getTag(guid)}
11
- end
13
+ # Returns the tags that are applied to this note.
14
+ #
15
+ # @return [Array<Evernote::EDAM::Type::Tag>]
16
+ def tags
17
+ @tags ||= (tagGuids || []).map{|guid| note_store.getTag(guid)}
18
+ end
12
19
 
13
- def add_resource(filename, image, mime)
20
+ # Add resource to this note.
21
+ #
22
+ # @param filename [String] the name of the resource
23
+ # @param file [File]
24
+ # @param mime [String] MIME type of the resource
25
+ #
26
+ # @return [String] Hexdigest of the given file
27
+ def add_resource(filename, file, mime)
14
28
  hash_func = Digest::MD5.new
15
29
 
16
30
  data = Evernote::EDAM::Type::Data.new
17
- data.size = image.size
18
- data.bodyHash = hash_func.digest(image)
19
- data.body = image
31
+ data.size = file.size
32
+ data.bodyHash = hash_func.digest(file)
33
+ data.body = file
20
34
 
21
35
  resource = Evernote::EDAM::Type::Resource.new
22
36
  resource.mime = mime
@@ -27,7 +41,7 @@ module Evernote
27
41
  self.resources = [] unless self.resources
28
42
  self.resources << resource
29
43
 
30
- hash_func.hexdigest(image)
44
+ hash_func.hexdigest(file)
31
45
  end
32
46
  end
33
47
  end
@@ -0,0 +1,16 @@
1
+ module Evernote
2
+ module EDAM
3
+ module Type
4
+ class Notebook
5
+
6
+ # Determines if the user can create notes in this notebook.
7
+ #
8
+ # @return [Boolean]
9
+ def writable?
10
+ !self.restrictions.noCreateNotes
11
+ end
12
+
13
+ end
14
+ end
15
+ end
16
+ end
@@ -2,25 +2,34 @@ module Evernote
2
2
  module EDAM
3
3
  module Type
4
4
  class Resource
5
- @note_by_options = {}
5
+ @note_by_options = {}
6
6
 
7
- def note(options)
8
- options = {
9
- with_content: false,
10
- with_resources_data: false,
11
- with_resources_recognition: false,
12
- with_resources_alternate_data: false
13
- }.merge(options)
7
+ # Returns the note that holds this resource.
8
+ #
9
+ # @param options [Hash] options for {http://dev.evernote.com/documentation/reference/NoteStore.html#Fn_NoteStore_getNote}.
10
+ # @option options [String] :with_content
11
+ # @option options [String] :with_resources_data
12
+ # @option options [String] :with_resources_recognition
13
+ # @option options [String] :with_resources_alternate_data
14
+ # @return [Evernote::EDAM::Type::Note]
15
+ def note(options={})
16
+ options = {
17
+ with_content: false,
18
+ with_resources_data: false,
19
+ with_resources_recognition: false,
20
+ with_resources_alternate_data: false
21
+ }.merge(options)
22
+
23
+ @note_by_opions[options] ||
24
+ (@note_by_options[options] = note_store.getNote(
25
+ noteGuid,
26
+ options[:with_content],
27
+ options[:with_resources_data],
28
+ options[:with_resources_recognition],
29
+ options[:with_resources_alternate_data])
30
+ )
31
+ end
14
32
 
15
- @note_by_opions[options] ||
16
- (@note_by_options[options] = note_store.getNote(
17
- noteGuid,
18
- options[:with_content],
19
- options[:with_resources_data],
20
- options[:with_resources_recognition],
21
- options[:with_resources_alternate_data])
22
- )
23
- end
24
33
  end
25
34
  end
26
35
  end
@@ -2,9 +2,14 @@ module Evernote
2
2
  module EDAM
3
3
  module Type
4
4
  class SharedNotebook
5
+
6
+ # Returns the associated notebook shared
7
+ #
8
+ # @return [Evernote::EDAM::Type::Notebook]
5
9
  def notebook
6
10
  @notebook ||= note_store.getNotebook(notebookGuid)
7
- end
11
+ end
12
+
8
13
  end
9
14
  end
10
15
  end
@@ -2,9 +2,14 @@ module Evernote
2
2
  module EDAM
3
3
  module Type
4
4
  class Tag
5
+
6
+ # Returns the tag that holds this tag within the tag organizational hierarchy.
7
+ #
8
+ # @return [Evernote::EDAM::Type::Tag]
5
9
  def parent
6
10
  @parent ||= note_store.getTag(parentGuid) if parentGuid
7
- end
11
+ end
12
+
8
13
  end
9
14
  end
10
15
  end
@@ -2,12 +2,21 @@ module Evernote
2
2
  module EDAM
3
3
  module Type
4
4
  class User
5
+
6
+ # Determines if this user is a part of a business
7
+ #
8
+ # @return [Boolean]
5
9
  def belongs_to_business?
6
10
  self.accounting.businessId != nil
7
11
  end
12
+
13
+ # Returns the business name
14
+ #
15
+ # @return [String]
8
16
  def business_name
9
17
  self.accounting.businessName
10
18
  end
19
+
11
20
  end
12
21
  end
13
22
  end
@@ -1,16 +1,17 @@
1
1
  require 'rubygems'
2
2
  require 'oauth'
3
3
  require 'yaml'
4
-
5
4
  require 'evernote-thrift'
6
5
 
7
6
  require 'evernote_types'
8
7
 
9
8
  require 'evernote_oauth/thrift_client_delegation'
10
- require 'evernote_oauth/client'
11
9
  require 'evernote_oauth/user_store'
12
10
  require 'evernote_oauth/note_store'
13
11
  require 'evernote_oauth/shared_note_store'
14
12
  require 'evernote_oauth/business_note_store'
13
+ require 'evernote_oauth/business_utils'
15
14
  require 'evernote_oauth/store_attachable'
16
15
  require 'evernote_oauth/version'
16
+
17
+ require 'evernote_oauth/client'
@@ -1,24 +1,32 @@
1
1
  module EvernoteOAuth
2
2
 
3
- class Client
3
+ module BusinessNoteStore
4
+ include UserStore
5
+
6
+ # Returns note_store for a business account
7
+ #
8
+ # @return [EvernoteOAuth::BusinessNoteStore::Store]
4
9
  def business_note_store(options={})
5
10
  auth = user_store.authenticateToBusiness(options[:token] || @token)
6
- EvernoteOAuth::BusinessNoteStore.new(
11
+ EvernoteOAuth::BusinessNoteStore::Store.new(
7
12
  token: auth.authenticationToken,
8
13
  client: thrift_client(::Evernote::EDAM::NoteStore::NoteStore::Client,
9
- auth.noteStoreUrl)
14
+ auth.noteStoreUrl),
15
+ user: auth.user
10
16
  )
11
17
  end
12
- end
13
18
 
14
- class BusinessNoteStore
15
- include ::EvernoteOAuth::ThriftClientDelegation
16
- attr_reader :token
19
+ class Store
20
+ include ::EvernoteOAuth::ThriftClientDelegation
21
+ attr_reader :token, :user
17
22
 
18
- def initialize(options={})
19
- @token = options[:token]
20
- @client = options[:client]
23
+ def initialize(options={})
24
+ @token = options[:token]
25
+ @client = options[:client]
26
+ @user = options[:user]
27
+ end
21
28
  end
29
+
22
30
  end
23
31
 
24
32
  end
@@ -0,0 +1,55 @@
1
+ module EvernoteOAuth
2
+
3
+ module BusinessUtils
4
+ include ::EvernoteOAuth::UserStore
5
+ include ::EvernoteOAuth::NoteStore
6
+ include ::EvernoteOAuth::SharedNoteStore
7
+ include ::EvernoteOAuth::BusinessNoteStore
8
+
9
+ # Creates a note in the given business notebook.
10
+ #
11
+ # @param note [Evernote::EDAM::Type::Note] See {http://dev.evernote.com/documentation/reference/Types.html#Struct_Note}.
12
+ # @param business_notebook [Evernote::EDAM::Type::LinkedNotebook] A LinkedNotebook object corresponding to the business notebook. See {http://dev.evernote.com/documentation/reference/Types.html#Struct_LinkedNotebook}.
13
+ # @return [Evernote::EDAM::Type::Note] The newly created Note from the service. The server-side GUIDs for the Note and any Resources will be saved in this object.
14
+ def create_note_in_business_notebook(note, business_notebook)
15
+ shared_notebook = shared_note_store(business_notebook).getSharedNotebookByAuth
16
+ note.notebookGuid = shared_notebook.notebookGuid
17
+ shared_note_store(business_notebook).createNote(note)
18
+ end
19
+
20
+ # Lists all business notebooks the user can access.
21
+ #
22
+ # @return [Array<Evernote::EDAM::Type::LinkedNotebook>] The list of LinkedNotebook. See {http://dev.evernote.com/documentation/reference/Types.html#Struct_LinkedNotebook}.
23
+ def list_business_notebooks
24
+ note_store.listLinkedNotebooks.select(&:businessId)
25
+ end
26
+
27
+ # Creates a business notebook in the business account and LinkedNotebook for the user.
28
+ #
29
+ # @param notebook [Evernote::EDAM::Type::Notebook] See {http://dev.evernote.com/documentation/reference/Types.html#Struct_Notebook}.
30
+ # @return [Evernote::EDAM::Type::LinkedNotebook] The LinkedNotebook corresponding to the notebook in the business account. See {http://dev.evernote.com/documentation/reference/Types.html#Struct_LinkedNotebook}.
31
+ def create_business_notebook(notebook)
32
+ business_notebook = business_note_store.createNotebook(notebook)
33
+ shared_notebook = business_notebook.sharedNotebooks.first
34
+ business_user = business_note_store.user
35
+ linked_notebook = Evernote::EDAM::Type::LinkedNotebook.new(
36
+ shareKey: shared_notebook.shareKey,
37
+ shareName: business_notebook.name,
38
+ username: business_user.username,
39
+ shardId: business_user.shardId
40
+ )
41
+ note_store.createLinkedNotebook(linked_notebook)
42
+ end
43
+
44
+ # Get a notebook object corresponding to the given business notebook.
45
+ #
46
+ # @param business_notebook [Evernote::EDAM::Type::LinkedNotebook] A LinkedNotebook object. See {http://dev.evernote.com/documentation/reference/Types.html#Struct_LinkedNotebook}.
47
+ # @return [Evernote::EDAM::Type::Notebook] A Notebook object corresponding to the given LinkedNotebook.
48
+ def get_corresponding_notebook(business_notebook)
49
+ shared_notebook = shared_note_store(business_notebook).getSharedNotebookByAuth
50
+ business_note_store.getNotebook(shared_notebook.notebookGuid)
51
+ end
52
+
53
+ end
54
+
55
+ end
@@ -1,5 +1,10 @@
1
1
  module EvernoteOAuth
2
2
  class Client
3
+ include ::EvernoteOAuth::UserStore
4
+ include ::EvernoteOAuth::NoteStore
5
+ include ::EvernoteOAuth::SharedNoteStore
6
+ include ::EvernoteOAuth::BusinessNoteStore
7
+ include ::EvernoteOAuth::BusinessUtils
3
8
 
4
9
  def initialize(options={})
5
10
  config_file = "config/evernote.yml"
@@ -60,7 +65,7 @@ module EvernoteOAuth
60
65
  end
61
66
 
62
67
  def thrift_client(client_class, url)
63
- if m = /:A=(.+):/.match(@token)
68
+ if m = /:A=([^:]+):/.match(@token)
64
69
  key_id = m[1]
65
70
  else
66
71
  key_id = @consumer_key || 'nil'
@@ -1,22 +1,29 @@
1
1
  module EvernoteOAuth
2
2
 
3
- class Client
3
+ module NoteStore
4
+ include ::EvernoteOAuth::UserStore
5
+
6
+ # Returns note_store
7
+ #
8
+ # @return [EvernoteOAuth::NoteStore::Store]
4
9
  def note_store(options={})
5
- @note_store = EvernoteOAuth::NoteStore.new(
6
- token: options[:token] || @token,
7
- client: thrift_client(::Evernote::EDAM::NoteStore::NoteStore::Client,
8
- options[:note_store_url] || user_store.getNoteStoreUrl)
10
+ @note_store = EvernoteOAuth::NoteStore::Store.new(
11
+ token: options[:token] || @token,
12
+ client: thrift_client(::Evernote::EDAM::NoteStore::NoteStore::Client,
13
+ options[:note_store_url] || user_store.getNoteStoreUrl)
9
14
  )
10
15
  end
11
- end
12
16
 
13
- class NoteStore
14
- include ::EvernoteOAuth::ThriftClientDelegation
17
+ class Store
18
+ include ::EvernoteOAuth::ThriftClientDelegation
19
+
20
+ def initialize(options={})
21
+ @token = options[:token]
22
+ @client = options[:client]
23
+ end
15
24
 
16
- def initialize(options={})
17
- @token = options[:token]
18
- @client = options[:client]
19
25
  end
26
+
20
27
  end
21
28
 
22
29
  end
@@ -1,26 +1,32 @@
1
1
  module EvernoteOAuth
2
2
 
3
- class Client
4
- def shared_note_store(shared_notebook, options={})
5
- EvernoteOAuth::SharedNoteStore.new(
6
- shared_notebook: shared_notebook,
3
+ module SharedNoteStore
4
+
5
+ # Returns note_store for a shared notebook
6
+ #
7
+ # @param linked_notebook [Evernote::EDAM::Type::LinkedNotebook]
8
+ # @return [EvernoteOAuth::SharedNoteStore::Store]
9
+ def shared_note_store(linked_notebook, options={})
10
+ EvernoteOAuth::SharedNoteStore::Store.new(
11
+ linked_notebook: linked_notebook,
7
12
  token: options[:token] || @token,
8
13
  client: thrift_client(::Evernote::EDAM::NoteStore::NoteStore::Client,
9
- shared_notebook.noteStoreUrl)
14
+ linked_notebook.noteStoreUrl)
10
15
  )
11
16
  end
12
- end
13
17
 
14
- class SharedNoteStore
15
- include ::EvernoteOAuth::ThriftClientDelegation
16
- attr_reader :token
18
+ class Store
19
+ include ::EvernoteOAuth::ThriftClientDelegation
20
+ attr_reader :token
17
21
 
18
- def initialize(options={})
19
- @shared_notebook = options[:shared_notebook]
20
- @client = options[:client]
21
- @token = authenticateToSharedNotebook(@shared_notebook.shareKey,
22
- options[:token]).authenticationToken
22
+ def initialize(options={})
23
+ @linked_notebook = options[:linked_notebook]
24
+ @client = options[:client]
25
+ @token = authenticateToSharedNotebook(@linked_notebook.shareKey,
26
+ options[:token]).authenticationToken
27
+ end
23
28
  end
29
+
24
30
  end
25
31
 
26
32
  end
@@ -10,21 +10,21 @@ module EvernoteOAuth
10
10
 
11
11
  def attach_store(type, *field_symbols)
12
12
  field_symbols.each do |fs|
13
- define_method(fs) do
14
- original = "@#{fs}".to_sym
15
- target = "@#{fs}_with_#{type}_stores".to_sym
16
- with_stores = (
17
- instance_variable_get(target) ||
18
- begin
19
- store_name = "#{type}_store"
20
- store = eval(store_name)
21
- [instance_variable_get(original)].flatten.each{|n|
22
- n.define_singleton_method(store_name.to_sym){store}
23
- }
24
- end
25
- )
26
- instance_variable_set(target, with_stores)
27
- end
13
+ define_method(fs) do
14
+ original = "@#{fs}".to_sym
15
+ target = "@#{fs}_with_#{type}_stores".to_sym
16
+ with_stores = (
17
+ instance_variable_get(target) ||
18
+ begin
19
+ store_name = "#{type}_store"
20
+ store = eval(store_name)
21
+ [instance_variable_get(original)].flatten.each{|n|
22
+ n.define_singleton_method(store_name.to_sym){store}
23
+ }
24
+ end
25
+ )
26
+ instance_variable_set(target, with_stores)
27
+ end
28
28
  end
29
29
  end
30
30
  end
@@ -5,15 +5,15 @@ module EvernoteOAuth
5
5
  method = @client.class.instance_method(name)
6
6
  parameters = method.parameters
7
7
  if parameters.size != args.size &&
8
- idx_token = parameters.index{|e| e.last == :authenticationToken}
9
- new_args = args.dup.insert(idx_token, @token)
10
- begin
11
- result = @client.send(name, *new_args, &block)
12
- rescue ArgumentError => e
13
- result = @client.send(name, *args, &block)
14
- end
8
+ idx_token = parameters.index{|e| e.last == :authenticationToken}
9
+ new_args = args.dup.insert(idx_token, @token)
10
+ begin
11
+ result = @client.send(name, *new_args, &block)
12
+ rescue ArgumentError => e
13
+ result = @client.send(name, *args, &block)
14
+ end
15
15
  else
16
- result = @client.send(name, *args, &block)
16
+ result = @client.send(name, *args, &block)
17
17
  end
18
18
 
19
19
  attr_name = underscore(self.class.name.split('::').last).to_sym
@@ -1,29 +1,34 @@
1
1
  module EvernoteOAuth
2
2
 
3
- class Client
3
+ module UserStore
4
+
5
+ # Returns user_store
6
+ #
7
+ # @return [EvernoteOAuth::UserStore::Store]
4
8
  def user_store
5
- @user_store = EvernoteOAuth::UserStore.new(
6
- token: @token,
7
- client: thrift_client(::Evernote::EDAM::UserStore::UserStore::Client,
8
- endpoint('edam/user'))
9
+ @user_store = EvernoteOAuth::UserStore::Store.new(
10
+ token: @token,
11
+ client: thrift_client(::Evernote::EDAM::UserStore::UserStore::Client,
12
+ endpoint('edam/user'))
9
13
  )
10
14
  end
11
- end
12
15
 
13
- class UserStore
14
- include ::EvernoteOAuth::ThriftClientDelegation
16
+ class Store
17
+ include ::EvernoteOAuth::ThriftClientDelegation
15
18
 
16
- def initialize(options={})
17
- @token = options[:token]
18
- @client = options[:client]
19
- raise 'API version is not up to date' unless version_valid?
20
- end
19
+ def initialize(options={})
20
+ @token = options[:token]
21
+ @client = options[:client]
22
+ raise 'API version is not up to date' unless version_valid?
23
+ end
21
24
 
22
- def version_valid?
23
- checkVersion("EDAMTest",
24
- ::Evernote::EDAM::UserStore::EDAM_VERSION_MAJOR,
25
- ::Evernote::EDAM::UserStore::EDAM_VERSION_MINOR)
25
+ def version_valid?
26
+ checkVersion("EDAMTest",
27
+ ::Evernote::EDAM::UserStore::EDAM_VERSION_MAJOR,
28
+ ::Evernote::EDAM::UserStore::EDAM_VERSION_MINOR)
29
+ end
26
30
  end
31
+
27
32
  end
28
33
 
29
34
  end
@@ -1,3 +1,3 @@
1
1
  module EvernoteOAuth
2
- VERSION = "0.1.8"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -2,6 +2,7 @@ require 'evernote_oauth/store_attachable'
2
2
 
3
3
  require 'evernote/edam/type/user'
4
4
  require 'evernote/edam/type/note'
5
+ require 'evernote/edam/type/notebook'
5
6
  require 'evernote/edam/type/resource'
6
7
  require 'evernote/edam/type/shared_notebook'
7
8
  require 'evernote/edam/type/tag'
@@ -9,3 +10,4 @@ require 'evernote/edam/type/tag'
9
10
  require 'evernote/edam/note_store/note_list'
10
11
  require 'evernote/edam/note_store/note_metadata'
11
12
  require 'evernote/edam/note_store/sync_chunk'
13
+
@@ -0,0 +1,23 @@
1
+ require File.join(File.dirname(__FILE__), "/../spec_helper")
2
+
3
+ describe "EvernoteOAuth::BusinessNoteStore" do
4
+ include EvernoteOAuth::BusinessNoteStore
5
+
6
+ context "#initialize" do
7
+ it "assigns instance variables" do
8
+ business_note_store = EvernoteOAuth::BusinessNoteStore::Store.new(client: 'client')
9
+ business_note_store.instance_variable_get(:@client).should == 'client'
10
+ end
11
+ end
12
+ context "#method_missing" do
13
+ it "dispatches method" do
14
+ mock_client = mock(Object)
15
+ mock_client.should_receive(:send).with(:call_method, 'args')
16
+ mock_client.class.should_receive(:instance_method).with(:call_method).and_return{
17
+ Proc.new {|a| a}
18
+ }
19
+ note_store = EvernoteOAuth::BusinessNoteStore::Store.new(client: mock_client)
20
+ note_store.call_method('args')
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,84 @@
1
+ require File.join(File.dirname(__FILE__), "/../spec_helper")
2
+
3
+ describe "EvernoteOAuth::BusinessUtils" do
4
+ include EvernoteOAuth::BusinessUtils
5
+
6
+ context "#create_note_in_business_notebook" do
7
+ it "calls createNote with shared_note_store" do
8
+ note = Evernote::EDAM::Type::Note.new
9
+ business_notebook = Evernote::EDAM::Type::LinkedNotebook.new
10
+ shared_notebook = Evernote::EDAM::Type::SharedNotebook.new(notebookGuid: 'notebook_guid')
11
+ shared_note_store = mock(Object)
12
+ shared_note_store.stub(:getSharedNotebookByAuth).and_return(shared_notebook)
13
+ shared_note_store.stub(:createNote).and_return(note)
14
+ should_receive(:shared_note_store).with(business_notebook).twice.and_return(shared_note_store)
15
+ create_note_in_business_notebook(note, business_notebook).should == note
16
+ end
17
+ end
18
+
19
+ context "#list_business_notebooks" do
20
+ it "calls listLinkedNotebooks with note_store" do
21
+ ln1 = Evernote::EDAM::Type::LinkedNotebook.new(businessId: 'Evernote')
22
+ ln2 = Evernote::EDAM::Type::LinkedNotebook.new
23
+ ln3 = Evernote::EDAM::Type::LinkedNotebook.new(businessId: 'Evernote')
24
+ note_store = mock(Object)
25
+ note_store.stub(:listLinkedNotebooks).and_return([ln1, ln2, ln3])
26
+ should_receive(:note_store).and_return(note_store)
27
+ list_business_notebooks.should == [ln1, ln3]
28
+ end
29
+ end
30
+
31
+ context "#create_business_notebook" do
32
+ it "calls createNote with shared_note_store" do
33
+ notebook = Evernote::EDAM::Type::Notebook.new
34
+ shared_notebook = Evernote::EDAM::Type::SharedNotebook.new(
35
+ shareKey: 'shareKey'
36
+ )
37
+ business_notebook = Evernote::EDAM::Type::Notebook.new(
38
+ name: 'name',
39
+ sharedNotebooks: [shared_notebook]
40
+ )
41
+ business_note_store = mock(Object)
42
+ business_note_store.stub(:createNotebook).with(notebook).and_return(business_notebook)
43
+ should_receive(:business_note_store).and_return(business_note_store)
44
+
45
+ business_user = Evernote::EDAM::Type::User.new(
46
+ username: 'username',
47
+ shardId: 'shardId'
48
+ )
49
+ user_store = mock(Object)
50
+ user_store.stub(:getUser).and_return(business_user)
51
+ should_receive(:user_store).and_return(user_store)
52
+
53
+ note_store = mock(Object)
54
+ note_store.should_receive(:createLinkedNotebook).with(
55
+ Evernote::EDAM::Type::LinkedNotebook.new(
56
+ shareKey: 'shareKey',
57
+ shareName: 'name',
58
+ username: 'username',
59
+ shardId: 'shardId'
60
+ )
61
+ )
62
+ should_receive(:note_store).and_return(note_store)
63
+
64
+ create_business_notebook(notebook)
65
+ end
66
+ end
67
+
68
+ context "#get_corresponding_notebook" do
69
+ it "calls getNotebookWithGuid with business_note_store" do
70
+ business_notebook = Evernote::EDAM::Type::LinkedNotebook.new
71
+ shared_notebook = Evernote::EDAM::Type::SharedNotebook.new(notebookGuid: 'notebook_guid')
72
+ shared_note_store = mock(Object)
73
+ shared_note_store.stub(:getSharedNotebookByAuth).and_return(shared_notebook)
74
+ should_receive(:shared_note_store).with(business_notebook).and_return(shared_note_store)
75
+
76
+ business_note_store = mock(Object)
77
+ business_note_store.should_receive(:getNotebookWithGuid).with('notebook_guid')
78
+ should_receive(:business_note_store).and_return(business_note_store)
79
+
80
+ get_corresponding_notebook(business_notebook)
81
+ end
82
+ end
83
+
84
+ end
@@ -35,21 +35,10 @@ describe "EvernoteOAuth::Client" do
35
35
  it "calls OAuth::Consumer#get_request_token" do
36
36
  mock_request_token = mock(OAuth::RequestToken)
37
37
  mock_consumer = mock(OAuth::Consumer)
38
- mock_consumer.should_receive(:get_request_token).and_return(mock_request_token)
39
- @client.should_receive(:consumer).and_return(mock_consumer)
38
+ mock_consumer.should_receive(:options).and_return({})
39
+ mock_consumer.should_receive(:get_request_token).with({}).and_return(mock_request_token)
40
+ @client.should_receive(:consumer).any_number_of_times.and_return(mock_consumer)
40
41
  @client.request_token.should == mock_request_token
41
42
  end
42
43
  end
43
- context "#authentication_request_token" do
44
- it "calls request_token with 'authorize_path' options" do
45
- option = {}
46
- mock_request_token = mock(OAuth::RequestToken)
47
- mock_consumer = mock(OAuth::Consumer)
48
- mock_consumer.should_receive(:options).and_return(option)
49
- @client.should_receive(:consumer).and_return(mock_consumer)
50
- @client.should_receive(:request_token).and_return(mock_request_token)
51
- @client.authentication_request_token.should == mock_request_token
52
- option[:authorize_path].should == '/OAuth.action'
53
- end
54
- end
55
44
  end
@@ -1,9 +1,11 @@
1
1
  require File.join(File.dirname(__FILE__), "/../spec_helper")
2
2
 
3
3
  describe "EvernoteOAuth::NoteStore" do
4
+ include EvernoteOAuth::NoteStore
5
+
4
6
  context "#initialize" do
5
7
  it "assigns instance variables" do
6
- note_store = EvernoteOAuth::NoteStore.new(client: 'client')
8
+ note_store = EvernoteOAuth::NoteStore::Store.new(client: 'client')
7
9
  note_store.instance_variable_get(:@client).should == 'client'
8
10
  end
9
11
  end
@@ -12,9 +14,9 @@ describe "EvernoteOAuth::NoteStore" do
12
14
  mock_client = mock(Object)
13
15
  mock_client.should_receive(:send).with(:call_method, 'args')
14
16
  mock_client.class.should_receive(:instance_method).with(:call_method).and_return{
15
- Proc.new {|a| a}
17
+ Proc.new {|a| a}
16
18
  }
17
- note_store = EvernoteOAuth::NoteStore.new(client: mock_client)
19
+ note_store = EvernoteOAuth::NoteStore::Store.new(client: mock_client)
18
20
  note_store.call_method('args')
19
21
  end
20
22
  end
@@ -1,15 +1,17 @@
1
1
  require File.join(File.dirname(__FILE__), "/../spec_helper")
2
2
 
3
3
  describe "EvernoteOAuth::SharedNoteStore" do
4
+ include EvernoteOAuth::SharedNoteStore
5
+
4
6
  context "#initialize" do
5
7
  it "assigns instance variables" do
6
8
  sn = Struct.new(:shareKey).new('shareKey')
7
9
  auth_token = Struct.new(:authenticationToken).new('token')
8
- EvernoteOAuth::SharedNoteStore.any_instance.should_receive(
9
- :authenticateToSharedNotebook).and_return(auth_token)
10
- note_store = EvernoteOAuth::SharedNoteStore.new(client: 'client', shared_notebook: sn)
11
- note_store.instance_variable_get(:@client).should == 'client'
12
- note_store.token.should == 'token'
10
+ EvernoteOAuth::SharedNoteStore::Store.any_instance.should_receive(
11
+ :authenticateToSharedNotebook).and_return(auth_token)
12
+ note_store = EvernoteOAuth::SharedNoteStore::Store.new(client: 'client', linked_notebook: sn)
13
+ note_store.instance_variable_get(:@client).should == 'client'
14
+ note_store.token.should == 'token'
13
15
  end
14
16
  end
15
17
  context "#method_missing" do
@@ -17,14 +19,14 @@ describe "EvernoteOAuth::SharedNoteStore" do
17
19
  mock_client = mock(Object)
18
20
  mock_client.should_receive(:send).with(:call_method, 'args')
19
21
  mock_client.class.should_receive(:instance_method).with(:call_method).and_return{
20
- Proc.new {|a| a}
22
+ Proc.new {|a| a}
21
23
  }
22
24
  sn = Struct.new(:shareKey).new('shareKey')
23
25
  auth_token = Struct.new(:authenticationToken).new('token')
24
- EvernoteOAuth::SharedNoteStore.any_instance.should_receive(
25
- :authenticateToSharedNotebook).and_return(auth_token)
26
- note_store = EvernoteOAuth::SharedNoteStore.new(client: mock_client, shared_notebook: sn)
27
- note_store.call_method('args')
26
+ EvernoteOAuth::SharedNoteStore::Store.any_instance.should_receive(
27
+ :authenticateToSharedNotebook).and_return(auth_token)
28
+ note_store = EvernoteOAuth::SharedNoteStore::Store.new(client: mock_client, linked_notebook: sn)
29
+ note_store.call_method('args')
28
30
  end
29
31
  end
30
32
  end
@@ -1,15 +1,17 @@
1
1
  require File.join(File.dirname(__FILE__), "/../spec_helper")
2
2
 
3
3
  describe "EvernoteOAuth::UserStore" do
4
+ include EvernoteOAuth::UserStore
5
+
4
6
  context "#initialize" do
5
7
  it "assigns instance variables and checks version" do
6
- EvernoteOAuth::UserStore.any_instance.stub(:version_valid?){true}
7
- user_store = EvernoteOAuth::UserStore.new(client: 'client')
8
+ EvernoteOAuth::UserStore::Store.any_instance.stub(:version_valid?){true}
9
+ user_store = EvernoteOAuth::UserStore::Store.new(client: 'client')
8
10
  user_store.instance_variable_get(:@client).should == 'client'
9
11
  end
10
12
  it "raises error when version is not valid" do
11
- EvernoteOAuth::UserStore.any_instance.stub(:version_valid?){false}
12
- lambda{EvernoteOAuth::UserStore.new(client: 'client')}.should raise_error
13
+ EvernoteOAuth::UserStore::Store.any_instance.stub(:version_valid?){false}
14
+ lambda{EvernoteOAuth::UserStore::Store.new(client: 'client')}.should raise_error
13
15
  end
14
16
  end
15
17
  context "#method_missing" do
@@ -17,10 +19,10 @@ describe "EvernoteOAuth::UserStore" do
17
19
  mock_client = mock(Object)
18
20
  mock_client.should_receive(:send).with(:call_method, 'args')
19
21
  mock_client.class.should_receive(:instance_method).with(:call_method).and_return{
20
- Proc.new {|a| a}
22
+ Proc.new {|a| a}
21
23
  }
22
- EvernoteOAuth::UserStore.any_instance.stub(:version_valid?){true}
23
- user_store = EvernoteOAuth::UserStore.new(client: mock_client)
24
+ EvernoteOAuth::UserStore::Store.any_instance.stub(:version_valid?){true}
25
+ user_store = EvernoteOAuth::UserStore::Store.new(client: mock_client)
24
26
  user_store.call_method('args')
25
27
  end
26
28
  end
@@ -1,4 +1,3 @@
1
- require 'evernote_oauth'
2
1
  require 'rspec'
3
2
 
4
3
  Dir.glob(File.join(File.join(File.dirname(__FILE__), "..", "lib"), "**.rb")).each do |file|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evernote_oauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evernote
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-18 00:00:00.000000000 Z
11
+ date: 2013-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oauth
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: redcarpet
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  description: evernote_oauth is a Ruby client for the Evernote API using OAuth and
56
84
  Thrift.
57
85
  email: api@evernote.com
@@ -67,11 +95,13 @@ files:
67
95
  - lib/evernote/edam/note_store/notes_metadata_list.rb
68
96
  - lib/evernote/edam/note_store/sync_chunk.rb
69
97
  - lib/evernote/edam/type/note.rb
98
+ - lib/evernote/edam/type/notebook.rb
70
99
  - lib/evernote/edam/type/resource.rb
71
100
  - lib/evernote/edam/type/shared_notebook.rb
72
101
  - lib/evernote/edam/type/tag.rb
73
102
  - lib/evernote/edam/type/user.rb
74
103
  - lib/evernote_oauth/business_note_store.rb
104
+ - lib/evernote_oauth/business_utils.rb
75
105
  - lib/evernote_oauth/client.rb
76
106
  - lib/evernote_oauth/note_store.rb
77
107
  - lib/evernote_oauth/shared_note_store.rb
@@ -81,6 +111,8 @@ files:
81
111
  - lib/evernote_oauth/version.rb
82
112
  - lib/evernote_oauth.rb
83
113
  - lib/evernote_types.rb
114
+ - spec/evernote_oauth/business_note_store_spec.rb
115
+ - spec/evernote_oauth/business_utils_spec.rb
84
116
  - spec/evernote_oauth/client_spec.rb
85
117
  - spec/evernote_oauth/note_store_spec.rb
86
118
  - spec/evernote_oauth/shared_note_store_spec.rb
@@ -112,3 +144,4 @@ signing_key:
112
144
  specification_version: 2
113
145
  summary: evernote_oauth is a Ruby client for the Evernote API using OAuth and Thrift.
114
146
  test_files: []
147
+ has_rdoc: false