-
Notifications
You must be signed in to change notification settings - Fork 2
/
sync.rb
53 lines (41 loc) · 995 Bytes
/
sync.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
#!/env/bin/ruby
# encoding: utf-8
require File.dirname(__FILE__) + '/comm.rb'
require 'net/http'
class MmrzSync
def urlencode params
URI.escape(params.collect{|k, v| "#{k}=#{v}"}.join('&'))
end
def version_to_int ver
ver.gsub(/[^\d]/, "").to_i
end
def get_remote_version
begin
uri = URI "#{COMM::SERVERADDR}/version_info"
rec = JSON.parse Net::HTTP.get(uri)
return rec['version_info']['GUI']
rescue
return nil
end
end
def get_word_book username, password
params = {
'username' => username,
'password' => password,
}
uri = URI("#{COMM::SERVERADDR}/download_wordbook/?" + urlencode(params))
received = JSON.parse Net::HTTP.get(uri)
verified = received['verified']
if not verified
return false
end
rows = received['wordbook']
dbMgr = MmrzDBManager.new
dbMgr.pruneDB
rows.each do |row|
dbMgr.insertDB row
end
dbMgr.closeDB
return true
end
end