mongo_http_sync 0.1.0 → 0.3.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: 468b9521a0b2dbe33db07f7b3447b18801dd4ce9
4
- data.tar.gz: 5fdad35814c5a4d22a82e6bebae7e310b32904c4
3
+ metadata.gz: d7577fa07921f970382f96c1441d662a4d4d15ba
4
+ data.tar.gz: ce199bafe2291c6566c8cf3a3d1cabe9f1949666
5
5
  SHA512:
6
- metadata.gz: 78596f81df22b0bb677a1edd6fe6d74e39e63da3a5ad82a76932dc0eea237417e2cc6d912726af1efe72d93a50393b451f68ef18f7a6c4894453f20fa37ee42f
7
- data.tar.gz: 6769a5a7064bf438ba48ad30408c06cb1672085a8b4aad8e233bde4df251e248d8b91d29774c8b0ea81d775c5c5d76f4eb7086c6e3f5b697415ac95b201c9a8c
6
+ metadata.gz: e77eb4731b00282bdd87afc33f6b20e118d3a6fb81af99c6aa5bf9508ede7c9f93d9bdc66116f442b1357865c58945b7769b483a572410fd464fd0cd9d84b6bb
7
+ data.tar.gz: e0314114dd6114b29e4df52d2f21a70362e0a0fa2993f6efa6629b04864be73b32fb9622eefc9b48e23b33c67b940da416890b3af222e24964b992d36e39a60f
@@ -0,0 +1,7 @@
1
+ require 'grape-entity'
2
+
3
+ module MongoHTTPSync
4
+ class Entity < Grape::Entity
5
+ expose :_id, :updated_at
6
+ end
7
+ end
@@ -0,0 +1,14 @@
1
+ require 'mongoid'
2
+ require 'active_support/concern'
3
+
4
+ module MongoHTTPSync
5
+ module ExportableDocument
6
+ extend ActiveSupport::Concern
7
+ include Mongoid::Timestamps::Updated
8
+
9
+ included do
10
+ scope :updated_since, ->(time) { where(updated_at: { '$gte' => time }) }
11
+ index updated_on: 1
12
+ end
13
+ end
14
+ end
@@ -9,15 +9,16 @@ module MongoHTTPSync
9
9
  @output = output
10
10
  end
11
11
 
12
- def import(url, key: 'id')
12
+ def import(url, key: :id, entity: nil)
13
13
  last_updated_doc = find_last_updated_doc
14
14
  newest_update = last_updated_doc['updated_at'] unless last_updated_doc.nil?
15
15
  unless newest_update.nil?
16
16
  url = append_query_param(url, 'updated_since', newest_update.utc.strftime('%Y-%m-%d %H:%M:%S.%L UTC'))
17
17
  end
18
- puts url
19
18
  Parser.parse(HTTP.get(url).body) do |json|
20
- json['_id'] = json.delete(key)
19
+ json[:_id] = json.delete(key)
20
+ json[:updated_at] = Time.parse(json[:updated_at])
21
+ json = entity.represent(json).as_json if entity.present?
21
22
  upsert(json)
22
23
  end
23
24
  end
@@ -12,7 +12,7 @@ module MongoHTTPSync
12
12
  end
13
13
 
14
14
  def upsert(json)
15
- @output.find(_id: json['_id']).update_one(json, upsert: true)
15
+ @output.find(_id: json[:_id]).update_one(json, upsert: true)
16
16
  end
17
17
 
18
18
  end
@@ -12,7 +12,7 @@ module MongoHTTPSync
12
12
  end
13
13
 
14
14
  def upsert(json)
15
- doc = @output.where(_id: json['_id']).first
15
+ doc = @output.where(_id: json[:_id]).first
16
16
  if doc.nil?
17
17
  @output.create! json
18
18
  else
@@ -31,7 +31,7 @@ module MongoHTTPSync
31
31
  end
32
32
 
33
33
  def hash_set(h,k,v)
34
- h[k] = v
34
+ h[k.to_sym] = v
35
35
  end
36
36
 
37
37
  def array_start
@@ -1,3 +1,3 @@
1
1
  module MongoHTTPSync
2
- VERSION = "0.1.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -1,7 +1,9 @@
1
1
  require "mongo_http_sync/version"
2
2
 
3
3
  module MongoHTTPSync
4
- autoload :MongoImporter, 'mongo_http_sync/mongo_importer'
5
- autoload :MongoidImporter, 'mongo_http_sync/mongoid_importer'
6
- autoload :Parser, 'mongo_http_sync/parser'
4
+ autoload :MongoImporter, 'mongo_http_sync/mongo_importer'
5
+ autoload :MongoidImporter, 'mongo_http_sync/mongoid_importer'
6
+ autoload :Parser, 'mongo_http_sync/parser'
7
+ autoload :Entity, 'mongo_http_sync/entity'
8
+ autoload :ExportableDocument, 'mongo_http_sync/exportable_document'
7
9
  end
@@ -30,4 +30,5 @@ Gem::Specification.new do |spec|
30
30
  spec.add_dependency "mongoid"
31
31
  spec.add_dependency "oj"
32
32
  spec.add_dependency "http"
33
+ spec.add_dependency "grape-entity"
33
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo_http_sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - André Aizim Kelmanson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-26 00:00:00.000000000 Z
11
+ date: 2017-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: grape-entity
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
139
153
  description: Synchronizes HTTP services with MongoDB
140
154
  email:
141
155
  - akelmanson@gmail.com
@@ -155,6 +169,8 @@ files:
155
169
  - bin/console
156
170
  - bin/setup
157
171
  - lib/mongo_http_sync.rb
172
+ - lib/mongo_http_sync/entity.rb
173
+ - lib/mongo_http_sync/exportable_document.rb
158
174
  - lib/mongo_http_sync/importer.rb
159
175
  - lib/mongo_http_sync/mongo_importer.rb
160
176
  - lib/mongo_http_sync/mongoid_importer.rb
@@ -181,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
197
  version: '0'
182
198
  requirements: []
183
199
  rubyforge_project:
184
- rubygems_version: 2.5.1
200
+ rubygems_version: 2.4.8
185
201
  signing_key:
186
202
  specification_version: 4
187
203
  summary: MongoDB HTTP Synchronizer