test_machine_shop 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.
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
@@ -0,0 +1,78 @@
1
+ require_relative '../spec_helper'
2
+
3
+ #MachineShop.api_base_url= 'http://machineshop.dev:3000/api/v0'
4
+ MachineShop.api_base_url= 'http://stage.services.machineshop.io/api/v0'
5
+
6
+ publisher_username = 'admin@csr.com'
7
+ publisher_password = 'password'
8
+
9
+ MachineShop.configure do |config|
10
+ config.db_name = "machineshop"
11
+ config.db_username="root"
12
+ config.db_password="root"
13
+ config.db_host= "localhost"
14
+ config.expiry_time= lambda{120.seconds.ago}
15
+
16
+ #second
17
+ end
18
+
19
+ auth_token, user = MachineShop::User.authenticate(
20
+ :email => publisher_username,
21
+ :password => publisher_password
22
+ )
23
+ # ap user
24
+
25
+
26
+ describe "test custome" do
27
+
28
+ it "should call get method " do
29
+ test = MachineShop.get("documents",auth_token,"1234")
30
+ end
31
+
32
+ it "should call post method " do
33
+
34
+ create_hash = {
35
+ :devices=>["52585e1d981800bab2000479"],
36
+ :device_instances=>[],
37
+ :rule=>{
38
+ :active=>true,
39
+ :description=>"bajratest",
40
+ :condition=>{
41
+ :type=>"and_rule_condition",
42
+ :rule_conditions=>[{
43
+
44
+ :property=>"var",
45
+ :value=>"30",
46
+ :type=>"equal_rule_condition"
47
+
48
+ }]
49
+ },
50
+ :then_actions=>[{
51
+ :priority=>"1",
52
+ :send_to=>"abc@me.com",
53
+ :type=>"email_rule_action"
54
+ }]
55
+ }
56
+ }
57
+
58
+ # ap "creating rule "
59
+ createdRule = MachineShop.post("rules",auth_token,create_hash)
60
+
61
+ end
62
+
63
+
64
+
65
+
66
+ it "should call put method " do
67
+ url = "/platform/customer/533009a0981800984500001e"
68
+ update_hash = {:notification_method => 'sms',:first_name=>'from_custom'}
69
+
70
+ MachineShop.put("rules",auth_token,"533009a0981800984500001e",update_hash)
71
+ end
72
+
73
+
74
+ it "should call delete method " do
75
+ MachineShop.delete("platform",auth_token,"53b52a8e9818005d8d000019")
76
+ end
77
+
78
+ end
@@ -0,0 +1,87 @@
1
+ require_relative '../spec_helper'
2
+
3
+
4
+ #MachineShop.api_base_url= 'http://machineshop.dev:3000/api/v0'
5
+ MachineShop.api_base_url= 'http://stage.services.machineshop.io/api/v0'
6
+
7
+ #publisher_username = 'publisher@machineshop.com'
8
+ publisher_username = 'admin@csr.com'
9
+ publisher_password = 'password'
10
+
11
+
12
+ auth_token, user = MachineShop::User.authenticate(
13
+ :email => publisher_username,
14
+ :password => publisher_password
15
+ )
16
+ describe MachineShop::Customer do
17
+
18
+ it "should get all the customers " do
19
+ customers = MachineShop::Customer.all({}, auth_token)
20
+
21
+ puts "customers are #{customers}"
22
+
23
+ #puts "first customer is : #{customers[0][:id]}"
24
+
25
+ customers.should_not be_nil
26
+ end
27
+
28
+ specificCustomer = nil
29
+ it "should create customer " do
30
+
31
+ specificCustomer = MachineShop::Customer.create({:email=>"bajratests@bajratechnologies.com",
32
+ :password=>'password',
33
+ :notification_method=>'sms',
34
+ :first_name=>'niroj',:last_name=>'sapkota',
35
+ :phone_number=>'98989898989',
36
+ :company_name=>'technology co'
37
+
38
+ },auth_token)
39
+
40
+ ap "created customer is"
41
+ ap specificCustomer.as_json
42
+ specificCustomer.should_not be_nil
43
+ end
44
+
45
+
46
+ retrieved_cust=nil
47
+ it "should get customer by customer id " do
48
+ ap "looking up customer before:"
49
+ ap specificCustomer.as_json
50
+
51
+ retrieved_cust = MachineShop::Customer.retrieve(specificCustomer.id, auth_token)
52
+
53
+ ap "looking up customer after:"
54
+ ap retrieved_cust.as_json
55
+
56
+ retrieved_cust.should_not be_nil
57
+ end
58
+
59
+
60
+ it "should update the customer with id " do
61
+
62
+ ap "updating customer with id : #{specificCustomer.id}"
63
+ update = MachineShop::Customer.update(specificCustomer.id,auth_token,{:notification_method => 'email',:first_name=>'testJohn'})
64
+ ap update.as_json
65
+ end
66
+
67
+
68
+ it "should update the customer from the retrieved obj id " do
69
+ ap "updating customer from the retrieved obj id : #{specificCustomer.id}"
70
+
71
+ update = retrieved_cust.update({:notification_method => 'email'})
72
+ ap update.as_json
73
+ end
74
+
75
+ #success test
76
+
77
+ it "should delete customer with id " do
78
+
79
+ #puts
80
+ puts "deleting customer with id : #{specificCustomer.id}"
81
+
82
+ delete = specificCustomer.delete
83
+ #delete = MachineShop::Customer.delete(customers[0].id,auth_token)
84
+ puts "delete #{delete}"
85
+ delete.http_code.should eq 200
86
+ end
87
+ end
@@ -0,0 +1,138 @@
1
+ require_relative '../spec_helper'
2
+
3
+ #MachineShop.api_base_url= 'http://machineshop.dev:3000/api/v0'
4
+ MachineShop.api_base_url= 'http://localhost:3000/api/v1'
5
+
6
+ #publisher_username = 'publisher@machineshop.com'
7
+ publisher_username = 'publisher@csr.com'
8
+ publisher_password = 'password'
9
+
10
+
11
+ MachineShop.configure do |config|
12
+ config.expiry_time = lambda{120.seconds.ago}
13
+ config.enable_caching = false
14
+ config.db_username="root"
15
+ config.db_password="root"
16
+ config.db_name="machineshop"
17
+ end
18
+
19
+ auth_token, user = MachineShop::Users.authenticate(
20
+ :email => publisher_username,
21
+ :password => publisher_password
22
+ )
23
+
24
+
25
+
26
+ describe MachineShop::DataSources do
27
+
28
+
29
+ specific_data_source = nil
30
+
31
+ data_source = nil
32
+ data_source_type = nil
33
+
34
+ it "should get all DataSources for the user" do
35
+ element_data = MachineShop::DataSources.all(
36
+ {:page => 1,
37
+ :per_page => 10},
38
+ auth_token)
39
+
40
+ ap element_data
41
+
42
+ data_source = element_data[0]
43
+ expect(data_source).to be_truthy
44
+ end
45
+
46
+
47
+ it "should update the DataSource " do
48
+ toUpdate = MachineShop::DataSources.retrieve(data_source.id, auth_token)
49
+
50
+ update = toUpdate.update({:name => "updated name"})
51
+
52
+ end
53
+
54
+ it "should delete datasource" do
55
+ toDelete = MachineShop::DataSources.retrieve(data_source.id,auth_token)
56
+ # ap toDelete
57
+
58
+ deleted = toDelete.delete
59
+ # ap deleted
60
+ end
61
+
62
+
63
+
64
+ it "should get all DataSourceTypes" do
65
+ element_data = MachineShop::DataSourceTypes.all(
66
+ {:page => 1,
67
+ :per_page => 10},
68
+ auth_token)
69
+ data_source_type = element_data[0]
70
+ end
71
+
72
+ it "should retrieve DataSource " do
73
+ specificDataSource = MachineShop::DataSourceTypes.retrieve(data_source_type.id, auth_token)
74
+
75
+ data_source = specificDataSource.create_data_source(
76
+
77
+ {:data_source =>"device",
78
+ # :data_source_type =>"5406d665faf3d9d39100000a",
79
+ :name =>"gem bata banako device type",
80
+ :user_name =>"niroj_username",
81
+ :sender =>"niroj@sender.com",
82
+ :password =>"password",
83
+ :pop_server =>"port_server",
84
+ :port =>"345"
85
+ })
86
+
87
+ end
88
+
89
+
90
+ it "should get create email DataSource " do
91
+
92
+ specificDataSource = MachineShop::DataSourceTypes.retrieve(data_source_type.id, auth_token)
93
+
94
+ data_source = specificDataSource.create_email_data_source(
95
+
96
+ {:data_source =>"device",
97
+ # :data_source_type =>"5406d665faf3d9d39100000a",
98
+ :name =>"gem bata banako email data source",
99
+ :user_name =>"gem_username",
100
+ :sender =>"droplet@sender.com",
101
+ :password =>"niroj_password",
102
+ :pop_server =>"niroj.com",
103
+ :port =>"12345"
104
+ })
105
+
106
+ end
107
+
108
+
109
+ # it "should get a data_source for the user by id" do
110
+ # specific_data_source = MachineShop::DataSources.retrieve(data_source.id, auth_token)
111
+
112
+ # ap specific_data_source
113
+
114
+ # specific_data_source.should_not be_nil
115
+ # # specific_data_source.should be_kind_of MachineShop::DataSources
116
+ # end
117
+
118
+
119
+ # it "should create data_source" do
120
+ # data_source_instance = specific_data_source.create_instance(
121
+ # {
122
+ # :name => "My little instance",
123
+ # :active => "yes"
124
+ # }
125
+
126
+
127
+ # )
128
+
129
+ # end
130
+
131
+
132
+
133
+ # it "should get instances of data_source data_source" do
134
+ # ins = specific_data_source.instances
135
+
136
+ # end
137
+
138
+ end
@@ -0,0 +1,77 @@
1
+ require_relative '../spec_helper'
2
+
3
+ #MachineShop.api_base_url= 'http://machineshop.dev:3000/api/v0'
4
+ MachineShop.api_base_url= 'http://localhost:3000/api/v1'
5
+ publisher_username = 'publisher@csr.com'
6
+ publisher_password = 'password'
7
+
8
+
9
+ MachineShop.configure do |config|
10
+ config.expiry_time = lambda{120.seconds.ago}
11
+ config.enable_caching = false
12
+ config.db_username="root"
13
+ config.db_password="root"
14
+ config.db_name="machineshop"
15
+ end
16
+
17
+ auth_token, user = MachineShop::Users.authenticate(
18
+ :email => publisher_username,
19
+ :password => publisher_password
20
+ )
21
+
22
+
23
+
24
+ describe MachineShop::DataSourceTypes do
25
+
26
+
27
+ specific_data_source = nil
28
+
29
+ data_source = nil
30
+
31
+ it "should get all DataSource types for the user" do
32
+ element_data = MachineShop::DataSourceTypes.all(
33
+ {:page => 1,
34
+ :per_page => 10},
35
+ auth_token)
36
+
37
+ ap element_data
38
+
39
+ data_source = element_data[0]
40
+ expect(data_source).to be_truthy
41
+ end
42
+
43
+
44
+ it "should create data_source_type" do
45
+ element_data = MachineShop::DataSourceTypes.create(
46
+ {
47
+ :exe_path =>"/path/exe",
48
+ :image_url =>"http://yahoo.com",
49
+ :init_cmd =>"start it up",
50
+ :init_params =>"now=true",
51
+ # :last_known_translator_port =>"null",
52
+ :long_description =>"Rajat's mobile",
53
+ :manual_url =>"http://snap.com",
54
+ :manufacturer =>"Snapdragon",
55
+ :model =>"Chinese",
56
+ :name =>"One Plus Onefrom gem",
57
+ :sample_data =>"expect this back",
58
+ :software =>"Android 4.04",
59
+ # :translator =>"null",
60
+ :type =>"Phone",
61
+ :unit_price =>"$100.00",
62
+ :active =>"true",
63
+ :payload =>"device.type"
64
+ }, auth_token
65
+ )
66
+ end
67
+
68
+ # it "should get a data_source for the user by id" do
69
+ # specific_data_source = MachineShop::DataSources.retrieve(data_source.id, auth_token)
70
+
71
+ # ap specific_data_source
72
+
73
+ # specific_data_source.should_not be_nil
74
+ # # specific_data_source.should be_kind_of MachineShop::DataSources
75
+ # end
76
+
77
+ end
@@ -0,0 +1,45 @@
1
+ require_relative '../spec_helper'
2
+
3
+ #MachineShop.api_base_url= 'http://machineshop.dev:3000/api/v0'
4
+ MachineShop.api_base_url= 'http://stage.services.machineshop.io/api/v0'
5
+
6
+ #publisher_username = 'publisher@machineshop.com'
7
+ publisher_username = 'publisher@csr.com'
8
+ publisher_password = 'password'
9
+
10
+
11
+ describe "#expiry_time" do
12
+ it "default value is 6" do
13
+ MachineShop::Configuration.new.expiry_time =23
14
+ # puts "original value is #{MachineShop::Configuration.expiry_time}"
15
+ end
16
+ end
17
+
18
+
19
+ describe "#expiry_time=" do
20
+ it "can set value" do
21
+ MachineShop.configure do |config|
22
+ config.expiry_time = 10
23
+ config.enable_caching = false
24
+ config.db_username="root"
25
+ config.db_password="root"
26
+ config.db_name="machineshop"
27
+ end
28
+
29
+ config = MachineShop.configuration
30
+
31
+
32
+ config.expiry_time = 7
33
+ expect(config.expiry_time).to eq(7)
34
+ puts "config.expiry_time #{config.expiry_time}"
35
+ end
36
+
37
+ it "should use activeRecord to create new record" do
38
+ end
39
+
40
+ it "stores into database" do
41
+ db = MachineShop::Database.new
42
+ rec = People.find_by(first_name: 'niroj')
43
+ ap rec.as_json
44
+ end
45
+ end
@@ -0,0 +1,73 @@
1
+ require_relative '../spec_helper'
2
+
3
+ #MachineShop.api_base_url= 'http://machineshop.dev:3000/api/v0'
4
+ MachineShop.api_base_url= 'http://stage.services.machineshop.io/api/v0'
5
+
6
+ #publisher_username = 'publisher@machineshop.com'
7
+ publisher_username = 'admin@csr.com'
8
+ publisher_password = 'password'
9
+
10
+
11
+ auth_token ="fghjkljkl"
12
+ # , user = MachineShop::User.authenticate(
13
+ # :email => publisher_username,
14
+ # :password => publisher_password
15
+ # )
16
+
17
+ describe MachineShop::DeviceInstance do
18
+
19
+
20
+ specificDevice = nil
21
+
22
+ device = nil
23
+
24
+ it "should get all devices for the user" do
25
+ element_data = MachineShop::DeviceInstance.all(
26
+ {:page => 1,
27
+ :per_page => 10},
28
+ auth_token)
29
+
30
+ ap "listing all devices"
31
+ puts element_data
32
+ device = element_data[0]
33
+ device.should_not be_nil
34
+ device.should be_kind_of MachineShop::Device
35
+ end
36
+
37
+
38
+
39
+
40
+ it "should get a device for the user by id" do
41
+ specificDevice = MachineShop::Device.retrieve(device.id, auth_token)
42
+
43
+ ap "Device by id"
44
+ ap specificDevice.as_json
45
+ specificDevice.should_not be_nil
46
+ specificDevice.should be_kind_of MachineShop::Device
47
+ end
48
+
49
+
50
+ it "should create device instance " do
51
+ device_instance = specificDevice.create_instance(
52
+ {
53
+ :name => "My little instance",
54
+ :active => "yes"
55
+ }
56
+
57
+
58
+ )
59
+
60
+ ap "creating instance"
61
+ ap device_instance.as_json
62
+ end
63
+
64
+
65
+
66
+ it "should get instances of device device" do
67
+ ins = specificDevice.instances
68
+
69
+ ap "ins "
70
+ ap ins.as_json
71
+ end
72
+
73
+ end