machineshop 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Readme_old.bkmMd ADDED
@@ -0,0 +1,782 @@
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
+ ### Authentication
24
+ Allow a user to authenticate
25
+
26
+ auth_token, user = MachineShop::User.authenticate(
27
+ :email => "username",
28
+ :password => "password"
29
+ )
30
+
31
+ ---
32
+ * ##### Http_method : Post
33
+
34
+ * ##### Parameters :
35
+ * email _string_
36
+ * password _string_
37
+
38
+ * ##### Response Example
39
+
40
+ ----
41
+ {
42
+ "id" => "8e98188e981800aaef000001",
43
+ "_id" => "8e98188e981800aaef000001",
44
+ "authentication_token" => "2jzZhuHWLZy9fsxcd36E",
45
+ "company_name" => "company_name",
46
+ "current_sign_in_at" => "2014-06-09T08:26:06Z",
47
+ "current_sign_in_ip" => "202.51.76.235",
48
+ "domain" => "john@domain.com",
49
+ "email" => "admin@domain.com",
50
+ "first_name" => "First_name",
51
+ "keychain" => {},
52
+ "last_name" => "Last_name",
53
+ "last_sign_in_at" => "2014-06-09T08:26:06Z",
54
+ "last_sign_in_ip" => "202.51.76.235",
55
+ "logo_url" => nil,
56
+ "name_space" => [
57
+ [0]
58
+ "test"
59
+ ],
60
+ "notification_method" => "sms",
61
+ "phone_number" => "+1 (123) 456-7890",
62
+ "role" => "admin",
63
+ "sign_in_count" => 234,
64
+ "tag_ids" => [],
65
+ "http_code" => 200
66
+ }
67
+
68
+ ### Get All user roles
69
+ Get all the roles assigned to the current user
70
+
71
+ MachineShop::User.all_roles(auth_token)
72
+
73
+ ---
74
+ * ##### Http_method : Get
75
+
76
+ * ##### Parameters :
77
+
78
+ * auth_token ___ _string_
79
+ > obtained from #authentication
80
+
81
+ * ##### Response Example
82
+
83
+ ----
84
+ [
85
+ "admin",
86
+ "publisher",
87
+ "consumer"]
88
+
89
+ ----
90
+ ### Retrieve user
91
+ Get User object to apply the following actions
92
+
93
+ > user.update,
94
+ > user.delete
95
+
96
+
97
+ MachineShop::User.retrieve(user_id, auth_token)
98
+
99
+ ---
100
+ * ##### Http_method : Get
101
+
102
+ * ##### Parameters :
103
+ * auth\_token _string_
104
+ * user\_id: _string_
105
+ > available in response object from #authentication
106
+
107
+ * ##### Response Example
108
+
109
+ > Same as from authenticate
110
+
111
+
112
+ ### Get the devices of the current user
113
+
114
+ MachineShop::Device.all(
115
+ {:page => 1,
116
+ :per_page => 10},
117
+ auth_token)
118
+
119
+ ---
120
+ * ##### Http_method : Get
121
+
122
+ * ##### Parameters :
123
+ * page _Integer_
124
+ > page number for pagination
125
+
126
+ * name _string_
127
+ > get device by name
128
+
129
+ * per\_page: _Integer_
130
+ > Number of items to display
131
+ * auth\_token
132
+
133
+ * ##### Response Example
134
+
135
+ ----
136
+
137
+ [{
138
+ "id": "9584216470180077f7000157",
139
+ "_id": "9584216470180077f7000157",
140
+ "active": true,
141
+ "created_at": "2014-06-09T09:16:06Z",
142
+ "deleted_at": null,
143
+ "exe_path": "/etc/foo",
144
+ "image_url": "http://someurl.com/your_image.png",
145
+ "init_cmd": "my_init_cmd",
146
+ "init_params": "{'init':'go'}",
147
+ "last_known_translator_port": null,
148
+ "long_description": "This device tracks position and test.",
149
+ "manual_url": "http://someurl.com/manual.pdf",
150
+ "manufacturer": "a company",
151
+ "model": "D-vice 1000",
152
+ "name": "my_device",
153
+ "rule_ids": [],
154
+ "sample_data": "some arbitrary sample data",
155
+ "software": null,
156
+ "tag_ids": [],
157
+ "translator": null,
158
+ "type": "Test",
159
+ "unit_price": "$199.99",
160
+ "updated_at": "2014-06-09T09:16:06Z",
161
+ "user_id": "11161696201800aaef0000459}, {
162
+ "id": "2065309466180077f7000157",
163
+ "_id": "2065309466180077f7000157",
164
+ "active": true,
165
+ "created_at": "2014-06-09T09:15:01Z",
166
+ "deleted_at": null,
167
+ "exe_path": "/etc/foo",
168
+ "image_url": "http://someurl.com/your_image.png",
169
+ "init_cmd": "my_init_cmd",
170
+ "init_params": "{'init':'go'}",
171
+ "last_known_translator_port": null,
172
+ "long_description": "This device tracks position and btest.",
173
+ "manual_url": "http://someurl.com/manual.pdf",
174
+ "manufacturer": "a company",
175
+ "model": "D-vice 1000",
176
+ "name": "my_device",
177
+ "rule_ids": [],
178
+ "sample_data": "some arbitrary sample data",
179
+ "software": null,
180
+ "tag_ids": [],
181
+ "translator": null,
182
+ "type": "Test",
183
+ "unit_price": "$199.99",
184
+ "updated_at": "2014-06-09T09:15:01Z",
185
+ "user_id": "11161696201800aaef0000459"} ]
186
+
187
+
188
+
189
+ ### Retrieve Device
190
+
191
+ specificDevice = MachineShop::Device.retrieve(device_id, auth_token)
192
+
193
+ ---
194
+ * ##### Http_method : Get
195
+
196
+ * ##### Parameters :
197
+ * device\_id
198
+ > device id
199
+
200
+ * auth\_token
201
+
202
+ * ##### Response Example
203
+
204
+ ----
205
+
206
+ {
207
+ "id" => "51795428911800d51400016c",
208
+ "_id" => "51795428911800d51400016c",
209
+ "active" => true,
210
+ "created_at" => "2014-06-09T10:02:50Z",
211
+ "deleted_at" => nil,
212
+ "exe_path" => "/etc/foo",
213
+ "image_url" => "http://someurl.com/your_image.png",
214
+ "init_cmd" => "my_init_cmd",
215
+ "init_params" => "{'init':'go'}",
216
+ "last_known_translator_port" => nil,
217
+ "long_description" => "This device tracks position and NCAA football conference.",
218
+ "manual_url" => "http://someurl.com/manual.pdf",
219
+ "manufacturer" => "a company",
220
+ "model" => "D-vice 1000",
221
+ "name" => "my_device",
222
+ "rule_ids" => [],
223
+ "sample_data" => "some arbitrary sample data",
224
+ "software" => nil,
225
+ "tag_ids" => [],
226
+ "translator" => nil,
227
+ "type" => "Test",
228
+ "unit_price" => "$199.99",
229
+ "updated_at" => "2014-06-09T10:02:50Z",
230
+ "user_id" => "11161696201800aaef000056",
231
+ "http_code" => 200}
232
+
233
+
234
+ ### Create device instance for the device
235
+
236
+ device_instance = specificDevice.create_instance(
237
+ {
238
+ :name => "My little instance",
239
+ :active => "yes"
240
+ }
241
+
242
+ ---
243
+ * ##### Http_method : Post
244
+
245
+ * ##### Parameters :
246
+ * name
247
+ * active
248
+
249
+ * ##### Response Example
250
+
251
+ ----
252
+
253
+ {
254
+ "id" => "30048840211800a9c600000c",
255
+ "_id" => "30048840211800a9c600000c",
256
+ "tag_ids" => [],
257
+ "rule_ids" => [],
258
+ "alert_count" => 0,
259
+ "name" => "My little instance",
260
+ "active" => true,
261
+ "device_id" => "531eafcb38300488402145",
262
+ "user_id" => "11800a9c1800aaef0004543",
263
+ "auth_token" => nil,
264
+ "updated_at" => "2014-03-11T06:41:42Z",
265
+ "created_at" => "2014-03-11T06:41:42Z",
266
+ "http_code" => 200}
267
+
268
+ ---
269
+
270
+
271
+ ### Create a device
272
+
273
+ Create a new device
274
+
275
+ newDevice = MachineShop::Device.create(
276
+ {
277
+ :name => "my_device",
278
+ :type => "Test",
279
+ :manufacturer => "a company",
280
+ :model => "D-vice 1000",
281
+ :active => "yes",
282
+ :init_cmd => "my_init_cmd",
283
+ :init_params => "{'init':'go'}",
284
+ :exe_path => "/etc/foo",
285
+ :unit_price => "$199.99",
286
+ :sample_data => "some arbitrary sample data",
287
+ :long_description => "This device tracks position of test.",
288
+ :image_url => "http://someurl.com/your_image.png",
289
+ :manual_url => "http://someurl.com/manual.pdf"},auth_token)
290
+
291
+ ---
292
+
293
+ * Http_method : Post
294
+
295
+
296
+ > Alternately the device instance can be created from this object as well
297
+
298
+ newDevice.create_instance(
299
+ {
300
+ :name => "My little instance",
301
+ :active => "yes"
302
+ }
303
+ )
304
+
305
+
306
+ ### Get the device instances
307
+ Get all the device instances of the user
308
+
309
+ MachineShop::DeviceInstance.all({:name => "instance_name"}, auth_token)
310
+
311
+ ---
312
+ > Pass first parameter as empty array if no filters to be applied
313
+
314
+ * ##### Http_method : Get
315
+
316
+ * ##### Parameters
317
+ * auth_token
318
+ * filter_parameters
319
+
320
+ * * name
321
+
322
+ * ##### Response Example
323
+
324
+ ----
325
+
326
+ {
327
+ "id" => "51795428911800d51400016c",
328
+ "_id" => "51795428911800d51400016c",
329
+ "active" => true,
330
+ "created_at" => "2014-06-09T10:02:50Z",
331
+ "deleted_at" => nil,
332
+ "exe_path" => "/etc/foo",
333
+ "image_url" => "http://someurl.com/your_image.png",
334
+ "init_cmd" => "my_init_cmd",
335
+ "init_params" => "{'init':'go'}",
336
+ "last_known_translator_port" => nil,
337
+ "long_description" => "This device tracks position and NCAA football conference.",
338
+ "manual_url" => "http://someurl.com/manual.pdf",
339
+ "manufacturer" => "a company",
340
+ "model" => "D-vice 1000",
341
+ "name" => "my_device",
342
+ "rule_ids" => [],
343
+ "sample_data" => "some arbitrary sample data",
344
+ "software" => nil,
345
+ "tag_ids" => [],
346
+ "translator" => nil,
347
+ "type" => "Test",
348
+ "unit_price" => "$199.99",
349
+ "updated_at" => "2014-06-09T10:02:50Z",
350
+ "user_id" => "11161696201800aaef000056",
351
+ "http_code" => 200}
352
+
353
+
354
+ > Another way
355
+
356
+ user.device_instances({:name => device_instance.name})
357
+ or without filters
358
+
359
+ user.device_instances
360
+ > Where user is the user object from the #Authenticate or retrieved user
361
+
362
+ specificDevice.instances
363
+ > where specficiDevice is the object from retrieve
364
+
365
+
366
+
367
+ ### Create Customers
368
+
369
+
370
+ specificCustomer =MachineShop::Customer.create({:email=>"test@domain.com",
371
+ :password=>'password',
372
+ :notification_method=>'sms',
373
+ :first_name=>'John',:last_name=>'Doe',
374
+ :phone_number=>'98989898989',
375
+ :company_name=>'technology co'
376
+
377
+ },auth_token)
378
+
379
+ ---
380
+ * ##### Http_method : Post
381
+
382
+ * ##### Parameters
383
+
384
+ * Post parameters: _array of params_
385
+ * auth_token
386
+
387
+ * ##### Response Example
388
+
389
+ ----
390
+
391
+ {
392
+ "id" => "958421647080007a004506b",
393
+ "_id" => "958421647080007a004506b",
394
+ "email" => "test@domain.com",
395
+ "domain" => "machineshop",
396
+ "sign_in_count" => 0,
397
+ "keychain" => {},
398
+ "notification_method" => "sms",
399
+ "first_name" => "John",
400
+ "last_name" => "Doe",
401
+ "phone_number" => "98989898989",
402
+ "company_name" => "technology co",
403
+ "publisher_id" => "3004884021800aaef0056893",
404
+ "role" => "consumer",
405
+ "logo_url" => nil,
406
+ "name_space" => [
407
+ [0]
408
+ "csr"
409
+ ],
410
+ "authentication_token" => "YLMDGOvdjyucLvwaJKfu",
411
+ "http_code" => 200
412
+ }
413
+
414
+ ---
415
+ ### Retrieve Customer
416
+ Retrieve customer by Id
417
+
418
+
419
+ retrievedCustomer = MachineShop::Customer.retrieve(customer_id, auth_token)
420
+
421
+ ---
422
+ * ##### Http_method : Get
423
+
424
+ * ##### Parameters
425
+
426
+ * customer\_id _string_
427
+ * auth_token
428
+
429
+ * ##### Response Example
430
+
431
+ ----
432
+ same as above
433
+
434
+ ----
435
+
436
+ ### Update Customer by Id
437
+
438
+
439
+ MachineShop::Customer.update(customer_id,auth_token,{:notification_method => 'email'})
440
+
441
+
442
+ ---
443
+ * ##### Http_method : Put
444
+
445
+ * ##### Parameters
446
+
447
+ * customer_id: _string_
448
+ * update parameters: _array of params_
449
+ * auth_token
450
+
451
+ * ##### Response Example
452
+
453
+ ----
454
+
455
+ {
456
+ "id": "958421647080007a004506b",
457
+ "_id": "958421647080007a004506b",
458
+ "email": "test@domain.com",
459
+ "domain": "machineshop",
460
+ "sign_in_count": 0,
461
+ "keychain": {},
462
+ "notification_method": "sms",
463
+ "first_name": "John",
464
+ "last_name": "Doe",
465
+ "phone_number": "98989898989",
466
+ "company_name": "technology co",
467
+ "publisher_id": "3004884021800aaef0056893",
468
+ "role": "consumer",
469
+ "logo_url": null,
470
+ "name_space": ["csr"],
471
+ "authentication_token": "YLMDGOvdjyucLvwaJKfu",
472
+ "http_code": 200
473
+ }
474
+
475
+
476
+ > Alternately
477
+
478
+ retrieved_cust.update({:notification_method => 'email'})
479
+
480
+
481
+ ### Delete Customer
482
+ Delete the Customer
483
+
484
+ retrievedCustomer.delete
485
+
486
+ ---
487
+ > retrievedCustomer is the retrieved customer object
488
+
489
+ * ##### Http_method : delete
490
+
491
+
492
+ * ##### Response Example
493
+
494
+ ----
495
+
496
+ {"http_code":200,"deleted":true}
497
+
498
+
499
+
500
+ ### List rules
501
+ List all the rules of user
502
+
503
+ MachineShop::Rule.all({},auth_token)
504
+
505
+ ---
506
+ > Filter parameters else empty array
507
+
508
+ * ##### Http_method : Get
509
+
510
+ * ##### Parameters
511
+
512
+ * filter parameters: _array of params_
513
+ * auth_token
514
+
515
+ * ##### Response Example
516
+
517
+ ----
518
+
519
+ {
520
+ "id": "958421647080007a004506b",
521
+ "_id": "958421647080007a004506b",
522
+ "actions": [{
523
+ "id": "958421647080007a0045062",
524
+ "_id": "958421647080007a0045062",
525
+ "send_to": "john@mach19.com",
526
+ "_type": "EmailAction"
527
+ }, {
528
+ "id": "958421647080007a0045063",
529
+ "_id": "958421647080007a0045063",
530
+ "send_to": "14794263982",
531
+ "_type": "SmsAction"
532
+ }],
533
+ "active": true,
534
+ "comparison_value": "0",
535
+ "created_at": "2012-09-26T20:33:19Z",
536
+ "deleted": false,
537
+ "deleted_at": null,
538
+ "description": "testing stage rule",
539
+ "device_attribute": "stage",
540
+ "device_ids": [],
541
+ "device_instance_ids": ["503900d2ab400015a5731125"],
542
+ "downstream_rule_id": null,
543
+ "last_run": "2012-09-28T18:53:58Z",
544
+ "last_run_status": "pass",
545
+ "modified_date": "2012-09-26T20:33:19Z",
546
+ "operator": "gt",
547
+ "plain_english": "This rule has no conditions.",
548
+ "rule_histories": [],
549
+ "tag_ids": [],
550
+ "updated_at": "2012-09-28T18:53:58Z",
551
+ "user_id": "3004884021800aaef0056893"}
552
+
553
+ ---
554
+
555
+
556
+ ### Create Rule
557
+ Create a rule
558
+
559
+ create_hash = {
560
+ :devices=>["52585e1d981800bab2000479"],
561
+ :device_instances=>[],
562
+ :rule=>{
563
+ :active=>true,
564
+ :description=>"test",
565
+ :condition=>{
566
+ :type=>"and_rule_condition",
567
+ :rule_conditions=>[{
568
+
569
+ :property=>"var",
570
+ :value=>"30",
571
+ :type=>"equal_rule_condition"
572
+
573
+ }]
574
+ },
575
+ :then_actions=>[{
576
+ :priority=>"1",
577
+ :send_to=>"abc@me.com",
578
+ :type=>"email_rule_action"
579
+ }]
580
+ } }
581
+
582
+ createdRule = MachineShop::Rule.create(create_hash,auth_token)
583
+
584
+ * ##### Http_method : Post
585
+
586
+ * ##### Parameters
587
+
588
+ * create parameter: _json array of params_
589
+ * auth_token
590
+
591
+ * ##### Response Example
592
+
593
+ ----
594
+
595
+ {
596
+ "id" => "5395b245385f7fe266000037",
597
+ "_id" => "5395b245385f7fe266000037",
598
+ "active" => true,
599
+ "created_at" => "2014-06-09T13:10:31Z",
600
+ "deleted_at" => nil,
601
+ "description" => "test",
602
+ "device_ids" => [],
603
+ "device_instance_ids" => [],
604
+ "downstream_rule_id" => nil,
605
+ "last_run_status" => "pass",
606
+ "plain_english" => "If var is equal to 30 then send an email to abc@me.com. Otherwise do nothing. ",
607
+ "tag_ids" => [],
608
+ "then_actions" => [
609
+ [0] {
610
+ "id" => "5395b247385f7fe26600003a",
611
+ "_id" => "5395b247385f7fe26600003a",
612
+ "created_at" => nil,
613
+ "deleted_at" => nil,
614
+ "priority" => "1",
615
+ "send_to" => "abc@me.com",
616
+ "updated_at" => nil,
617
+ "type" => "email_rule_action"
618
+ }
619
+ ],
620
+ "updated_at" => "2014-06-09T13:10:31Z",
621
+ "user_id" => "52160c8e981800aaef000001",
622
+ "http_code" => 200}
623
+
624
+
625
+ ----
626
+
627
+
628
+
629
+ ### Retrieve Rule
630
+ specificRule = MachineShop::Rule.retrieve("rule_id",auth_token)
631
+
632
+ * ##### Http_method : Get
633
+
634
+ * ##### Parameters
635
+
636
+ * rule\_id: _string_
637
+
638
+ * auth_token
639
+
640
+ * ##### Response Example
641
+
642
+ ----
643
+
644
+ {
645
+ "id" => "5395b245385f7fe266000037",
646
+ "_id" => "5395b245385f7fe266000037",
647
+ "active" => true,
648
+ "created_at" => "2014-06-09T13:10:31Z",
649
+ "deleted_at" => nil,
650
+ "description" => "test",
651
+ "device_ids" => [],
652
+ "device_instance_ids" => [],
653
+ "downstream_rule_id" => nil,
654
+ "last_run_status" => "pass",
655
+ "plain_english" => "If var is equal to 30 then send an email to abc@me.com. Otherwise do nothing. ",
656
+ "tag_ids" => [],
657
+ "then_actions" => [
658
+ [0] {
659
+ "id" => "5395b247385f7fe26600003a",
660
+ "_id" => "5395b247385f7fe26600003a",
661
+ "created_at" => nil,
662
+ "deleted_at" => nil,
663
+ "priority" => "1",
664
+ "send_to" => "abc@me.com",
665
+ "updated_at" => nil,
666
+ "type" => "email_rule_action"
667
+ }
668
+ ],
669
+ "updated_at" => "2014-06-09T13:10:31Z",
670
+ "user_id" => "52160c8e981800aaef000001"}
671
+
672
+ ---
673
+
674
+ ### Delete Rule
675
+ Delete the rule
676
+
677
+ specificRule.delete
678
+
679
+ > specificRule is the retrieve rule object
680
+
681
+ * ##### Http_method : Delete
682
+
683
+ * ##### Response Example
684
+
685
+ ----
686
+
687
+ {"http_code":200,"deleted":true}
688
+
689
+ ----
690
+
691
+ ### Get join rule conditions
692
+ Get join rule conditions
693
+
694
+ MachineShop::Rule.get_join_rule_conditions(auth_token)
695
+
696
+ * ##### Http_method : Get
697
+
698
+ * ##### Parameters
699
+
700
+
701
+ * auth_token
702
+
703
+ * ##### Response Example
704
+
705
+ ----
706
+ [
707
+ ["A few conditions where only one needs to be true.", "or_rule_condition"],
708
+ ["A few conditions that must all be true.", "and_rule_condition"]]
709
+
710
+ ----
711
+
712
+ ### Get comparison rule_conditions
713
+
714
+ MachineShop::Rule.get_comparison_rule_conditions(auth_token)
715
+
716
+ * ##### Http_method : Get
717
+
718
+ * ##### Parameters
719
+
720
+
721
+ * auth_token
722
+
723
+ * ##### Response Example
724
+
725
+ ----
726
+ [
727
+ [
728
+ ["A numeric payload value is greater than a specified threshold."]
729
+ ["greater_than_rule_condition"]
730
+ ],
731
+ [
732
+ ["A payload value is not the same as the specified value."]
733
+ ["not_equal_rule_condition"]
734
+ ]]
735
+
736
+ ----
737
+
738
+
739
+ ### Get rule by device_instance id
740
+ MachineShop::Rule.get_by_device_instance(auth_token,'device_instance_id')
741
+
742
+ * ##### Http_method : Get
743
+
744
+ * ##### Parameters
745
+ * device_instance_id
746
+
747
+
748
+ * auth_token
749
+
750
+ * ##### Response Example
751
+
752
+ ----
753
+ {: _id => "958421647080007a004506b",
754
+ : active => true,
755
+ : created_at => "2014-02-05T21:22:53Z",
756
+ : deleted_at => nil,
757
+ : description => "testsamplems",
758
+ : device_ids => [],
759
+ : device_instance_ids => ["52b20004758a004506800ba8"],
760
+ : downstream_rule_id => nil,
761
+ : last_run_status => "pass",
762
+ : 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.",
763
+ : tag_ids => [],
764
+ : then_actions => [{: _id => "506852b0475004a800b2008a",
765
+ : created_at => nil,
766
+ : deleted_at => nil,
767
+ : priority => "1",
768
+ : send_to => "test@domain.com",
769
+ : updated_at => nil,
770
+ : type => "email_rule_action"
771
+ }], : updated_at => "2014-02-05T21:22:53Z",
772
+ : user_id => "3004884021800aaef0056893"}
773
+
774
+ ----
775
+
776
+ ## Contributing
777
+
778
+ 1. Fork it
779
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
780
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
781
+ 4. Push to the branch (`git push origin my-new-feature`)
782
+ 5. Create new Pull Request