rhosync 2.0.0.beta1 → 2.0.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +5 -20
- data/Rakefile +7 -5
- data/bench/lib/bench.rb +1 -2
- data/doc/protocol.html +154 -80
- data/lib/rhosync/client_sync.rb +7 -6
- data/lib/rhosync/console/app/routes/auth.rb +0 -2
- data/lib/rhosync/console/app/routes/client.rb +4 -5
- data/lib/rhosync/console/app/routes/docs.rb +25 -7
- data/lib/rhosync/console/app/routes/home.rb +1 -1
- data/lib/rhosync/console/app/routes/user.rb +6 -7
- data/lib/rhosync/console/app/views/doc.erb +3 -51
- data/lib/rhosync/console/app/views/docdata.erb +28 -0
- data/lib/rhosync/console/app/views/docs.erb +2 -1
- data/lib/rhosync/console/app/views/index.erb +1 -1
- data/lib/rhosync/console/app/views/select_doc.erb +19 -0
- data/lib/rhosync/console/app/views/upload_doc.erb +23 -0
- data/lib/rhosync/console/rhosync_api.rb +31 -30
- data/lib/rhosync/license.rb +1 -1
- data/lib/rhosync/tasks.rb +26 -12
- data/lib/rhosync/version.rb +1 -1
- data/spec/api/create_client_spec.rb +1 -1
- data/spec/api/create_user_spec.rb +1 -1
- data/spec/api/delete_client_spec.rb +1 -1
- data/spec/api/delete_user_spec.rb +2 -2
- data/spec/api/get_api_token_spec.rb +1 -2
- data/spec/api/get_source_params_spec.rb +1 -1
- data/spec/api/list_client_docs_spec.rb +1 -1
- data/spec/api/list_clients_spec.rb +2 -2
- data/spec/api/list_source_docs_spec.rb +2 -2
- data/spec/api/list_sources_spec.rb +4 -4
- data/spec/api/list_users_spec.rb +3 -3
- data/spec/api/set_refresh_time_spec.rb +8 -8
- data/spec/api/upload_file_spec.rb +2 -2
- data/spec/apps/rhotestapp/sources/simple_adapter.rb +3 -2
- data/spec/client_spec.rb +1 -1
- data/spec/client_sync_spec.rb +45 -17
- data/spec/doc/doc_spec.rb +21 -7
- data/spec/license_spec.rb +1 -1
- data/spec/perf/bulk_data_perf_spec.rb +0 -1
- data/spec/perf/perf_spec_helper.rb +2 -0
- data/spec/perf/store_perf_spec.rb +0 -1
- data/spec/server/server_spec.rb +8 -10
- metadata +39 -37
data/lib/rhosync/client_sync.rb
CHANGED
@@ -34,8 +34,8 @@ module Rhosync
|
|
34
34
|
|
35
35
|
def search(params)
|
36
36
|
res = []
|
37
|
-
return _resend_search_result
|
38
|
-
_ack_search(params[:
|
37
|
+
return _resend_search_result if params[:token] and params[:resend]
|
38
|
+
_ack_search(params[:token]) if params[:token]
|
39
39
|
res = _do_search(params[:search]) if params[:search]
|
40
40
|
res
|
41
41
|
end
|
@@ -158,10 +158,11 @@ module Rhosync
|
|
158
158
|
return [] unless params[:sources]
|
159
159
|
res = []
|
160
160
|
params[:sources].each do |source|
|
161
|
-
s = Source.load(source,{:app_id => client.app_id,
|
161
|
+
s = Source.load(source['name'],{:app_id => client.app_id,
|
162
162
|
:user_id => client.user_id})
|
163
|
-
client.source_name = source
|
163
|
+
client.source_name = source['name']
|
164
164
|
cs = ClientSync.new(s,client,params[:p_size])
|
165
|
+
params[:token] = source['token'] if source['token']
|
165
166
|
search_res = cs.search(params)
|
166
167
|
res << search_res if search_res
|
167
168
|
end
|
@@ -193,7 +194,7 @@ module Rhosync
|
|
193
194
|
end
|
194
195
|
|
195
196
|
private
|
196
|
-
def _resend_search_result
|
197
|
+
def _resend_search_result
|
197
198
|
_format_search_result
|
198
199
|
end
|
199
200
|
|
@@ -221,7 +222,7 @@ module Rhosync
|
|
221
222
|
res,diffsize = compute_search
|
222
223
|
return [] if res.empty?
|
223
224
|
[ {'version'=>VERSION},
|
224
|
-
{'
|
225
|
+
{'token' => search_token},
|
225
226
|
{'source'=>@source.name},
|
226
227
|
{'count'=>res.size},
|
227
228
|
{'insert'=>res} ]
|
@@ -2,12 +2,10 @@ class RhosyncConsole::Server
|
|
2
2
|
post '/login' do
|
3
3
|
begin
|
4
4
|
session[:server] = params[:server]
|
5
|
-
session[:app_name] = APP_NAME
|
6
5
|
session[:login] = params[:login]
|
7
6
|
session[:errors] = nil
|
8
7
|
|
9
8
|
verify_presence_of :server, "Server is not provaided."
|
10
|
-
verify_presence_of :app_name, "Application name is not provaided."
|
11
9
|
verify_presence_of :login, "Login is not provaided."
|
12
10
|
|
13
11
|
unless session[:errors]
|
@@ -3,8 +3,7 @@ class RhosyncConsole::Server
|
|
3
3
|
get '/device/create' do
|
4
4
|
session[:errors] = nil
|
5
5
|
handle_api_error("Can't create new device") do
|
6
|
-
RhosyncApi::create_client(session[:server],
|
7
|
-
session[:app_name],session[:token],params[:user_id])
|
6
|
+
RhosyncApi::create_client(session[:server],session[:token],params[:user_id])
|
8
7
|
end
|
9
8
|
redirect url("/user?user_id=#{CGI.escape(params[:user_id])}"), 303
|
10
9
|
end
|
@@ -12,18 +11,18 @@ class RhosyncConsole::Server
|
|
12
11
|
get '/device' do
|
13
12
|
@attributes = []
|
14
13
|
handle_api_error("Can't load list of device attributes") do
|
15
|
-
@attributes = RhosyncApi::get_client_params(session[:server],session[:
|
14
|
+
@attributes = RhosyncApi::get_client_params(session[:server],session[:token],params[:device_id])
|
16
15
|
end
|
17
16
|
@sources = []
|
18
17
|
handle_api_error("Can't load list of sources") do
|
19
|
-
@sources = RhosyncApi::list_sources(session[:server],session[:
|
18
|
+
@sources = RhosyncApi::list_sources(session[:server],session[:token],:all)
|
20
19
|
end
|
21
20
|
erb :client
|
22
21
|
end
|
23
22
|
|
24
23
|
get '/device/delete' do
|
25
24
|
handle_api_error("Can't delete device #{params[:device_id]}") do
|
26
|
-
RhosyncApi::delete_client(session[:server],session[:
|
25
|
+
RhosyncApi::delete_client(session[:server],session[:token],
|
27
26
|
params[:user_id],params[:device_id])
|
28
27
|
end
|
29
28
|
redirect url(session[:errors] ? "/device?user_id=#{CGI.escape(params[:user_id])}&device_id=#{CGI.escape(params[:device_id])}" :
|
@@ -2,8 +2,8 @@ class RhosyncConsole::Server
|
|
2
2
|
get '/docs' do
|
3
3
|
@src_params = []
|
4
4
|
handle_api_error("Can't load list of source attributes") do
|
5
|
-
@src_params = RhosyncApi::get_source_params(
|
6
|
-
session[:
|
5
|
+
@src_params = RhosyncApi::get_source_params(
|
6
|
+
session[:server],session[:token],params[:source_id])
|
7
7
|
end
|
8
8
|
@docs = []
|
9
9
|
@docs_name = ''
|
@@ -13,8 +13,7 @@ class RhosyncConsole::Server
|
|
13
13
|
if params[:device_id]
|
14
14
|
@docs_name = "device #{params[:device_id]}"
|
15
15
|
@back_href = url("device?user_id=#{CGI.escape(params[:user_id])}&device_id=#{CGI.escape(params[:device_id])}")
|
16
|
-
@docs = RhosyncApi::list_client_docs(session[:server],
|
17
|
-
session[:app_name],session[:token],params[:source_id],params[:device_id])
|
16
|
+
@docs = RhosyncApi::list_client_docs(session[:server],session[:token],params[:source_id],params[:device_id])
|
18
17
|
else
|
19
18
|
if params[:user_id]=='*'
|
20
19
|
@docs_name = "app partition"
|
@@ -24,12 +23,27 @@ class RhosyncConsole::Server
|
|
24
23
|
@back_href = url("user?user_id=#{CGI.escape(params[:user_id])}")
|
25
24
|
end
|
26
25
|
@docs = RhosyncApi::list_source_docs(session[:server],
|
27
|
-
session[:
|
26
|
+
session[:token],params[:source_id],params[:user_id])
|
28
27
|
end
|
29
28
|
end
|
30
29
|
erb :docs
|
31
30
|
end
|
32
31
|
|
32
|
+
get '/doc/select' do
|
33
|
+
if params[:dbkey].nil?
|
34
|
+
@dbkey = ''
|
35
|
+
@data = {}
|
36
|
+
else
|
37
|
+
@dbkey = params[:dbkey]
|
38
|
+
@is_string = doc_is_string
|
39
|
+
handle_api_error("Can't load document") do
|
40
|
+
@data = RhosyncApi::get_db_doc(session[:server],
|
41
|
+
session[:token],params[:dbkey],@is_string ? :string : '')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
erb :select_doc
|
45
|
+
end
|
46
|
+
|
33
47
|
get '/doc' do
|
34
48
|
@data = {}
|
35
49
|
@is_string = doc_is_string
|
@@ -51,7 +65,9 @@ class RhosyncConsole::Server
|
|
51
65
|
end
|
52
66
|
@result_name = "Clear result"
|
53
67
|
@status = "Successfully cleared: [#{CGI.unescape(params[:dbkey])}]"
|
54
|
-
@back_href =
|
68
|
+
@back_href = params[:user_id] ?
|
69
|
+
url("doc?#{doc_params}&dbkey=#{CGI.escape(params[:dbkey])}") :
|
70
|
+
url("doc/select?dbkey=#{CGI.escape(params[:dbkey])}")
|
55
71
|
erb :result
|
56
72
|
end
|
57
73
|
|
@@ -77,7 +93,9 @@ class RhosyncConsole::Server
|
|
77
93
|
end
|
78
94
|
@result_name = "Upload result"
|
79
95
|
@status = "Successfully uploadad data to: [#{CGI.unescape(params[:doc])}]"
|
80
|
-
@back_href =
|
96
|
+
@back_href = params[:user_id] ?
|
97
|
+
url("doc?#{doc_params}&dbkey=#{params[:doc]}") :
|
98
|
+
url("doc/select?dbkey=#{params[:doc]}")
|
81
99
|
erb :result
|
82
100
|
end
|
83
101
|
|
@@ -7,7 +7,7 @@ class RhosyncConsole::Server
|
|
7
7
|
end
|
8
8
|
@sources = nil
|
9
9
|
handle_api_error("Can't load list of application partition sources") do
|
10
|
-
@sources = RhosyncApi::list_sources(session[:server],session[:
|
10
|
+
@sources = RhosyncApi::list_sources(session[:server],session[:token],:app)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
erb :index
|
@@ -2,8 +2,7 @@ class RhosyncConsole::Server
|
|
2
2
|
get '/users' do
|
3
3
|
@users = []
|
4
4
|
handle_api_error("Can't load list of users") do
|
5
|
-
@users = RhosyncApi::list_users(
|
6
|
-
session[:server],session[:app_name],session[:token])
|
5
|
+
@users = RhosyncApi::list_users(session[:server],session[:token])
|
7
6
|
end
|
8
7
|
erb :users
|
9
8
|
end
|
@@ -18,7 +17,7 @@ class RhosyncConsole::Server
|
|
18
17
|
unless session[:errors]
|
19
18
|
handle_api_error("Can't create new user") do
|
20
19
|
RhosyncApi::create_user(session[:server],
|
21
|
-
session[:
|
20
|
+
session[:token],params[:login],params[:password])
|
22
21
|
end
|
23
22
|
end
|
24
23
|
redirect url(session[:errors] ? '/user/new' : '/users'), 303
|
@@ -28,18 +27,18 @@ class RhosyncConsole::Server
|
|
28
27
|
@devices = []
|
29
28
|
handle_api_error("Can't load list of devices") do
|
30
29
|
@devices = RhosyncApi::list_clients(
|
31
|
-
session[:server],session[:
|
30
|
+
session[:server],session[:token],params[:user_id])
|
32
31
|
end
|
33
32
|
@sources = []
|
34
33
|
handle_api_error("Can't load list of user partition sources") do
|
35
|
-
@sources = RhosyncApi::list_sources(session[:server],session[:
|
34
|
+
@sources = RhosyncApi::list_sources(session[:server],session[:token],:user)
|
36
35
|
end
|
37
36
|
erb :user
|
38
37
|
end
|
39
38
|
|
40
39
|
get '/user/delete' do
|
41
40
|
handle_api_error("Can't delete user #{params[:user_id]}") do
|
42
|
-
RhosyncApi::delete_user(session[:server],session[:
|
41
|
+
RhosyncApi::delete_user(session[:server],session[:token],params[:user_id])
|
43
42
|
end
|
44
43
|
redirect url(session[:errors] ? "/user?user_id=#{CGI.escape(params[:user_id])}" : '/users'), 303
|
45
44
|
end
|
@@ -47,7 +46,7 @@ class RhosyncConsole::Server
|
|
47
46
|
get '/user/ping' do
|
48
47
|
@sources = []
|
49
48
|
handle_api_error("Can't load list of user partition sources") do
|
50
|
-
@sources = RhosyncApi::list_sources(session[:server],session[:
|
49
|
+
@sources = RhosyncApi::list_sources(session[:server],session[:token],:all)
|
51
50
|
end
|
52
51
|
erb :ping
|
53
52
|
end
|
@@ -3,54 +3,6 @@
|
|
3
3
|
<div class='panel'>
|
4
4
|
<a href='<%= @back_href%>' class='nav_button'>Back</a>
|
5
5
|
</div>
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
<input type='hidden' name='doc' value='<%= "#{CGI.escape(params[:dbkey])}"%>'/>
|
10
|
-
<table>
|
11
|
-
<%if @is_string%>
|
12
|
-
<tr>
|
13
|
-
<td>Token string:</td>
|
14
|
-
<td><input type='text' name='string' value=''/></td>
|
15
|
-
</tr>
|
16
|
-
<%else%>
|
17
|
-
<tr>
|
18
|
-
<td>Data (hash of hashes in json):</td>
|
19
|
-
<td><input type='file' name='file' value=''/></td>
|
20
|
-
</tr>
|
21
|
-
<%end%>
|
22
|
-
<tr>
|
23
|
-
<td></td>
|
24
|
-
<td><input type='submit' value='Submit'/></td>
|
25
|
-
</tr>
|
26
|
-
</table>
|
27
|
-
</form>
|
28
|
-
</div>
|
29
|
-
<h2>Data</h2>
|
30
|
-
<div class='panel'>
|
31
|
-
<%if @data.size > 0%>
|
32
|
-
<div class='panel'>
|
33
|
-
<a href='<%=url("doc/clear?#{@back_params}&dbkey=#{CGI.escape(params[:dbkey])}")%>' class='nav_button'>Clear document</a>
|
34
|
-
</div>
|
35
|
-
<%if @is_string%>
|
36
|
-
<p>[<%=@data%>]</p>
|
37
|
-
<%else%>
|
38
|
-
<table>
|
39
|
-
<%@data.each do |obj_id,obj|%>
|
40
|
-
<tr>
|
41
|
-
<td colspan=3>[<%=obj_id%>]</td>
|
42
|
-
</tr>
|
43
|
-
<%obj.each do |attrib,value|%>
|
44
|
-
<tr>
|
45
|
-
<td></td>
|
46
|
-
<td><%=attrib%>:</td>
|
47
|
-
<td><%=value%></td>
|
48
|
-
</tr>
|
49
|
-
<%end%>
|
50
|
-
<%end%>
|
51
|
-
</table>
|
52
|
-
<%end%>
|
53
|
-
<%else%>
|
54
|
-
<p>Document is empty</p>
|
55
|
-
<%end%>
|
56
|
-
</div>
|
6
|
+
<%= erb(:upload_doc, :layout => false) %>
|
7
|
+
<%= erb(:docdata, :layout => false) %>
|
8
|
+
<br/>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
<h2>Data</h2>
|
2
|
+
<div class='panel'>
|
3
|
+
<%if @data.size > 0%>
|
4
|
+
<div class='panel'>
|
5
|
+
<a href='<%=url("doc/clear?#{@back_params}&dbkey=#{CGI.escape(params[:dbkey])}")%>' class='nav_button'>Clear document</a>
|
6
|
+
</div>
|
7
|
+
<%if @is_string%>
|
8
|
+
<p>[<%=@data%>]</p>
|
9
|
+
<%else%>
|
10
|
+
<table>
|
11
|
+
<%@data.each do |obj_id,obj|%>
|
12
|
+
<tr>
|
13
|
+
<td colspan=3>[<%=obj_id%>]</td>
|
14
|
+
</tr>
|
15
|
+
<%obj.each do |attrib,value|%>
|
16
|
+
<tr>
|
17
|
+
<td></td>
|
18
|
+
<td><%=attrib%>:</td>
|
19
|
+
<td><%=value%></td>
|
20
|
+
</tr>
|
21
|
+
<%end%>
|
22
|
+
<%end%>
|
23
|
+
</table>
|
24
|
+
<%end%>
|
25
|
+
<%else%>
|
26
|
+
<p>Document is empty</p>
|
27
|
+
<%end%>
|
28
|
+
</div>
|
@@ -11,6 +11,7 @@
|
|
11
11
|
</div>
|
12
12
|
<div class='panel'>
|
13
13
|
<a href="<%=url('reset')%>" class='nav_button'>Reset</a>
|
14
|
+
<a href="<%=url('doc/select')%>" class='nav_button'>Show server document</a>
|
14
15
|
</div>
|
15
16
|
<div class='panel'>
|
16
17
|
<a href="<%=url('users')%>" class='nav_button'>Application users</a>
|
@@ -29,7 +30,6 @@
|
|
29
30
|
<h1>Login</h1>
|
30
31
|
<%=show_errors%>
|
31
32
|
<form action="<%=url('login')%>" method='POST'>
|
32
|
-
<input type="hidden" name='app_name' value='application'/>
|
33
33
|
<table>
|
34
34
|
<tr>
|
35
35
|
<td>Server:</td>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<h1>Document <%= @dbkey%></h1>
|
2
|
+
<%=show_errors%>
|
3
|
+
<div class='panel'>
|
4
|
+
<a href='<%= url('/')%>' class='nav_button'>Back</a>
|
5
|
+
</div>
|
6
|
+
<form action=<%= url('doc/select')%> method='GET'>
|
7
|
+
<table>
|
8
|
+
<tr>
|
9
|
+
<td>Doc DB key: </db>
|
10
|
+
<td><input name='dbkey' value='<%= @dbkey%>' size=64/></td>
|
11
|
+
</tr>
|
12
|
+
</table>
|
13
|
+
<input type='submit' value='Submit'>
|
14
|
+
</form>
|
15
|
+
<%if params[:dbkey]%>
|
16
|
+
<%= erb(:upload_doc, :layout => false) %>
|
17
|
+
<%end%>
|
18
|
+
<%= erb(:docdata, :layout => false) %>
|
19
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<h2>Upload document</h2>
|
2
|
+
<div class='panel'>
|
3
|
+
<form action='<%=url("doc/upload?#{@back_params}")%>' method='post' enctype="multipart/form-data">
|
4
|
+
<input type='hidden' name='doc' value='<%= "#{CGI.escape(params[:dbkey])}"%>'/>
|
5
|
+
<table>
|
6
|
+
<%if @is_string%>
|
7
|
+
<tr>
|
8
|
+
<td>Token string:</td>
|
9
|
+
<td><input type='text' name='string' value=''/></td>
|
10
|
+
</tr>
|
11
|
+
<%else%>
|
12
|
+
<tr>
|
13
|
+
<td>Data (hash of hashes in json):</td>
|
14
|
+
<td><input type='file' name='file' value=''/></td>
|
15
|
+
</tr>
|
16
|
+
<%end%>
|
17
|
+
<tr>
|
18
|
+
<td></td>
|
19
|
+
<td><input type='submit' value='Submit'/></td>
|
20
|
+
</tr>
|
21
|
+
</table>
|
22
|
+
</form>
|
23
|
+
</div>
|
@@ -9,72 +9,73 @@ module RhosyncApi
|
|
9
9
|
RestClient.post("#{server}/api/get_api_token",'',{:cookies => res.cookies})
|
10
10
|
end
|
11
11
|
|
12
|
-
def list_users(server,
|
12
|
+
def list_users(server,token)
|
13
13
|
JSON.parse(RestClient.post("#{server}/api/list_users",
|
14
|
-
{:
|
14
|
+
{:api_token => token}.to_json, :content_type => :json).body)
|
15
15
|
end
|
16
16
|
|
17
|
-
def create_user(server,
|
17
|
+
def create_user(server,token,login,password)
|
18
18
|
RestClient.post("#{server}/api/create_user",
|
19
|
-
{:
|
20
|
-
:attributes => {:login => login, :password => password}}.to_json,
|
19
|
+
{:api_token => token,:attributes => {:login => login, :password => password}}.to_json,
|
21
20
|
:content_type => :json)
|
22
21
|
end
|
23
22
|
|
24
|
-
def delete_user(server,
|
23
|
+
def delete_user(server,token,user_id)
|
25
24
|
RestClient.post("#{server}/api/delete_user",
|
26
|
-
{:
|
25
|
+
{:api_token => token, :user_id => user_id}.to_json,
|
27
26
|
:content_type => :json)
|
28
27
|
end
|
29
28
|
|
30
|
-
def list_clients(server,
|
31
|
-
JSON.parse(RestClient.post("#{server}/api/list_clients",
|
32
|
-
:api_token => token, :user_id => user_id}.to_json, :content_type => :json).body)
|
29
|
+
def list_clients(server,token,user_id)
|
30
|
+
JSON.parse(RestClient.post("#{server}/api/list_clients",
|
31
|
+
{:api_token => token, :user_id => user_id}.to_json, :content_type => :json).body)
|
33
32
|
end
|
34
33
|
|
35
|
-
def create_client(server,
|
34
|
+
def create_client(server,token,user_id)
|
36
35
|
RestClient.post("#{server}/api/create_client",
|
37
|
-
{:
|
36
|
+
{:api_token => token, :user_id => user_id}.to_json,
|
38
37
|
:content_type => :json).body
|
39
38
|
end
|
40
39
|
|
41
|
-
def delete_client(server,
|
40
|
+
def delete_client(server,token,user_id,client_id)
|
42
41
|
RestClient.post("#{server}/api/delete_client",
|
43
|
-
{:
|
42
|
+
{:api_token => token, :user_id => user_id,
|
44
43
|
:client_id => client_id}.to_json, :content_type => :json)
|
45
44
|
end
|
46
45
|
|
47
|
-
def get_client_params(server,
|
48
|
-
JSON.parse(RestClient.post("#{server}/api/get_client_params",
|
49
|
-
:api_token => token, :client_id => client_id}.to_json, :content_type => :json).body)
|
46
|
+
def get_client_params(server,token,client_id)
|
47
|
+
JSON.parse(RestClient.post("#{server}/api/get_client_params",
|
48
|
+
{:api_token => token, :client_id => client_id}.to_json, :content_type => :json).body)
|
50
49
|
end
|
51
50
|
|
52
|
-
def list_sources(server,
|
53
|
-
JSON.parse(RestClient.post("#{server}/api/list_sources",
|
54
|
-
:api_token => token, :partition_type => partition}.to_json, :content_type => :json).body)
|
51
|
+
def list_sources(server,token,partition='all')
|
52
|
+
JSON.parse(RestClient.post("#{server}/api/list_sources",
|
53
|
+
{:api_token => token, :partition_type => partition}.to_json, :content_type => :json).body)
|
55
54
|
end
|
56
55
|
|
57
|
-
def get_source_params(server,
|
58
|
-
JSON.parse(RestClient.post("#{server}/api/get_source_params",
|
59
|
-
:api_token => token, :source_id => source_id}.to_json, :content_type => :json).body)
|
56
|
+
def get_source_params(server,token,source_id)
|
57
|
+
JSON.parse(RestClient.post("#{server}/api/get_source_params",
|
58
|
+
{:api_token => token, :source_id => source_id}.to_json, :content_type => :json).body)
|
60
59
|
end
|
61
60
|
|
62
|
-
def list_source_docs(server,
|
63
|
-
JSON.parse(RestClient.post("#{server}/api/list_source_docs",
|
64
|
-
:api_token => token, :source_id => source_id, :user_id => user_id}.to_json, :content_type => :json).body)
|
61
|
+
def list_source_docs(server,token,source_id,user_id='*')
|
62
|
+
JSON.parse(RestClient.post("#{server}/api/list_source_docs",
|
63
|
+
{:api_token => token, :source_id => source_id, :user_id => user_id}.to_json, :content_type => :json).body)
|
65
64
|
end
|
66
65
|
|
67
|
-
def list_client_docs(server,
|
68
|
-
JSON.parse(RestClient.post("#{server}/api/list_client_docs",
|
69
|
-
:api_token => token, :source_id => source_id, :client_id => client_id}.to_json, :content_type => :json).body)
|
66
|
+
def list_client_docs(server,token,source_id,client_id)
|
67
|
+
JSON.parse(RestClient.post("#{server}/api/list_client_docs",
|
68
|
+
{:api_token => token, :source_id => source_id, :client_id => client_id}.to_json, :content_type => :json).body)
|
70
69
|
end
|
71
|
-
|
70
|
+
|
71
|
+
#TODO: figure out data_type programmatically
|
72
72
|
def get_db_doc(server,token,doc,data_type='')
|
73
73
|
res = RestClient.post("#{server}/api/get_db_doc",
|
74
74
|
{:api_token => token, :doc => doc, :data_type => data_type}.to_json, :content_type => :json).body
|
75
75
|
data_type=='' ? JSON.parse(res) : res
|
76
76
|
end
|
77
77
|
|
78
|
+
#TODO: figure out data_type programmatically
|
78
79
|
def set_db_doc(server,token,doc,data={},data_type='')
|
79
80
|
RestClient.post("#{server}/api/set_db_doc",
|
80
81
|
{:api_token => token, :doc => doc, :data => data, :data_type => data_type}.to_json, :content_type => :json)
|
data/lib/rhosync/license.rb
CHANGED
data/lib/rhosync/tasks.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'json'
|
2
|
-
require 'mechanize'
|
3
2
|
require 'zip/zip'
|
4
3
|
require 'uri'
|
5
4
|
require File.join(File.dirname(__FILE__),'console','rhosync_api')
|
@@ -47,6 +46,10 @@ module Rhosync
|
|
47
46
|
def rhosync_pid
|
48
47
|
"/tmp/rhosync.pid"
|
49
48
|
end
|
49
|
+
|
50
|
+
def windows?
|
51
|
+
RUBY_PLATFORM =~ /(win|w)32$/
|
52
|
+
end
|
50
53
|
end
|
51
54
|
end
|
52
55
|
|
@@ -62,13 +65,20 @@ namespace :rhosync do
|
|
62
65
|
$url = "#{$url}:#{uri.port}" if uri.port && uri.port != 80
|
63
66
|
$host = uri.host
|
64
67
|
$port = uri.port
|
65
|
-
$agent = Mechanize.new
|
66
68
|
$appname = $settings[env][:syncserver].split('/').last
|
67
69
|
$token_file = File.join(ENV['HOME'],'.rhosync_token')
|
68
70
|
$token = File.read($token_file) if File.exist?($token_file)
|
69
71
|
end
|
70
72
|
|
71
|
-
|
73
|
+
task :dtach_installed do
|
74
|
+
if !windows? and (`which dtach` == '')
|
75
|
+
puts "WARNING: dtach not installed or not on path, some tasks will not work!"
|
76
|
+
puts " Install with '[sudo] rake dtach:install'"
|
77
|
+
exit
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
desc "Reset the rhosync database (you will need to run rhosync:get_token afterwards)"
|
72
82
|
task :reset => :config do
|
73
83
|
RhosyncApi.reset($url,$token)
|
74
84
|
end
|
@@ -130,21 +140,25 @@ namespace :rhosync do
|
|
130
140
|
end
|
131
141
|
|
132
142
|
desc "Start rhosync server"
|
133
|
-
task :start do
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
143
|
+
task :start => :dtach_installed do
|
144
|
+
if windows?
|
145
|
+
puts 'Starting server in new window...'
|
146
|
+
system('start cmd.exe /c rackup config.ru')
|
147
|
+
else
|
148
|
+
puts 'Detach with Ctrl+\ Re-attach with rake rhosync:attach'
|
149
|
+
sleep 2
|
150
|
+
sh "dtach -A #{rhosync_socket} rackup config.ru -P #{rhosync_pid}"
|
151
|
+
end
|
138
152
|
end
|
139
153
|
|
140
154
|
desc "Stop rhosync server"
|
141
|
-
task :stop do
|
142
|
-
sh "cat #{rhosync_pid} | xargs kill -3"
|
155
|
+
task :stop => :dtach_installed do
|
156
|
+
sh "cat #{rhosync_pid} | xargs kill -3" unless windows?
|
143
157
|
end
|
144
158
|
|
145
159
|
desc "Attach to rhosync console"
|
146
|
-
task :attach do
|
147
|
-
sh "dtach -a #{rhosync_socket}"
|
160
|
+
task :attach => :dtach_installed do
|
161
|
+
sh "dtach -a #{rhosync_socket}" unless windows?
|
148
162
|
end
|
149
163
|
end
|
150
164
|
|
data/lib/rhosync/version.rb
CHANGED
@@ -4,7 +4,7 @@ describe "RhosyncApiCreateUser" do
|
|
4
4
|
it_should_behave_like "ApiHelper"
|
5
5
|
|
6
6
|
it "should create client for a user" do
|
7
|
-
post "/api/create_client", {:
|
7
|
+
post "/api/create_client", {:api_token => @api_token, :user_id => @u_fields[:login]}
|
8
8
|
last_response.should be_ok
|
9
9
|
clients = User.load(@u_fields[:login]).clients.members
|
10
10
|
clients.size.should == 2
|
@@ -4,7 +4,7 @@ describe "RhosyncApiCreateUser" do
|
|
4
4
|
it_should_behave_like "ApiHelper"
|
5
5
|
|
6
6
|
it "should create user as admin" do
|
7
|
-
params = {:
|
7
|
+
params = {:api_token => @api_token,
|
8
8
|
:attributes => {:login => 'testuser1', :password => 'testpass1'}}
|
9
9
|
post "/api/create_user", params
|
10
10
|
last_response.should be_ok
|
@@ -4,7 +4,7 @@ describe "RhosyncApiDeleteUser" do
|
|
4
4
|
it_should_behave_like "ApiHelper"
|
5
5
|
|
6
6
|
it "should delete client" do
|
7
|
-
post "/api/delete_client", {:
|
7
|
+
post "/api/delete_client", {:api_token => @api_token,
|
8
8
|
:user_id => @u_fields[:login], :client_id => @c.id}
|
9
9
|
last_response.should be_ok
|
10
10
|
Client.is_exist?(@c.id).should == false
|
@@ -4,12 +4,12 @@ describe "RhosyncApiDeleteUser" do
|
|
4
4
|
it_should_behave_like "ApiHelper"
|
5
5
|
|
6
6
|
it "should delete user" do
|
7
|
-
params = {:
|
7
|
+
params = {:api_token => @api_token,
|
8
8
|
:attributes => {:login => 'testuser1', :password => 'testpass1'}}
|
9
9
|
post "/api/create_user", params
|
10
10
|
last_response.should be_ok
|
11
11
|
User.is_exist?(params[:attributes][:login]).should == true
|
12
|
-
post "/api/delete_user", {:
|
12
|
+
post "/api/delete_user", {:api_token => @api_token,
|
13
13
|
:user_id => params[:attributes][:login]}
|
14
14
|
last_response.should be_ok
|
15
15
|
User.is_exist?(params[:attributes][:login]).should == false
|
@@ -17,8 +17,7 @@ describe "RhosyncApiGetApiToken" do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should return 422 if no token provided" do
|
20
|
-
params = {:
|
21
|
-
{:login => 'testuser1', :password => 'testpass1'}}
|
20
|
+
params = {:attributes => {:login => 'testuser1', :password => 'testpass1'}}
|
22
21
|
post "/api/create_user", params
|
23
22
|
last_response.status.should == 422
|
24
23
|
end
|
@@ -4,7 +4,7 @@ describe "RhosyncApiGetSourceParams" do
|
|
4
4
|
it_should_behave_like "ApiHelper"
|
5
5
|
|
6
6
|
it "should list source attributes" do
|
7
|
-
post "/api/get_source_params", {:
|
7
|
+
post "/api/get_source_params", {:api_token => @api_token, :source_id =>"SampleAdapter"}
|
8
8
|
JSON.parse(last_response.body).should == [
|
9
9
|
{"name"=>"rho__id", "value"=>"SampleAdapter", "type"=>"string"},
|
10
10
|
{"name"=>"source_id", "value"=>nil, "type"=>"integer"},
|
@@ -4,7 +4,7 @@ describe "RhosyncApiListClientDocs" do
|
|
4
4
|
it_should_behave_like "ApiHelper"
|
5
5
|
|
6
6
|
it "should list client documents" do
|
7
|
-
post "/api/list_client_docs", {:
|
7
|
+
post "/api/list_client_docs", {:api_token => @api_token,
|
8
8
|
:source_id => "SimpleAdapter", :client_id => @c.id}
|
9
9
|
JSON.parse(last_response.body).should == {
|
10
10
|
"cd"=>"client:application:testuser:#{@c.id}:SimpleAdapter:cd",
|