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.
Files changed (43) hide show
  1. data/README.md +5 -20
  2. data/Rakefile +7 -5
  3. data/bench/lib/bench.rb +1 -2
  4. data/doc/protocol.html +154 -80
  5. data/lib/rhosync/client_sync.rb +7 -6
  6. data/lib/rhosync/console/app/routes/auth.rb +0 -2
  7. data/lib/rhosync/console/app/routes/client.rb +4 -5
  8. data/lib/rhosync/console/app/routes/docs.rb +25 -7
  9. data/lib/rhosync/console/app/routes/home.rb +1 -1
  10. data/lib/rhosync/console/app/routes/user.rb +6 -7
  11. data/lib/rhosync/console/app/views/doc.erb +3 -51
  12. data/lib/rhosync/console/app/views/docdata.erb +28 -0
  13. data/lib/rhosync/console/app/views/docs.erb +2 -1
  14. data/lib/rhosync/console/app/views/index.erb +1 -1
  15. data/lib/rhosync/console/app/views/select_doc.erb +19 -0
  16. data/lib/rhosync/console/app/views/upload_doc.erb +23 -0
  17. data/lib/rhosync/console/rhosync_api.rb +31 -30
  18. data/lib/rhosync/license.rb +1 -1
  19. data/lib/rhosync/tasks.rb +26 -12
  20. data/lib/rhosync/version.rb +1 -1
  21. data/spec/api/create_client_spec.rb +1 -1
  22. data/spec/api/create_user_spec.rb +1 -1
  23. data/spec/api/delete_client_spec.rb +1 -1
  24. data/spec/api/delete_user_spec.rb +2 -2
  25. data/spec/api/get_api_token_spec.rb +1 -2
  26. data/spec/api/get_source_params_spec.rb +1 -1
  27. data/spec/api/list_client_docs_spec.rb +1 -1
  28. data/spec/api/list_clients_spec.rb +2 -2
  29. data/spec/api/list_source_docs_spec.rb +2 -2
  30. data/spec/api/list_sources_spec.rb +4 -4
  31. data/spec/api/list_users_spec.rb +3 -3
  32. data/spec/api/set_refresh_time_spec.rb +8 -8
  33. data/spec/api/upload_file_spec.rb +2 -2
  34. data/spec/apps/rhotestapp/sources/simple_adapter.rb +3 -2
  35. data/spec/client_spec.rb +1 -1
  36. data/spec/client_sync_spec.rb +45 -17
  37. data/spec/doc/doc_spec.rb +21 -7
  38. data/spec/license_spec.rb +1 -1
  39. data/spec/perf/bulk_data_perf_spec.rb +0 -1
  40. data/spec/perf/perf_spec_helper.rb +2 -0
  41. data/spec/perf/store_perf_spec.rb +0 -1
  42. data/spec/server/server_spec.rb +8 -10
  43. metadata +39 -37
@@ -34,8 +34,8 @@ module Rhosync
34
34
 
35
35
  def search(params)
36
36
  res = []
37
- return _resend_search_result(params[:search_token]) if params[:search_token] and params[:resend]
38
- _ack_search(params[:search_token]) if params[:search_token]
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(search_token)
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
- {'search_token' => search_token},
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[:app_name],session[:token],params[:device_id])
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[:app_name],session[:token],:all)
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[:app_name],session[:token],
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(session[:server],
6
- session[:app_name],session[:token],params[:source_id])
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[:app_name],session[:token],params[:source_id],params[:user_id])
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 = url("doc?#{doc_params}&dbkey=#{CGI.escape(params[:dbkey])}")
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 = url("doc?#{doc_params}&dbkey=#{params[:doc]}")
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[:app_name],session[:token],:app)
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[:app_name],session[:token],params[:login],params[:password])
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[:app_name],session[:token],params[:user_id])
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[:app_name],session[:token],:user)
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[:app_name],session[:token],params[:user_id])
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[:app_name],session[:token],:all)
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
- <h2>Upload document</h2>
7
- <div class='panel'>
8
- <form action='<%=url("doc/upload?#{@back_params}")%>' method='post' enctype="multipart/form-data">
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>
@@ -26,4 +26,5 @@
26
26
  </tr>
27
27
  <%end%>
28
28
  </table>
29
- </div>
29
+ </div>
30
+ <br/>
@@ -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,app_name,token)
12
+ def list_users(server,token)
13
13
  JSON.parse(RestClient.post("#{server}/api/list_users",
14
- {:app_name => app_name, :api_token => token}.to_json, :content_type => :json).body)
14
+ {:api_token => token}.to_json, :content_type => :json).body)
15
15
  end
16
16
 
17
- def create_user(server,app_name,token,login,password)
17
+ def create_user(server,token,login,password)
18
18
  RestClient.post("#{server}/api/create_user",
19
- {:app_name => app_name, :api_token => token,
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,app_name,token,user_id)
23
+ def delete_user(server,token,user_id)
25
24
  RestClient.post("#{server}/api/delete_user",
26
- {:app_name => app_name, :api_token => token, :user_id => user_id}.to_json,
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,app_name,token,user_id)
31
- JSON.parse(RestClient.post("#{server}/api/list_clients", {:app_name => app_name,
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,app_name,token,user_id)
34
+ def create_client(server,token,user_id)
36
35
  RestClient.post("#{server}/api/create_client",
37
- {:app_name => app_name, :api_token => token, :user_id => user_id}.to_json,
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,app_name,token,user_id,client_id)
40
+ def delete_client(server,token,user_id,client_id)
42
41
  RestClient.post("#{server}/api/delete_client",
43
- {:app_name => app_name, :api_token => token, :user_id => user_id,
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,app_name,token,client_id)
48
- JSON.parse(RestClient.post("#{server}/api/get_client_params", {:app_name => app_name,
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,app_name,token,partition='all')
53
- JSON.parse(RestClient.post("#{server}/api/list_sources", {:app_name => app_name,
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,app_name,token,source_id)
58
- JSON.parse(RestClient.post("#{server}/api/get_source_params", {:app_name => app_name,
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,app_name,token,source_id,user_id='*')
63
- JSON.parse(RestClient.post("#{server}/api/list_source_docs", {:app_name => app_name,
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,app_name,token,source_id,client_id)
68
- JSON.parse(RestClient.post("#{server}/api/list_client_docs", {:app_name => app_name,
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)
@@ -34,7 +34,7 @@ module Rhosync
34
34
  end
35
35
  end
36
36
  unless incr
37
- msg = "WARNING: Maximum # of clients exceeded for this license."
37
+ msg = "WARNING: Maximum # of devices exceeded for this license."
38
38
  log msg; raise LicenseSeatsExceededException.new(msg)
39
39
  end
40
40
  end
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
- desc "Reset the rhosync database (you will need to run rhosync:get_api_token afterwards)"
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
- puts 'Detach with Ctrl+\ Re-attach with rake rhosync:attach'
135
- sleep 1
136
- command = "dtach -A #{rhosync_socket} rackup config.ru -P #{rhosync_pid}"
137
- sh command
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
 
@@ -1,3 +1,3 @@
1
1
  module Rhosync
2
- VERSION = '2.0.0.beta1'
2
+ VERSION = '2.0.0.beta2'
3
3
  end
@@ -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", {:app_name => @test_app_name, :api_token => @api_token, :user_id => @u_fields[:login]}
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 = {:app_name => @test_app_name, :api_token => @api_token,
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", {:app_name => @test_app_name, :api_token => @api_token,
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 = {:app_name => @test_app_name, :api_token => @api_token,
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", {:app_name => @test_app_name, :api_token => @api_token,
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 = {:app_name => @test_app_name, :attributes =>
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", {:app_name => @test_app_name, :api_token => @api_token, :source_id =>"SampleAdapter"}
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", {:app_name => @test_app_name, :api_token => @api_token,
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",