rhoconnect 3.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +208 -0
- data/CREDITS +38 -0
- data/Gemfile +18 -0
- data/Gemfile.lock +97 -0
- data/LICENSE +75 -0
- data/README.md +10 -0
- data/Rakefile +82 -0
- data/bench/bench +7 -0
- data/bench/bench_runner.rb +112 -0
- data/bench/benchapp/Gemfile +21 -0
- data/bench/benchapp/Gemfile.lock +76 -0
- data/bench/benchapp/Rakefile +22 -0
- data/bench/benchapp/application.rb +39 -0
- data/bench/benchapp/config.ru +36 -0
- data/bench/benchapp/settings/license.key +1 -0
- data/bench/benchapp/settings/settings.yml +20 -0
- data/bench/benchapp/sources/mock_adapter.rb +55 -0
- data/bench/benchapp/sources/queue_mock_adapter.rb +2 -0
- data/bench/benchapp/spec/sources/mock_adapter_spec.rb +25 -0
- data/bench/benchapp/spec/sources/queue_mock_adapter_spec.rb +25 -0
- data/bench/benchapp/spec/spec_helper.rb +42 -0
- data/bench/blobapp/Gemfile +31 -0
- data/bench/blobapp/Gemfile.lock +103 -0
- data/bench/blobapp/Rakefile +25 -0
- data/bench/blobapp/application.rb +44 -0
- data/bench/blobapp/config.ru +36 -0
- data/bench/blobapp/settings/license.key +1 -0
- data/bench/blobapp/settings/settings.yml +16 -0
- data/bench/blobapp/sources/blob_adapter.rb +71 -0
- data/bench/blobapp/spec/sources/blob_adapter_spec.rb +25 -0
- data/bench/blobapp/spec/spec_helper.rb +42 -0
- data/bench/lib/bench/cli.rb +16 -0
- data/bench/lib/bench/logging.rb +13 -0
- data/bench/lib/bench/mock_client.rb +41 -0
- data/bench/lib/bench/result.rb +50 -0
- data/bench/lib/bench/runner.rb +107 -0
- data/bench/lib/bench/session.rb +67 -0
- data/bench/lib/bench/statistics.rb +56 -0
- data/bench/lib/bench/test_data.rb +98 -0
- data/bench/lib/bench/timer.rb +10 -0
- data/bench/lib/bench/utils.rb +49 -0
- data/bench/lib/bench.rb +129 -0
- data/bench/lib/testdata/100-data.txt +148 -0
- data/bench/lib/testdata/5-data.txt +9 -0
- data/bench/lib/testdata/images/icon.ico +0 -0
- data/bench/lib/testdata/images/icon.png +0 -0
- data/bench/lib/testdata/images/loading-Landscape.png +0 -0
- data/bench/lib/testdata/images/loading-LandscapeLeft.png +0 -0
- data/bench/lib/testdata/images/loading-LandscapeRight.png +0 -0
- data/bench/lib/testdata/images/loading-Portrait.png +0 -0
- data/bench/lib/testdata/images/loading-PortraitUpsideDown.png +0 -0
- data/bench/lib/testdata/images/loading.png +0 -0
- data/bench/lib/testdata/images/loading@2x.png +0 -0
- data/bench/run_bench.sh +42 -0
- data/bench/run_blob_script.sh +3 -0
- data/bench/run_cud_script.sh +3 -0
- data/bench/run_query_md_script.sh +3 -0
- data/bench/run_query_only_script.sh +3 -0
- data/bench/run_query_script.sh +3 -0
- data/bench/scripts/blob_cud_script.rb +98 -0
- data/bench/scripts/cud_script.rb +92 -0
- data/bench/scripts/helpers.rb +101 -0
- data/bench/scripts/query_md_script.rb +45 -0
- data/bench/scripts/query_only_script.rb +51 -0
- data/bench/scripts/query_script.rb +45 -0
- data/bench/spec/bench_spec_helper.rb +33 -0
- data/bench/spec/logging_spec.rb +15 -0
- data/bench/spec/mock_adapter_spec.rb +61 -0
- data/bench/spec/mock_client_spec.rb +65 -0
- data/bench/spec/result_spec.rb +61 -0
- data/bench/spec/utils_spec.rb +36 -0
- data/bin/rhoconnect +34 -0
- data/bin/rhoconnect-setup +84 -0
- data/doc/async-jobs.txt +69 -0
- data/doc/authentication.txt +76 -0
- data/doc/benchmarks.txt +168 -0
- data/doc/blob-sync.txt +130 -0
- data/doc/bulk-sync.txt +102 -0
- data/doc/client.txt +432 -0
- data/doc/command-line.txt +210 -0
- data/doc/contributing.txt +60 -0
- data/doc/deploying.txt +82 -0
- data/doc/install.txt +28 -0
- data/doc/introduction.txt +20 -0
- data/doc/licensing.txt +18 -0
- data/doc/metadata.txt +458 -0
- data/doc/migration.txt +182 -0
- data/doc/public/css/print.css +29 -0
- data/doc/public/css/screen.css +257 -0
- data/doc/public/css/style.css +20 -0
- data/doc/push.txt +135 -0
- data/doc/release.txt +41 -0
- data/doc/rest-api.txt +367 -0
- data/doc/source-adapters.txt +325 -0
- data/doc/stats-middleware.txt +69 -0
- data/doc/testing.txt +222 -0
- data/doc/tutorial.txt +315 -0
- data/doc/web-console.txt +35 -0
- data/examples/simple/Rakefile +14 -0
- data/examples/simple/application.rb +27 -0
- data/examples/simple/config.ru +49 -0
- data/examples/simple/settings/license.key +1 -0
- data/examples/simple/settings/settings.yml +23 -0
- data/examples/simple/sources/sample_adapter.rb +5 -0
- data/examples/simple/sources/simple_adapter.rb +5 -0
- data/generators/rhoconnect.rb +119 -0
- data/generators/templates/application/Gemfile +21 -0
- data/generators/templates/application/Rakefile +22 -0
- data/generators/templates/application/application.rb +39 -0
- data/generators/templates/application/config.ru +36 -0
- data/generators/templates/application/settings/license.key +1 -0
- data/generators/templates/application/settings/settings.yml +14 -0
- data/generators/templates/application/spec/spec_helper.rb +42 -0
- data/generators/templates/source/source_adapter.rb +47 -0
- data/generators/templates/source/source_spec.rb +25 -0
- data/install.sh +408 -0
- data/installer/unix-like/rho_connect_install_checkers.rb +140 -0
- data/installer/unix-like/rho_connect_install_constants.rb +51 -0
- data/installer/unix-like/rho_connect_install_debian.rb +63 -0
- data/installer/unix-like/rho_connect_install_dnd.rb +58 -0
- data/installer/unix-like/rho_connect_install_get_params.rb +30 -0
- data/installer/unix-like/rho_connect_install_installers.rb +142 -0
- data/installer/unix-like/rho_connect_install_utilities.rb +85 -0
- data/installer/unix-like/rho_connect_install_yum.rb +63 -0
- data/installer/unix-like/rhoinstaller.rb +89 -0
- data/installer/utils/create_texts.rb +366 -0
- data/installer/utils/install_test.rb +140 -0
- data/installer/windows/EnvVarUpdate.nsh +328 -0
- data/installer/windows/ServiceLib.nsh +369 -0
- data/installer/windows/configUi.ini +44 -0
- data/installer/windows/icon.ico +0 -0
- data/installer/windows/rhosync.nsi +418 -0
- data/installer/windows/uninstall.bat +7 -0
- data/lib/rhoconnect/api/admin/get_api_token.rb +14 -0
- data/lib/rhoconnect/api/admin/get_license_info.rb +8 -0
- data/lib/rhoconnect/api/admin/login.rb +6 -0
- data/lib/rhoconnect/api/admin/reset.rb +10 -0
- data/lib/rhoconnect/api/admin/stats.rb +21 -0
- data/lib/rhoconnect/api/application/bulk_data.rb +7 -0
- data/lib/rhoconnect/api/application/clientcreate.rb +8 -0
- data/lib/rhoconnect/api/application/clientlogin.rb +6 -0
- data/lib/rhoconnect/api/application/clientregister.rb +6 -0
- data/lib/rhoconnect/api/application/clientreset.rb +6 -0
- data/lib/rhoconnect/api/application/query.rb +7 -0
- data/lib/rhoconnect/api/application/queue_updates.rb +6 -0
- data/lib/rhoconnect/api/application/search.rb +6 -0
- data/lib/rhoconnect/api/client/create_client.rb +3 -0
- data/lib/rhoconnect/api/client/delete_client.rb +5 -0
- data/lib/rhoconnect/api/client/get_client_params.rb +3 -0
- data/lib/rhoconnect/api/client/list_client_docs.rb +12 -0
- data/lib/rhoconnect/api/client/list_clients.rb +3 -0
- data/lib/rhoconnect/api/client/ping.rb +7 -0
- data/lib/rhoconnect/api/source/get_adapter.rb +3 -0
- data/lib/rhoconnect/api/source/get_db_doc.rb +7 -0
- data/lib/rhoconnect/api/source/get_source_params.rb +3 -0
- data/lib/rhoconnect/api/source/list_source_docs.rb +10 -0
- data/lib/rhoconnect/api/source/list_sources.rb +15 -0
- data/lib/rhoconnect/api/source/push_deletes.rb +8 -0
- data/lib/rhoconnect/api/source/push_objects.rb +8 -0
- data/lib/rhoconnect/api/source/save_adapter.rb +3 -0
- data/lib/rhoconnect/api/source/set_db_doc.rb +8 -0
- data/lib/rhoconnect/api/source/set_refresh_time.rb +8 -0
- data/lib/rhoconnect/api/source/upload_file.rb +4 -0
- data/lib/rhoconnect/api/user/create_user.rb +7 -0
- data/lib/rhoconnect/api/user/delete_user.rb +9 -0
- data/lib/rhoconnect/api/user/list_users.rb +3 -0
- data/lib/rhoconnect/api/user/update_user.rb +4 -0
- data/lib/rhoconnect/api_token.rb +19 -0
- data/lib/rhoconnect/app.rb +76 -0
- data/lib/rhoconnect/bulk_data/bulk_data.rb +88 -0
- data/lib/rhoconnect/bulk_data/syncdb.index.schema +4 -0
- data/lib/rhoconnect/bulk_data/syncdb.schema +41 -0
- data/lib/rhoconnect/bulk_data.rb +2 -0
- data/lib/rhoconnect/client.rb +96 -0
- data/lib/rhoconnect/client_sync.rb +412 -0
- data/lib/rhoconnect/console/app/helpers/auth_helper.rb +22 -0
- data/lib/rhoconnect/console/app/helpers/extensions.rb +19 -0
- data/lib/rhoconnect/console/app/helpers/helpers.rb +57 -0
- data/lib/rhoconnect/console/app/public/ThickBox.css +649 -0
- data/lib/rhoconnect/console/app/public/home.css +438 -0
- data/lib/rhoconnect/console/app/public/images/foot_logo_rhoconnect.png +0 -0
- data/lib/rhoconnect/console/app/public/images/header_halo.jpg +0 -0
- data/lib/rhoconnect/console/app/public/images/land_separator.gif +0 -0
- data/lib/rhoconnect/console/app/public/images/landing_header.jpg +0 -0
- data/lib/rhoconnect/console/app/public/images/logo_rhoconnect.png +0 -0
- data/lib/rhoconnect/console/app/public/images/rhomobile_rhohub_logo.png +0 -0
- data/lib/rhoconnect/console/app/public/images/tabs_separator.png +0 -0
- data/lib/rhoconnect/console/app/public/jqplot/excanvas.min.js +35 -0
- data/lib/rhoconnect/console/app/public/jqplot/jqplot.barRenderer.min.js +34 -0
- data/lib/rhoconnect/console/app/public/jqplot/jqplot.canvasAxisLabelRenderer.js +187 -0
- data/lib/rhoconnect/console/app/public/jqplot/jqplot.canvasAxisTickRenderer.js +226 -0
- data/lib/rhoconnect/console/app/public/jqplot/jqplot.canvasTextRenderer.js +408 -0
- data/lib/rhoconnect/console/app/public/jqplot/jqplot.categoryAxisRenderer.min.js +34 -0
- data/lib/rhoconnect/console/app/public/jqplot/jqplot.cursor.js +952 -0
- data/lib/rhoconnect/console/app/public/jqplot/jqplot.dateAxisRenderer.js +313 -0
- data/lib/rhoconnect/console/app/public/jqplot/jqplot.dateAxisRenderer.min.js +34 -0
- data/lib/rhoconnect/console/app/public/jqplot/jqplot.pointLabels.min.js +34 -0
- data/lib/rhoconnect/console/app/public/jqplot/jquery-1.4.2.min.js +154 -0
- data/lib/rhoconnect/console/app/public/jqplot/jquery.jqplot.min.css +1 -0
- data/lib/rhoconnect/console/app/public/jqplot/jquery.jqplot.min.js +34 -0
- data/lib/rhoconnect/console/app/public/main.css +7 -0
- data/lib/rhoconnect/console/app/public/reset.css +76 -0
- data/lib/rhoconnect/console/app/public/style.css +2201 -0
- data/lib/rhoconnect/console/app/public/text.txt +0 -0
- data/lib/rhoconnect/console/app/routes/adapter.rb +28 -0
- data/lib/rhoconnect/console/app/routes/auth.rb +29 -0
- data/lib/rhoconnect/console/app/routes/client.rb +31 -0
- data/lib/rhoconnect/console/app/routes/docs.rb +145 -0
- data/lib/rhoconnect/console/app/routes/heroku.rb +19 -0
- data/lib/rhoconnect/console/app/routes/home.rb +63 -0
- data/lib/rhoconnect/console/app/routes/timing.rb +242 -0
- data/lib/rhoconnect/console/app/routes/user.rb +117 -0
- data/lib/rhoconnect/console/app/views/adapter.erb +16 -0
- data/lib/rhoconnect/console/app/views/client.erb +30 -0
- data/lib/rhoconnect/console/app/views/content.erb +14 -0
- data/lib/rhoconnect/console/app/views/doc.erb +8 -0
- data/lib/rhoconnect/console/app/views/docdata.erb +28 -0
- data/lib/rhoconnect/console/app/views/docs.erb +30 -0
- data/lib/rhoconnect/console/app/views/edituser.erb +13 -0
- data/lib/rhoconnect/console/app/views/headermenu.erb +40 -0
- data/lib/rhoconnect/console/app/views/home.erb +24 -0
- data/lib/rhoconnect/console/app/views/index.erb +58 -0
- data/lib/rhoconnect/console/app/views/jqplot.erb +52 -0
- data/lib/rhoconnect/console/app/views/layout.erb +165 -0
- data/lib/rhoconnect/console/app/views/login.erb +26 -0
- data/lib/rhoconnect/console/app/views/newuser.erb +17 -0
- data/lib/rhoconnect/console/app/views/ping.erb +28 -0
- data/lib/rhoconnect/console/app/views/result.erb +11 -0
- data/lib/rhoconnect/console/app/views/rightboxlinks.erb +15 -0
- data/lib/rhoconnect/console/app/views/select_doc.erb +17 -0
- data/lib/rhoconnect/console/app/views/upload_doc.erb +23 -0
- data/lib/rhoconnect/console/app/views/user.erb +29 -0
- data/lib/rhoconnect/console/app/views/users.erb +12 -0
- data/lib/rhoconnect/console/rhoconnect_api.rb +245 -0
- data/lib/rhoconnect/console/server.rb +32 -0
- data/lib/rhoconnect/console.rb +3 -0
- data/lib/rhoconnect/cors.rb +229 -0
- data/lib/rhoconnect/credential.rb +9 -0
- data/lib/rhoconnect/db_adapter.rb +46 -0
- data/lib/rhoconnect/document.rb +49 -0
- data/lib/rhoconnect/dynamic_adapter.rb +91 -0
- data/lib/rhoconnect/generator.rb +1 -0
- data/lib/rhoconnect/jobs/bulk_data_job.rb +203 -0
- data/lib/rhoconnect/jobs/ping_job.rb +46 -0
- data/lib/rhoconnect/jobs/source_job.rb +16 -0
- data/lib/rhoconnect/license.rb +86 -0
- data/lib/rhoconnect/lock_ops.rb +11 -0
- data/lib/rhoconnect/model.rb +414 -0
- data/lib/rhoconnect/ping/android.rb +56 -0
- data/lib/rhoconnect/ping/apple.rb +52 -0
- data/lib/rhoconnect/ping/blackberry.rb +56 -0
- data/lib/rhoconnect/ping.rb +3 -0
- data/lib/rhoconnect/read_state.rb +31 -0
- data/lib/rhoconnect/rho_indifferent_access.rb +88 -0
- data/lib/rhoconnect/server/views/index.erb +13 -0
- data/lib/rhoconnect/server.rb +286 -0
- data/lib/rhoconnect/source.rb +289 -0
- data/lib/rhoconnect/source_adapter.rb +123 -0
- data/lib/rhoconnect/source_sync.rb +302 -0
- data/lib/rhoconnect/stats/middleware.rb +20 -0
- data/lib/rhoconnect/stats/record.rb +108 -0
- data/lib/rhoconnect/store.rb +232 -0
- data/lib/rhoconnect/tasks.rb +350 -0
- data/lib/rhoconnect/test_methods.rb +220 -0
- data/lib/rhoconnect/user.rb +95 -0
- data/lib/rhoconnect/version.rb +3 -0
- data/lib/rhoconnect/x_domain_session_wrapper.rb +53 -0
- data/lib/rhoconnect.rb +285 -0
- data/rhoconnect.gemspec +67 -0
- data/spec/api/admin/api_token_spec.rb +14 -0
- data/spec/api/admin/get_api_token_spec.rb +36 -0
- data/spec/api/admin/get_license_info_spec.rb +38 -0
- data/spec/api/admin/reset_spec.rb +22 -0
- data/spec/api/admin/stats_spec.rb +66 -0
- data/spec/api/api_helper.rb +21 -0
- data/spec/api/application/rhoconnect_api_spec.rb +548 -0
- data/spec/api/client/create_client_spec.rb +13 -0
- data/spec/api/client/delete_client_spec.rb +13 -0
- data/spec/api/client/get_client_params_spec.rb +18 -0
- data/spec/api/client/list_client_docs_spec.rb +32 -0
- data/spec/api/client/list_clients_spec.rb +22 -0
- data/spec/api/client/ping_spec.rb +23 -0
- data/spec/api/rhosync_api_spec.rb.orig +606 -0
- data/spec/api/source/adapter_spec.rb +29 -0
- data/spec/api/source/get_db_doc_spec.rb +21 -0
- data/spec/api/source/get_source_params_spec.rb +32 -0
- data/spec/api/source/list_source_docs_spec.rb +25 -0
- data/spec/api/source/list_sources_spec.rb +26 -0
- data/spec/api/source/push_deletes_spec.rb +18 -0
- data/spec/api/source/push_objects_spec.rb +27 -0
- data/spec/api/source/set_db_doc_spec.rb +19 -0
- data/spec/api/source/set_refresh_time_spec.rb +43 -0
- data/spec/api/source/upload_file_spec.rb +26 -0
- data/spec/api/user/create_user_spec.rb +16 -0
- data/spec/api/user/delete_user_spec.rb +36 -0
- data/spec/api/user/list_users_spec.rb +30 -0
- data/spec/api/user/update_user_spec.rb +31 -0
- data/spec/api_token_spec.rb +14 -0
- data/spec/app_spec.rb +18 -0
- data/spec/apps/emptyapp/application.rb +27 -0
- data/spec/apps/emptyapp/settings/license.key +1 -0
- data/spec/apps/emptyapp/settings/settings.yml +14 -0
- data/spec/apps/rhotestapp/Rakefile +1 -0
- data/spec/apps/rhotestapp/application.rb +19 -0
- data/spec/apps/rhotestapp/config.ru +1 -0
- data/spec/apps/rhotestapp/settings/apple_fake_cert.pem +1 -0
- data/spec/apps/rhotestapp/settings/license.key +1 -0
- data/spec/apps/rhotestapp/settings/settings.yml +36 -0
- data/spec/apps/rhotestapp/sources/base_adapter.rb +9 -0
- data/spec/apps/rhotestapp/sources/fixed_schema_adapter.rb +28 -0
- data/spec/apps/rhotestapp/sources/sample_adapter.rb +71 -0
- data/spec/apps/rhotestapp/sources/simple_adapter.rb +41 -0
- data/spec/apps/rhotestapp/sources/sub_adapter.rb +7 -0
- data/spec/apps/rhotestapp/vendor/mygem-0.1.0/lib/mygem/mygem.rb +8 -0
- data/spec/apps/rhotestapp/vendor/mygem-0.1.0/lib/mygem.rb +1 -0
- data/spec/bulk_data/bulk_data_spec.rb +97 -0
- data/spec/client_spec.rb +124 -0
- data/spec/client_sync_spec.rb +774 -0
- data/spec/doc/base.html +72 -0
- data/spec/doc/doc_spec.rb +376 -0
- data/spec/doc/footer.html +4 -0
- data/spec/doc/header.html +30 -0
- data/spec/document_spec.rb +31 -0
- data/spec/dynamic_adapter_spec.rb +43 -0
- data/spec/factories/factories.rb +17 -0
- data/spec/generator/generator_spec.rb +58 -0
- data/spec/generator/generator_spec_helper.rb +9 -0
- data/spec/jobs/bulk_data_job_spec.rb +125 -0
- data/spec/jobs/ping_job_spec.rb +102 -0
- data/spec/jobs/source_job_spec.rb +29 -0
- data/spec/license_spec.rb +66 -0
- data/spec/model_spec.rb +273 -0
- data/spec/perf/bulk_data_perf_spec.rb +32 -0
- data/spec/perf/perf_spec_helper.rb +50 -0
- data/spec/perf/store_perf_spec.rb +27 -0
- data/spec/ping/android_spec.rb +91 -0
- data/spec/ping/apple_spec.rb +70 -0
- data/spec/ping/blackberry_spec.rb +62 -0
- data/spec/read_state_spec.rb +35 -0
- data/spec/rhosync_spec.rb +75 -0
- data/spec/server/cors_spec.rb +287 -0
- data/spec/server/server_spec.rb +470 -0
- data/spec/server/x_domain_session_wrapper_spec.rb +150 -0
- data/spec/source_adapter_spec.rb +125 -0
- data/spec/source_spec.rb +114 -0
- data/spec/source_sync_spec.rb +328 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +231 -0
- data/spec/stats/middleware_spec.rb +53 -0
- data/spec/stats/record_spec.rb +92 -0
- data/spec/store_spec.rb +251 -0
- data/spec/support/shared_examples.rb +168 -0
- data/spec/sync_states_spec.rb +72 -0
- data/spec/test_methods_spec.rb +134 -0
- data/spec/testdata/1000-data.txt +1414 -0
- data/spec/testdata/compressed/compress-data.txt +1 -0
- data/spec/testdata/upload1.txt +1 -0
- data/spec/testdata/upload2.txt +1 -0
- data/spec/user_spec.rb +139 -0
- data/tasks/redis.rake +206 -0
- metadata +706 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
<h1>User: <%=params[:user_id]%></h1>
|
2
|
+
<%=show_errors%>
|
3
|
+
<div class="panel">
|
4
|
+
<a href='<%=url_path("user/delete?user_id=#{CGI.escape(params[:user_id])}")%>' class='nav_button'>Delete user</a>
|
5
|
+
</div>
|
6
|
+
<div class="panel">
|
7
|
+
<a href='<%=url_path("user/ping?user_id=#{CGI.escape(params[:user_id])}")%>' class='nav_button'>Ping User</a>
|
8
|
+
</div>
|
9
|
+
<h2>User partition sources</h2>
|
10
|
+
|
11
|
+
[
|
12
|
+
<%@sources.each_index do |i|%>
|
13
|
+
<a href='javascript:void(0);' onclick="loadXMLDoc('<%=url_path("docs?source_id=#{@sources[i]}&user_id=#{CGI.escape(params[:user_id])}")%>','main_box');"><%=i==0?'':','%>"<%=@sources[i]%>"</a>
|
14
|
+
<%end%>
|
15
|
+
]
|
16
|
+
|
17
|
+
<h2>Registered Devices</h2>
|
18
|
+
|
19
|
+
<a href="javascript:void(0);" onclick="loadXMLDoc('<%=url_path("device/create?user_id=#{CGI.escape(params[:user_id])}")%>','');loadXMLDoc('<%=url_path("user?user_id=#{CGI.escape(params[:user_id])}")%>','main_box');" class='nav_button'>Create Device</a>
|
20
|
+
|
21
|
+
<div class="panel">
|
22
|
+
[
|
23
|
+
<%@devices.each_index do |i|%>
|
24
|
+
<a href="javascript:void(0);" onclick="loadXMLDoc('<%=url_path("device?user_id=#{CGI.escape(params[:user_id])}&device_id=#{CGI.escape(@devices[i])}")%>','main_box');">
|
25
|
+
<%=i==0?'':','%>"<%=@devices[i]%>"
|
26
|
+
</a>
|
27
|
+
<%end%>
|
28
|
+
]
|
29
|
+
</div>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<a href="javascript:void(0);" onclick="loadXMLDoc('<%=url_path('user/new')%>','main_box');" class='nav_button'>Create User</a>
|
2
|
+
|
3
|
+
<h2>Registered users</h2>
|
4
|
+
<%if is_errors?%>
|
5
|
+
<%= show_errors%>
|
6
|
+
<%else%>
|
7
|
+
[
|
8
|
+
<%@users.each_index do |i|%>
|
9
|
+
<a href="javascript:void(0);" onclick="loadXMLDoc('<%=url_path("user?user_id=#{CGI.escape(@users[i])}")%>','main_box');"><%=i==0?'':','%>"<%=@users[i]%>"</a>
|
10
|
+
<%end%>
|
11
|
+
]
|
12
|
+
<%end%>
|
@@ -0,0 +1,245 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
path = File.join(File.dirname(__FILE__),'..','..')
|
3
|
+
$:.unshift path
|
4
|
+
require 'rhoconnect'
|
5
|
+
include Rhoconnect
|
6
|
+
|
7
|
+
module RhoconnectApi
|
8
|
+
class << self
|
9
|
+
|
10
|
+
def get_token(server,login,password)
|
11
|
+
if directcall?(server)
|
12
|
+
Server.get_api_token(nil,User.authenticate(login,password))
|
13
|
+
else
|
14
|
+
do_login(server,login,password)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def list_users(server,token)
|
19
|
+
if directcall?(server) and verify_token(token)
|
20
|
+
JSON.parse(Server.list_users(nil,api_user(token)))
|
21
|
+
else
|
22
|
+
JSON.parse(RestClient.post("#{server}/api/user/list_users",
|
23
|
+
{:api_token => token}.to_json, :content_type => :json).body)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def save_adapter(server,token,adapter_url)
|
28
|
+
if directcall?(server) and verify_token(token)
|
29
|
+
Server.save_adapter({:attributes => {'adapter_url' => adapter_url}},nil)
|
30
|
+
else
|
31
|
+
RestClient.post("#{server}/api/source/save_adapter",
|
32
|
+
{:api_token => token,:attributes => {:adapter_url => adapter_url}}.to_json,
|
33
|
+
:content_type => :json)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def create_user(server,token,login,password)
|
38
|
+
if directcall?(server) and verify_token(token)
|
39
|
+
Server.create_user({:attributes => {'login' => login, 'password' => password}},nil)
|
40
|
+
else
|
41
|
+
RestClient.post("#{server}/api/user/create_user",
|
42
|
+
{:api_token => token,:attributes => {:login => login, :password => password}}.to_json,
|
43
|
+
:content_type => :json)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def update_user(server,token,attributes)
|
48
|
+
if directcall?(server) and verify_token(token)
|
49
|
+
Server.update_user({:attributes => attributes},api_user(token))
|
50
|
+
else
|
51
|
+
RestClient.post("#{server}/api/user/update_user",
|
52
|
+
{:api_token => token,:attributes => attributes}.to_json,
|
53
|
+
:content_type => :json)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def delete_user(server,token,user_id)
|
58
|
+
if directcall?(server) and verify_token(token)
|
59
|
+
Server.delete_user({:user_id => user_id},nil)
|
60
|
+
else
|
61
|
+
RestClient.post("#{server}/api/user/delete_user",
|
62
|
+
{:api_token => token, :user_id => user_id}.to_json,
|
63
|
+
:content_type => :json)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def list_clients(server,token,user_id)
|
68
|
+
if directcall?(server) and verify_token(token)
|
69
|
+
JSON.parse(Server.list_clients({:user_id => user_id},nil))
|
70
|
+
else
|
71
|
+
JSON.parse(RestClient.post("#{server}/api/client/list_clients",
|
72
|
+
{:api_token => token, :user_id => user_id}.to_json, :content_type => :json).body)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def create_client(server,token,user_id)
|
77
|
+
if directcall?(server) and verify_token(token)
|
78
|
+
Server.create_client({:user_id => user_id},nil)
|
79
|
+
else
|
80
|
+
RestClient.post("#{server}/api/client/create_client",
|
81
|
+
{:api_token => token, :user_id => user_id}.to_json,
|
82
|
+
:content_type => :json).body
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def delete_client(server,token,user_id,client_id)
|
87
|
+
if directcall?(server) and verify_token(token)
|
88
|
+
Server.delete_client({:user_id => user_id,:client_id => client_id},nil)
|
89
|
+
else
|
90
|
+
RestClient.post("#{server}/api/client/delete_client",
|
91
|
+
{:api_token => token, :user_id => user_id,
|
92
|
+
:client_id => client_id}.to_json, :content_type => :json)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def get_client_params(server,token,client_id)
|
97
|
+
if directcall?(server) and verify_token(token)
|
98
|
+
JSON.parse(Server.get_client_params({:client_id => client_id},nil))
|
99
|
+
else
|
100
|
+
JSON.parse(RestClient.post("#{server}/api/client/get_client_params",
|
101
|
+
{:api_token => token, :client_id => client_id}.to_json, :content_type => :json).body)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def get_adapter(server,token)
|
106
|
+
if directcall?(server) and verify_token(token)
|
107
|
+
JSON.parse(Server.get_adapter({},nil))
|
108
|
+
else
|
109
|
+
JSON.parse(RestClient.post("#{server}/api/source/get_adapter",
|
110
|
+
{:api_token => token}.to_json, :content_type => :json).body)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def list_sources(server,token,partition='all')
|
115
|
+
if directcall?(server) and verify_token(token)
|
116
|
+
JSON.parse(Server.list_sources({:partition_type => partition.to_s},nil))
|
117
|
+
else
|
118
|
+
JSON.parse(RestClient.post("#{server}/api/source/list_sources",
|
119
|
+
{:api_token => token, :partition_type => partition}.to_json, :content_type => :json).body)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def get_source_params(server,token,source_id)
|
124
|
+
if directcall?(server) and verify_token(token)
|
125
|
+
JSON.parse(Server.get_source_params({:source_id => source_id},nil))
|
126
|
+
else
|
127
|
+
JSON.parse(RestClient.post("#{server}/api/source/get_source_params",
|
128
|
+
{:api_token => token, :source_id => source_id}.to_json, :content_type => :json).body)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def list_source_docs(server,token,source_id,user_id='*')
|
133
|
+
if directcall?(server) and verify_token(token)
|
134
|
+
JSON.parse(Server.list_source_docs({:source_id => source_id, :user_id => user_id},nil))
|
135
|
+
else
|
136
|
+
JSON.parse(RestClient.post("#{server}/api/source/list_source_docs",
|
137
|
+
{:api_token => token, :source_id => source_id, :user_id => user_id}.to_json, :content_type => :json).body)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def list_client_docs(server,token,source_id,client_id)
|
142
|
+
if directcall?(server) and verify_token(token)
|
143
|
+
JSON.parse(Server.list_client_docs({:source_id => source_id, :client_id => client_id},nil))
|
144
|
+
else
|
145
|
+
JSON.parse(RestClient.post("#{server}/api/client/list_client_docs",
|
146
|
+
{:api_token => token, :source_id => source_id, :client_id => client_id}.to_json, :content_type => :json).body)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
#TODO: figure out data_type programmatically
|
151
|
+
def get_db_doc(server,token,doc,data_type='')
|
152
|
+
res = ""
|
153
|
+
if directcall?(server) and verify_token(token)
|
154
|
+
res = Server.get_db_doc({:doc => doc, :data_type => data_type},nil)
|
155
|
+
else
|
156
|
+
res = RestClient.post("#{server}/api/source/get_db_doc",
|
157
|
+
{:api_token => token, :doc => doc, :data_type => data_type}.to_json, :content_type => :json).body
|
158
|
+
end
|
159
|
+
data_type=='' ? JSON.parse(res) : res
|
160
|
+
end
|
161
|
+
|
162
|
+
#TODO: figure out data_type programmatically
|
163
|
+
def set_db_doc(server,token,doc,data={},data_type='')
|
164
|
+
if directcall?(server) and verify_token(token)
|
165
|
+
Server.set_db_doc({:doc => doc, :data => data, :data_type => data_type},nil)
|
166
|
+
else
|
167
|
+
RestClient.post("#{server}/api/source/set_db_doc",
|
168
|
+
{:api_token => token, :doc => doc, :data => data, :data_type => data_type}.to_json, :content_type => :json)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def reset(server,token)
|
173
|
+
if directcall?(server) and verify_token(token)
|
174
|
+
Server.reset({:api_token => token},api_user(token))
|
175
|
+
else
|
176
|
+
RestClient.post("#{server}/api/admin/reset",
|
177
|
+
{:api_token => token}.to_json, :content_type => :json)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def ping(server,token,user_id,params)
|
182
|
+
ping_params = {'api_token' => token, 'user_id' => user_id}
|
183
|
+
[:message,:badge,:sound,:vibrate,:sources,:async].each do |part|
|
184
|
+
part = part.to_s
|
185
|
+
ping_params.merge!(part => params[part]) if params[part]
|
186
|
+
end
|
187
|
+
if directcall?(server) and verify_token(token)
|
188
|
+
Server.ping(ping_params,nil)
|
189
|
+
else
|
190
|
+
RestClient.post("#{server}/api/client/ping",ping_params.to_json, :content_type => :json)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def get_license_info(server,token)
|
195
|
+
if directcall?(server) and verify_token(token)
|
196
|
+
JSON.parse(Server.get_license_info(nil,nil))
|
197
|
+
else
|
198
|
+
JSON.parse(RestClient.post("#{server}/api/admin/get_license_info",
|
199
|
+
{:api_token => token}.to_json, :content_type => :json).body)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
def stats(server,token,params)
|
204
|
+
if directcall?(server) and verify_token(token)
|
205
|
+
Server.stats(params,api_user(token))
|
206
|
+
else
|
207
|
+
RestClient.post("#{server}/api/admin/stats",
|
208
|
+
{:api_token => token}.merge!(params).to_json, :content_type => :json).body
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
private
|
213
|
+
|
214
|
+
def do_login(server,login,password)
|
215
|
+
RestClient.post("#{server}/api/admin/admin",
|
216
|
+
{:login => login, :password => password}.to_json,
|
217
|
+
:content_type => :json).body
|
218
|
+
end
|
219
|
+
|
220
|
+
def directcall?(server)
|
221
|
+
server.nil? or server.length == 0
|
222
|
+
end
|
223
|
+
|
224
|
+
def api_user(token)
|
225
|
+
ApiToken.load(token).user
|
226
|
+
end
|
227
|
+
|
228
|
+
def verify_token(token)
|
229
|
+
raise ApiException.new(422, "Invalid/missing API user") unless api_user(token); true
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
class Server
|
234
|
+
def self.api(method_name,namespace = nil, verb = :post, &block)
|
235
|
+
self.class.send(:define_method, method_name, &block) unless namespace == :application
|
236
|
+
end
|
237
|
+
|
238
|
+
def self.app_api(method_name, namespace = nil, verb = :post, &block)
|
239
|
+
# this is not used in RhoconnectAPI::Server
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
include RhoconnectApi
|
245
|
+
Dir[File.join(File.dirname(__FILE__),'..','api','**','*.rb')].each { |api| load api }
|
@@ -0,0 +1,32 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
require 'rubygems'
|
3
|
+
require 'sinatra/base'
|
4
|
+
require 'erb'
|
5
|
+
require 'json'
|
6
|
+
require 'rhoconnect_api'
|
7
|
+
|
8
|
+
module RhoconnectConsole
|
9
|
+
class << self
|
10
|
+
ROOT_DIR = File.dirname(File.expand_path(__FILE__)) unless defined? ROOT_DIR
|
11
|
+
def root_path(*args)
|
12
|
+
File.join(ROOT_DIR, *args)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class Server < Sinatra::Base
|
17
|
+
set :views, RhoconnectConsole::root_path("app","views")
|
18
|
+
set :public, RhoconnectConsole::root_path("app","public")
|
19
|
+
set :static, true
|
20
|
+
use Rack::Session::Cookie
|
21
|
+
HEROKU_NAV = ENV['INSTANCE_ID'] ? RestClient.get('http://nav.heroku.com/v1/providers/header') : nil
|
22
|
+
before do
|
23
|
+
headers['Expires'] = 'Sun, 19 Nov 1978 05:00:00 GMT'
|
24
|
+
headers['Cache-Control'] = 'no-store, no-cache, must-revalidate'
|
25
|
+
headers['Pragma'] = 'no-cache'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
Dir[File.join(File.dirname(__FILE__),"app/**/*.rb")].each do |file|
|
31
|
+
require file
|
32
|
+
end
|
@@ -0,0 +1,229 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module Rack
|
4
|
+
class Cors
|
5
|
+
def initialize(app, opts={})
|
6
|
+
@app = app
|
7
|
+
@logger = opts[:logger]
|
8
|
+
yield self if block_given?
|
9
|
+
end
|
10
|
+
|
11
|
+
def allow
|
12
|
+
all_resources << (resources = Resources.new)
|
13
|
+
yield resources
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
if env['HTTP_ORIGIN'] == 'null'
|
18
|
+
env['HTTP_ORIGIN'] = 'file://'
|
19
|
+
end
|
20
|
+
if env['HTTP_X_ORIGIN'] and not env['HTTP_ORIGIN']
|
21
|
+
puts 'ORIGIN header is empty, X-ORIGIN workaround header applied.'
|
22
|
+
env['HTTP_ORIGIN'] = env['HTTP_X_ORIGIN']
|
23
|
+
end
|
24
|
+
cors_headers = nil
|
25
|
+
if env['HTTP_ORIGIN']
|
26
|
+
debug(env) do
|
27
|
+
[ 'Incoming Headers:',
|
28
|
+
" Origin: #{env['HTTP_ORIGIN']}",
|
29
|
+
" Access-Control-Request-Method: #{env['HTTP_ACCESS_CONTROL_REQUEST_METHOD']}",
|
30
|
+
" Access-Control-Request-Headers: #{env['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}"
|
31
|
+
].join("\n")
|
32
|
+
end
|
33
|
+
if env['REQUEST_METHOD'] == 'OPTIONS'
|
34
|
+
if headers = process_preflight(env)
|
35
|
+
debug(env) do
|
36
|
+
"Preflight Headers:\n" +
|
37
|
+
headers.collect{|kv| " #{kv.join(': ')}"}.join("\n")
|
38
|
+
end
|
39
|
+
return [200, headers, ['']]
|
40
|
+
end
|
41
|
+
else
|
42
|
+
cors_headers = process_cors(env)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
status, headers, body = @app.call env
|
46
|
+
headers = headers.merge(cors_headers) if cors_headers
|
47
|
+
[status, headers, body]
|
48
|
+
end
|
49
|
+
|
50
|
+
protected
|
51
|
+
def debug(env, message = nil, &block)
|
52
|
+
logger = @logger || env['rack.logger'] || begin
|
53
|
+
@logger = ::Logger.new(STDOUT).tap {|logger| logger.level = ::Logger::Severity::INFO}
|
54
|
+
end
|
55
|
+
logger.debug(message, &block)
|
56
|
+
#TODO: remove debug output from code!
|
57
|
+
message = yield
|
58
|
+
puts message
|
59
|
+
end
|
60
|
+
|
61
|
+
def all_resources
|
62
|
+
@all_resources ||= []
|
63
|
+
end
|
64
|
+
|
65
|
+
def process_preflight(env)
|
66
|
+
resource = find_resource(env['HTTP_ORIGIN'], env['PATH_INFO'])
|
67
|
+
resource && resource.process_preflight(env)
|
68
|
+
end
|
69
|
+
|
70
|
+
def process_cors(env)
|
71
|
+
resource = find_resource(env['HTTP_ORIGIN'], env['PATH_INFO'])
|
72
|
+
resource.to_headers(env) if resource
|
73
|
+
end
|
74
|
+
|
75
|
+
def find_resource(origin, path)
|
76
|
+
allowed = all_resources.detect {|r| r.allow_origin?(origin)}
|
77
|
+
allowed ? allowed.find_resource(path) : nil
|
78
|
+
end
|
79
|
+
|
80
|
+
class Resources
|
81
|
+
|
82
|
+
def initialize
|
83
|
+
@origins = []
|
84
|
+
@resources = []
|
85
|
+
@public_resources = false
|
86
|
+
end
|
87
|
+
|
88
|
+
def origins(*args)
|
89
|
+
@origins = args.flatten.collect do |n|
|
90
|
+
if n.class == Regexp
|
91
|
+
n
|
92
|
+
else
|
93
|
+
case n
|
94
|
+
when /^[a-z]+:\/\// then n
|
95
|
+
when '*'
|
96
|
+
@public_resources = true
|
97
|
+
n
|
98
|
+
else
|
99
|
+
"http://#{n}"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def resource(path, opts={})
|
106
|
+
@resources << Resource.new(public_resources?, path, opts)
|
107
|
+
end
|
108
|
+
|
109
|
+
def public_resources?
|
110
|
+
@public_resources
|
111
|
+
end
|
112
|
+
|
113
|
+
def allow_origin?(source)
|
114
|
+
result = public_resources? || @origins.include?(source) ||
|
115
|
+
(not (@origins.select {|n| n.class == Regexp && n.match(source)}).empty?)
|
116
|
+
#TODO: to fix "n.match(source)". Unsure, but it may lead to security risks.
|
117
|
+
result
|
118
|
+
end
|
119
|
+
|
120
|
+
def find_resource(path)
|
121
|
+
@resources.detect{|r| r.match?(path)}
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
class Resource
|
126
|
+
attr_accessor :path, :methods, :headers, :expose, :max_age, :credentials, :pattern
|
127
|
+
|
128
|
+
def initialize(public_resource, path, opts={})
|
129
|
+
self.path = path
|
130
|
+
self.methods = ensure_enum(opts[:methods]) || [:get]
|
131
|
+
self.credentials = opts[:credentials] || true
|
132
|
+
self.max_age = opts[:max_age] || 1728000
|
133
|
+
self.pattern = compile(path)
|
134
|
+
@public_resource = public_resource
|
135
|
+
|
136
|
+
self.headers = case opts[:headers]
|
137
|
+
when :any then :any
|
138
|
+
when nil then nil
|
139
|
+
else
|
140
|
+
[opts[:headers]].flatten.collect{|h| h.downcase}
|
141
|
+
end
|
142
|
+
|
143
|
+
self.expose = case opts[:expose]
|
144
|
+
when nil then nil
|
145
|
+
else
|
146
|
+
[opts[:expose]].flatten
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def match?(path)
|
151
|
+
pattern =~ path
|
152
|
+
end
|
153
|
+
|
154
|
+
def process_preflight(env)
|
155
|
+
return nil if invalid_method_request?(env) || invalid_headers_request?(env)
|
156
|
+
{'Content-Type' => 'text/plain'}.merge(to_preflight_headers(env))
|
157
|
+
end
|
158
|
+
|
159
|
+
def to_headers(env)
|
160
|
+
x_origin = env['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']
|
161
|
+
h = { 'Access-Control-Allow-Origin' => public_resource? ? '*' : env['HTTP_ORIGIN'],
|
162
|
+
'Access-Control-Allow-Methods' => methods.collect{|m| m.to_s.upcase}.join(', '),
|
163
|
+
'Access-Control-Expose-Headers' => expose.nil? ? '' : expose.join(', '),
|
164
|
+
'Access-Control-Max-Age' => max_age.to_s }
|
165
|
+
h['Access-Control-Allow-Credentials'] = 'true' if credentials
|
166
|
+
h
|
167
|
+
end
|
168
|
+
|
169
|
+
protected
|
170
|
+
def public_resource?
|
171
|
+
@public_resource
|
172
|
+
end
|
173
|
+
|
174
|
+
def to_preflight_headers(env)
|
175
|
+
h = to_headers(env)
|
176
|
+
if env['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']
|
177
|
+
h.merge!('Access-Control-Allow-Headers' => env['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])
|
178
|
+
end
|
179
|
+
h
|
180
|
+
end
|
181
|
+
|
182
|
+
def invalid_method_request?(env)
|
183
|
+
request_method = env['HTTP_ACCESS_CONTROL_REQUEST_METHOD']
|
184
|
+
request_method.nil? || !methods.include?(request_method.downcase.to_sym)
|
185
|
+
end
|
186
|
+
|
187
|
+
def invalid_headers_request?(env)
|
188
|
+
request_headers = env['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']
|
189
|
+
request_headers && !allow_headers?(request_headers)
|
190
|
+
end
|
191
|
+
|
192
|
+
def allow_headers?(request_headers)
|
193
|
+
return false if headers.nil?
|
194
|
+
headers == :any || begin
|
195
|
+
request_headers = request_headers.split(/,\s*/) if request_headers.kind_of?(String)
|
196
|
+
request_headers.all?{|h| headers.include?(h.downcase)}
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
def ensure_enum(v)
|
201
|
+
return nil if v.nil?
|
202
|
+
[v].flatten
|
203
|
+
end
|
204
|
+
|
205
|
+
def compile(path)
|
206
|
+
if path.respond_to? :to_str
|
207
|
+
special_chars = %w{. + ( )}
|
208
|
+
pattern =
|
209
|
+
path.to_str.gsub(/((:\w+)|[\*#{special_chars.join}])/) do |match|
|
210
|
+
case match
|
211
|
+
when "*"
|
212
|
+
"(.*?)"
|
213
|
+
when *special_chars
|
214
|
+
Regexp.escape(match)
|
215
|
+
else
|
216
|
+
"([^/?&#]+)"
|
217
|
+
end
|
218
|
+
end
|
219
|
+
/^#{pattern}$/
|
220
|
+
elsif path.respond_to? :match
|
221
|
+
path
|
222
|
+
else
|
223
|
+
raise TypeError, path
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
end
|
229
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
unless defined?(JRUBY_VERSION)
|
2
|
+
require 'sqlite3'
|
3
|
+
else
|
4
|
+
require 'dbi'
|
5
|
+
require 'dbd/Jdbc'
|
6
|
+
require 'jdbc/sqlite3'
|
7
|
+
end
|
8
|
+
require 'singleton'
|
9
|
+
|
10
|
+
class DBAdapter
|
11
|
+
include Singleton
|
12
|
+
|
13
|
+
# Return the database connection...
|
14
|
+
# For JRuby platform returned connection has extra missing singleton methods ('execute_batch' and 'close'),
|
15
|
+
# and redefined 'transaction' method (to manage DBI auto-commit behavior)
|
16
|
+
def get_connection(dbfile)
|
17
|
+
if defined?(JRUBY_VERSION) # JRuby
|
18
|
+
db = DBI.connect("DBI:Jdbc:SQLite:#{dbfile}", nil, nil, 'driver' => 'org.sqlite.JDBC')
|
19
|
+
class << db
|
20
|
+
# jdbc/sqlite3 has no Database#execute_batch method
|
21
|
+
def execute_batch(batch)
|
22
|
+
batch.strip.split(';').each do |sth|
|
23
|
+
self.do(sth.strip)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# jdbc/sqlite3 instead of 'close' uses 'disconnect' method
|
28
|
+
def close
|
29
|
+
self.disconnect
|
30
|
+
end
|
31
|
+
|
32
|
+
alias_method :do_transaction, :transaction
|
33
|
+
# Disable auto-commit, perform transaction and restore default DBI auto-commit behavior
|
34
|
+
def transaction &block
|
35
|
+
self['AutoCommit'] = false
|
36
|
+
self.do_transaction &block
|
37
|
+
self['AutoCommit'] = true
|
38
|
+
end
|
39
|
+
end
|
40
|
+
else # Ruby 1.8/1.9
|
41
|
+
db = SQLite3::Database.new(dbfile)
|
42
|
+
end
|
43
|
+
|
44
|
+
db
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Document
|
2
|
+
|
3
|
+
# Store wrapper methods for document
|
4
|
+
def get_data(doctype,type=Hash)
|
5
|
+
Store.get_data(docname(doctype),type)
|
6
|
+
end
|
7
|
+
|
8
|
+
def get_value(doctype)
|
9
|
+
Store.get_value(docname(doctype))
|
10
|
+
end
|
11
|
+
|
12
|
+
def put_data(doctype,data,append=false)
|
13
|
+
Store.put_data(docname(doctype),data,append)
|
14
|
+
end
|
15
|
+
|
16
|
+
def put_value(doctype,data)
|
17
|
+
Store.put_value(docname(doctype),data)
|
18
|
+
end
|
19
|
+
|
20
|
+
def delete_data(doctype,data)
|
21
|
+
Store.delete_data(docname(doctype),data)
|
22
|
+
end
|
23
|
+
|
24
|
+
def flash_data(doctype)
|
25
|
+
Store.flash_data(docname(doctype))
|
26
|
+
end
|
27
|
+
|
28
|
+
def flash_source_data(doctype, from_source)
|
29
|
+
self.source_name=from_source
|
30
|
+
docnamestr = docname('') + doctype
|
31
|
+
Store.flash_data(docnamestr)
|
32
|
+
end
|
33
|
+
|
34
|
+
def rename(srcdoctype,dstdoctype)
|
35
|
+
Store.rename(docname(srcdoctype),docname(dstdoctype))
|
36
|
+
end
|
37
|
+
|
38
|
+
# Generate the fully-qualified docname
|
39
|
+
def docname(doctype)
|
40
|
+
"#{self.class.class_prefix(self.class)}:#{self.app_id}:#{self.doc_suffix(doctype)}"
|
41
|
+
end
|
42
|
+
|
43
|
+
# Update count for a given document
|
44
|
+
def update_count(doctype,count)
|
45
|
+
name = docname(doctype)
|
46
|
+
value = Store.db.get(name).to_i + count
|
47
|
+
Store.db.set(name,value < 0 ? 0 : value)
|
48
|
+
end
|
49
|
+
end
|