rhoconnect 3.2.1 → 3.3.1.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (221) hide show
  1. data/CHANGELOG.md +24 -5
  2. data/Gemfile +2 -2
  3. data/Gemfile.lock +20 -20
  4. data/bench/benchapp/Gemfile +17 -20
  5. data/bench/benchapp/config.ru +2 -2
  6. data/bench/benchapp/settings/settings.yml +3 -3
  7. data/bench/blobapp/Gemfile +16 -13
  8. data/bench/blobapp/config.ru +2 -2
  9. data/bench/blobapp/settings/settings.yml +5 -3
  10. data/bench/lib/bench.rb +35 -32
  11. data/bench/lib/bench/session.rb +9 -1
  12. data/bench/scripts/blob_cud_script.rb +13 -17
  13. data/bench/scripts/cud_script.rb +11 -12
  14. data/bench/scripts/helpers.rb +5 -7
  15. data/bench/scripts/query_md_script.rb +18 -12
  16. data/bench/scripts/query_only_script.rb +19 -11
  17. data/bench/scripts/query_script.rb +17 -13
  18. data/bench/scripts/test_query_script.rb +46 -17
  19. data/bench/scripts/test_source_script.rb +7 -7
  20. data/commands/commands/dtach_commands/dtach_install.rb +44 -16
  21. data/commands/commands/rhoconnect/spec.rb +13 -9
  22. data/commands/commands/rhoconnect/version.rb +6 -0
  23. data/commands/execute.rb +10 -6
  24. data/doc/deploying.txt +75 -13
  25. data/doc/install.txt +3 -3
  26. data/doc/push-client-setup.txt +1 -1
  27. data/doc/rest-api.txt +4 -23
  28. data/doc/rhoconnect-redis-stack.txt +26 -7
  29. data/doc/settings.txt +9 -3
  30. data/examples/simple/Gemfile +3 -1
  31. data/examples/simple/application.rb +5 -0
  32. data/examples/simple/config.ru +3 -2
  33. data/examples/simple/my_server.rb +14 -0
  34. data/examples/simple/settings/settings.yml +1 -0
  35. data/generators/templates/application/Gemfile +4 -4
  36. data/generators/templates/application/application.rb +4 -0
  37. data/generators/templates/application/settings/settings.yml +4 -1
  38. data/installer/unix-like/create_texts.rb +39 -1
  39. data/installer/unix-like/rho_connect_install_constants.rb +1 -1
  40. data/installer/utils/package_upload/repos.rake +7 -5
  41. data/lib/rhoconnect.rb +3 -2
  42. data/lib/rhoconnect/api/app/ans_login.rb +3 -0
  43. data/lib/rhoconnect/api/app/bulk_data.rb +6 -0
  44. data/lib/rhoconnect/api/{source → app}/fast_delete.rb +1 -1
  45. data/lib/rhoconnect/api/{source → app}/fast_insert.rb +2 -2
  46. data/lib/rhoconnect/api/{source → app}/fast_update.rb +2 -2
  47. data/lib/rhoconnect/api/app/login.rb +5 -0
  48. data/lib/rhoconnect/api/{source → app}/push_deletes.rb +1 -1
  49. data/lib/rhoconnect/api/{source → app}/push_objects.rb +1 -1
  50. data/lib/rhoconnect/api/app/query.rb +4 -0
  51. data/lib/rhoconnect/api/app/queue_updates.rb +94 -0
  52. data/lib/rhoconnect/api/app/search.rb +4 -0
  53. data/lib/rhoconnect/api/client/client_get_db_doc.rb +5 -0
  54. data/lib/rhoconnect/api/client/client_set_db_doc.rb +8 -0
  55. data/lib/rhoconnect/api/client/create.rb +7 -0
  56. data/lib/rhoconnect/api/client/get_client_params.rb +2 -1
  57. data/lib/rhoconnect/api/client/list_client_docs.rb +2 -1
  58. data/lib/rhoconnect/api/client/register.rb +12 -0
  59. data/lib/rhoconnect/api/client/reset.rb +5 -0
  60. data/lib/rhoconnect/api/{source → readstate}/set_refresh_time.rb +2 -1
  61. data/lib/rhoconnect/api/source/get_source_params.rb +3 -2
  62. data/lib/rhoconnect/api/source/list_sources.rb +2 -1
  63. data/lib/rhoconnect/api/source/update_source_params.rb +3 -3
  64. data/lib/rhoconnect/api/store/get_db_doc.rb +4 -0
  65. data/lib/rhoconnect/api/store/set_db_doc.rb +7 -0
  66. data/lib/rhoconnect/api/system/get_adapter.rb +4 -0
  67. data/lib/rhoconnect/api/{admin → system}/get_license_info.rb +2 -1
  68. data/lib/rhoconnect/api/system/login.rb +15 -0
  69. data/lib/rhoconnect/api/{admin → system}/reset.rb +3 -2
  70. data/lib/rhoconnect/api/system/save_adapter.rb +4 -0
  71. data/lib/rhoconnect/api/{admin → system}/stats.rb +2 -1
  72. data/lib/rhoconnect/api/user/create_user.rb +2 -2
  73. data/lib/rhoconnect/api/user/delete_client.rb +6 -0
  74. data/lib/rhoconnect/api/user/delete_user.rb +2 -1
  75. data/lib/rhoconnect/api/user/list_clients.rb +4 -0
  76. data/lib/rhoconnect/api/user/list_source_docs.rb +11 -0
  77. data/lib/rhoconnect/api/user/list_users.rb +1 -1
  78. data/lib/rhoconnect/api/user/ping.rb +7 -0
  79. data/lib/rhoconnect/api/user/show_user.rb +3 -0
  80. data/lib/rhoconnect/api/user/update_user.rb +3 -2
  81. data/lib/rhoconnect/api/user/user_get_db_doc.rb +5 -0
  82. data/lib/rhoconnect/api/user/user_set_db_doc.rb +10 -0
  83. data/lib/rhoconnect/app.rb +12 -2
  84. data/lib/rhoconnect/async.rb +6 -10
  85. data/lib/rhoconnect/bulk_data/bulk_data.rb +4 -4
  86. data/lib/rhoconnect/client.rb +10 -9
  87. data/lib/rhoconnect/client_sync.rb +24 -19
  88. data/lib/rhoconnect/document.rb +18 -4
  89. data/lib/rhoconnect/graph_helper.rb +4 -2
  90. data/lib/rhoconnect/jobs/bulk_data_job.rb +1 -1
  91. data/lib/rhoconnect/jobs/ping_job.rb +39 -29
  92. data/lib/rhoconnect/middleware/admin_user.rb +23 -0
  93. data/lib/rhoconnect/middleware/body_content_type_parser.rb +35 -0
  94. data/lib/rhoconnect/{cors.rb → middleware/cors.rb} +1 -0
  95. data/lib/rhoconnect/middleware/current_app.rb +16 -0
  96. data/lib/rhoconnect/middleware/current_request.rb +16 -0
  97. data/lib/rhoconnect/middleware/current_user.rb +17 -0
  98. data/lib/rhoconnect/middleware/helpers.rb +105 -0
  99. data/lib/rhoconnect/middleware/login_required.rb +22 -0
  100. data/lib/rhoconnect/{stats/middleware.rb → middleware/stats.rb} +5 -3
  101. data/lib/rhoconnect/middleware/x_domain_session_wrapper.rb +58 -0
  102. data/lib/rhoconnect/ping.rb +1 -0
  103. data/lib/rhoconnect/ping/apple.rb +18 -16
  104. data/lib/rhoconnect/ping/blackberry.rb +9 -9
  105. data/lib/rhoconnect/ping/rhoconnect_push.rb +45 -0
  106. data/lib/rhoconnect/server.rb +98 -91
  107. data/lib/rhoconnect/source.rb +5 -1
  108. data/lib/rhoconnect/source_sync.rb +4 -3
  109. data/lib/rhoconnect/stats/record.rb +15 -15
  110. data/lib/rhoconnect/store.rb +253 -75
  111. data/lib/rhoconnect/tasks.rb +3 -3
  112. data/lib/rhoconnect/version.rb +1 -1
  113. data/lib/rhoconnect/web-console/controllers/admins.js +1 -14
  114. data/lib/rhoconnect/web-console/models/adapter.js +18 -8
  115. data/lib/rhoconnect/web-console/models/client.js +15 -9
  116. data/lib/rhoconnect/web-console/models/doc.js +7 -11
  117. data/lib/rhoconnect/web-console/models/session.js +5 -2
  118. data/lib/rhoconnect/web-console/models/source.js +55 -36
  119. data/lib/rhoconnect/web-console/models/user.js +20 -11
  120. data/lib/rhoconnect/web-console/public/backbone.js +8 -2
  121. data/lib/rhoconnect/web-console/templates/index.erb +11 -5
  122. data/lib/rhoconnect/web-console/views/doc.js +6 -8
  123. data/lib/rhoconnect/web-console/views/edit_user.js +6 -3
  124. data/lib/rhoconnect/web-console/views/home.js +98 -25
  125. data/lib/rhoconnect/web-console/views/index.js +1 -1
  126. data/lib/rhoconnect/web-console/views/new_ping.js +6 -3
  127. data/lib/rhoconnect/web-console/views/server_doc.js +12 -4
  128. data/lib/rhoconnect/web-console/views/show_device.js +6 -3
  129. data/rhoconnect.gemspec +1 -2
  130. data/spec/api/{source → app}/fast_delete_spec.rb +4 -4
  131. data/spec/api/{source → app}/fast_insert_spec.rb +4 -4
  132. data/spec/api/{source → app}/fast_update_spec.rb +22 -6
  133. data/spec/api/{source → app}/push_deletes_spec.rb +2 -2
  134. data/spec/api/app/push_objects_spec.rb +45 -0
  135. data/spec/api/client/client_get_db_doc_spec.rb +31 -0
  136. data/spec/api/client/client_set_db_doc_spec.rb +14 -0
  137. data/spec/api/client/get_client_params_spec.rb +3 -2
  138. data/spec/api/client/list_client_docs_spec.rb +2 -2
  139. data/spec/api/{source → readstate}/set_refresh_time_spec.rb +15 -9
  140. data/spec/api/source/get_source_params_spec.rb +3 -2
  141. data/spec/api/source/list_sources_spec.rb +3 -9
  142. data/spec/api/source/update_source_params_spec.rb +4 -4
  143. data/spec/api/store/get_db_doc_spec.rb +32 -0
  144. data/spec/api/store/set_db_doc_spec.rb +43 -0
  145. data/spec/api/system/adapter_spec.rb +33 -0
  146. data/spec/api/{admin → system}/get_license_info_spec.rb +2 -5
  147. data/spec/api/{admin/get_api_token_spec.rb → system/login_spec.rb} +4 -11
  148. data/spec/api/{admin → system}/reset_spec.rb +2 -2
  149. data/spec/api/{admin → system}/stats_spec.rb +19 -13
  150. data/spec/api/user/create_user_spec.rb +15 -8
  151. data/spec/api/{client → user}/delete_client_spec.rb +3 -4
  152. data/spec/api/user/delete_user_spec.rb +33 -4
  153. data/spec/api/user/list_clients_spec.rb +30 -0
  154. data/spec/api/user/list_source_docs_spec.rb +35 -0
  155. data/spec/api/user/list_users_spec.rb +5 -6
  156. data/spec/api/{client → user}/ping_spec.rb +4 -6
  157. data/spec/api/user/show_user_spec.rb +14 -0
  158. data/spec/api/user/update_user_spec.rb +28 -10
  159. data/spec/api/user/user_get_db_doc_spec.rb +16 -0
  160. data/spec/api/user/user_set_db_doc_spec.rb +41 -0
  161. data/spec/apps/rhotestapp/application.rb +4 -0
  162. data/spec/apps/rhotestapp/settings/settings.yml +3 -1
  163. data/spec/bulk_data/bulk_data_spec.rb +13 -0
  164. data/spec/client_sync_spec.rb +41 -59
  165. data/spec/document_spec.rb +23 -0
  166. data/spec/javascripts/doc_view_spec.js +1 -1
  167. data/spec/javascripts/home_view_spec.js +10 -5
  168. data/spec/javascripts/index_view_spec.js +1 -1
  169. data/spec/jobs/ping_job_spec.rb +26 -0
  170. data/spec/perf/store_perf_spec.rb +1 -1
  171. data/spec/ping/android_spec.rb +0 -7
  172. data/spec/ping/apple_spec.rb +7 -0
  173. data/spec/ping/blackberry_spec.rb +10 -0
  174. data/spec/ping/rhoconnect_push_spec.rb +58 -0
  175. data/spec/server/cors_spec.rb +1 -1
  176. data/spec/server/server_spec.rb +152 -104
  177. data/spec/{stats/middleware_spec.rb → server/stats_spec.rb} +4 -5
  178. data/spec/server/x_domain_session_wrapper_spec.rb +3 -3
  179. data/spec/source_spec.rb +2 -2
  180. data/spec/source_sync_spec.rb +2 -0
  181. data/spec/spec_helper.rb +17 -3
  182. data/spec/stats/record_spec.rb +18 -19
  183. data/spec/store_spec.rb +51 -26
  184. data/spec/support/shared_examples.rb +4 -0
  185. data/spec/sync_states_spec.rb +2 -2
  186. metadata +104 -88
  187. data/bench/benchapp/Gemfile.lock +0 -87
  188. data/bench/blobapp/Gemfile.lock +0 -107
  189. data/bench/lib/testdata/5-data.txt +0 -8
  190. data/doc/release.txt +0 -41
  191. data/lib/rhoconnect/api/admin/get_api_token.rb +0 -14
  192. data/lib/rhoconnect/api/admin/login.rb +0 -6
  193. data/lib/rhoconnect/api/application/bulk_data.rb +0 -7
  194. data/lib/rhoconnect/api/application/clientcreate.rb +0 -8
  195. data/lib/rhoconnect/api/application/clientlogin.rb +0 -6
  196. data/lib/rhoconnect/api/application/clientregister.rb +0 -13
  197. data/lib/rhoconnect/api/application/clientreset.rb +0 -6
  198. data/lib/rhoconnect/api/application/query.rb +0 -7
  199. data/lib/rhoconnect/api/application/queue_updates.rb +0 -20
  200. data/lib/rhoconnect/api/application/search.rb +0 -6
  201. data/lib/rhoconnect/api/client/create_client.rb +0 -3
  202. data/lib/rhoconnect/api/client/delete_client.rb +0 -5
  203. data/lib/rhoconnect/api/client/list_clients.rb +0 -3
  204. data/lib/rhoconnect/api/client/ping.rb +0 -7
  205. data/lib/rhoconnect/api/source/get_adapter.rb +0 -3
  206. data/lib/rhoconnect/api/source/get_db_doc.rb +0 -7
  207. data/lib/rhoconnect/api/source/list_source_docs.rb +0 -10
  208. data/lib/rhoconnect/api/source/save_adapter.rb +0 -3
  209. data/lib/rhoconnect/api/source/set_db_doc.rb +0 -10
  210. data/lib/rhoconnect/api/source/upload_file.rb +0 -4
  211. data/lib/rhoconnect/body_content_type_parser.rb +0 -32
  212. data/lib/rhoconnect/x_domain_session_wrapper.rb +0 -53
  213. data/spec/api/admin/api_token_spec.rb +0 -13
  214. data/spec/api/client/create_client_spec.rb +0 -13
  215. data/spec/api/client/list_clients_spec.rb +0 -22
  216. data/spec/api/source/adapter_spec.rb +0 -29
  217. data/spec/api/source/get_db_doc_spec.rb +0 -21
  218. data/spec/api/source/list_source_docs_spec.rb +0 -25
  219. data/spec/api/source/push_objects_spec.rb +0 -27
  220. data/spec/api/source/set_db_doc_spec.rb +0 -32
  221. data/spec/api/source/upload_file_spec.rb +0 -26
@@ -12,6 +12,7 @@
12
12
  :licensefile: settings/license.key
13
13
  :redis: localhost:6379
14
14
  :syncserver: http://localhost:9292/api/application/
15
+ :push_server: http://appmike:appmikepwd@localhost:8675/
15
16
  :test:
16
17
  :licensefile: settings/license.key
17
18
  :redis: localhost:6379
@@ -8,9 +8,9 @@ gem 'win32-process', :platforms => [:mswin, :mingw]
8
8
 
9
9
  # use thin and eventmachine everywhere except JRuby
10
10
  platforms :ruby, :ruby_19, :mingw, :mingw_19 do
11
- gem "eventmachine", "~> 1.0.0.beta"
12
- # using thin by default
13
- gem 'thin'
11
+ gem "eventmachine", "~> 1.0.0.beta"
12
+ # using thin by default
13
+ gem 'thin'
14
14
  end
15
15
 
16
16
  # for async framework
@@ -36,7 +36,7 @@ group :development do
36
36
  end
37
37
 
38
38
  group :test do
39
+ gem 'rspec', '~> 2.10.0'
39
40
  gem 'rack-test', '>= 0.5.3', :require => "rack/test"
40
- gem 'rspec', '~> 2.6.0'
41
41
  gem 'rhomobile-debug', ">= 1.0.2"
42
42
  end
@@ -3,6 +3,10 @@ class Application < Rhoconnect::Base
3
3
  def authenticate(username,password,session)
4
4
  true # do some interesting authentication here...
5
5
  end
6
+
7
+ def ans_authenticate(username,password)
8
+ true # optionally handle rhoconnect push authentication...
9
+ end
6
10
 
7
11
  # Add hooks for application startup here
8
12
  # Don't forget to call super at the end!
@@ -4,11 +4,14 @@
4
4
  :licensefile: settings/license.key
5
5
  :redis: localhost:6379
6
6
  :syncserver: http://localhost:9292/api/application/
7
+ :push_server: http://appname:secret@localhost:8675/
7
8
  :test:
8
9
  :licensefile: settings/license.key
9
10
  :redis: localhost:6379
10
11
  :syncserver: http://localhost:9292/api/application/
12
+ :push_server: http://appname:secret@localhost:8675/
11
13
  :production:
12
14
  :licensefile: settings/license.key
13
15
  :redis: localhost:6379
14
- :syncserver: http://localhost:9292/api/application/
16
+ :syncserver: http://localhost:9292/api/application/
17
+ :push_server: http://appname:secret@localhost:8675/
@@ -493,7 +493,45 @@ def nginx_readme
493
493
  - Thin configuration file (/etc/thin/rhoapp.yml)
494
494
 
495
495
  By default, init script start cluster of 2 servers running on UNIX domain sockets.
496
- Nginx connected to cluster via upstream block in nginx config file.
496
+ Nginx connected to cluster via upstream block in nginx config file.
497
+
498
+ To deploy and develop your rhoconnect app on nginx and thin servers:
499
+ a) Copy your rhoconnect project to default location to `/opt/nginx/html` directory
500
+
501
+ b) Set up for it `nginx` owner
502
+ $ cd /opt/nginx/html
503
+ $ sudo chown -R nginx:nginx your_rhoconnect_app/
504
+
505
+ c) Make sure that your app is bundled properly
506
+ $ cd your_rhoconnect_app
507
+ $ sudo /opt/rhconnect/bin/bundle install
508
+
509
+ d) Configure Nginx virtual host for your rhoconnect application. For that edit the file
510
+ `/opt/nginx/conf/conf.d/rhoconnect.conf`, so that it reflects your specifications (root directive)
511
+ # ...
512
+ server {
513
+ listen 80;
514
+ root /opt/nginx/html/your_rhoconnect_app/public; # Be sure your app have 'public' folder and root directive
515
+ # point to it!
516
+ # ...
517
+ }
518
+
519
+ e) Edit Thin `/etc/thin/rhoapp.yml` configuration file directly
520
+ ---
521
+ chdir: /opt/nginx/html/your_rhoconnect_app
522
+ # ...
523
+
524
+ or as root user generate a new one
525
+ $ env PATH=/opt/rhoconnect/bin:$PATH thin config -C /etc/thin/your_rhoconnect_app.yml \
526
+ -c /opt/nginx/html/your_rhoconnect_app/ \
527
+ --socket /tmp/thin.sock --servers 2 --log /opt/nginx/logs/thin.log \
528
+ --pid /var/run/thin.pid -e production
529
+
530
+ f) As root user restart Nginx, and Thin servers
531
+ /etc/init.d/nginx restart
532
+ /etc/init.d/thin restart
533
+
534
+ For monitoring and troubleshooting purposes visit web console of your app and look at log files in `/opt/nginx/logs`.
497
535
  _NGINX_README_
498
536
  readme
499
537
  end
@@ -11,7 +11,7 @@ module Constants
11
11
  RUBY = "ruby-1.9.3-p194"
12
12
  REDIS = "redis-2.4.13"
13
13
  SQLITE3 = "sqlite-autoconf-3071000"
14
- NGINX = "nginx-1.2.0"
14
+ NGINX = "nginx-1.3.0"
15
15
  PASSENGER_ROOT = "/opt/rhoconnect/lib/ruby/gems/1.9.1/gems/passenger"
16
16
 
17
17
  SOFTWARE = [ REDIS, SQLITE3, RUBY, NGINX ]
@@ -105,12 +105,14 @@ task "build:repos", :build_type, :build_number do |t, args|
105
105
  file_to_rename = File.open(file, 'r')
106
106
  old_name = File.expand_path(file)
107
107
  new_name = old_name.gsub(/(#{arch})$/, "#{build_number}.\\1" )
108
- File.rename(old_name, new_name)
108
+ #File.rename(old_name, new_name)
109
+ log = `sudo mv #{old_name} #{new_name} 2>&1`
110
+ raise "#{log}" if $? != 0
109
111
  @deb_pkg = File.basename(new_name) if arch == 'deb'
110
- end #if
111
- end #do
112
- end #do
113
- end #if
112
+ end
113
+ end
114
+ end
115
+ end
114
116
 
115
117
  # REPOIFY!
116
118
  cmd "sudo reprepro -b #{PKG_DIR}/deb includedeb rhoconnect #{PKG_DIR}/deb/#{@deb_pkg}"
@@ -11,14 +11,13 @@ require 'rhoconnect/lock_ops'
11
11
  require 'rhoconnect/model'
12
12
  require 'rhoconnect/source'
13
13
  require 'rhoconnect/store'
14
- require 'rhoconnect/stats/record'
15
- require 'rhoconnect/stats/middleware'
16
14
  require 'rhoconnect/user'
17
15
  require 'rhoconnect/api_token'
18
16
  require 'rhoconnect/app'
19
17
  require 'rhoconnect/client'
20
18
  require 'rhoconnect/read_state'
21
19
  require 'rhoconnect/client_sync'
20
+ require 'rhoconnect/stats/record'
22
21
  require 'rhoconnect/source_adapter'
23
22
  require 'rhoconnect/source_sync'
24
23
  require 'rhoconnect/rho_indifferent_access'
@@ -41,6 +40,8 @@ module Rhoconnect
41
40
  # Used by application authenticate to indicate login failure
42
41
  class LoginException < RuntimeError; end
43
42
 
43
+ API_VERSION = 'v1'.freeze
44
+
44
45
  extend self
45
46
 
46
47
  class << self
@@ -0,0 +1,3 @@
1
+ Server.api4 :ans_login, :get, "/rc/#{Rhoconnect::API_VERSION}/app/ans_login", false, nil do |params,user,server|
2
+ server.do_ans_login
3
+ end
@@ -0,0 +1,6 @@
1
+ Server.api4 :bulk_data, :post, "/rc/#{Rhoconnect::API_VERSION}/app/bulk_data", \
2
+ false, {:verb => :get, :url => ['/application/bulk_data', '/api/application/bulk_data']} do |params,user,server|
3
+ server.content_type :json
4
+ data = ClientSync.bulk_data(params[:partition].to_sym,server.current_client)
5
+ data.to_json
6
+ end
@@ -1,4 +1,4 @@
1
- Server.api :fast_delete, :source do |params,user|
1
+ Server.api4 :fast_delete, :post, "/app/#{Rhoconnect::API_VERSION}/:source_id/fast_delete", true, {:verb => :post, :url => ['/api/fast_delete', '/api/source/fast_delete']} do |params,user|
2
2
  source = Source.load(params[:source_id],{:app_id=>APP_NAME,:user_id=>params[:user_id]})
3
3
  # if source does not exist create one for dynamic adapter
4
4
  source = Source.create({:name => params[:source_id]},{:app_id => APP_NAME,:user_id=>params[:user_id]}) unless source
@@ -1,4 +1,4 @@
1
- Server.api :fast_insert, :source do |params,user|
1
+ Server.api4 :fast_insert, :post, "/app/#{Rhoconnect::API_VERSION}/:source_id/fast_insert", true, {:verb => :post, :url => ['/api/fast_insert', '/api/source/fast_insert']} do |params,user|
2
2
  source = Source.load(params[:source_id],{:app_id=>APP_NAME,:user_id=>params[:user_id]})
3
3
  # if source does not exist create one for dynamic adapter
4
4
  source = Source.create({:name => params[:source_id]},{:app_id => APP_NAME,:user_id=>params[:user_id]}) unless source
@@ -7,4 +7,4 @@ Server.api :fast_insert, :source do |params,user|
7
7
  raise_on_expire = params[:raise_on_expire] || false
8
8
  source_sync.fast_insert(params[:data], timeout,raise_on_expire)
9
9
  'done'
10
- end
10
+ end
@@ -1,4 +1,4 @@
1
- Server.api :fast_update, :source do |params,user|
1
+ Server.api4 :fast_update, :post, "/app/#{Rhoconnect::API_VERSION}/:source_id/fast_update", true, {:verb => :post, :url => ['/api/fast_update', '/api/source/fast_update']} do |params,user|
2
2
  source = Source.load(params[:source_id],{:app_id=>APP_NAME,:user_id=>params[:user_id]})
3
3
  # if source does not exist create one for dynamic adapter
4
4
  source = Source.create({:name => params[:source_id]},{:app_id => APP_NAME,:user_id=>params[:user_id]}) unless source
@@ -7,4 +7,4 @@ Server.api :fast_update, :source do |params,user|
7
7
  raise_on_expire = params[:raise_on_expire] || false
8
8
  source_sync.fast_update(params[:delete_data], params[:data],timeout,raise_on_expire)
9
9
  'done'
10
- end
10
+ end
@@ -0,0 +1,5 @@
1
+ Server.api4 :clientlogin, :post, "/rc/#{Rhoconnect::API_VERSION}/app/login", \
2
+ false, {:verb => :post, :url => ['/application/clientlogin', '/api/application/clientlogin']} do |params,user,server|
3
+ server.logout
4
+ server.do_login
5
+ end
@@ -1,4 +1,4 @@
1
- Server.api :push_deletes, :source do |params,user|
1
+ Server.api4 :push_deletes, :post, "/app/#{Rhoconnect::API_VERSION}/:source_id/push_deletes", true, {:verb => :post, :url => ['/api/push_deletes', '/api/source/push_deletes']} do |params,user|
2
2
  source = Source.load(params[:source_id],{:app_id=>APP_NAME,:user_id=>params[:user_id]})
3
3
  # if source does not exist create one for dynamic adapter
4
4
  source = Source.create({:name => params[:source_id]},{:app_id => APP_NAME,:user_id=>params[:user_id]}) unless source
@@ -1,4 +1,4 @@
1
- Server.api :push_objects, :source do |params,user|
1
+ Server.api4 :push_objects, :post, "/app/#{Rhoconnect::API_VERSION}/:source_id/push_objects", true, {:verb => :post, :url => ['/api/push_objects', '/api/source/push_objects']} do |params,user|
2
2
  source = Source.load(params[:source_id],{:app_id=>APP_NAME,:user_id=>params[:user_id]})
3
3
  # if source does not exist create one for dynamic adapter
4
4
  source = Source.create({:name => params[:source_id]},{:app_id => APP_NAME,:user_id=>params[:user_id]}) unless source
@@ -0,0 +1,4 @@
1
+ Server.api4 :query, :get, "/app/#{Rhoconnect::API_VERSION}/:source_name", false, {:verb => :get, :url => ['/api/application', '/application', '/api/application/query']} do |params,user,server|
2
+ server.content_type :json
3
+ res = server.current_client_sync.send_cud(params[:token],params[:query]).to_json
4
+ end
@@ -0,0 +1,94 @@
1
+ Server.api4 :queue_updates, :post, "/app/#{Rhoconnect::API_VERSION}/:source_name/queue_updates", false, {:verb => :post, :url => ['/api/application', '/application', '/api/application/queue_updates']} do |params,user,server|
2
+ begin
3
+ if params["cud"]
4
+ cud = JSON.parse(params["cud"])
5
+ params.delete("cud")
6
+ params.merge!(cud)
7
+ end
8
+ rescue JSON::ParserError => jpe
9
+ log jpe.message + jpe.backtrace.join("\n")
10
+ throw :halt, [500, "Server error while processing client data"]
11
+ rescue Exception => e
12
+ log e.message + e.backtrace.join("\n")
13
+ throw :halt, [500, "Internal server error"]
14
+ end
15
+
16
+ server.catch_all do
17
+ server.current_client_sync.receive_cud(params)
18
+ server.status 200
19
+ end
20
+ end
21
+
22
+ Server.api4 :queue_creates, :post, "/app/#{Rhoconnect::API_VERSION}/:source_name", false, nil do |params,user,server|
23
+ begin
24
+ if params["cud"]
25
+ cud = JSON.parse(params["cud"])
26
+ params.delete("cud")
27
+ params.merge!(cud)
28
+ end
29
+ rescue JSON::ParserError => jpe
30
+ log jpe.message + jpe.backtrace.join("\n")
31
+ throw :halt, [500, "Server error while processing client data"]
32
+ rescue Exception => e
33
+ log e.message + e.backtrace.join("\n")
34
+ throw :halt, [500, "Internal server error"]
35
+ end
36
+
37
+ server.catch_all do
38
+ server.current_client_sync.receive_cud(params)
39
+ server.status 200
40
+ end
41
+ end
42
+
43
+ Server.api4 :queue_update, :put, "/app/#{Rhoconnect::API_VERSION}/:source_name/:id", false, nil do |params,user,server|
44
+ begin
45
+ if params["cud"]
46
+ cud = JSON.parse(params["cud"])
47
+ params.delete("cud")
48
+ params.merge!(cud)
49
+ end
50
+ rescue JSON::ParserError => jpe
51
+ log jpe.message + jpe.backtrace.join("\n")
52
+ throw :halt, [500, "Server error while processing client data"]
53
+ rescue Exception => e
54
+ log e.message + e.backtrace.join("\n")
55
+ throw :halt, [500, "Internal server error"]
56
+ end
57
+
58
+ begin
59
+ if params["update"]
60
+ cud = params["update"]
61
+ params.delete("update")
62
+ params.merge!("update" => {params[:id] => cud})
63
+ end
64
+ rescue JSON::ParserError => jpe
65
+ log jpe.message + jpe.backtrace.join("\n")
66
+ throw :halt, [500, "Server error while processing client data"]
67
+ rescue Exception => e
68
+ log e.message + e.backtrace.join("\n")
69
+ throw :halt, [500, "Internal server error"]
70
+ end
71
+
72
+ server.catch_all do
73
+ server.current_client_sync.receive_cud(params)
74
+ server.status 200
75
+ end
76
+ end
77
+
78
+ Server.api4 :queue_delete, :delete, "/app/#{Rhoconnect::API_VERSION}/:source_name/:id", false, nil do |params,user,server|
79
+ begin
80
+ obj = server.current_client.get_object(:cd, params[:id])
81
+ params.merge!("delete" => { params[:id] => obj } )
82
+ rescue JSON::ParserError => jpe
83
+ log jpe.message + jpe.backtrace.join("\n")
84
+ throw :halt, [500, "Server error while processing client data"]
85
+ rescue Exception => e
86
+ log e.message + e.backtrace.join("\n")
87
+ throw :halt, [500, "Internal server error"]
88
+ end
89
+
90
+ server.catch_all do
91
+ server.current_client_sync.receive_cud(params)
92
+ server.status 200
93
+ end
94
+ end
@@ -0,0 +1,4 @@
1
+ Server.api4 :search, :post, "/rc/#{Rhoconnect::API_VERSION}/app/search", false, {:verb => :get, :url => ['/application/search', '/api/application/search']} do |params,user,server|
2
+ server.content_type :json
3
+ ClientSync.search_all(server.current_client,params).to_json
4
+ end
@@ -0,0 +1,5 @@
1
+ Server.api4 :client_get_db_doc, :get, "/rc/#{Rhoconnect::API_VERSION}/clients/:client_id/sources/:source_id/docs/:doc", true, nil do |params,user|
2
+ c = Client.load(params[:client_id],{:source_name => params[:source_id]})
3
+ db_key = c.docname(params[:doc])
4
+ Store.get_db_doc(db_key)
5
+ end
@@ -0,0 +1,8 @@
1
+ Server.api4 :client_set_db_doc, :post, "/rc/#{Rhoconnect::API_VERSION}/clients/:client_id/sources/:source_id/docs/:doc", true, nil do |params,user|
2
+ c = Client.load(params[:client_id],{:source_name => params[:source_id]})
3
+ db_key = c.docname(params[:doc])
4
+ append_to_doc = params[:append]
5
+ append_to_doc ||= false
6
+ Store.set_db_doc(db_key,params[:data],append_to_doc)
7
+ ''
8
+ end
@@ -0,0 +1,7 @@
1
+ Server.api4 :clientcreate, :post, "/rc/#{Rhoconnect::API_VERSION}/clients", \
2
+ false, {:verb => :get, :url => ['/application/clientcreate', '/api/application/clientcreate']} do |params,user,server|
3
+ server.content_type :json
4
+ client = Client.create(:user_id => server.current_user.id,:app_id => server.current_app.id)
5
+ client.update_fields(params)
6
+ { "client" => { "client_id" => client.id.to_s } }.to_json
7
+ end
@@ -1,3 +1,4 @@
1
- Server.api :get_client_params, :client do |params,user|
1
+ Server.api4 :get_client_params, :get, "/rc/#{Rhoconnect::API_VERSION}/clients/:client_id", \
2
+ true, {:verb => :post, :url => ['/api/get_client_params', '/api/client/get_client_params']} do |params,user|
2
3
  Client.load(params[:client_id],{:source_name => '*'}).to_array.to_json
3
4
  end
@@ -1,4 +1,5 @@
1
- Server.api :list_client_docs, :client do |params,user|
1
+ Server.api4 :list_client_docs, :get, "/rc/#{Rhoconnect::API_VERSION}/clients/:client_id/sources/:source_id/docnames", \
2
+ true, {:verb => :post, :url => ['/api/list_client_docs', '/api/client/list_client_docs']} do |params,user|
2
3
  c = Client.load(params[:client_id],{:source_name => params[:source_id]})
3
4
  res = {}
4
5
  [:cd,:cd_size,:create,:update,:delete,
@@ -0,0 +1,12 @@
1
+ Server.api4 :clientregister, :post, "/rc/#{Rhoconnect::API_VERSION}/clients/:client_id/register", \
2
+ false, {:verb => :post, :url => ['/application/clientregister', '/api/application/clientregister'] } do |params,user,server|
3
+ current_client = server.current_client
4
+ if current_client.nil? and server.current_user and server.current_app
5
+ fields = {:user_id => server.current_user.id}
6
+ fields[:id] = params[:client_id].to_s
7
+ fields[:app_id] = server.current_app.id
8
+ current_client = Client.create(fields)
9
+ end
10
+ current_client.update_fields(params)
11
+ server.status 200
12
+ end
@@ -0,0 +1,5 @@
1
+ Server.api4 :clientreset, :post, "/rc/#{Rhoconnect::API_VERSION}/clients/:client_id/reset", \
2
+ false, {:verb => :get, :url => ['/application/clientreset', '/api/application/clientreset']} do |params,user,server|
3
+ ClientSync.reset(server.current_client, params)
4
+ server.status 200
5
+ end
@@ -1,4 +1,5 @@
1
- Server.api :set_refresh_time, :source do |params,user|
1
+ Server.api4 :set_refresh_time, :put, "/rc/#{Rhoconnect::API_VERSION}/readstate/users/:user_name/sources/:source_name", \
2
+ true, {:verb => :post, :url => ['/api/set_refresh_time', '/api/source/set_refresh_time']} do |params,user|
2
3
  source = Source.load(params[:source_name],
3
4
  {:app_id => APP_NAME, :user_id => params[:user_name]})
4
5
  source.poll_interval = params[:poll_interval] if params[:poll_interval]
@@ -1,3 +1,4 @@
1
- Server.api :get_source_params, :source do |params,user|
2
- Source.load(params[:source_id],{:app_id => APP_NAME,:user_id => "*"}).to_array.to_json
1
+ Server.api4 :get_source_params, :get, "/rc/#{Rhoconnect::API_VERSION}/sources/:source_id", \
2
+ true, {:verb => :post, :url => ['/api/get_source_params', '/api/source/get_source_params']} do |params,user|
3
+ Source.load(params[:source_id],{:app_id => APP_NAME,:user_id => '*'}).to_array.to_json
3
4
  end
@@ -1,4 +1,5 @@
1
- Server.api :list_sources, :source do |params,user|
1
+ Server.api4 :list_sources, :get, "/rc/#{Rhoconnect::API_VERSION}/sources/type/:partition_type", \
2
+ true, {:verb => :post, :url => ['/api/list_sources', '/api/source/list_sources']} do |params,user|
2
3
  sources = App.load(APP_NAME).sources
3
4
  if params['partition_type'].nil? or params['partition_type'] == 'all'
4
5
  sources.to_json
@@ -1,6 +1,6 @@
1
- Server.api :update_source_params, :source do |params,user|
2
- source = Source.load(params[:source_name],
3
- {:app_id => APP_NAME, :user_id => params[:user_name]})
1
+ Server.api4 :update_source_params, :put, "/rc/#{Rhoconnect::API_VERSION}/sources/:source_id", true, nil do |params,user|
2
+ source = Source.load(params[:source_id],
3
+ {:app_id => APP_NAME, :user_id => '*'})
4
4
  source.update_fields(params[:data])
5
5
  ''
6
6
  end
@@ -0,0 +1,4 @@
1
+ Server.api4 :get_db_doc, :get, "/rc/#{Rhoconnect::API_VERSION}/store/:doc", \
2
+ true, {:verb => :post, :url => ['/api/get_db_doc', '/api/source/get_db_doc']} do |params,user|
3
+ Store.get_db_doc(params[:doc])
4
+ end
@@ -0,0 +1,7 @@
1
+ Server.api4 :set_db_doc, :post, "/rc/#{Rhoconnect::API_VERSION}/store/:doc", \
2
+ true, {:verb => :post, :url => ['/api/set_db_doc', '/api/source/set_db_doc'] } do |params,user|
3
+ append_to_doc = params[:append]
4
+ append_to_doc ||= false
5
+ Store.set_db_doc(params[:doc],params[:data],append_to_doc)
6
+ ''
7
+ end
@@ -0,0 +1,4 @@
1
+ Server.api4 :get_adapter, :get, "/rc/#{Rhoconnect::API_VERSION}/system/appserver", \
2
+ true, {:verb => :post, :url => ['/api/get_adapter', '/api/source/get_adapter']} do |params,user|
3
+ {:adapter_url => Rhoconnect.appserver}.to_json
4
+ end