machineshop 1.0.0 → 1.0.2
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.
- checksums.yaml +4 -4
- data/lib/machineshop.rb +146 -142
- data/lib/machineshop/api_operations/create.rb +1 -1
- data/lib/machineshop/api_operations/delete.rb +1 -1
- data/lib/machineshop/api_operations/list.rb +1 -1
- data/lib/machineshop/api_operations/update.rb +1 -1
- data/lib/machineshop/api_resource.rb +1 -1
- data/lib/machineshop/configuration.rb +5 -2
- data/lib/machineshop/data_source_types.rb +1 -1
- data/lib/machineshop/data_sources.rb +2 -2
- data/lib/machineshop/device.rb +1 -1
- data/lib/machineshop/device_instance.rb +1 -1
- data/lib/machineshop/end_points.rb +30 -0
- data/lib/machineshop/mapping.rb +3 -3
- data/lib/machineshop/models/api_endpoint.rb +8 -0
- data/lib/machineshop/models/api_request.rb +1 -0
- data/lib/machineshop/models/schema.rb +15 -0
- data/lib/machineshop/rule.rb +6 -22
- data/lib/machineshop/user.rb +3 -3
- data/lib/machineshop/users.rb +3 -3
- data/lib/machineshop/util.rb +82 -5
- data/lib/machineshop/utility.rb +2 -2
- data/lib/machineshop/version.rb +1 -1
- data/machineshop.gemspec +2 -6
- data/spec/lib/api_calls_spec.rb +628 -0
- data/spec/lib/custom_endpoint_test.rb +78 -0
- data/spec/lib/customer_spec.rb +39 -14
- data/spec/lib/data_source.rb +2 -0
- data/spec/lib/database_spec.rb +3 -1
- data/spec/lib/device_instances.rb +9 -1
- data/spec/lib/device_spec.rb +24 -0
- data/spec/lib/endpoint_spec.rb +37 -0
- data/spec/lib/{test_spec.rb → geocode_spec} +12 -14
- data/spec/lib/mapping_spec.rb +11 -0
- data/spec/lib/meter_spec.rb +8 -0
- data/spec/lib/report_spec.rb +6 -0
- data/spec/lib/rule_spec.rb +50 -26
- data/spec/lib/user_spec.rb +11 -0
- data/spec/spec_helper.rb +10 -1
- metadata +12 -5
- data/lib/machineshop/models/people.rb +0 -13
@@ -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
|
data/spec/lib/customer_spec.rb
CHANGED
@@ -9,54 +9,79 @@ publisher_username = 'admin@csr.com'
|
|
9
9
|
publisher_password = 'password'
|
10
10
|
|
11
11
|
|
12
|
-
auth_token, user = MachineShop::User.authenticate(
|
13
|
-
:email => publisher_username,
|
14
|
-
:password => publisher_password
|
15
|
-
)
|
12
|
+
auth_token, user = MachineShop::User.authenticate(
|
13
|
+
:email => publisher_username,
|
14
|
+
:password => publisher_password
|
15
|
+
)
|
16
16
|
describe MachineShop::Customer do
|
17
17
|
|
18
18
|
it "should get all the customers " do
|
19
19
|
customers = MachineShop::Customer.all({}, auth_token)
|
20
20
|
|
21
|
+
puts "customers are #{customers}"
|
22
|
+
|
23
|
+
#puts "first customer is : #{customers[0][:id]}"
|
24
|
+
|
21
25
|
customers.should_not be_nil
|
22
26
|
end
|
23
27
|
|
24
|
-
|
28
|
+
specificCustomer = nil
|
25
29
|
it "should create customer " do
|
26
30
|
|
27
31
|
specificCustomer = MachineShop::Customer.create({:email=>"bajratests@bajratechnologies.com",
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
32
|
+
:password=>'password',
|
33
|
+
:notification_method=>'sms',
|
34
|
+
:first_name=>'niroj',:last_name=>'sapkota',
|
35
|
+
:phone_number=>'98989898989',
|
36
|
+
:company_name=>'technology co'
|
33
37
|
|
34
|
-
|
38
|
+
},auth_token)
|
35
39
|
|
40
|
+
ap "created customer is"
|
41
|
+
ap specificCustomer.as_json
|
36
42
|
specificCustomer.should_not be_nil
|
37
43
|
end
|
38
44
|
|
39
45
|
|
40
|
-
|
46
|
+
retrieved_cust=nil
|
41
47
|
it "should get customer by customer id " do
|
48
|
+
ap "looking up customer before:"
|
49
|
+
ap specificCustomer.as_json
|
50
|
+
|
42
51
|
retrieved_cust = MachineShop::Customer.retrieve(specificCustomer.id, auth_token)
|
43
|
-
|
52
|
+
|
53
|
+
ap "looking up customer after:"
|
54
|
+
ap retrieved_cust.as_json
|
55
|
+
|
44
56
|
retrieved_cust.should_not be_nil
|
45
57
|
end
|
46
58
|
|
47
59
|
|
48
60
|
it "should update the customer with id " do
|
61
|
+
|
62
|
+
ap "updating customer with id : #{specificCustomer.id}"
|
49
63
|
update = MachineShop::Customer.update(specificCustomer.id,auth_token,{:notification_method => 'email',:first_name=>'testJohn'})
|
50
|
-
update.
|
64
|
+
ap update.as_json
|
51
65
|
end
|
52
66
|
|
53
67
|
|
54
68
|
it "should update the customer from the retrieved obj id " do
|
69
|
+
ap "updating customer from the retrieved obj id : #{specificCustomer.id}"
|
70
|
+
|
55
71
|
update = retrieved_cust.update({:notification_method => 'email'})
|
72
|
+
ap update.as_json
|
56
73
|
end
|
74
|
+
|
75
|
+
#success test
|
57
76
|
|
58
77
|
it "should delete customer with id " do
|
78
|
+
|
79
|
+
#puts
|
80
|
+
puts "deleting customer with id : #{specificCustomer.id}"
|
81
|
+
|
59
82
|
delete = specificCustomer.delete
|
83
|
+
#delete = MachineShop::Customer.delete(customers[0].id,auth_token)
|
84
|
+
puts "delete #{delete}"
|
60
85
|
delete.http_code.should eq 200
|
61
86
|
end
|
62
87
|
end
|
data/spec/lib/data_source.rb
CHANGED
data/spec/lib/database_spec.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require_relative '../spec_helper'
|
2
2
|
|
3
|
-
require 'machineshop/models/people'
|
4
3
|
#MachineShop.api_base_url= 'http://machineshop.dev:3000/api/v0'
|
5
4
|
MachineShop.api_base_url= 'http://stage.services.machineshop.io/api/v0'
|
6
5
|
|
@@ -12,6 +11,7 @@ publisher_password = 'password'
|
|
12
11
|
describe "#expiry_time" do
|
13
12
|
it "default value is 6" do
|
14
13
|
MachineShop::Configuration.new.expiry_time =23
|
14
|
+
# puts "original value is #{MachineShop::Configuration.expiry_time}"
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -31,6 +31,7 @@ describe "#expiry_time=" do
|
|
31
31
|
|
32
32
|
config.expiry_time = 7
|
33
33
|
expect(config.expiry_time).to eq(7)
|
34
|
+
puts "config.expiry_time #{config.expiry_time}"
|
34
35
|
end
|
35
36
|
|
36
37
|
it "should use activeRecord to create new record" do
|
@@ -39,5 +40,6 @@ describe "#expiry_time=" do
|
|
39
40
|
it "stores into database" do
|
40
41
|
db = MachineShop::Database.new
|
41
42
|
rec = People.find_by(first_name: 'niroj')
|
43
|
+
ap rec.as_json
|
42
44
|
end
|
43
45
|
end
|
@@ -8,7 +8,7 @@ publisher_username = 'admin@csr.com'
|
|
8
8
|
publisher_password = 'password'
|
9
9
|
|
10
10
|
|
11
|
-
auth_token ="
|
11
|
+
auth_token ="fghjkljkl"
|
12
12
|
# , user = MachineShop::User.authenticate(
|
13
13
|
# :email => publisher_username,
|
14
14
|
# :password => publisher_password
|
@@ -27,6 +27,8 @@ device = nil
|
|
27
27
|
:per_page => 10},
|
28
28
|
auth_token)
|
29
29
|
|
30
|
+
ap "listing all devices"
|
31
|
+
puts element_data
|
30
32
|
device = element_data[0]
|
31
33
|
device.should_not be_nil
|
32
34
|
device.should be_kind_of MachineShop::Device
|
@@ -38,6 +40,8 @@ device = nil
|
|
38
40
|
it "should get a device for the user by id" do
|
39
41
|
specificDevice = MachineShop::Device.retrieve(device.id, auth_token)
|
40
42
|
|
43
|
+
ap "Device by id"
|
44
|
+
ap specificDevice.as_json
|
41
45
|
specificDevice.should_not be_nil
|
42
46
|
specificDevice.should be_kind_of MachineShop::Device
|
43
47
|
end
|
@@ -53,6 +57,8 @@ device = nil
|
|
53
57
|
|
54
58
|
)
|
55
59
|
|
60
|
+
ap "creating instance"
|
61
|
+
ap device_instance.as_json
|
56
62
|
end
|
57
63
|
|
58
64
|
|
@@ -60,6 +66,8 @@ device = nil
|
|
60
66
|
it "should get instances of device device" do
|
61
67
|
ins = specificDevice.instances
|
62
68
|
|
69
|
+
ap "ins "
|
70
|
+
ap ins.as_json
|
63
71
|
end
|
64
72
|
|
65
73
|
end
|
data/spec/lib/device_spec.rb
CHANGED
@@ -30,6 +30,8 @@ describe MachineShop::Device do
|
|
30
30
|
:per_page => 10},
|
31
31
|
auth_token)
|
32
32
|
|
33
|
+
ap "listing all devices"
|
34
|
+
puts element_data
|
33
35
|
device = element_data[0]
|
34
36
|
device.should_not be_nil
|
35
37
|
device.should be_kind_of MachineShop::Device
|
@@ -41,6 +43,8 @@ specificDevice = nil
|
|
41
43
|
it "should get a device for the user by id" do
|
42
44
|
specificDevice = MachineShop::Device.retrieve(device[:id], auth_token)
|
43
45
|
|
46
|
+
ap "Device by id"
|
47
|
+
ap specificDevice.as_json
|
44
48
|
specificDevice.should_not be_nil
|
45
49
|
specificDevice.should be_kind_of MachineShop::Device
|
46
50
|
end
|
@@ -50,6 +54,8 @@ specificDevice = nil
|
|
50
54
|
it "should delete device" do
|
51
55
|
delete = specificDevice.delete
|
52
56
|
|
57
|
+
ap "Delete Device by id"
|
58
|
+
ap delete.as_json
|
53
59
|
delete.http_code.should eq 200
|
54
60
|
end
|
55
61
|
|
@@ -92,6 +98,8 @@ describe MachineShop::DeviceInstance do
|
|
92
98
|
},
|
93
99
|
auth_token)
|
94
100
|
|
101
|
+
ap "device created:"
|
102
|
+
ap device.as_json
|
95
103
|
|
96
104
|
# Now create an instance
|
97
105
|
device_instance = device.create_instance(
|
@@ -101,6 +109,9 @@ describe MachineShop::DeviceInstance do
|
|
101
109
|
}
|
102
110
|
)
|
103
111
|
|
112
|
+
ap "creating device instance"
|
113
|
+
ap device_instance.as_json
|
114
|
+
|
104
115
|
device_instance.should_not be_nil
|
105
116
|
device_instance.should be_kind_of MachineShop::DeviceInstance
|
106
117
|
end
|
@@ -109,6 +120,10 @@ describe MachineShop::DeviceInstance do
|
|
109
120
|
it "should get device instances" do
|
110
121
|
element_data = MachineShop::DeviceInstance.all({}, auth_token)
|
111
122
|
|
123
|
+
ap "getting all device instances"
|
124
|
+
|
125
|
+
ap device_instance.as_json
|
126
|
+
|
112
127
|
device_instance = element_data[0]
|
113
128
|
element_data.should_not be_nil
|
114
129
|
element_data.should_not be_empty
|
@@ -120,6 +135,9 @@ describe MachineShop::DeviceInstance do
|
|
120
135
|
it "should get a device instance by id" do
|
121
136
|
element_data = MachineShop::DeviceInstance.retrieve("5395835f385f7f53ec000160", auth_token)
|
122
137
|
|
138
|
+
ap "Device Instance by id: "
|
139
|
+
ap element_data.as_json
|
140
|
+
|
123
141
|
element_data.should_not be_nil
|
124
142
|
element_data.should be_kind_of MachineShop::DeviceInstance
|
125
143
|
end
|
@@ -127,6 +145,9 @@ describe MachineShop::DeviceInstance do
|
|
127
145
|
it "should get a device instance by name" do
|
128
146
|
element_data = MachineShop::DeviceInstance.all({:name => device_instance.name}, auth_token)
|
129
147
|
|
148
|
+
ap "Device Instance by name: "
|
149
|
+
ap element_data.as_json
|
150
|
+
|
130
151
|
element_data.should_not be_nil
|
131
152
|
element_data.should_not be_empty
|
132
153
|
end
|
@@ -134,6 +155,9 @@ describe MachineShop::DeviceInstance do
|
|
134
155
|
it "should get all devices via a user" do
|
135
156
|
element_data = user.device_instances
|
136
157
|
|
158
|
+
ap "Device Instance via user "
|
159
|
+
ap element_data.as_json
|
160
|
+
|
137
161
|
element_data.should_not be_nil
|
138
162
|
element_data.should_not be_empty
|
139
163
|
end
|
@@ -0,0 +1,37 @@
|
|
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
|
+
#second
|
16
|
+
end
|
17
|
+
|
18
|
+
# auth_token, user = MachineShop::User.authenticate(
|
19
|
+
# :email => publisher_username,
|
20
|
+
# :password => publisher_password
|
21
|
+
# )
|
22
|
+
|
23
|
+
# ap "auth_token #{auth_token}"
|
24
|
+
|
25
|
+
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
26
|
+
|
27
|
+
auth_token="2jzZmcHWLZyghsxcB16E"
|
28
|
+
# => admin
|
29
|
+
|
30
|
+
# auth_token="WPyus6qzPxaPbNN1V5qb" # => publisher
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
describe MachineShop::EndPoints do
|
35
|
+
element_data = MachineShop::EndPoints.all("v0",auth_token)
|
36
|
+
# # element_data = MachineShop::EndPoints.all({:namespace=>"secm"},auth_token)
|
37
|
+
end
|
@@ -12,34 +12,32 @@ MachineShop.configure do |config|
|
|
12
12
|
config.db_password="root"
|
13
13
|
config.db_host= "localhost"
|
14
14
|
config.expiry_time= lambda{120.seconds.ago}
|
15
|
-
|
15
|
+
#second
|
16
16
|
end
|
17
17
|
|
18
18
|
auth_token, user = MachineShop::User.authenticate(
|
19
19
|
:email => publisher_username,
|
20
20
|
:password => publisher_password
|
21
21
|
)
|
22
|
+
# ap user
|
22
23
|
|
23
|
-
describe MachineShop::
|
24
|
+
describe MachineShop::Mapping do
|
24
25
|
|
25
26
|
device = nil
|
26
27
|
|
27
|
-
it "should get
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
{:page => 1,
|
33
|
-
:per_page => 10,
|
34
|
-
:name=>"my_device"
|
28
|
+
it "should get a geocoded address" do
|
29
|
+
element_data = MachineShop::Mapping.geocode(
|
30
|
+
{
|
31
|
+
:latlng => "40.714224,-73.961452",
|
32
|
+
# :sensor => "false"
|
35
33
|
},
|
36
34
|
auth_token)
|
35
|
+
ap element_data.as_json
|
36
|
+
element_data.should_not be_nil
|
37
|
+
element_data.should_not be_empty
|
38
|
+
end
|
37
39
|
|
38
|
-
device = element_data[0]
|
39
|
-
device.should_not be_nil
|
40
|
-
device.should be_kind_of MachineShop::Device
|
41
40
|
|
42
|
-
end
|
43
41
|
end
|
44
42
|
|
45
43
|
|
data/spec/lib/mapping_spec.rb
CHANGED
@@ -16,6 +16,7 @@ publisher_password = 'password'
|
|
16
16
|
describe MachineShop::Mapping do
|
17
17
|
|
18
18
|
it "should get a geocoded address" do
|
19
|
+
ap "geocoding address"
|
19
20
|
element_data = MachineShop::Mapping.geocode(
|
20
21
|
{
|
21
22
|
:address => "1600 Amphitheatre Parkway, Mountain View, CA",
|
@@ -23,11 +24,15 @@ describe MachineShop::Mapping do
|
|
23
24
|
},
|
24
25
|
auth_token)
|
25
26
|
|
27
|
+
ap element_data.as_json
|
28
|
+
#puts "GEO: #{element_data}"
|
29
|
+
|
26
30
|
element_data.should_not be_nil
|
27
31
|
element_data.should_not be_empty
|
28
32
|
end
|
29
33
|
|
30
34
|
it "should get directions" do
|
35
|
+
ap "getting directions"
|
31
36
|
element_data = MachineShop::Mapping.directions(
|
32
37
|
{
|
33
38
|
:origin => "Denver",
|
@@ -35,12 +40,15 @@ describe MachineShop::Mapping do
|
|
35
40
|
:sensor => "false"
|
36
41
|
},
|
37
42
|
auth_token)
|
43
|
+
# ap element_data.as_json
|
44
|
+
#puts "GEO: #{element_data}"
|
38
45
|
|
39
46
|
element_data.should_not be_nil
|
40
47
|
element_data.should_not be_empty
|
41
48
|
end
|
42
49
|
|
43
50
|
it "should get distance" do
|
51
|
+
ap "getting distance "
|
44
52
|
element_data = MachineShop::Mapping.distance(
|
45
53
|
{
|
46
54
|
:origins => "Vancouver BC",
|
@@ -50,6 +58,9 @@ describe MachineShop::Mapping do
|
|
50
58
|
:sensor => "false"
|
51
59
|
},
|
52
60
|
auth_token)
|
61
|
+
ap element_data.as_json
|
62
|
+
#puts "GEO: #{element_data}"
|
63
|
+
|
53
64
|
element_data.should_not be_nil
|
54
65
|
element_data.should_not be_empty
|
55
66
|
end
|