-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
58 lines (53 loc) · 1.37 KB
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
require 'sinatra'
require 'json'
require_relative 'initializer/mongoid'
require_relative 'spec/hoge'
require_relative 'lib/delta_pack_builder'
get '/deltas/from::ust' do
content_type :json
{
"_id" => "8932-302023-320323-923332",
"model1" => [
{
"deviceToken" => "huga",
"localTimestamp" => 240661481,
"isDeleted" => false,
"gid" => "9EA989A1-B5B6-481E-8D75-23533EC9ABA8"
},
{
"deviceToken" => "huga",
"localTimestamp" => 240661482,
"isDeleted" => false,
"gid" => "9EA989A1-B5B6-4S1E-8D75-23533EC9ABA8"
},
{
"deviceToken" => "huga",
"localTimestamp" => 220661482,
"isDeleted" => false,
"gid" => "9EA989A1-B5B6-481E-8D72-23533EC9ABA8"
},
{
"deviceToken" => "huga",
"localTimestamp" => 12344,
"isDeleted" => false,
"gid" => "9EA989A1-B5B6-481E-8D7A-23533EC9ABA8"
}
]
}.to_json
builder = DeltaPackBuilder.new
builder.push_documents Hoge.all
builder.json
end
post '/deltas' do
params.each do |model_name, deltas|
if model_name == "_id"
puts "received DeltaPack^#{deltas}"
next
end
deltas.each do |delta|
puts "save #{delta} in #{model_name}"
end
end
content_type :json
{result: 200}.to_json
end