test_machine_shop 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +7 -0
  2. data/.idea/.name +1 -0
  3. data/.idea/.rakeTasks +7 -0
  4. data/.idea/compiler.xml +23 -0
  5. data/.idea/copyright/profiles_settings.xml +5 -0
  6. data/.idea/encodings.xml +5 -0
  7. data/.idea/inspectionProfiles/Project_Default.xml +7 -0
  8. data/.idea/inspectionProfiles/profiles_settings.xml +7 -0
  9. data/.idea/machineshop.iml +194 -0
  10. data/.idea/misc.xml +5 -0
  11. data/.idea/modules.xml +9 -0
  12. data/.idea/scopes/scope_settings.xml +5 -0
  13. data/.idea/vcs.xml +7 -0
  14. data/.idea/workspace.xml +722 -0
  15. data/Gemfile +9 -0
  16. data/LICENSE +22 -0
  17. data/README.md +977 -0
  18. data/Rakefile +8 -0
  19. data/doc.txt +50 -0
  20. data/lib/machineshop.rb +475 -0
  21. data/lib/machineshop/api_operations/create.rb +17 -0
  22. data/lib/machineshop/api_operations/delete.rb +11 -0
  23. data/lib/machineshop/api_operations/list.rb +16 -0
  24. data/lib/machineshop/api_operations/update.rb +11 -0
  25. data/lib/machineshop/api_resource.rb +35 -0
  26. data/lib/machineshop/configuration.rb +14 -0
  27. data/lib/machineshop/customer.rb +15 -0
  28. data/lib/machineshop/data_source_types.rb +28 -0
  29. data/lib/machineshop/data_sources.rb +35 -0
  30. data/lib/machineshop/database.rb +59 -0
  31. data/lib/machineshop/device.rb +30 -0
  32. data/lib/machineshop/device_instance.rb +30 -0
  33. data/lib/machineshop/end_points.rb +30 -0
  34. data/lib/machineshop/errors/api_connection_error.rb +4 -0
  35. data/lib/machineshop/errors/api_error.rb +4 -0
  36. data/lib/machineshop/errors/authentication_error.rb +4 -0
  37. data/lib/machineshop/errors/database_error.rb +5 -0
  38. data/lib/machineshop/errors/invalid_request_error.rb +10 -0
  39. data/lib/machineshop/errors/machineshop_error.rb +20 -0
  40. data/lib/machineshop/errors/schema_error.rb +5 -0
  41. data/lib/machineshop/json.rb +21 -0
  42. data/lib/machineshop/machineshop_cache.rb +49 -0
  43. data/lib/machineshop/machineshop_object.rb +165 -0
  44. data/lib/machineshop/mapping.rb +34 -0
  45. data/lib/machineshop/meter.rb +12 -0
  46. data/lib/machineshop/models/api_endpoint.rb +8 -0
  47. data/lib/machineshop/models/api_request.rb +28 -0
  48. data/lib/machineshop/models/schema.rb +184 -0
  49. data/lib/machineshop/report.rb +11 -0
  50. data/lib/machineshop/rule.rb +42 -0
  51. data/lib/machineshop/user.rb +43 -0
  52. data/lib/machineshop/users.rb +43 -0
  53. data/lib/machineshop/util.rb +193 -0
  54. data/lib/machineshop/utility.rb +30 -0
  55. data/lib/machineshop/version.rb +3 -0
  56. data/machineshop.gemspec +35 -0
  57. data/spec/lib/api_calls_spec.rb +628 -0
  58. data/spec/lib/custom_endpoint_test.rb +78 -0
  59. data/spec/lib/customer_spec.rb +87 -0
  60. data/spec/lib/data_source.rb +138 -0
  61. data/spec/lib/data_source_type_spec.rb +77 -0
  62. data/spec/lib/database_spec.rb +45 -0
  63. data/spec/lib/device_instances.rb +73 -0
  64. data/spec/lib/device_spec.rb +172 -0
  65. data/spec/lib/endpoint_spec.rb +37 -0
  66. data/spec/lib/geocode_spec +45 -0
  67. data/spec/lib/mapping_spec.rb +68 -0
  68. data/spec/lib/meter_spec.rb +49 -0
  69. data/spec/lib/report_spec.rb +52 -0
  70. data/spec/lib/rule_spec.rb +130 -0
  71. data/spec/lib/user_spec.rb +58 -0
  72. data/spec/spec_helper.rb +12 -0
  73. metadata +235 -0
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in machineshop.gemspec
4
+ gemspec
5
+
6
+ # gem "mysql"
7
+ gem "activerecord"
8
+ gem "awesome_print"
9
+ gem 'will_paginate'
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 John Cox
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,977 @@
1
+ # MachineShop
2
+
3
+ Wraps the machineshop API
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'machineshop'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install machineshop
18
+
19
+
20
+
21
+ ## Usage
22
+
23
+ ### Setting client specific platform URL
24
+
25
+
26
+ > **Caution: Only If you have custom API endpoints**
27
+
28
+ MachineShop.api_base_url= 'http://stage.services.machineshop.io/api/v0/myClient'
29
+
30
+
31
+
32
+ ### Authentication
33
+ Allow a user to authenticate
34
+
35
+ auth_token, user = MachineShop::User.authenticate(
36
+ :email => "username",
37
+ :password => "password"
38
+ )
39
+
40
+
41
+ * ##### Http_method : Post
42
+
43
+ * ##### Parameters :
44
+ * email _string_
45
+ * password _string_
46
+
47
+ ##### Response Example
48
+
49
+
50
+ {
51
+ "id" => "8e98188e981800aaef000001",
52
+ "_id" => "8e98188e981800aaef000001",
53
+ "authentication_token" => "2jzZhuHWLZy9fsxcd36E",
54
+ "company_name" => "company_name",
55
+ "current_sign_in_at" => "2014-06-09T08:26:06Z",
56
+ "current_sign_in_ip" => "202.51.76.235",
57
+ "domain" => "john@domain.com",
58
+ "email" => "admin@domain.com",
59
+ "first_name" => "First_name",
60
+ "keychain" => {},
61
+ "last_name" => "Last_name",
62
+ "last_sign_in_at" => "2014-06-09T08:26:06Z",
63
+ "last_sign_in_ip" => "202.51.76.235",
64
+ "logo_url" => nil,
65
+ "name_space" => [
66
+ [0]
67
+ "test"
68
+ ],
69
+ "notification_method" => "sms",
70
+ "phone_number" => "+1 (123) 456-7890",
71
+ "role" => "admin",
72
+ "sign_in_count" => 234,
73
+ "tag_ids" => [],
74
+ "http_code" => 200}
75
+
76
+ ### Get All user roles
77
+ Get all the roles assigned to the current user
78
+
79
+ MachineShop::User.all_roles(auth_token)
80
+
81
+
82
+ * ##### Http_method : Get
83
+
84
+ * ##### Parameters :
85
+
86
+ * auth\_token: _string_
87
+ > obtained from #authentication
88
+
89
+ ##### Response Example
90
+
91
+
92
+ [
93
+ "admin",
94
+ "publisher",
95
+ "consumer"]
96
+
97
+ ----
98
+ ### Retrieve user
99
+ Get User object to apply the following actions
100
+
101
+ > user.update,
102
+ > user.delete
103
+
104
+ MachineShop::User.retrieve(user_id, auth_token)
105
+
106
+ * ##### Http_method : Get
107
+
108
+ * ##### Parameters :
109
+ * auth\_token _string_
110
+ * user\_id: _string_
111
+
112
+
113
+ > auth_token available in response object from #authentication
114
+
115
+ ##### Response Example
116
+
117
+
118
+ > Same as from authenticate
119
+
120
+
121
+ ### Get the devices of the current user
122
+
123
+ MachineShop::Device.all(
124
+ {:page => 1,
125
+ :per_page => 10},
126
+ auth_token)
127
+
128
+ * ##### Http_method : Get
129
+
130
+ * ##### Parameters :
131
+ * page _Integer_
132
+ > page number for pagination
133
+
134
+ * name _string_
135
+ > get device by name
136
+
137
+ * per\_page: _Integer_
138
+ > Number of items to display
139
+ * auth\_token
140
+
141
+ ##### Response Example
142
+
143
+
144
+ [{
145
+ "id": "9584216470180077f7000157",
146
+ "_id": "9584216470180077f7000157",
147
+ "active": true,
148
+ "created_at": "2014-06-09T09:16:06Z",
149
+ "deleted_at": null,
150
+ "exe_path": "/etc/foo",
151
+ "image_url": "http://someurl.com/your_image.png",
152
+ "init_cmd": "my_init_cmd",
153
+ "init_params": "{'init':'go'}",
154
+ "last_known_translator_port": null,
155
+ "long_description": "This device tracks position and test.",
156
+ "manual_url": "http://someurl.com/manual.pdf",
157
+ "manufacturer": "a company",
158
+ "model": "D-vice 1000",
159
+ "name": "my_device",
160
+ "rule_ids": [],
161
+ "sample_data": "some arbitrary sample data",
162
+ "software": null,
163
+ "tag_ids": [],
164
+ "translator": null,
165
+ "type": "Test",
166
+ "unit_price": "$199.99",
167
+ "updated_at": "2014-06-09T09:16:06Z",
168
+ "user_id": "11161696201800aaef0000459}, {
169
+ "id": "2065309466180077f7000157",
170
+ "_id": "2065309466180077f7000157",
171
+ "active": true,
172
+ "created_at": "2014-06-09T09:15:01Z",
173
+ "deleted_at": null,
174
+ "exe_path": "/etc/foo",
175
+ "image_url": "http://someurl.com/your_image.png",
176
+ "init_cmd": "my_init_cmd",
177
+ "init_params": "{'init':'go'}",
178
+ "last_known_translator_port": null,
179
+ "long_description": "This device tracks position and btest.",
180
+ "manual_url": "http://someurl.com/manual.pdf",
181
+ "manufacturer": "a company",
182
+ "model": "D-vice 1000",
183
+ "name": "my_device",
184
+ "rule_ids": [],
185
+ "sample_data": "some arbitrary sample data",
186
+ "software": null,
187
+ "tag_ids": [],
188
+ "translator": null,
189
+ "type": "Test",
190
+ "unit_price": "$199.99",
191
+ "updated_at": "2014-06-09T09:15:01Z",
192
+ "user_id": "11161696201800aaef0000459"} ]
193
+
194
+
195
+ ---
196
+ ### Retrieve Device
197
+
198
+ specificDevice = MachineShop::Device.retrieve(device_id, auth_token)
199
+
200
+ * ##### Http_method : Get
201
+
202
+ * ##### Parameters :
203
+ * device\_id
204
+
205
+ > device id
206
+
207
+ * auth\_token
208
+
209
+
210
+ ##### Response Example
211
+
212
+
213
+ {
214
+ "id" => "51795428911800d51400016c",
215
+ "_id" => "51795428911800d51400016c",
216
+ "active" => true,
217
+ "created_at" => "2014-06-09T10:02:50Z",
218
+ "deleted_at" => nil,
219
+ "exe_path" => "/etc/foo",
220
+ "image_url" => "http://someurl.com/your_image.png",
221
+ "init_cmd" => "my_init_cmd",
222
+ "init_params" => "{'init':'go'}",
223
+ "last_known_translator_port" => nil,
224
+ "long_description" => "This device tracks position and NCAA football conference.",
225
+ "manual_url" => "http://someurl.com/manual.pdf",
226
+ "manufacturer" => "a company",
227
+ "model" => "D-vice 1000",
228
+ "name" => "my_device",
229
+ "rule_ids" => [],
230
+ "sample_data" => "some arbitrary sample data",
231
+ "software" => nil,
232
+ "tag_ids" => [],
233
+ "translator" => nil,
234
+ "type" => "Test",
235
+ "unit_price" => "$199.99",
236
+ "updated_at" => "2014-06-09T10:02:50Z",
237
+ "user_id" => "11161696201800aaef000056",
238
+ "http_code" => 200}
239
+
240
+ ---
241
+
242
+ ### Create device instance for the device
243
+
244
+ device_instance = specificDevice.create_instance(
245
+ {
246
+ :name => "My little instance",
247
+ :active => "yes"
248
+ }
249
+
250
+
251
+
252
+ * ##### Http_method : Post
253
+
254
+ * ##### Parameters :
255
+ * name
256
+ * active
257
+
258
+ ##### Response Example
259
+
260
+
261
+
262
+
263
+ {
264
+ "id" => "30048840211800a9c600000c",
265
+ "_id" => "30048840211800a9c600000c",
266
+ "tag_ids" => [],
267
+ "rule_ids" => [],
268
+ "alert_count" => 0,
269
+ "name" => "My little instance",
270
+ "active" => true,
271
+ "device_id" => "531eafcb38300488402145",
272
+ "user_id" => "11800a9c1800aaef0004543",
273
+ "auth_token" => nil,
274
+ "updated_at" => "2014-03-11T06:41:42Z",
275
+ "created_at" => "2014-03-11T06:41:42Z",
276
+ "http_code" => 200}
277
+
278
+ ---
279
+
280
+
281
+ ### Create a device
282
+
283
+ Create a new device
284
+
285
+ newDevice = MachineShop::Device.create(
286
+ {
287
+ :name => "my_device",
288
+ :type => "Test",
289
+ :manufacturer => "a company",
290
+ :model => "D-vice 1000",
291
+ :active => "yes",
292
+ :init_cmd => "my_init_cmd",
293
+ :init_params => "{'init':'go'}",
294
+ :exe_path => "/etc/foo",
295
+ :unit_price => "$199.99",
296
+ :sample_data => "some arbitrary sample data",
297
+ :long_description => "This device tracks position of test.",
298
+ :image_url => "http://someurl.com/your_image.png",
299
+ :manual_url => "http://someurl.com/manual.pdf"},auth_token)
300
+
301
+
302
+
303
+ * Http_method : Post
304
+
305
+
306
+ > Alternately the device instance can be created from this object as well
307
+
308
+ newDevice.create_instance(
309
+ {
310
+ :name => "My little instance",
311
+ :active => "yes"
312
+ }
313
+ )
314
+
315
+ ---
316
+
317
+ ### Get the device instances
318
+ Get all the device instances of the user
319
+
320
+ MachineShop::DeviceInstance.all({:name => "instance_name"}, auth_token)
321
+
322
+
323
+ > Pass first parameter as empty array if no filters to be applied
324
+
325
+ * ##### Http_method : Get
326
+
327
+ * ##### Parameters
328
+ * auth_token
329
+ * filter_parameters
330
+
331
+ * * name
332
+
333
+ ##### Response Example
334
+
335
+
336
+ {
337
+ "id" => "51795428911800d51400016c",
338
+ "_id" => "51795428911800d51400016c",
339
+ "active" => true,
340
+ "created_at" => "2014-06-09T10:02:50Z",
341
+ "deleted_at" => nil,
342
+ "exe_path" => "/etc/foo",
343
+ "image_url" => "http://someurl.com/your_image.png",
344
+ "init_cmd" => "my_init_cmd",
345
+ "init_params" => "{'init':'go'}",
346
+ "last_known_translator_port" => nil,
347
+ "long_description" => "This device tracks position and NCAA football conference.",
348
+ "manual_url" => "http://someurl.com/manual.pdf",
349
+ "manufacturer" => "a company",
350
+ "model" => "D-vice 1000",
351
+ "name" => "my_device",
352
+ "rule_ids" => [],
353
+ "sample_data" => "some arbitrary sample data",
354
+ "software" => nil,
355
+ "tag_ids" => [],
356
+ "translator" => nil,
357
+ "type" => "Test",
358
+ "unit_price" => "$199.99",
359
+ "updated_at" => "2014-06-09T10:02:50Z",
360
+ "user_id" => "11161696201800aaef000056",
361
+ "http_code" => 200}
362
+
363
+
364
+ > Another way
365
+
366
+ user.device_instances({:name => device_instance.name})
367
+ or without filters
368
+
369
+ user.device_instances
370
+ > Where user is the user object from the #Authenticate or retrieved user
371
+
372
+ specificDevice.instances
373
+ > where specficiDevice is the object from retrieve
374
+
375
+
376
+ ---
377
+
378
+ ### Create Customers
379
+
380
+
381
+ specificCustomer =MachineShop::Customer.create({:email=>"test@domain.com",
382
+ :password=>'password',
383
+ :notification_method=>'sms',
384
+ :first_name=>'John',:last_name=>'Doe',
385
+ :phone_number=>'98989898989',
386
+ :company_name=>'technology co'
387
+
388
+ },auth_token)
389
+
390
+
391
+ * ##### Http_method : Post
392
+
393
+ * ##### Parameters
394
+
395
+ * Post parameters: _array of params_
396
+ * auth_token
397
+
398
+ ##### Response Example
399
+
400
+
401
+
402
+ {
403
+ "id" => "958421647080007a004506b",
404
+ "_id" => "958421647080007a004506b",
405
+ "email" => "test@domain.com",
406
+ "domain" => "machineshop",
407
+ "sign_in_count" => 0,
408
+ "keychain" => {},
409
+ "notification_method" => "sms",
410
+ "first_name" => "John",
411
+ "last_name" => "Doe",
412
+ "phone_number" => "98989898989",
413
+ "company_name" => "technology co",
414
+ "publisher_id" => "3004884021800aaef0056893",
415
+ "role" => "consumer",
416
+ "logo_url" => nil,
417
+ "name_space" => [
418
+ [0]
419
+ "csr"
420
+ ],
421
+ "authentication_token" => "YLMDGOvdjyucLvwaJKfu",
422
+ "http_code" => 200
423
+ }
424
+
425
+ ---
426
+ ### Retrieve Customer
427
+ Retrieve customer by Id
428
+
429
+
430
+ retrievedCustomer = MachineShop::Customer.retrieve(customer_id, auth_token)
431
+
432
+
433
+ * ##### Http_method : Get
434
+
435
+ * ##### Parameters
436
+
437
+ * customer\_id _string_
438
+ * auth_token
439
+
440
+ ##### Response Example
441
+
442
+
443
+
444
+ same as above
445
+
446
+ ----
447
+
448
+ ### Update Customer by Id
449
+
450
+
451
+ MachineShop::Customer.update(customer_id,auth_token,{:notification_method => 'email'})
452
+
453
+
454
+
455
+ * ##### Http_method : Put
456
+
457
+ * ##### Parameters
458
+
459
+ * customer_id: _string_
460
+ * update parameters: _array of params_
461
+ * auth_token
462
+
463
+ ##### Response Example
464
+
465
+
466
+
467
+ {
468
+ "id": "958421647080007a004506b",
469
+ "_id": "958421647080007a004506b",
470
+ "email": "test@domain.com",
471
+ "domain": "machineshop",
472
+ "sign_in_count": 0,
473
+ "keychain": {},
474
+ "notification_method": "sms",
475
+ "first_name": "John",
476
+ "last_name": "Doe",
477
+ "phone_number": "98989898989",
478
+ "company_name": "technology co",
479
+ "publisher_id": "3004884021800aaef0056893",
480
+ "role": "consumer",
481
+ "logo_url": null,
482
+ "name_space": ["csr"],
483
+ "authentication_token": "YLMDGOvdjyucLvwaJKfu",
484
+ "http_code": 200
485
+ }
486
+
487
+
488
+ > Alternately
489
+
490
+ retrieved_cust.update({:notification_method => 'email'})
491
+
492
+
493
+ ---
494
+ ### Delete Customer
495
+ Delete the Customer
496
+
497
+ retrievedCustomer.delete
498
+
499
+
500
+ > retrievedCustomer is the retrieved customer object
501
+
502
+ * ##### Http_method : delete
503
+
504
+
505
+ ##### Response Example
506
+
507
+
508
+
509
+ {"http_code":200,"deleted":true}
510
+
511
+
512
+ ---
513
+
514
+ ### List rules
515
+ List all the rules of user
516
+
517
+ MachineShop::Rule.all({},auth_token)
518
+
519
+
520
+ > First parameters is filters or empty array should be provided
521
+
522
+ * ##### Http_method : Get
523
+
524
+ * ##### Parameters
525
+
526
+ * filter parameters: _array of params_
527
+ * auth_token
528
+
529
+ ##### Response Example
530
+
531
+
532
+
533
+ {
534
+ "id": "958421647080007a004506b",
535
+ "_id": "958421647080007a004506b",
536
+ "actions": [{
537
+ "id": "958421647080007a0045062",
538
+ "_id": "958421647080007a0045062",
539
+ "send_to": "john@mach19.com",
540
+ "_type": "EmailAction"
541
+ }, {
542
+ "id": "958421647080007a0045063",
543
+ "_id": "958421647080007a0045063",
544
+ "send_to": "14794263982",
545
+ "_type": "SmsAction"
546
+ }],
547
+ "active": true,
548
+ "comparison_value": "0",
549
+ "created_at": "2012-09-26T20:33:19Z",
550
+ "deleted": false,
551
+ "deleted_at": null,
552
+ "description": "testing stage rule",
553
+ "device_attribute": "stage",
554
+ "device_ids": [],
555
+ "device_instance_ids": ["503900d2ab400015a5731125"],
556
+ "downstream_rule_id": null,
557
+ "last_run": "2012-09-28T18:53:58Z",
558
+ "last_run_status": "pass",
559
+ "modified_date": "2012-09-26T20:33:19Z",
560
+ "operator": "gt",
561
+ "plain_english": "This rule has no conditions.",
562
+ "rule_histories": [],
563
+ "tag_ids": [],
564
+ "updated_at": "2012-09-28T18:53:58Z",
565
+ "user_id": "3004884021800aaef0056893"}
566
+
567
+ ---
568
+
569
+
570
+ ### Create Rule
571
+ Create a rule
572
+
573
+ create_hash = {
574
+ :devices=>["52585e1d981800bab2000479"],
575
+ :device_instances=>[],
576
+ :rule=>{
577
+ :active=>true,
578
+ :description=>"test",
579
+ :condition=>{
580
+ :type=>"and_rule_condition",
581
+ :rule_conditions=>[{
582
+
583
+ :property=>"var",
584
+ :value=>"30",
585
+ :type=>"equal_rule_condition"
586
+
587
+ }]
588
+ },
589
+ :then_actions=>[{
590
+ :priority=>"1",
591
+ :send_to=>"abc@me.com",
592
+ :type=>"email_rule_action"
593
+ }]
594
+ } }
595
+
596
+ createdRule = MachineShop::Rule.create(create_hash,auth_token)
597
+
598
+ * ##### Http_method : Post
599
+
600
+ * ##### Parameters
601
+
602
+ * create parameter: _json array of params_
603
+ * auth_token
604
+
605
+ ##### Response Example
606
+
607
+
608
+
609
+ {
610
+ "id" => "5395b245385f7fe266000037",
611
+ "_id" => "5395b245385f7fe266000037",
612
+ "active" => true,
613
+ "created_at" => "2014-06-09T13:10:31Z",
614
+ "deleted_at" => nil,
615
+ "description" => "test",
616
+ "device_ids" => [],
617
+ "device_instance_ids" => [],
618
+ "downstream_rule_id" => nil,
619
+ "last_run_status" => "pass",
620
+ "plain_english" => "If var is equal to 30 then send an email to abc@me.com. Otherwise do nothing. ",
621
+ "tag_ids" => [],
622
+ "then_actions" => [
623
+ [0] {
624
+ "id" => "5395b247385f7fe26600003a",
625
+ "_id" => "5395b247385f7fe26600003a",
626
+ "created_at" => nil,
627
+ "deleted_at" => nil,
628
+ "priority" => "1",
629
+ "send_to" => "abc@me.com",
630
+ "updated_at" => nil,
631
+ "type" => "email_rule_action"
632
+ }
633
+ ],
634
+ "updated_at" => "2014-06-09T13:10:31Z",
635
+ "user_id" => "52160c8e981800aaef000001",
636
+ "http_code" => 200}
637
+
638
+
639
+ ----
640
+
641
+
642
+
643
+ ### Retrieve Rule
644
+ specificRule = MachineShop::Rule.retrieve(rule_id,auth_token)
645
+
646
+ * ##### Http_method : Get
647
+
648
+ * ##### Parameters
649
+
650
+ * rule\_id: _string_
651
+
652
+ * auth_token
653
+
654
+ ##### Response Example
655
+
656
+
657
+
658
+ {
659
+ "id" => "5395b245385f7fe266000037",
660
+ "_id" => "5395b245385f7fe266000037",
661
+ "active" => true,
662
+ "created_at" => "2014-06-09T13:10:31Z",
663
+ "deleted_at" => nil,
664
+ "description" => "test",
665
+ "device_ids" => [],
666
+ "device_instance_ids" => [],
667
+ "downstream_rule_id" => nil,
668
+ "last_run_status" => "pass",
669
+ "plain_english" => "If var is equal to 30 then send an email to abc@me.com. Otherwise do nothing. ",
670
+ "tag_ids" => [],
671
+ "then_actions" => [
672
+ [0] {
673
+ "id" => "5395b247385f7fe26600003a",
674
+ "_id" => "5395b247385f7fe26600003a",
675
+ "created_at" => nil,
676
+ "deleted_at" => nil,
677
+ "priority" => "1",
678
+ "send_to" => "abc@me.com",
679
+ "updated_at" => nil,
680
+ "type" => "email_rule_action"
681
+ }
682
+ ],
683
+ "updated_at" => "2014-06-09T13:10:31Z",
684
+ "user_id" => "52160c8e981800aaef000001"}
685
+
686
+ ---
687
+
688
+ ### Delete Rule
689
+ Delete the rule
690
+
691
+ specificRule.delete
692
+
693
+ > specificRule is the retrieve rule object
694
+
695
+ * ##### Http_method : Delete
696
+
697
+ ##### Response Example
698
+
699
+
700
+
701
+ {"http_code":200,"deleted":true}
702
+
703
+ ---
704
+
705
+ ### Get join rule conditions
706
+ Get join rule conditions
707
+
708
+ MachineShop::Rule.get_join_rule_conditions(auth_token)
709
+
710
+ * ##### Http_method : Get
711
+
712
+ * ##### Parameters
713
+
714
+
715
+ * auth_token
716
+
717
+ ##### Response Example
718
+
719
+
720
+
721
+ [
722
+ ["A few conditions where only one needs to be true.", "or_rule_condition"],
723
+ ["A few conditions that must all be true.", "and_rule_condition"]]
724
+
725
+ ----
726
+
727
+ ### Get comparison rule_conditions
728
+
729
+ MachineShop::Rule.get_comparison_rule_conditions(auth_token)
730
+
731
+ * ##### Http_method : Get
732
+
733
+ * ##### Parameters
734
+
735
+
736
+ * auth_token
737
+
738
+ ##### Response Example
739
+
740
+
741
+ [
742
+ [
743
+ ["A numeric payload value is greater than a specified threshold."]
744
+ ["greater_than_rule_condition"]
745
+ ],
746
+ [
747
+ ["A payload value is not the same as the specified value."]
748
+ ["not_equal_rule_condition"]
749
+ ]]
750
+
751
+ ----
752
+
753
+
754
+ ### Get rule by device_instance id
755
+ MachineShop::Rule.get_by_device_instance(auth_token,'device_instance_id')
756
+
757
+ * ##### Http_method : Get
758
+
759
+ * ##### Parameters
760
+ * device_instance_id
761
+
762
+
763
+ * auth_token
764
+
765
+ ##### Response Example
766
+
767
+
768
+ {: _id => "958421647080007a004506b",
769
+ : active => true,
770
+ : created_at => "2014-02-05T21:22:53Z",
771
+ : deleted_at => nil,
772
+ : description => "testsamplems",
773
+ : device_ids => [],
774
+ : device_instance_ids => ["52b20004758a004506800ba8"],
775
+ : downstream_rule_id => nil,
776
+ : last_run_status => "pass",
777
+ : plain_english => "If temp is equal to 44 then send an email to test@domain.com. Otherwise do nothing. This rule applies to these device instances: test_device.",
778
+ : tag_ids => [],
779
+ : then_actions => [{: _id => "506852b0475004a800b2008a",
780
+ : created_at => nil,
781
+ : deleted_at => nil,
782
+ : priority => "1",
783
+ : send_to => "test@domain.com",
784
+ : updated_at => nil,
785
+ : type => "email_rule_action"
786
+ }], : updated_at => "2014-02-05T21:22:53Z",
787
+ : user_id => "3004884021800aaef0056893"}
788
+
789
+ ----
790
+
791
+
792
+ ### Get Reports
793
+ Get all the report of the device
794
+
795
+ MachineShop::Report.all({:device_instance_id => '958421647080007a004506b',:per_page=>'10',}, auth_token)
796
+
797
+ > First parameter should be empty array if no filter is to be applied.
798
+
799
+ * ##### Http_method : Get
800
+
801
+ * ##### Parameters
802
+ * device\_instance\_id: _string_
803
+
804
+ * per\_page: _string_
805
+
806
+
807
+ * auth_token
808
+
809
+ ##### Response Example
810
+
811
+
812
+ {
813
+ "id": "958421647080007a004506b",
814
+ "_id": "958421647080007a004506b",
815
+ "created_at": "2014-06-10T08:19:34Z",
816
+ "deleted_at": null,
817
+ "device_datetime": "2014-06-10T08:19:37+00:00",
818
+ "device_instance_id": "3004884021800aaef0056893",
819
+ "duplicate": false,
820
+ "payload": {
821
+ "event": {
822
+ "eventIdx": 0,
823
+ "policy_id": "f7f8a8e538530000092d1c6b",
824
+ "values": {
825
+ "lightLevel": 320456,
826
+ "fixType": 3,
827
+ "motion": {
828
+ "distance": 0,
829
+ "floor_change": 0,
830
+ "context": 5,
831
+ "steps": 0
832
+ },
833
+ "batteryExternalPower": false,
834
+ "utcTime": 1402388377,
835
+ "temperature": 429,
836
+ "health": {
837
+ "temp4": 15515,
838
+ "heartRateMon": {
839
+ "devBodyLoc": 141,
840
+ "rr": 15504,
841
+ "heartRate": 142,
842
+ "devName": "One_HRM",
843
+ "energy": 15503
844
+ },
845
+ "sensorPod": {
846
+ "devBodyLoc": 151,
847
+ "distance": 15507,
848
+ "floor_change": -107,
849
+ "context": 146,
850
+ "stride_len": 150,
851
+ "devName": "myPod",
852
+ "steps": 15508
853
+ },
854
+ "temp2": 15513,
855
+ "temp3": 15514,
856
+ "temp1": 15512
857
+ },
858
+ "location": {
859
+ "altitude": 0,
860
+ "hor_error_min": 0,
861
+ "latitude": 64.37989,
862
+ "vert_error": 0,
863
+ "hor_error_max": 0,
864
+ "longitude": -122.08374
865
+ },
866
+ "pressure": 42,
867
+ "speed": {
868
+ "heading": 9000,
869
+ "ver_speed": 0,
870
+ "hor_speed": 10000
871
+ },
872
+ "batteryLevel": 87
873
+ },
874
+ "reportMask": 14463
875
+ },
876
+ "sequenceId": 44725
877
+ },
878
+ "profile_timestamps": {
879
+ "translator": "2014-06-10T08:19:37Z",
880
+ "worker": "2014-06-10T08:19:34Z",
881
+ "device": "2014-06-10T08:19:37Z",
882
+ "platform": "2014-06-10T08:19:50Z"
883
+ },
884
+ "raw_data": "AQEAAgAAFnRyYWNrZXIAc2ltdWxhdG9yAENTUgCutQEAOH8BJl+Xgrc7f+YAAAAAAAAAACcQAAAjKAUAAAAAAAAAAABTlr+ZAAMBrQAqAFc/DU9uZV9TZW5zcm9Qb2SRkgAAPJQAADyTlZaXB09uZV9IUk2NjjyPPJA8mDyZPJo8mwAE48gAAA==",
885
+ "report_processor": "java",
886
+ "stale": null,
887
+ "updated_at": "2014-06-10T08:19:34Z"}
888
+
889
+ ---
890
+
891
+
892
+ ### Retrieve Report by report_id
893
+ Get all the report of the device
894
+
895
+ MachineShop::Report.retrieve(report_id,auth_token)
896
+
897
+ > First parameter should be an empty array if no filter is to be applied.
898
+
899
+ * ##### Http_method : Get
900
+
901
+ * ##### Parameters
902
+ * report\_id: _string_
903
+ * auth_token
904
+
905
+ ##### Response Example
906
+ Same as above
907
+ ---
908
+
909
+
910
+ ### Get Meters
911
+ Get all the meters
912
+
913
+ MachineShop::Meter.all({}, auth_token)
914
+
915
+
916
+ * ##### Http_method : Get
917
+
918
+ * ##### Parameters
919
+
920
+ * auth_token
921
+
922
+ ##### Response Example
923
+
924
+
925
+ {
926
+ "id": "958421647080007a004506b",
927
+ "_id": "958421647080007a004506b",
928
+ "body": null,
929
+ "client_ip": "110.34.0.243",
930
+ "created_at": "2014-06-03T17:45:08Z",
931
+ "device_instance_id": null,
932
+ "request_at": "2014-06-03T17:45:10+00:00",
933
+ "request_method": "get",
934
+ "request_path": "/api/v0/platform/device",
935
+ "request_route": "get '/device'",
936
+ "response_code": 200,
937
+ "updated_at": "2014-06-03T17:45:08Z",
938
+ "user_id": "3004884021800aaef0056893"}
939
+
940
+
941
+ > meters via user
942
+
943
+ user.meters
944
+
945
+ > where user is the object obtaied from #authentication
946
+
947
+ user = MachineShop::User.authenticate(
948
+ :email => publisher_username,
949
+ :password => publisher_password
950
+ ---
951
+
952
+
953
+ ### Retrieve meter
954
+ Get meter by meter_id
955
+
956
+ MachineShop::Meter.retrieve(meter_id, auth_token)
957
+
958
+ * ##### Http_method : Get
959
+
960
+ * ##### Parameters
961
+ * meter\_id: _string_
962
+ * auth_token
963
+
964
+ ##### Response Example
965
+
966
+ same as above
967
+
968
+ ---
969
+
970
+
971
+ ## Contributing
972
+
973
+ 1. Fork it
974
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
975
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
976
+ 4. Push to the branch (`git push origin my-new-feature`)
977
+ 5. Create new Pull Request