machineshop 0.0.4 → 1.0.0
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/Gemfile +3 -2
- data/lib/machineshop.rb +289 -53
- data/lib/machineshop/configuration.rb +1 -1
- data/lib/machineshop/data_source_types.rb +28 -0
- data/lib/machineshop/data_sources.rb +35 -0
- data/lib/machineshop/database.rb +34 -87
- data/lib/machineshop/errors/schema_error.rb +5 -0
- data/lib/machineshop/machineshop_object.rb +2 -1
- data/lib/machineshop/models/api_request.rb +27 -0
- data/lib/machineshop/models/people.rb +13 -0
- data/lib/machineshop/models/schema.rb +169 -0
- data/lib/machineshop/users.rb +43 -0
- data/lib/machineshop/util.rb +2 -1
- data/lib/machineshop/version.rb +1 -1
- data/machineshop.gemspec +16 -1
- data/spec/lib/customer_spec.rb +17 -39
- data/spec/lib/data_source.rb +136 -0
- data/spec/lib/data_source_type_spec.rb +77 -0
- data/spec/lib/database_spec.rb +43 -0
- data/spec/lib/device_instances.rb +10 -13
- data/spec/lib/device_spec.rb +13 -27
- data/spec/lib/mapping_spec.rb +3 -11
- data/spec/lib/meter_spec.rb +3 -8
- data/spec/lib/report_spec.rb +2 -8
- data/spec/lib/rule_spec.rb +37 -52
- data/spec/lib/test_spec.rb +47 -0
- data/spec/lib/user_spec.rb +4 -11
- data/spec/spec_helper.rb +0 -1
- metadata +49 -8
- data/Readme_old.bkmMd +0 -782
- data/spec/lib/api_calls_spec.rb +0 -624
data/lib/machineshop/util.rb
CHANGED
data/lib/machineshop/version.rb
CHANGED
data/machineshop.gemspec
CHANGED
@@ -17,8 +17,23 @@ Gem::Specification.new do |gem|
|
|
17
17
|
|
18
18
|
gem.add_development_dependency 'rake'
|
19
19
|
gem.add_development_dependency 'rspec'
|
20
|
-
|
20
|
+
|
21
|
+
# gem.add_development_dependency 'mysql'
|
22
|
+
|
23
|
+
# gem.add_runtime_dependency 'mysql'
|
24
|
+
gem.add_dependency 'mysql'
|
25
|
+
|
21
26
|
gem.add_dependency 'addressable'
|
22
27
|
gem.add_dependency 'rest-client'#, '~> 1.6.7'
|
23
28
|
gem.add_dependency('multi_json', '>= 1.0.4', '< 2')
|
29
|
+
# gem.add_dependency('activerecord', '>= 4.1.1')
|
30
|
+
gem.add_dependency('activerecord', '>= 4.0.0')
|
31
|
+
gem.required_ruby_version = '>= 1.9.3'
|
32
|
+
gem.post_install_message = "Thanks for installing Machineshop gem, Enjoy!!"
|
33
|
+
gem.requirements << 'mysql, activerecord'
|
34
|
+
|
35
|
+
|
36
|
+
# Test for rake task database
|
37
|
+
# gem.executables << 'rake'
|
38
|
+
# gem.extensions << 'lib/machineshop/models/schema.rb'
|
24
39
|
end
|
data/spec/lib/customer_spec.rb
CHANGED
@@ -1,84 +1,62 @@
|
|
1
1
|
require_relative '../spec_helper'
|
2
2
|
|
3
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
|
+
|
4
7
|
#publisher_username = 'publisher@machineshop.com'
|
5
8
|
publisher_username = 'admin@csr.com'
|
6
9
|
publisher_password = 'password'
|
7
10
|
|
8
11
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
12
|
+
auth_token, user = MachineShop::User.authenticate(
|
13
|
+
:email => publisher_username,
|
14
|
+
:password => publisher_password
|
15
|
+
)
|
13
16
|
describe MachineShop::Customer do
|
14
17
|
|
15
18
|
it "should get all the customers " do
|
16
19
|
customers = MachineShop::Customer.all({}, auth_token)
|
17
20
|
|
18
|
-
puts "customers are #{customers}"
|
19
|
-
|
20
|
-
#puts "first customer is : #{customers[0][:id]}"
|
21
|
-
|
22
21
|
customers.should_not be_nil
|
23
22
|
end
|
24
23
|
|
25
|
-
|
24
|
+
specificCustomer = nil
|
26
25
|
it "should create customer " do
|
27
26
|
|
28
27
|
specificCustomer = MachineShop::Customer.create({:email=>"bajratests@bajratechnologies.com",
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
:password=>'password',
|
29
|
+
:notification_method=>'sms',
|
30
|
+
:first_name=>'niroj',:last_name=>'sapkota',
|
31
|
+
:phone_number=>'98989898989',
|
32
|
+
:company_name=>'technology co'
|
34
33
|
|
35
|
-
|
34
|
+
},auth_token)
|
36
35
|
|
37
|
-
ap "created customer is"
|
38
|
-
ap specificCustomer.as_json
|
39
36
|
specificCustomer.should_not be_nil
|
40
37
|
end
|
41
38
|
|
42
39
|
|
43
|
-
|
40
|
+
retrieved_cust=nil
|
44
41
|
it "should get customer by customer id " do
|
45
|
-
ap "looking up customer before:"
|
46
|
-
ap specificCustomer.as_json
|
47
|
-
|
48
42
|
retrieved_cust = MachineShop::Customer.retrieve(specificCustomer.id, auth_token)
|
49
|
-
|
50
|
-
ap "looking up customer after:"
|
51
|
-
ap retrieved_cust.as_json
|
52
|
-
|
43
|
+
|
53
44
|
retrieved_cust.should_not be_nil
|
54
45
|
end
|
55
46
|
|
56
47
|
|
57
48
|
it "should update the customer with id " do
|
58
|
-
|
59
|
-
ap "updating customer with id : #{specificCustomer.id}"
|
60
49
|
update = MachineShop::Customer.update(specificCustomer.id,auth_token,{:notification_method => 'email',:first_name=>'testJohn'})
|
61
|
-
|
50
|
+
update.should_not be_nil
|
62
51
|
end
|
63
52
|
|
64
53
|
|
65
54
|
it "should update the customer from the retrieved obj id " do
|
66
|
-
ap "updating customer from the retrieved obj id : #{specificCustomer.id}"
|
67
|
-
|
68
55
|
update = retrieved_cust.update({:notification_method => 'email'})
|
69
|
-
ap update.as_json
|
70
56
|
end
|
71
|
-
|
72
|
-
#success test
|
73
57
|
|
74
58
|
it "should delete customer with id " do
|
75
|
-
|
76
|
-
#puts
|
77
|
-
puts "deleting customer with id : #{specificCustomer.id}"
|
78
|
-
|
79
59
|
delete = specificCustomer.delete
|
80
|
-
#delete = MachineShop::Customer.delete(customers[0].id,auth_token)
|
81
|
-
puts "delete #{delete}"
|
82
60
|
delete.http_code.should eq 200
|
83
61
|
end
|
84
62
|
end
|
@@ -0,0 +1,136 @@
|
|
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
|
+
data_source = element_data[0]
|
41
|
+
expect(data_source).to be_truthy
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
it "should update the DataSource " do
|
46
|
+
toUpdate = MachineShop::DataSources.retrieve(data_source.id, auth_token)
|
47
|
+
|
48
|
+
update = toUpdate.update({:name => "updated name"})
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should delete datasource" do
|
53
|
+
toDelete = MachineShop::DataSources.retrieve(data_source.id,auth_token)
|
54
|
+
# ap toDelete
|
55
|
+
|
56
|
+
deleted = toDelete.delete
|
57
|
+
# ap deleted
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
it "should get all DataSourceTypes" do
|
63
|
+
element_data = MachineShop::DataSourceTypes.all(
|
64
|
+
{:page => 1,
|
65
|
+
:per_page => 10},
|
66
|
+
auth_token)
|
67
|
+
data_source_type = element_data[0]
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should retrieve DataSource " do
|
71
|
+
specificDataSource = MachineShop::DataSourceTypes.retrieve(data_source_type.id, auth_token)
|
72
|
+
|
73
|
+
data_source = specificDataSource.create_data_source(
|
74
|
+
|
75
|
+
{:data_source =>"device",
|
76
|
+
# :data_source_type =>"5406d665faf3d9d39100000a",
|
77
|
+
:name =>"gem bata banako device type",
|
78
|
+
:user_name =>"niroj_username",
|
79
|
+
:sender =>"niroj@sender.com",
|
80
|
+
:password =>"password",
|
81
|
+
:pop_server =>"port_server",
|
82
|
+
:port =>"345"
|
83
|
+
})
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
it "should get create email DataSource " do
|
89
|
+
|
90
|
+
specificDataSource = MachineShop::DataSourceTypes.retrieve(data_source_type.id, auth_token)
|
91
|
+
|
92
|
+
data_source = specificDataSource.create_email_data_source(
|
93
|
+
|
94
|
+
{:data_source =>"device",
|
95
|
+
# :data_source_type =>"5406d665faf3d9d39100000a",
|
96
|
+
:name =>"gem bata banako email data source",
|
97
|
+
:user_name =>"gem_username",
|
98
|
+
:sender =>"droplet@sender.com",
|
99
|
+
:password =>"niroj_password",
|
100
|
+
:pop_server =>"niroj.com",
|
101
|
+
:port =>"12345"
|
102
|
+
})
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
# it "should get a data_source for the user by id" do
|
108
|
+
# specific_data_source = MachineShop::DataSources.retrieve(data_source.id, auth_token)
|
109
|
+
|
110
|
+
# ap specific_data_source
|
111
|
+
|
112
|
+
# specific_data_source.should_not be_nil
|
113
|
+
# # specific_data_source.should be_kind_of MachineShop::DataSources
|
114
|
+
# end
|
115
|
+
|
116
|
+
|
117
|
+
# it "should create data_source" do
|
118
|
+
# data_source_instance = specific_data_source.create_instance(
|
119
|
+
# {
|
120
|
+
# :name => "My little instance",
|
121
|
+
# :active => "yes"
|
122
|
+
# }
|
123
|
+
|
124
|
+
|
125
|
+
# )
|
126
|
+
|
127
|
+
# end
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
# it "should get instances of data_source data_source" do
|
132
|
+
# ins = specific_data_source.instances
|
133
|
+
|
134
|
+
# end
|
135
|
+
|
136
|
+
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,43 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
require 'machineshop/models/people'
|
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 = 'publisher@csr.com'
|
9
|
+
publisher_password = 'password'
|
10
|
+
|
11
|
+
|
12
|
+
describe "#expiry_time" do
|
13
|
+
it "default value is 6" do
|
14
|
+
MachineShop::Configuration.new.expiry_time =23
|
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
|
+
end
|
35
|
+
|
36
|
+
it "should use activeRecord to create new record" do
|
37
|
+
end
|
38
|
+
|
39
|
+
it "stores into database" do
|
40
|
+
db = MachineShop::Database.new
|
41
|
+
rec = People.find_by(first_name: 'niroj')
|
42
|
+
end
|
43
|
+
end
|
@@ -1,13 +1,18 @@
|
|
1
1
|
require_relative '../spec_helper'
|
2
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'
|
3
7
|
publisher_username = 'admin@csr.com'
|
4
8
|
publisher_password = 'password'
|
5
9
|
|
6
10
|
|
7
|
-
auth_token
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
+
auth_token ="some_token"
|
12
|
+
# , user = MachineShop::User.authenticate(
|
13
|
+
# :email => publisher_username,
|
14
|
+
# :password => publisher_password
|
15
|
+
# )
|
11
16
|
|
12
17
|
describe MachineShop::DeviceInstance do
|
13
18
|
|
@@ -17,13 +22,11 @@ specificDevice = nil
|
|
17
22
|
device = nil
|
18
23
|
|
19
24
|
it "should get all devices for the user" do
|
20
|
-
element_data = MachineShop::
|
25
|
+
element_data = MachineShop::DeviceInstance.all(
|
21
26
|
{:page => 1,
|
22
27
|
:per_page => 10},
|
23
28
|
auth_token)
|
24
29
|
|
25
|
-
ap "listing all devices"
|
26
|
-
puts element_data
|
27
30
|
device = element_data[0]
|
28
31
|
device.should_not be_nil
|
29
32
|
device.should be_kind_of MachineShop::Device
|
@@ -35,8 +38,6 @@ device = nil
|
|
35
38
|
it "should get a device for the user by id" do
|
36
39
|
specificDevice = MachineShop::Device.retrieve(device.id, auth_token)
|
37
40
|
|
38
|
-
ap "Device by id"
|
39
|
-
ap specificDevice.as_json
|
40
41
|
specificDevice.should_not be_nil
|
41
42
|
specificDevice.should be_kind_of MachineShop::Device
|
42
43
|
end
|
@@ -52,8 +53,6 @@ device = nil
|
|
52
53
|
|
53
54
|
)
|
54
55
|
|
55
|
-
ap "creating instance"
|
56
|
-
ap device_instance.as_json
|
57
56
|
end
|
58
57
|
|
59
58
|
|
@@ -61,8 +60,6 @@ device = nil
|
|
61
60
|
it "should get instances of device device" do
|
62
61
|
ins = specificDevice.instances
|
63
62
|
|
64
|
-
ap "ins "
|
65
|
-
ap ins.as_json
|
66
63
|
end
|
67
64
|
|
68
65
|
end
|