Class: Everdone::Sync
- Inherits:
-
Object
- Object
- Everdone::Sync
- Defined in:
- lib/everdone/sync.rb
Instance Method Summary collapse
- #add_to_processed(new_processed) ⇒ Object
- #close(new_processed) ⇒ Object
- #get_processed_total ⇒ Object
- #init_data ⇒ Object
-
#initialize(config, todoist) ⇒ Sync
constructor
A new instance of Sync.
- #is_already_processed(item_id) ⇒ Object
- #marshall ⇒ Object
- #unmarshall(data) ⇒ Object
Constructor Details
#initialize(config, todoist) ⇒ Sync
Returns a new instance of Sync.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/everdone/sync.rb', line 11 def initialize(config, todoist) @config = config @todoist = todoist @data = {} @current_item_id = nil items = @todoist.get_items_by_project_name(@config.todoist_sync_tracking_project) raise "Too many items in Todoist project used for syncing (#{@config.todoist_sync_tracking_project}): #{items.length}" if items.length > 1 if items.length == 0 then initData() else @current_item_id = items[0]['id'] notes = @todoist.get_notes(@current_item_id) unmarshall(notes[0]['content']) if notes and notes.length > 0 end end |
Instance Method Details
#add_to_processed(new_processed) ⇒ Object
50 51 52 |
# File 'lib/everdone/sync.rb', line 50 def add_to_processed(new_processed) @data['processed'].push(new_processed) end |
#close(new_processed) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/everdone/sync.rb', line 36 def close(new_processed) @data['processed'].concat(new_processed) new_item_id = @todoist.add_item_to_project_by_name(@config.todoist_sync_tracking_project, "Evernote sync data from #{DateTime.now.to_s} total processed = #{self.get_processed_total()}", 1) new_data = self.marshall @todoist.add_note(new_item_id, new_data) @todoist.delete_item_by_id(@current_item_id) if @current_item_id end |
#get_processed_total ⇒ Object
46 47 48 |
# File 'lib/everdone/sync.rb', line 46 def get_processed_total() return @data['processed'].length end |
#init_data ⇒ Object
27 28 29 30 |
# File 'lib/everdone/sync.rb', line 27 def init_data @data['created'] = DateTime.now @data['processed'] = [] end |
#is_already_processed(item_id) ⇒ Object
32 33 34 |
# File 'lib/everdone/sync.rb', line 32 def is_already_processed(item_id) return !@data['processed'].find_index(item_id).nil? end |
#marshall ⇒ Object
54 55 56 57 |
# File 'lib/everdone/sync.rb', line 54 def marshall data = JSON.generate(@data) return data end |
#unmarshall(data) ⇒ Object
59 60 61 |
# File 'lib/everdone/sync.rb', line 59 def unmarshall(data) @data = JSON.parse(data) end |