Module: Googletastic::Sync

Defined in:
lib/googletastic/sync.rb

Defined Under Namespace

Modules: Document, Form

Class Method Summary collapse

Class Method Details

.cleanup(syncables, options) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/googletastic/sync.rb', line 28

def cleanup(syncables, options)
  syncables.each do |syncable|
    syncable.synced_at = Time.now
    syncable.save!
    path = File.join(options[:folder], syncable.title)
    path += options[:ext] if options.has_key?(:ext)
    begin
      File.delete(path)
    rescue Exception => e
      
    end
  end
end

.post(options = {}) ⇒ Object

POSTs to your registered application



18
19
20
21
22
23
24
25
26
# File 'lib/googletastic/sync.rb', line 18

def post(options = {})
  url = URI.parse(options[:url])
  # POST update to registered application
  http = Net::HTTP.new(url.host, url.port)
  header = options[:header] || {}
  header.merge!('Content-Type' =>'application/json')
  data = options[:data].to_json
  response = http.post(options[:path], data, header)
end

.push(username, password, options = {}) ⇒ Object



13
14
15
# File 'lib/googletastic/sync.rb', line 13

def push(username, password, options = {})
  Googletastic.client_for(:app_engine).push(username, password, options)
end

.sync_documents(documents, options = {}, &block) ⇒ Object



5
6
7
# File 'lib/googletastic/sync.rb', line 5

def sync_documents(documents, options = {}, &block)
  Googletastic::Document.sync(documents, options, &block)
end

.sync_forms(forms, options = {}, &block) ⇒ Object



9
10
11
# File 'lib/googletastic/sync.rb', line 9

def sync_forms(forms, options = {}, &block)
  Googletastic::Form.sync(forms, options, &block)
end