machineshop 1.0.2 → 1.1.1

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 (97) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +45 -0
  3. data/{Gemfile → machineshop/Gemfile} +0 -0
  4. data/{LICENSE → machineshop/LICENSE} +0 -0
  5. data/{Rakefile → machineshop/Rakefile} +0 -0
  6. data/{doc.txt → machineshop/doc.txt} +0 -0
  7. data/{lib → machineshop/lib}/machineshop.rb +29 -18
  8. data/{lib → machineshop/lib}/machineshop/api_operations/create.rb +0 -0
  9. data/{lib → machineshop/lib}/machineshop/api_operations/delete.rb +0 -0
  10. data/{lib → machineshop/lib}/machineshop/api_operations/list.rb +0 -0
  11. data/{lib → machineshop/lib}/machineshop/api_operations/update.rb +0 -0
  12. data/machineshop/lib/machineshop/api_proxies.rb +20 -0
  13. data/{lib → machineshop/lib}/machineshop/api_resource.rb +1 -1
  14. data/{lib → machineshop/lib}/machineshop/configuration.rb +2 -1
  15. data/machineshop/lib/machineshop/custom_api.rb +28 -0
  16. data/machineshop/lib/machineshop/custom_apis.rb +21 -0
  17. data/{lib → machineshop/lib}/machineshop/customer.rb +1 -1
  18. data/machineshop/lib/machineshop/customers.rb +20 -0
  19. data/{lib → machineshop/lib}/machineshop/data_source_types.rb +12 -2
  20. data/machineshop/lib/machineshop/data_sources.rb +57 -0
  21. data/{lib → machineshop/lib}/machineshop/database.rb +0 -0
  22. data/{lib → machineshop/lib}/machineshop/device.rb +0 -0
  23. data/{lib → machineshop/lib}/machineshop/device_instance.rb +0 -0
  24. data/{lib → machineshop/lib}/machineshop/end_points.rb +0 -0
  25. data/{lib → machineshop/lib}/machineshop/errors/api_connection_error.rb +0 -0
  26. data/{lib → machineshop/lib}/machineshop/errors/api_error.rb +0 -0
  27. data/{lib → machineshop/lib}/machineshop/errors/authentication_error.rb +0 -0
  28. data/{lib → machineshop/lib}/machineshop/errors/database_error.rb +0 -0
  29. data/{lib → machineshop/lib}/machineshop/errors/invalid_request_error.rb +0 -0
  30. data/{lib → machineshop/lib}/machineshop/errors/machineshop_error.rb +0 -0
  31. data/{lib → machineshop/lib}/machineshop/errors/schema_error.rb +0 -0
  32. data/machineshop/lib/machineshop/gateway_configs.rb +34 -0
  33. data/machineshop/lib/machineshop/gateway_data_source_types.rb +18 -0
  34. data/machineshop/lib/machineshop/gateway_data_sources.rb +60 -0
  35. data/{lib → machineshop/lib}/machineshop/json.rb +0 -0
  36. data/{lib → machineshop/lib}/machineshop/machineshop_cache.rb +0 -0
  37. data/{lib → machineshop/lib}/machineshop/machineshop_object.rb +7 -2
  38. data/{lib → machineshop/lib}/machineshop/mapping.rb +0 -0
  39. data/{lib → machineshop/lib}/machineshop/meter.rb +1 -2
  40. data/{lib → machineshop/lib}/machineshop/models/api_endpoint.rb +0 -0
  41. data/{lib → machineshop/lib}/machineshop/models/api_request.rb +0 -0
  42. data/{lib → machineshop/lib}/machineshop/models/schema.rb +2 -1
  43. data/machineshop/lib/machineshop/monitor.rb +39 -0
  44. data/machineshop/lib/machineshop/report.rb +11 -0
  45. data/{lib/machineshop/report.rb → machineshop/lib/machineshop/reports.rb} +3 -1
  46. data/machineshop/lib/machineshop/routes.rb +29 -0
  47. data/{lib → machineshop/lib}/machineshop/rule.rb +0 -0
  48. data/machineshop/lib/machineshop/rules.rb +56 -0
  49. data/{lib → machineshop/lib}/machineshop/user.rb +22 -4
  50. data/machineshop/lib/machineshop/users.rb +81 -0
  51. data/{lib → machineshop/lib}/machineshop/util.rb +22 -11
  52. data/{lib → machineshop/lib}/machineshop/utility.rb +0 -0
  53. data/{lib → machineshop/lib}/machineshop/version.rb +1 -1
  54. data/{machineshop.gemspec → machineshop/machineshop.gemspec} +2 -1
  55. data/{spec → machineshop/spec}/lib/api_calls_spec.rb +0 -0
  56. data/machineshop/spec/lib/api_proxies_spec.rb +91 -0
  57. data/machineshop/spec/lib/custom_api_spec.rb +0 -0
  58. data/machineshop/spec/lib/custom_api_vo_spec.rb +77 -0
  59. data/{spec → machineshop/spec}/lib/custom_endpoint_test.rb +0 -0
  60. data/{spec → machineshop/spec}/lib/customer_spec.rb +21 -8
  61. data/{spec → machineshop/spec}/lib/data_source.rb +0 -0
  62. data/{spec → machineshop/spec}/lib/data_source_type_spec.rb +0 -0
  63. data/{spec → machineshop/spec}/lib/database_spec.rb +0 -0
  64. data/{spec → machineshop/spec}/lib/device_instances.rb +0 -0
  65. data/{spec → machineshop/spec}/lib/device_spec.rb +0 -0
  66. data/{spec → machineshop/spec}/lib/endpoint_spec.rb +0 -0
  67. data/{spec → machineshop/spec}/lib/geocode_spec +0 -0
  68. data/machineshop/spec/lib/logo_spec.rb +51 -0
  69. data/{spec → machineshop/spec}/lib/mapping_spec.rb +0 -0
  70. data/{spec → machineshop/spec}/lib/meter_spec.rb +3 -3
  71. data/machineshop/spec/lib/monitor_spec.rb +50 -0
  72. data/machineshop/spec/lib/new_api_key.rb +28 -0
  73. data/machineshop/spec/lib/report_spec.rb +91 -0
  74. data/machineshop/spec/lib/reports_v1_spec.rb +65 -0
  75. data/machineshop/spec/lib/routes_spec.rb +26 -0
  76. data/{spec → machineshop/spec}/lib/rule_spec.rb +30 -24
  77. data/machineshop/spec/lib/user_spec.rb +99 -0
  78. data/machineshop/spec/lib/v1_rules_spec.rb +106 -0
  79. data/{spec → machineshop/spec}/spec_helper.rb +0 -0
  80. metadata +115 -110
  81. data/.idea/.name +0 -1
  82. data/.idea/.rakeTasks +0 -7
  83. data/.idea/compiler.xml +0 -23
  84. data/.idea/copyright/profiles_settings.xml +0 -5
  85. data/.idea/encodings.xml +0 -5
  86. data/.idea/inspectionProfiles/Project_Default.xml +0 -7
  87. data/.idea/inspectionProfiles/profiles_settings.xml +0 -7
  88. data/.idea/machineshop.iml +0 -194
  89. data/.idea/misc.xml +0 -5
  90. data/.idea/modules.xml +0 -9
  91. data/.idea/scopes/scope_settings.xml +0 -5
  92. data/.idea/vcs.xml +0 -7
  93. data/.idea/workspace.xml +0 -722
  94. data/lib/machineshop/data_sources.rb +0 -35
  95. data/lib/machineshop/users.rb +0 -43
  96. data/spec/lib/report_spec.rb +0 -52
  97. data/spec/lib/user_spec.rb +0 -58
@@ -0,0 +1,18 @@
1
+ module MachineShop
2
+ class GatewayDataSourceTypes < APIResource
3
+ include MachineShop::APIOperations::List
4
+ include MachineShop::APIOperations::Create
5
+ include MachineShop::APIOperations::Update
6
+ include MachineShop::APIOperations::Delete
7
+
8
+ def self.update(id,auth_token,params={})
9
+ response = MachineShop.gem_put(self.url+"/#{id}", auth_token, params)
10
+ Util.convert_to_machineshop_object(response, auth_token, self.class_name)
11
+ end
12
+
13
+ def self.delete(id, auth_token)
14
+ MachineShop.gem_delete(self.url + "/#{id}", auth_token, {})
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,60 @@
1
+ module MachineShop
2
+ class GatewayDataSources < APIResource
3
+ include MachineShop::APIOperations::List
4
+ include MachineShop::APIOperations::Create
5
+ include MachineShop::APIOperations::Update
6
+ include MachineShop::APIOperations::Delete
7
+
8
+ def self.update(id,auth_token,params={})
9
+ response = MachineShop.gem_put(self.url+"/#{id}", auth_token, params)
10
+ Util.convert_to_machineshop_object(response, auth_token, self.class_name)
11
+ end
12
+
13
+ def self.delete(id, auth_token)
14
+ MachineShop.gem_delete(self.url + "/#{id}", auth_token, {})
15
+ end
16
+
17
+ def self.get_attached_data_sources(gateway_data_source_id, auth_token)
18
+ response = MachineShop.gem_get("/platform/gateway_data_sources/#{gateway_data_source_id}/attached_data_sources", auth_token)
19
+ Util.convert_to_machineshop_object(response, auth_token, self.class_name)
20
+ end
21
+
22
+ def self.send_config(unique_id, auth_token)
23
+ MachineShop.gem_get("/platform/gateway_data_sources/#{unique_id}/config", auth_token)
24
+ end
25
+
26
+ def self.reset_gateway(id, auth_token)
27
+ MachineShop.gem_post("/platform/gateway_data_sources/#{id}/reset", auth_token, {})
28
+ end
29
+
30
+ def self.attach_data_sources(auth_token, params={})
31
+ MachineShop.gem_post("/platform/data_sources", auth_token, params)
32
+ end
33
+
34
+ def self.update_attached_data_sources(id, parent_gateway_id, auth_token, params={})
35
+ response = MachineShop.gem_put("/platform/gateway_data_sources/#{parent_gateway_id}/attached_data_sources/#{id}", auth_token, params)
36
+ Util.convert_to_machineshop_object(response, auth_token, self.class_name)
37
+ end
38
+
39
+ def self.remove_attached_data_source(id, ds_id, auth_token)
40
+ MachineShop.gem_delete("/platform/gateway_data_sources/#{id}/attached_data_sources/#{ds_id}", auth_token)
41
+ end
42
+
43
+ def self.initiate_log_upload(id, auth_token, params={})
44
+ MachineShop.gem_post("/platform/gateway_data_sources/#{id}/log_upload", auth_token, params)
45
+ end
46
+
47
+ def self.change_log_level(id, log_level, auth_token, params={})
48
+ MachineShop.gem_post("/platform/gateway_data_sources/#{id}/log_level/#{log_level}", auth_token, params)
49
+ end
50
+
51
+ def self.download_log_files(id, auth_token)
52
+ MachineShop.gem_get("/platform/gateway_data_sources/#{id}/logs", auth_token)
53
+ end
54
+
55
+ def self.firmware_update(id, auth_token, params={})
56
+ MachineShop.gem_post("/platform/gateway_data_sources/#{id}/update_firmware", auth_token, params)
57
+ end
58
+
59
+ end
60
+ end
@@ -31,7 +31,9 @@ module MachineShop
31
31
  end
32
32
 
33
33
  def self.construct_from(values, auth_token=nil)
34
- values[:id] = values[:_id] if values[:_id]
34
+ if(!values[:id])
35
+ values[:id] = values[:_id] if values[:_id]
36
+ end
35
37
  obj = self.new(values[:id], auth_token)
36
38
  obj.refresh_from(values, auth_token)
37
39
  obj
@@ -54,7 +56,10 @@ module MachineShop
54
56
  else
55
57
  #do nothing
56
58
  end
57
- values[:id] = values[:_id] if values[:_id]
59
+
60
+ if(!values[:id])
61
+ values[:id] = values[:_id] if values[:_id]
62
+ end
58
63
 
59
64
  removed = partial ? Set.new : Set.new(@values.keys - values.keys)
60
65
  added = Set.new(values.keys - @values.keys)
@@ -3,8 +3,7 @@ module MachineShop
3
3
  include MachineShop::APIOperations::List
4
4
 
5
5
  def self.url()
6
- ret = "/platform/data/#{CGI.escape(class_name.underscore)}"
7
- ret
6
+ "/platform/data/#{CGI.escape(class_name.underscore)}"
8
7
  end
9
8
 
10
9
  end
@@ -60,7 +60,7 @@ ActiveRecord::Schema.define do
60
60
  t.string :updated_at
61
61
  t.string :created_at
62
62
  t.text :data_source_type
63
- t.string :last_report
63
+ t.text :last_report
64
64
  t.string :report_count
65
65
  t.string :active
66
66
 
@@ -109,6 +109,7 @@ ActiveRecord::Schema.define do
109
109
  t.string :stale
110
110
  t.string :updated_at
111
111
  t.string :auth_token
112
+ t.string :data_source_id
112
113
  end
113
114
 
114
115
  create_table :comparison_rule_conditions_caches do |t|
@@ -0,0 +1,39 @@
1
+ module MachineShop
2
+ class Monitor < APIResource
3
+ include MachineShop::APIOperations::List
4
+
5
+ def self.url()
6
+ "/platform/data/#{CGI.escape(class_name.underscore)}"
7
+ # ret
8
+ end
9
+
10
+ def self.total_reports_per_day(start_date, end_date, auth_token)
11
+ MachineShop.gem_get(data_url+"/total_reports_per_day/#{start_date}/#{end_date}",auth_token)
12
+ end
13
+
14
+ #for v0
15
+ def self.reports_per_device_instance_per_day(start_date, end_date, auth_token)
16
+ MachineShop.gem_get(data_url+"/reports_per_device_instance_per_day/#{start_date}/#{end_date}",auth_token)
17
+ end
18
+
19
+ #for v1
20
+ def self.reports_per_data_source_per_day(start_date, end_date, auth_token)
21
+ MachineShop.gem_get(data_url+"/reports_per_data_source_per_day/#{start_date}/#{end_date}",auth_token)
22
+ end
23
+
24
+ def self.api_requests_per_day(start_date, end_date, auth_token)
25
+ MachineShop.gem_get(data_url+"/api_requests_per_day/#{start_date}/#{end_date}",auth_token)
26
+ end
27
+
28
+ def self.rule_last_run_summary(auth_token)
29
+ MachineShop.gem_get(data_url+"/rule_last_run_summary",auth_token)
30
+ end
31
+
32
+ private
33
+ def self.data_url
34
+ "/platform/data"
35
+ end
36
+
37
+ end
38
+
39
+ end
@@ -0,0 +1,11 @@
1
+ module MachineShop
2
+ class Report < APIResource
3
+ include MachineShop::APIOperations::List
4
+ include MachineShop::APIOperations::Create
5
+
6
+ def self.url()
7
+ "/monitor/#{CGI.escape(class_name.underscore)}"
8
+ end
9
+
10
+ end
11
+ end
@@ -1,9 +1,11 @@
1
1
  module MachineShop
2
- class Report < APIResource
2
+ class Reports < APIResource
3
3
  include MachineShop::APIOperations::List
4
+ include MachineShop::APIOperations::Create
4
5
 
5
6
  def self.url()
6
7
  ret = "/monitor/#{CGI.escape(class_name.underscore)}"
8
+ ap ret
7
9
  ret
8
10
  end
9
11
 
@@ -0,0 +1,29 @@
1
+ #User Routes
2
+ module MachineShop
3
+
4
+ class Routes < APIResource
5
+ include MachineShop::APIOperations::List
6
+
7
+ def self.authorized_routes_json(auth_token)
8
+ auth_routes = MachineShop.gem_get("/platform/authorized_routes/", auth_token, nil)
9
+ end
10
+
11
+ def self.single_authorized_route(id,auth_token)
12
+ auth_routes = MachineShop.gem_get("/platform/authorized_routes/"+id, auth_token, nil)
13
+ end
14
+
15
+ def self.single_authorized_route_put(id,json,auth_token)
16
+ auth_routes = MachineShop.gem_put("/platform/authorized_routes/"+id, auth_token, json)
17
+ end
18
+
19
+ private
20
+ def self.url
21
+ '/platform/routes?flag=portal'
22
+ end
23
+
24
+
25
+ end
26
+
27
+
28
+ end
29
+
@@ -0,0 +1,56 @@
1
+ module MachineShop
2
+ class Rules < APIResource
3
+ include MachineShop::APIOperations::List
4
+ include MachineShop::APIOperations::Create
5
+ include MachineShop::APIOperations::Delete
6
+ include MachineShop::APIOperations::Update
7
+
8
+
9
+
10
+ def self.get_join_rule_conditions(auth_token)
11
+ url = platform_url + "/join_rule_conditions"
12
+ MachineShop.gem_get(url, auth_token)
13
+ end
14
+
15
+ def self.get_comparison_rule_conditions(auth_token)
16
+ url = platform_url + "/comparison_rule_conditions"
17
+ MachineShop.gem_get(url, auth_token)
18
+ end
19
+
20
+ def self.get_deleted(auth_token)
21
+ url = platform_url + "/deleted"
22
+ MachineShop.gem_get(url, auth_token)
23
+ end
24
+
25
+ # def self.get_by_device_instance(auth_token,id)
26
+ # url = platform_url + "/device_instance/#{id}"
27
+ # MachineShop.gem_get(url, auth_token)
28
+ # end
29
+
30
+ def self.get_by_data_source(id,auth_token)
31
+ url = platform_url + "/data_sources/#{id}"
32
+ MachineShop.gem_get(url, auth_token)
33
+ end
34
+
35
+ # def post_rule(auth_token, rule_hash)
36
+ # url = platform_url
37
+ # MachineShop.gem_post(url, auth_token, rule_hash)
38
+ # end
39
+
40
+ def self.delete_rule(id,auth_token)
41
+ url = platform_url + "/#{id}"
42
+ MachineShop.gem_delete(url, auth_token)
43
+ end
44
+
45
+ def self.update(id,auth_token,params={})
46
+ response = MachineShop.gem_put(platform_url+"/#{id}", auth_token, params)
47
+ Util.convert_to_machineshop_object(response, auth_token, self.class_name)
48
+ end
49
+
50
+ private
51
+ def self.platform_url
52
+ '/platform/rules'
53
+ end
54
+
55
+ end
56
+ end
@@ -3,12 +3,11 @@ module MachineShop
3
3
 
4
4
  # Specific API calls
5
5
  def self.authenticate(user_hash)
6
- #user_hash is => { email: email, password: password }
7
6
  response = MachineShop.gem_post(authenticate_url, nil, user_hash)
8
7
  auth_token = response[:authentication_token]
9
- id = response[:_id]
10
-
11
- return auth_token, self.retrieve(id, auth_token)
8
+ # id = response[:_id]
9
+ return auth_token, response
10
+ # return auth_token, self.retrieve(id, auth_token)
12
11
  end
13
12
 
14
13
  def self.all_roles(auth_token)
@@ -28,6 +27,25 @@ module MachineShop
28
27
  filters.merge!(:user_id => self.id)
29
28
  MachineShop::Meter.all(filters, @auth_token)
30
29
  end
30
+
31
+ def self.update(id,auth_token,params={})
32
+ response = MachineShop.gem_put(self.url+"/#{id}", auth_token, params)
33
+ Util.convert_to_machineshop_object(response, auth_token, self.class_name)
34
+ end
35
+
36
+
37
+ def self.create_user_logo(user_id, params, auth_token)
38
+ MachineShop.gem_multipart(self.url+"/#{user_id}/logo", auth_token, params)
39
+ end
40
+
41
+ def self.delete_user_logo(user_id, auth_token)
42
+ MachineShop.gem_delete(self.url+"/#{user_id}/logo", auth_token)
43
+ end
44
+
45
+ def self.check_user_versions(user_hash)
46
+ MachineShop.gem_get("/user_session/user/versions",nil, user_hash)
47
+ end
48
+
31
49
 
32
50
  private
33
51
 
@@ -0,0 +1,81 @@
1
+ module MachineShop
2
+ class Users < APIResource
3
+ include MachineShop::APIOperations::List
4
+ include MachineShop::APIOperations::Create
5
+ include MachineShop::APIOperations::Delete
6
+ include MachineShop::APIOperations::Update
7
+
8
+ # Specific API calls
9
+ def self.authenticate(user_hash)
10
+ response = MachineShop.gem_post(authenticate_url, nil, user_hash)
11
+ auth_token = response[:authentication_token]
12
+ # id = response[:_id]
13
+ return auth_token, response
14
+
15
+ # return auth_token, self.retrieve(id, auth_token)
16
+ end
17
+
18
+ def self.all_roles(auth_token)
19
+ MachineShop.gem_get(self.role_url, auth_token)
20
+ end
21
+
22
+ def all_roles
23
+ MachineShop.gem_get(self.class.role_url, @auth_token)
24
+ end
25
+
26
+ def self.new_api_key(user_id,auth_token)
27
+ MachineShop.gem_get("#{self.url}/#{user_id}/new_api_key", auth_token)
28
+ end
29
+
30
+ def device_instances(filters={})
31
+ filters.merge!(:user_id => self.id)
32
+ MachineShop::DeviceInstance.all(filters, @auth_token)
33
+ end
34
+
35
+ def meters(filters={})
36
+ filters.merge!(:user_id => self.id)
37
+ MachineShop::Meter.all(filters, @auth_token)
38
+ end
39
+
40
+ def self.update(id,auth_token,params={})
41
+ response = MachineShop.gem_put(self.url+"/#{id}", auth_token, params)
42
+ Util.convert_to_machineshop_object(response, auth_token, self.class_name)
43
+ end
44
+
45
+
46
+ def self.create_user_logo(user_id, params, auth_token)
47
+ MachineShop.gem_multipart("/platform/users/#{user_id}/logo", auth_token, params)
48
+ end
49
+
50
+ def self.delete_user_logo(user_id, auth_token)
51
+ MachineShop.gem_delete("/platform/users/#{user_id}/logo", auth_token)
52
+ end
53
+
54
+ def self.check_user_versions(user_hash)
55
+ MachineShop.gem_get("/user_session/user/versions",nil, user_hash)
56
+ end
57
+
58
+ def self.delete(id,auth_token)
59
+ MachineShop.gem_delete(self.url+"/#{id}", auth_token)
60
+ end
61
+
62
+ def self.password_reset(params_hash)
63
+ MachineShop.gem_post("/platform/password_reset",nil, params_hash)
64
+ end
65
+
66
+ def self.password_reset_complete(reset_token,password_hash)
67
+ MachineShop.gem_post("/platform/password_reset/#{reset_token}",nil, password_hash)
68
+ end
69
+
70
+ private
71
+
72
+ def self.authenticate_url
73
+ '/platform/user/authenticate'
74
+ end
75
+
76
+ def self.role_url
77
+ '/platform/roles'
78
+ end
79
+
80
+ end
81
+ end
@@ -21,12 +21,19 @@ module MachineShop
21
21
  'DeviceInstance' => DeviceInstance,
22
22
  'Mapping' => Mapping,
23
23
  'Meter' => Meter,
24
+ 'Monitor' => Monitor,
24
25
  'Report' => Report,
26
+ 'Reports' => Reports,
25
27
  'Rule' => Rule,
26
- # 'User' => User,
28
+ 'Rules' => Rules,
29
+ 'User' => User,
27
30
  'Users' => Users,
28
31
  'Utility' => Utility,
29
- 'Customer'=> Customer
32
+ 'Customer'=> Customer,
33
+ 'Customers'=> Customers,
34
+ 'CustomApi'=> CustomApi,
35
+ 'ApiProxies'=> ApiProxies,
36
+ # 'CustomApis'=> CustomApis
30
37
  }
31
38
  case resp
32
39
  when Array
@@ -121,15 +128,19 @@ module MachineShop
121
128
 
122
129
  #Check if db_connected
123
130
  def self.db_connected?
124
- db_connected = true
125
- begin
126
- MachineShop::Database.new
127
- rescue DatabaseError =>e
128
- # puts e.message
129
- db_connected= false
130
- rescue SchemaError =>e
131
- # puts e.message
132
- # db_connected=true
131
+ db_connected = true
132
+ if MachineShop.configuration.enable_caching
133
+ begin
134
+ MachineShop::Database.new
135
+ rescue DatabaseError =>e
136
+ # puts e.message
137
+ db_connected= false
138
+ rescue SchemaError =>e
139
+ # puts e.message
140
+ # db_connected=true
141
+ end
142
+ else
143
+ db_connected = false
133
144
  end
134
145
 
135
146
  db_connected