Module: MongoHTTPSync::Importer

Included in:
MongoImporter, MongoidImporter
Defined in:
lib/mongo_http_sync/importer.rb

Instance Method Summary collapse

Instance Method Details

#import(url, key: 'id') ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/mongo_http_sync/importer.rb', line 12

def import(url, key: 'id')
  last_updated_doc = find_last_updated_doc
  newest_update = last_updated_doc['updated_at'] unless last_updated_doc.nil?
  unless newest_update.nil?
    url = append_query_param(url, 'updated_since', newest_update.utc.strftime('%Y-%m-%d %H:%M:%S.%L UTC'))
  end
  puts url
  Parser.parse(HTTP.get(url).body) do |json|
    json['_id'] = json.delete(key)
    upsert(json)
  end
end

#initialize(output) ⇒ Object



8
9
10
# File 'lib/mongo_http_sync/importer.rb', line 8

def initialize(output)
  @output = output
end