Class: SkypeArchive::Model
- Inherits:
-
Object
- Object
- SkypeArchive::Model
- Defined in:
- lib/skype_archive/model.rb
Constant Summary collapse
- LAST_SYNC_FILE =
"/tmp/skype_archive_last_sync"
Instance Attribute Summary collapse
-
#account_name ⇒ Object
readonly
Returns the value of attribute account_name.
Instance Method Summary collapse
-
#initialize(account_name) ⇒ Model
constructor
A new instance of Model.
- #last_sync_time ⇒ Object
- #search(text, options = {}) ⇒ Object
- #sync ⇒ Object
- #sync_contacts ⇒ Object
- #sync_conversations ⇒ Object
- #sync_messages(start_time = 0, end_time = Time.now.to_i) ⇒ Object
- #sync_participants ⇒ Object
- #update_sync_file(time) ⇒ Object
Constructor Details
#initialize(account_name) ⇒ Model
Returns a new instance of Model.
13 14 15 |
# File 'lib/skype_archive/model.rb', line 13 def initialize(account_name) @account_name = account_name end |
Instance Attribute Details
#account_name ⇒ Object (readonly)
Returns the value of attribute account_name.
11 12 13 |
# File 'lib/skype_archive/model.rb', line 11 def account_name @account_name end |
Instance Method Details
#last_sync_time ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/skype_archive/model.rb', line 75 def last_sync_time if File.exists?(LAST_SYNC_FILE) File.read(LAST_SYNC_FILE).to_i else Time.now.to_i - 3600 * 24 * 30 end end |
#search(text, options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/skype_archive/model.rb', line 17 def search(text, ={}) query = connection[:Messages].filter(:type => 61).filter("body_xml LIKE ?", "%#{text}%") query = query.filter("from_dispname LIKE ?", "%#{[:author]}%") if [:author] query = query.filter("timestamp > ?", [:timestamp]) if [:timestamp] if [:conversation] convo_ids = connection[:Conversations].filter("displayname LIKE ?", "%#{[:conversation]}%").all.map { |convo| convo[:id] } query = query.filter("convo_id in ?", convo_ids) end query = query.select(:author, :from_dispname, :body_xml, :timestamp) query.all.map { |attrs| Message.new(attrs) } end |
#sync ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/skype_archive/model.rb', line 29 def sync start_time = last_sync_time end_time = Time.now.to_i sync_contacts sync_conversations sync_participants (start_time, end_time) update_sync_file(end_time) end |
#sync_contacts ⇒ Object
39 40 41 42 43 |
# File 'lib/skype_archive/model.rb', line 39 def sync_contacts contacts = connection[:Contacts].select(:skypename, :displayname).all RestClient.post "#{URL}/users", contacts.to_json, :content_type => :json, :accept => :json contacts end |
#sync_conversations ⇒ Object
45 46 47 48 49 |
# File 'lib/skype_archive/model.rb', line 45 def sync_conversations @conversations = connection[:Conversations].filter(:type => 2).select(:id, :identity, :displayname).all RestClient.post "#{URL}/conversations", @conversations.to_json, :content_type => :json, :accept => :json @conversations end |
#sync_messages(start_time = 0, end_time = Time.now.to_i) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/skype_archive/model.rb', line 62 def (start_time=0, end_time=Time.now.to_i) @conversations or sync_conversations @conversations.each do |convo| = connection[:Messages].filter("convo_id = ? and timestamp >= ? and timestamp <= ?", convo[:id], start_time, end_time). select(:author, :from_dispname, :remote_id, :body_xml, :timestamp). all.map { |attrs| Message.new(attrs) } unless .empty? url = "#{URL}/conversations/#{Base64.encode64(convo[:identity])[0...-1]}/messages" RestClient.post url, .to_json, :content_type => :json, :accept => :json end end end |
#sync_participants ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/skype_archive/model.rb', line 51 def sync_participants @conversations or sync_conversations @conversations.each do |convo| participants = connection[:Participants].filter(:convo_id => convo[:id]).select(:identity).all unless participants.empty? url = "#{URL}/conversations/#{Base64.encode64(convo[:identity])[0...-1]}/participants" RestClient.post url, participants.to_json, :content_type => :json, :accept => :json end end end |
#update_sync_file(time) ⇒ Object
83 84 85 86 87 |
# File 'lib/skype_archive/model.rb', line 83 def update_sync_file(time) File.open(LAST_SYNC_FILE, 'w') do |file| file.puts time end end |