rhoconnect 4.0.0.beta.10 → 4.0.0.beta.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. data/CHANGELOG.md +11 -0
  2. data/Gemfile.lock +6 -6
  3. data/Rakefile +1 -1
  4. data/commands/generators/controller.rb +1 -1
  5. data/commands/generators/model.rb +1 -1
  6. data/doc/deploying.txt +41 -38
  7. data/doc/source-adapters-js.txt +263 -0
  8. data/generators/templates/application/controllers/js/application_controller.js +6 -4
  9. data/generators/templates/source/controllers/js/controller.js +4 -4
  10. data/generators/templates/source/models/js/model.js +3 -1
  11. data/install.sh +76 -6
  12. data/installer/utils/constants.rb +4 -4
  13. data/js-adapters/ballroom.js +6 -7
  14. data/js-adapters/node_channel.rb +14 -8
  15. data/js-adapters/request.js +7 -8
  16. data/js-adapters/response.js +10 -2
  17. data/js-adapters/rhoconnect_helpers.js +34 -33
  18. data/js-adapters/router.js +15 -12
  19. data/lib/rhoconnect/controller/js_base.rb +2 -7
  20. data/lib/rhoconnect/document.rb +1 -1
  21. data/lib/rhoconnect/model/base.rb +25 -10
  22. data/lib/rhoconnect/model/js_base.rb +4 -3
  23. data/lib/rhoconnect/source.rb +15 -1
  24. data/lib/rhoconnect/version.rb +1 -1
  25. data/spec/apps/rhotestapp/models/js/js_sample.js +61 -14
  26. data/spec/apps/rhotestapp/models/ruby/sample_adapter.rb +5 -0
  27. data/spec/controllers/js_base_spec.rb +16 -11
  28. data/spec/models/js_model_spec.rb +68 -7
  29. data/spec/server/server_spec.rb +28 -0
  30. data/spec/source_adapter_spec.rb +0 -11
  31. data/spec/source_spec.rb +39 -0
  32. data/spec/spec_helper.rb +11 -0
  33. metadata +4 -44
  34. data/lib/rhoconnect/api/app/ans_login.rb +0 -3
  35. data/lib/rhoconnect/api/app/bulk_data.rb +0 -10
  36. data/lib/rhoconnect/api/app/fast_delete.rb +0 -11
  37. data/lib/rhoconnect/api/app/fast_insert.rb +0 -11
  38. data/lib/rhoconnect/api/app/fast_update.rb +0 -11
  39. data/lib/rhoconnect/api/app/login.rb +0 -5
  40. data/lib/rhoconnect/api/app/push_deletes.rb +0 -12
  41. data/lib/rhoconnect/api/app/push_objects.rb +0 -12
  42. data/lib/rhoconnect/api/app/query.rb +0 -8
  43. data/lib/rhoconnect/api/app/queue_updates.rb +0 -98
  44. data/lib/rhoconnect/api/app/search.rb +0 -8
  45. data/lib/rhoconnect/api/client/client_get_db_doc.rb +0 -5
  46. data/lib/rhoconnect/api/client/client_set_db_doc.rb +0 -8
  47. data/lib/rhoconnect/api/client/create.rb +0 -7
  48. data/lib/rhoconnect/api/client/get_client_params.rb +0 -4
  49. data/lib/rhoconnect/api/client/list_client_docs.rb +0 -17
  50. data/lib/rhoconnect/api/client/register.rb +0 -12
  51. data/lib/rhoconnect/api/client/reset.rb +0 -5
  52. data/lib/rhoconnect/api/readstate/set_refresh_time.rb +0 -9
  53. data/lib/rhoconnect/api/source/get_source_params.rb +0 -4
  54. data/lib/rhoconnect/api/source/list_sources.rb +0 -16
  55. data/lib/rhoconnect/api/source/update_source_params.rb +0 -6
  56. data/lib/rhoconnect/api/store/get_db_doc.rb +0 -4
  57. data/lib/rhoconnect/api/store/set_db_doc.rb +0 -7
  58. data/lib/rhoconnect/api/system/get_adapter.rb +0 -4
  59. data/lib/rhoconnect/api/system/get_license_info.rb +0 -9
  60. data/lib/rhoconnect/api/system/login.rb +0 -15
  61. data/lib/rhoconnect/api/system/reset.rb +0 -11
  62. data/lib/rhoconnect/api/system/save_adapter.rb +0 -4
  63. data/lib/rhoconnect/api/system/stats.rb +0 -22
  64. data/lib/rhoconnect/api/user/create_user.rb +0 -7
  65. data/lib/rhoconnect/api/user/delete_client.rb +0 -6
  66. data/lib/rhoconnect/api/user/delete_user.rb +0 -11
  67. data/lib/rhoconnect/api/user/list_clients.rb +0 -4
  68. data/lib/rhoconnect/api/user/list_source_docs.rb +0 -11
  69. data/lib/rhoconnect/api/user/list_users.rb +0 -3
  70. data/lib/rhoconnect/api/user/ping.rb +0 -3
  71. data/lib/rhoconnect/api/user/show_user.rb +0 -3
  72. data/lib/rhoconnect/api/user/update_user.rb +0 -5
  73. data/lib/rhoconnect/api/user/user_get_db_doc.rb +0 -5
  74. data/lib/rhoconnect/api/user/user_set_db_doc.rb +0 -10
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## 4.0.0.beta.12 (2013-04-26)
2
+ * B-104783 - Add Node package dependency for Ubuntu/CentOS packages
3
+ * B-91486 - Redis custom partitions
4
+ * B-99049 - Implement 4.0 routes support in RhoConnect-Client
5
+ * B-104736 - Additional JS API methods added:
6
+ * Store: getData, putData, getValue, putValue
7
+ * Model: stashResult, storeBlob, getData(md)
8
+ * B-104738 - JS API documentation now available on edgedocs
9
+
10
+ ## 4.0.0.beta.11 (skipped for RMS version parity)
11
+
1
12
  ## 4.0.0.beta.10 (2013-04-18)
2
13
  * B-103674 - Add specs for testing blank rhoconnect app (run "rhoconnect" from any directory)
3
14
  * B-103671 - RhoConnect JavaScript support added
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rhoconnect (4.0.0.beta.10)
4
+ rhoconnect (4.0.0.beta.12)
5
5
  bundler (~> 1.0)
6
6
  connection_pool (~> 1.0.0)
7
7
  json (~> 1.7.7)
@@ -50,7 +50,7 @@ GEM
50
50
  multi_json (~> 1.0)
51
51
  extlib (0.9.16)
52
52
  ffaker (1.14.0)
53
- ffi (1.7.0)
53
+ ffi (1.8.1)
54
54
  fog (1.10.1)
55
55
  builder
56
56
  excon (~> 0.20)
@@ -84,7 +84,7 @@ GEM
84
84
  rainbow
85
85
  sprockets (~> 2)
86
86
  json (1.7.7)
87
- mime-types (1.22)
87
+ mime-types (1.23)
88
88
  mono_logger (1.0.1)
89
89
  multi_json (1.7.2)
90
90
  nest (1.1.2)
@@ -104,7 +104,7 @@ GEM
104
104
  rack (>= 1.0)
105
105
  rainbow (1.1.4)
106
106
  rake (10.0.4)
107
- redis (3.0.3)
107
+ redis (3.0.4)
108
108
  redis-namespace (1.2.1)
109
109
  redis (~> 3.0.0)
110
110
  resque (1.24.1)
@@ -140,7 +140,7 @@ GEM
140
140
  rack (~> 1.5, >= 1.5.2)
141
141
  rack-protection (~> 1.4)
142
142
  tilt (~> 1.3, >= 1.3.4)
143
- sprockets (2.9.2)
143
+ sprockets (2.9.3)
144
144
  hike (~> 1.2)
145
145
  multi_json (~> 1.0)
146
146
  rack (~> 1.0)
@@ -156,7 +156,7 @@ GEM
156
156
  rack (>= 1.0.0)
157
157
  thor (0.15.4)
158
158
  tilt (1.3.7)
159
- uuidtools (2.1.3)
159
+ uuidtools (2.1.4)
160
160
  vegas (0.1.11)
161
161
  rack (>= 1.0.0)
162
162
  webmock (1.9.3)
data/Rakefile CHANGED
@@ -141,7 +141,7 @@ def build_pkg(dist, arch, deps)
141
141
  Dir.chdir("./pkg") # it created by build task and should already exist
142
142
 
143
143
  # Construct fpm command
144
- fpm_cmd = "fpm -s dir -t #{dist} -n rhoconnect -v #{version} -a #{arch} -C #{build_dir} " +
144
+ fpm_cmd = "fpm -s dir -t #{dist} -n rhoconnect -v #{version} -a #{arch} -C #{build_dir} --epoch 1 " +
145
145
  "--before-install #{before_install_script} --after-install #{after_install_script} " +
146
146
  "--before-remove #{before_remove_script} --after-remove #{after_remove_script} " +
147
147
  "--prefix #{prefix} --description #{description}"
@@ -1,5 +1,5 @@
1
1
  Execute.define_task do
2
- desc "source NAME", "Generate a new source adapter controller"
2
+ desc "source NAME", "Generate a new source adapter controller", :hide => true
3
3
  def controller(name,platform='ruby')
4
4
  Rhoconnect.run_cli(Dir.pwd, 'thorhoconnect', Rhoconnect::VERSION, ARGV)
5
5
  end #source
@@ -1,5 +1,5 @@
1
1
  Execute.define_task do
2
- desc "source NAME", "Generate a new source adapter model"
2
+ desc "source NAME", "Generate a new source adapter model", :hide => true
3
3
  def model(name,platform='ruby')
4
4
  Rhoconnect.run_cli(Dir.pwd, 'thorhoconnect', Rhoconnect::VERSION, ARGV)
5
5
  end #model
data/doc/deploying.txt CHANGED
@@ -12,6 +12,8 @@ Every package provides the following components:
12
12
 
13
13
  * Ruby 1.9.3-p392
14
14
 
15
+ * Node.js, version v0.10.4
16
+
15
17
  * Nginx HTTP server, release 1.3.x
16
18
 
17
19
  * Thin application server, release 1.5.x
@@ -31,8 +33,8 @@ Add the following line to the end of your <b>/etc/apt/sources.list</b>:
31
33
 
32
34
  :::text
33
35
  deb http://rhoconnect.s3.amazonaws.com/packages/deb rhoconnect main
34
-
35
- **NOTE: If you want to get the package with cool new features from the Beta repository, then define
36
+
37
+ **NOTE: If you want to get the package with cool new features from the Beta repository, then define
36
38
  repo url as `http://rhoconnect.s3.amazonaws.com/beta-packages/deb`**
37
39
 
38
40
  Once the repo is added apt-get needs to be updated:
@@ -46,30 +48,31 @@ Once that is done, it is time to install RhoConnect:
46
48
  $ sudo apt-get install rhoconnect
47
49
 
48
50
  #### Steps for RedHat-Based Linux Users
49
- Prerequisites: target Linux server should include CentOS Development tools.
51
+ Prerequisites: target Linux server should include CentOS Development tools.
50
52
  To install them, use the this command
51
53
 
52
- :::term
54
+ :::term
53
55
  $ yum groupinstall 'Development Tools'
54
-
56
+
55
57
  It will install for you such tools as GNU GCC C/C++ compiler, make and others.
56
58
 
57
- Vanilla CentOS distribution does not include some packages required by RhoConnect installer. To resolve dependencies you
59
+ Vanilla CentOS distribution does not include some packages required by RhoConnect installer. To resolve dependencies you
58
60
  might wanted to use [Extra Packages for Enterprise Linux (EPEL) ](http://fedoraproject.org/wiki/EPEL)
59
- repository.
61
+ repository and install Python26 out of it.
60
62
 
61
63
  For example, to enable EPEL repository for CentOS 5.x release execute these commands:
62
64
 
63
65
  :::term
64
- $ wget http://mirror.us.leaseweb.net/epel/5/i386/epel-release-5-4.noarch.rpm
65
- $ rpm -i epel-release-5-4.noarch.rpm
66
+ $ wget http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
67
+ $ rpm -i epel-release-5*.rpm
66
68
  $ yum update
69
+ $ yum install python26
67
70
 
68
71
  For CentOS 6.x release:
69
72
 
70
73
  :::term
71
- $ wget http://ftp.osuosl.org/pub/fedora-epel/6/i386/epel-release-6-8.noarch.rpm
72
- $ rpm -i epel-release-6-8.noarch.rpm
74
+ $ wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
75
+ $ rpm -i epel-release-6*.rpm
73
76
  $ yum update
74
77
 
75
78
  Now you can create a file named <b>rhoconnect.repo</b> in the <b>/etc/yum.repos.d/</b> directory:
@@ -87,7 +90,7 @@ Copy and paste these contents into the file.
87
90
  gpgcheck=0
88
91
 
89
92
  **NOTE: If you want to get the package with cool new features from the Beta repository, then define baseurl as
90
- `baseurl=http://rhoconnect.s3.amazonaws.com/beta-packages/rpm`**
93
+ `baseurl=http://rhoconnect.s3.amazonaws.com/beta-packages/rpm`**
91
94
 
92
95
  Once that is done, it is time to install RhoConnect:
93
96
 
@@ -234,7 +237,7 @@ f) As root user restart Thin, and Nginx servers
234
237
 
235
238
  **NOTE: Deploying multiple rhoconnect apps on nginx has not yet been tested. Perform these steps only if you are experienced with nginx.**
236
239
 
237
- To deploy and develop two rhoconnect applications on nginx and thin servers,
240
+ To deploy and develop two rhoconnect applications on nginx and thin servers,
238
241
  refer to the nginx documentation on [nginx server blocks](http://wiki.nginx.org/ServerBlockExample) to see how to configure an nginx sever for multiple host names.
239
242
 
240
243
  For each rhoconnect app, you need to set up its own redis instance. Refer to [the redis quick start documentation](http://redis.io/topics/quickstart).
@@ -253,16 +256,16 @@ or install required gems as `sudo /opt/rhoconnect/bin/gem install gem_name`**
253
256
  ## Nginx configuration for SSL with self-signed certificate
254
257
 
255
258
  ### About Self-Signed Certificates
256
- A SSL certificate is a way to encrypt a site's information and create a more secure connection.
259
+ A SSL certificate is a way to encrypt a site's information and create a more secure connection.
257
260
  This chapter will take you through generating a self-signed certificate to use with Nginx.
258
261
 
259
262
  ### Create a Directory for the Certificate
260
- The SSL certificate has 2 main parts: the certificate itself and the public key. To make all of the relevant files easy to access, you should create a directory to store them in:
263
+ The SSL certificate has 2 main parts: the certificate itself and the public key. To make all of the relevant files easy to access, you should create a directory to store them in:
261
264
 
262
265
  :::term
263
266
  $ sudo mkdir /opt/nginx/ssl
264
267
 
265
- We will perform the next few steps within the directory:
268
+ We will perform the next few steps within the directory:
266
269
 
267
270
  :::term
268
271
  $ cd /opt/nginx/ssl
@@ -272,21 +275,21 @@ We will perform the next few steps within the directory:
272
275
  Start by creating the private server key. During this process, you will be asked to enter a specific passphrase. Be sure to note this phrase carefully, if you forget it or lose it, you will not be able to access the certificate.
273
276
 
274
277
  :::term
275
- $ openssl genrsa -des3 -out server.key 1024
278
+ $ openssl genrsa -des3 -out server.key 1024
276
279
  Generating RSA private key, 1024 bit long modulus
277
280
  ..........++++++
278
281
  ..................++++++
279
282
  e is 65537 (0x10001)
280
283
  Enter pass phrase for server.key:
281
284
  Verifying - Enter pass phrase for server.key:
282
-
283
- Follow up by creating a certificate signing request:
285
+
286
+ Follow up by creating a certificate signing request:
284
287
 
285
288
  :::term
286
289
  $ openssl req -new -key server.key -out server.csr
287
290
 
288
- This command will prompt terminal to display a lists of fields that need to be filled in.
289
- The most important line is "Common Name". Enter your official domain name here or,
291
+ This command will prompt terminal to display a lists of fields that need to be filled in.
292
+ The most important line is "Common Name". Enter your official domain name here or,
290
293
  if you don't have one yet, your site's IP address. Leave the challenge password and optional company name blank.
291
294
  :::term
292
295
  Enter pass phrase for server.key:
@@ -308,8 +311,8 @@ if you don't have one yet, your site's IP address. Leave the challenge password
308
311
  Please enter the following 'extra' attributes
309
312
  to be sent with your certificate request
310
313
  A challenge password []:
311
- An optional company name []:
312
-
314
+ An optional company name []:
315
+
313
316
  ### Remove the Passphrase
314
317
  We are almost finished creating the certificate. However, it would serve us to remove the passphrase. Although having the passphrase in place does provide heightened security, the issue starts when one tries to reload nginx. In the event that nginx crashes or needs to reboot, you will always have to re-enter your passphrase to get your entire web server back online.
315
318
 
@@ -326,14 +329,14 @@ Keep in mind that you can specify how long the certificate should remain valid b
326
329
  :::term
327
330
  $ openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
328
331
  Signature ok
329
- subject= ...
332
+ subject= ...
330
333
  Getting Private key
331
334
 
332
335
  ### Set Up the Certificate
333
336
  Now we have all of the required components of the finished certificate.
334
337
  The next thing to do is to set up the virtual host to serve your domain from HTTS connection.
335
338
 
336
- Update existing Nginx `/opt/nginx/conf/conf.d/https_rhoconnect.conf` configuration file by including the newly signed certificate and private key:
339
+ Update existing Nginx `/opt/nginx/conf/conf.d/https_rhoconnect.conf` configuration file by including the newly signed certificate and private key:
337
340
  :::term
338
341
  upstream thin_cluster {
339
342
  # ...
@@ -352,12 +355,12 @@ Update existing Nginx `/opt/nginx/conf/conf.d/https_rhoconnect.conf` configurati
352
355
 
353
356
  ssl on;
354
357
  ssl_certificate /opt/nginx/ssl/server.crt;
355
- ssl_certificate_key /opt/nginx/ssl/server.key;
358
+ ssl_certificate_key /opt/nginx/ssl/server.key;
356
359
  }
357
-
360
+
358
361
 
359
362
  ### Activate the Virtual Host
360
- Restart nginx:
363
+ Restart nginx:
361
364
  :::term
362
365
  $ /etc/init.d/nginx restart
363
366
 
@@ -425,7 +428,7 @@ You can start a redis server using the following command.
425
428
  $ sudo /etc/init.d/redis start
426
429
 
427
430
  ### RhoConnect Push Service
428
- You can create a RhoConnect Push production environment on Linux servers by installing prepackaged software for
431
+ You can create a RhoConnect Push production environment on Linux servers by installing prepackaged software for
429
432
  Ubuntu (12.x) and CentOS (5.x/6.x). In a few clicks, you will have installed on your Linux server.
430
433
 
431
434
  * Node.js with Npm package manager
@@ -457,8 +460,8 @@ Node.js requires python 2.6 which is not available for CentOS 5 stock version.
457
460
  For this flavor of linux you need to manually install EPEL repo and install python26 RPM out of it:
458
461
 
459
462
  :::term
460
- $ wget http://mirror.chpc.utah.edu/pub/epel/5/i386/epel-release-5-4.noarch.rpm
461
- $ rpm -i epel-release-5-4.noarch.rpm
463
+ $ wget http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
464
+ $ rpm -i epel-release-5*.rpm
462
465
  $ yum install python26
463
466
 
464
467
 
@@ -489,9 +492,9 @@ and deploy it into the J2EE App Server.
489
492
  Deploying the WAR container varies per J2EE App Server, for JBoss it is necessary
490
493
  to place the WAR file into the server's deploy directory.
491
494
 
492
- #### Deploying warbler package on Apache Tomcat web server
493
- To successfully deploy warbler package on Tomcat you need to make rhoconnect app be the default app. There are a few ways to reach
494
- this goal and we describe only a couple of them.
495
+ #### Deploying warbler package on Apache Tomcat web server
496
+ To successfully deploy warbler package on Tomcat you need to make rhoconnect app be the default app. There are a few ways to reach
497
+ this goal and we describe only a couple of them.
495
498
 
496
499
  ##### Method 1
497
500
 
@@ -504,7 +507,7 @@ this goal and we describe only a couple of them.
504
507
  4) Drop the `ROOT.war` file directly in the `$CATALINA_BASE/webapps` directory
505
508
 
506
509
  5) Start Tomcat `startup.sh`
507
-
510
+
508
511
  ##### Method 2
509
512
 
510
513
  1) Stop Tomcat
@@ -514,7 +517,7 @@ this goal and we describe only a couple of them.
514
517
  3) Turn off autoDeploy and deployOnStartup in your Host element in the server.xml file.
515
518
 
516
519
  4) Explicitly define your application context in server.xml, specifying both path (must be empty!) and docBase.
517
-
520
+
518
521
  :::xml
519
522
  <Host name="localhost" appBase="webapps"
520
523
  unpackWARs="true" autoDeploy="false" deployOnStartup="false">
@@ -523,8 +526,8 @@ this goal and we describe only a couple of them.
523
526
  <!-- ... -->
524
527
  </Host>
525
528
 
526
- 5) Start Tomcat
527
-
529
+ 5) Start Tomcat
530
+
528
531
  ## Deploying on Heroku
529
532
 
530
533
  #### Prerequisites
@@ -0,0 +1,263 @@
1
+ RhoConnect Source Adapters (JavaScript)
2
+ ===
3
+
4
+ ## Generating the Source Adapter from the Command Line
5
+
6
+ To generate a JavaScript source adapter for your RhoConnect application, you can run the `rhoconnect source --js` command within your application directory.
7
+
8
+ :::term
9
+ $ rhoconnect source --help
10
+ Usage: rhoconnect source [options] [args]
11
+
12
+ Generates a new source adapter (Controller/Model pair).
13
+ Required:
14
+ name - source name (i.e. product)
15
+
16
+
17
+ Options specific for this generator:
18
+ --js generate JavaScript code
19
+
20
+ General options:
21
+ -p, --pretend Run, but do not make any changes.
22
+ -f, --force Overwrite files that already exist.
23
+ -s, --skip Skip files that already exist.
24
+ -d, --delete Delete files that have previously been generated with this generator.
25
+ --no-color Don't colorize the output
26
+ -h, --help Show this message
27
+ --debug Do not catch errors
28
+
29
+
30
+ For the storeserver application example, within the storeserver directory, run:
31
+
32
+ :::term
33
+ $ rhoconnect source product --js
34
+ Generating with source generator:
35
+ [ADDED] models/js/product.js
36
+ [ADDED] controllers/js/product_controller.js
37
+
38
+
39
+ ## Understanding the Generated Controller File
40
+
41
+ The generated source adapter's controller file (in this case, `controllers/product_controller.js`) is similar to the code listing below.
42
+ Its purpose is to define the RhoConnect application HTTP end point and to register the corresponding SYNC routes.
43
+
44
+ :::javascript
45
+ var app = require("ballroom");
46
+ var helpers = require("rhoconnect_helpers");
47
+
48
+ app.controllerName("Product");
49
+ app.registerHandler("sync");
50
+
51
+ // Add your custom routes here
52
+
53
+ ## Understanding the Generated Model File
54
+
55
+ The generated source adapter's model file (in this case, `models/product.js`) is similar to the code listing below:
56
+
57
+ :::javascript
58
+ var Product = function(){
59
+
60
+ this.login = function(resp){
61
+ // TODO: Login to your data source here if necessary
62
+ resp.send(true);
63
+ };
64
+
65
+ this.query = function(resp){
66
+ var result = {};
67
+ // TODO: Query your backend data source and assign the records
68
+ // to a nested hash structure. Then return your result.
69
+ // For example:
70
+ //
71
+ // {
72
+ // "1": {"name": "Acme", "industry": "Electronics"},
73
+ // "2": {"name": "Best", "industry": "Software"}
74
+ // }
75
+ resp.send(result);
76
+ };
77
+
78
+ this.create = function(resp){
79
+ // TODO: Create a new record in your backend data source. Then
80
+ // return the result.
81
+ resp.send('someId');
82
+ };
83
+
84
+ this.update = function(resp){
85
+ // TODO: Update an existing record in your backend data source.
86
+ // Then return the result.
87
+ resp.send(true);
88
+ };
89
+
90
+ this.del = function(resp){
91
+ // TODO: Delete an existing record in your backend data source
92
+ // if applicable. Be sure to have a hash key and value for
93
+ // "object" and return the result.
94
+ resp.send(true);
95
+ };
96
+
97
+ this.logoff = function(resp){
98
+ // TODO: Logout from the data source if necessary.
99
+ resp.send(true);
100
+ };
101
+ };
102
+
103
+ module.exports = new Product();
104
+
105
+ ## Source Adapter API
106
+
107
+ ### Source Adapter Controller API
108
+
109
+ You can use the following methods and techniques inside of your source adapter controller.
110
+
111
+ * [controllerName](/rhoconnectapi/source-adapter-controller-api-js#controllernamename) - Name of the source adapter controller.
112
+ * [registerHandler](/rhoconnectapi/source-adapter-controller-api-js#registerhandlername) - Register a RhoConnect handler for the controller.
113
+ * [get](/rhoconnectapi/source-adapter-controller-api-js#getroute-options-callback) - Define a GET route.
114
+ * [post](/rhoconnectapi/source-adapter-controller-api-js#postroute-options-callback) - Define a POST route.
115
+ * [put](/rhoconnectapi/source-adapter-controller-api-js#putroute-options-callback) - Define a PUT route.
116
+ * [del](/rhoconnectapi/source-adapter-controller-api-js#delroute-options-callback) - Define a DELETE route.
117
+ * [currentUser](/rhoconnectapi/source-adapter-model-api-js#currentuser) - Returns the current user who called the adapter's model.
118
+ * [loadModel](http://localhost:9393/rhoconnectapi/source-adapter-controller-api-js#loadmodelname) - Returns the current model instance for this controller.
119
+
120
+ ### Source Adapter Model API
121
+
122
+ You can write the following methods for your source adapter model. These methods will be called by the controller at run-time and allow your source adapter model to interact with your backend service.
123
+
124
+ * [login](/rhoconnectapi/source-adapter-model-api-js#login) - Login to your backend service.
125
+ * [logoff](/rhoconnectapi/source-adapter-model-api-js#logoff) - Logoff from your backend service.
126
+ * [query](/rhoconnectapi/source-adapter-model-api-js#query) - Query your backend service and build a hash of hashes.
127
+ * [create](/rhoconnectapi/source-adapter-model-api-js#create) - Create a new record in the backend.
128
+ * [update](/rhoconnectapi/source-adapter-model-api-js#update) - Update an existing record in the backend.
129
+ * [del](/rhoconnectapi/source-adapter-model-api-js#del) - Delete an existing record in the backend.
130
+ * [stashResult](/rhoconnectapi/source-adapter-model-api-js#stashresultresp) - Saves the current state of the result to redis and sets it `undefined`.
131
+ * [getData](/rhoconnectapi/source-adapter-model-api-js#getdataresp-callback) - Get the model document data from Store.
132
+ * [currentUser](/rhoconnectapi/source-adapter-model-api-js#currentuser) - Returns the current user who called the adapter's model.
133
+ * [storeBlob](/rhoconnectapi/source-adapter-model-api-js#storeblob) - Save the incoming blob data into permanent storage for the future processing.
134
+
135
+
136
+ ### Request API
137
+ The [request object](/rhoconnectapi/source-adapter-request-api-js) contains information about the HTTP request the app is receiving.
138
+
139
+ * [params](/rhoconnectapi/source-adapter-request-api-js#params) - Access in the incoming request parameters (i.e. from the HTTP query string).
140
+ * [header](/rhoconnectapi/source-adapter-request-api-js#header) - HTTP request headers.
141
+ * [model](/rhoconnectapi/source-adapter-request-api-js#model) - The corresponding model name of the request.
142
+
143
+ ### Response API
144
+ The [response](/rhoconnectapi/source-adapter-response-api-js) is used to pass application control and return the `result` hash to RhoConnect.
145
+
146
+ * [params](/rhoconnectapi/source-adapter-response-api-js#params) - Access in the incoming request parameters (i.e. from the HTTP query string).
147
+ * [header](/rhoconnectapi/source-adapter-response-api-js#header) - HTTP request headers.
148
+ * [send](/rhoconnectapi/source-adapter-response-api-js#sendvalue) - Return program control (most controller and model methods will need to do this).
149
+ * [exception](/rhoconnectapi/source-adapter-response-api-js#exception) - Holds the exception for the request (if one is raised).
150
+ * [currentUser](/rhoconnectapi/source-adapter-model-api-js#currentuser) - Returns the current user who called the adapter's model.
151
+
152
+ ## Store API
153
+ RhoConnect provides a simple [redis interface](/rhoconnectapi/source-adapter-store-api-js) for saving/retrieving arbitrary data. This is useful if you want to save data in your application to be used later (i.e. in an async job or a subsequent source adapter execution).
154
+
155
+ * [getValue](/rhoconnectapi/source-adapter-store-api-js#getvaluerespcallback) - Retrieve a simple value from redis.
156
+ * [putValue](/rhoconnectapi/source-adapter-store-api-js#putvaluerespcallback) - Add a simple value to redis.
157
+ * [getData](/rhoconnectapi/source-adapter-store-api-js#getdatarespcallback) - Retrieve an array or hash from redis.
158
+ * [putData](/rhoconnectapi/source-adapter-store-api-js#putdatarespcallback) - Add an array or hash to redis.
159
+
160
+ ## Sample Model
161
+ Here's a complete example of how the completed [product model might look](https://gist.github.com/larsburgess/87753882f3a4a366b48b):
162
+
163
+ :::javascript
164
+ var http = require('http');
165
+ var host = 'rhostore.herokuapp.com';
166
+
167
+ var Product = function(){
168
+
169
+ this.login = function(resp){
170
+ resp.send(true);
171
+ };
172
+
173
+ this.query = function(resp){
174
+ var result = {};
175
+ var str = '';
176
+
177
+ http.request('http://' + host + '/products.json', function(res){
178
+ res.on('data', function(chunk){
179
+ str += chunk;
180
+ });
181
+ res.on('end', function(){
182
+ var data = JSON.parse(str);
183
+ for(var i in data){
184
+ var item = data[i];
185
+ result[item.product.id.toString()] = item.product;
186
+ }
187
+ resp.send(result);
188
+ });
189
+ }).end();
190
+ };
191
+
192
+ this.create = function(resp){
193
+ var postData = JSON.stringify({ 'product': resp.params.create_object });
194
+ var str = '';
195
+ var options = {
196
+ host: host,
197
+ path: '/products.json',
198
+ method: 'POST',
199
+ headers: { 'Content-Type': 'application/json' }
200
+ };
201
+ var req = http.request(options, function(res){
202
+ res.on('data', function(chunk){
203
+ str += chunk;
204
+ });
205
+ res.on('end', function(){
206
+ var data = JSON.parse(str);
207
+ resp.send(data.product.id.toString());
208
+ });
209
+ });
210
+ req.write(postData);
211
+ req.end();
212
+ };
213
+
214
+ this.update = function(resp){
215
+ var objId = resp.params.update_object.id;
216
+ var putData = JSON.stringify({ "product": resp.params.update_object });
217
+ // Remove the id from the hash, we don't need it.
218
+ delete putData.id;
219
+ var options = {
220
+ host: host,
221
+ path: '/products/' + objId + '.json',
222
+ method: 'PUT',
223
+ headers: { 'Content-Type': 'application/json' }
224
+ };
225
+ var req = http.request(options, function(res){
226
+ res.on('data', function(){});
227
+ res.on('end', function(){
228
+ resp.send(true);
229
+ });
230
+ res.on('error', function(){
231
+ resp.send(false);
232
+ });
233
+ });
234
+ req.write(putData);
235
+ req.end();
236
+ };
237
+
238
+ this.del = function(resp){
239
+ var objId = resp.params.delete_object.id;
240
+ var options = {
241
+ host: host,
242
+ path: '/products/' + objId + '.json',
243
+ method: 'DELETE',
244
+ headers: { 'Content-Type': 'application/json' }
245
+ };
246
+ var req = http.request(options, function(res){
247
+ res.on('data', function(){});
248
+ res.on('end', function(){
249
+ resp.send(true);
250
+ });
251
+ res.on('error', function(){
252
+ resp.send(false);
253
+ });
254
+ });
255
+ req.end();
256
+ };
257
+
258
+ this.logoff = function(resp){
259
+ resp.send(true);
260
+ };
261
+ };
262
+
263
+ module.exports = new Product();
@@ -1,13 +1,15 @@
1
- var app = require("ballroom");
2
- app.controllerName("Application");
1
+ var app = require('ballroom');
2
+ var rc = require('rhoconnect_helpers');
3
+ app.controllerName('Application');
3
4
 
4
- app.post("/login",{"rc_handler":"authenticate"}, function(req,resp){
5
+ app.post('/login',{'rc_handler':'authenticate',
6
+ 'deprecated_route': {'verb': 'post', 'url': ['/application/clientlogin']}}, function(req,resp){
5
7
  var login = req.params.login;
6
8
  var password = req.params.password;
7
9
  resp.send(true);
8
10
  });
9
11
 
10
- app.get("/rps_login",{"rc_handler":"rps_authenticate"}, function(req,resp){
12
+ app.get('/rps_login',{'rc_handler':'rps_authenticate'}, function(req,resp){
11
13
  var login = req.params.login;
12
14
  var password = req.params.password;
13
15
  resp.send(true);
@@ -1,7 +1,7 @@
1
- var app = require("ballroom");
2
- var helpers = require("rhoconnect_helpers");
1
+ var app = require('ballroom');
2
+ var rc = require('rhoconnect_helpers');
3
3
 
4
- app.controllerName("<%=class_name%>");
5
- app.registerHandler("sync");
4
+ app.controllerName('<%=class_name%>');
5
+ app.registerHandler('sync');
6
6
 
7
7
  // Add your custom routes here
@@ -1,4 +1,6 @@
1
- var <%=class_name%> = function() {
1
+ var rc = require('rhoconnect_helpers');
2
+
3
+ var <%=class_name%> = function(){
2
4
 
3
5
  this.login = function(resp){
4
6
  // TODO: Login to your data source here if necessary