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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3c441ae662e654ac372b9769d7b30dd03acaa18c
4
- data.tar.gz: 2447a88093b40b35e9fbc01795406260622507d3
3
+ metadata.gz: 4b0a0136b4c4cd5790096b60321711db8041599a
4
+ data.tar.gz: 8b9cc59f1fad9fa1da4c43535c15d2093626a2ed
5
5
  SHA512:
6
- metadata.gz: 45cceddbd5c827716a615014bfb9f1b7e32924f0031db5b1e65f6c084cf5de12a79408582a6b1f8aa4c2f7d58a9bae25a2a124857779e73c2b9f744f9cfc2f7e
7
- data.tar.gz: e8b4b81157b84c98a1a33be04fc77c7e48fa134ec302188d4bb2ce28ab21ba8cf5fbda921f2f2ecb27de401cdf25f42d63f64be5f43a8e0bc7033d8ff0dad0a5
6
+ metadata.gz: 0a0238549fe978afc7d723a810d725d6aa5f21799ac43ae37881739655fa3939c33da59111c98426f5ddfebbedb7a62ec4198024fb076b28660d5a751b0fa0a3
7
+ data.tar.gz: 7fe74c5078503d400d8767867d37be486429f535f9eac715f859fe00a6844bc3cc429bf757baa9b68fbabcbeac8453c6967116f432dd1dfdd325b206bdf9970e
@@ -0,0 +1,45 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ ../.project
19
+ .project
20
+
21
+ # Ignore all logfiles and tempfiles.
22
+ /log/*.log
23
+ /tmp
24
+
25
+ # Ignore all mac metadata files and emacs autosaves
26
+ auto-save-list
27
+ custom.el
28
+ url/
29
+ .org-id-locations
30
+ \#*
31
+ org-mode-config.el
32
+ *~
33
+ .#*
34
+ \#*\#
35
+ *.log
36
+ .DS_Store
37
+ org-clock-save.el
38
+ emacs-config.el
39
+
40
+ # Ignore rvm
41
+ .rvmrc
42
+ .project
43
+ nbproject/
44
+ .idea
45
+ .idea/*
File without changes
File without changes
File without changes
File without changes
@@ -31,10 +31,18 @@ require 'machineshop/device'
31
31
  require 'machineshop/machineshop_object'
32
32
  require 'machineshop/mapping'
33
33
  require 'machineshop/meter'
34
+ require 'machineshop/monitor'
34
35
  require 'machineshop/report'
36
+ require 'machineshop/reports'
35
37
  require 'machineshop/customer'
38
+ require 'machineshop/customers'
39
+ # require 'machineshop/custom_apis'
40
+ require 'machineshop/api_proxies'
41
+ require 'machineshop/custom_api'
42
+ require 'machineshop/routes'
36
43
  require 'machineshop/rule'
37
- # require 'machineshop/user'
44
+ require 'machineshop/rules'
45
+ require 'machineshop/user'
38
46
  require 'machineshop/users'
39
47
  require 'machineshop/utility'
40
48
  require 'machineshop/json'
@@ -43,6 +51,10 @@ require 'machineshop/end_points'
43
51
 
44
52
  require 'machineshop/data_sources'
45
53
  require 'machineshop/data_source_types'
54
+ require 'machineshop/gateway_data_sources'
55
+ require 'machineshop/gateway_data_source_types'
56
+
57
+ require 'machineshop/gateway_configs'
46
58
 
47
59
  # Errors
48
60
  require 'machineshop/errors/machineshop_error'
@@ -59,7 +71,7 @@ require 'machineshop/models/api_endpoint'
59
71
  module MachineShop
60
72
  class << self
61
73
  # @@api_base_url = 'http://api.machineshop.io/api/v0'
62
- @@api_base_url = 'http://stage.services.machineshop.io/api/v0'
74
+ @@api_base_url = 'http://stage.services.machineshop.io/api/v1'
63
75
 
64
76
  #configs starts
65
77
  attr_writer :configuration
@@ -117,33 +129,34 @@ module MachineShop
117
129
  platform_request(url, auth_token, body_hash, :post)
118
130
  end
119
131
 
120
- def gem_delete(url, auth_token, body_hash)
121
- platform_request(url, auth_token, body_hash, :delete)
132
+ def gem_delete(url, auth_token, *params)
133
+ platform_request(url, auth_token, nil ,:delete)
122
134
  end
123
135
 
124
136
  def gem_put(url, auth_token, body_hash)
125
137
  platform_request(url, auth_token, body_hash, :put)
126
138
  end
127
139
 
140
+ def gem_multipart(url, auth_token, body_hash)
141
+ platform_request(url, auth_token, body_hash, :post, true)
142
+ end
143
+
128
144
  def headers(auth_token)
129
145
  header ={:content_type => :json,
130
- :accept => :json}
131
- header.merge!({ authorization: "Basic " + Base64.encode64(auth_token + ':X') }) if auth_token
132
- header
133
- end
146
+ :accept => :json}
147
+ header.merge!({ authorization: "Basic " + Base64.encode64(auth_token + ':X') }) if auth_token
148
+ header
149
+ end
134
150
 
135
- def platform_request(url, auth_token, body_hash=nil, http_verb=:get )
136
- rbody=nil
137
- cachedContent = :true
151
+ def platform_request(url, auth_token, body_hash=nil, http_verb=:get , multipart=false)
152
+ rbody=nil
153
+ cachedContent = :true
138
154
  # ApiRequest.cache(url,MachineShop.configuration.expiry_time)
139
155
  if http_verb==:get
140
156
 
141
157
  if Util.db_connected?
142
- xpired=true
143
158
 
144
159
  ApiRequest.cache(url, auth_token, MachineShop.configuration.expiry_time) do
145
- xpired=false
146
- puts "Not expired , calling from local "
147
160
  rbody = get_from_cache(url,body_hash,auth_token)
148
161
  rcode="200"
149
162
  end
@@ -176,14 +189,13 @@ module MachineShop
176
189
  :url => api_uri,
177
190
  :headers => headers,
178
191
  :open_timeout => 30,
179
- :payload => MachineShop::JSON.dump(body_hash),
192
+ # :payload => MachineShop::JSON.dump(body_hash),
180
193
  :timeout => 80
181
194
  }
182
195
 
196
+ opts[:payload] = multipart ? {:multipart=>true}.merge!(body_hash) :MachineShop::JSON.dump(body_hash)
183
197
  end
184
198
 
185
- puts "request params: #{opts} "
186
-
187
199
  begin
188
200
  response = execute_request(opts)
189
201
 
@@ -208,7 +220,6 @@ module MachineShop
208
220
  end
209
221
 
210
222
  rbody = response.body
211
- # puts rbody
212
223
  rcode = response.code
213
224
  end
214
225
 
@@ -0,0 +1,20 @@
1
+ #User Defined API for V1
2
+ module MachineShop
3
+ class ApiProxies < APIResource
4
+ include MachineShop::APIOperations::List
5
+ include MachineShop::APIOperations::Create
6
+ # include MachineShop::APIOperations::Delete
7
+ # include MachineShop::APIOperations::Update
8
+
9
+
10
+ def self.update(id,auth_token,params={})
11
+ response = MachineShop.gem_put(self.url+"/#{id}", auth_token, params)
12
+ Util.convert_to_machineshop_object(response, auth_token, self.class_name)
13
+ end
14
+
15
+ def self.delete(id,auth_token)
16
+ response = MachineShop.gem_delete(self.url+"/#{id}", auth_token, {})
17
+ end
18
+ end
19
+ end
20
+
@@ -20,7 +20,7 @@ module MachineShop
20
20
  ret
21
21
  end
22
22
 
23
- def refresh
23
+ def refresh
24
24
  response = MachineShop.gem_get(url, @auth_token)
25
25
  refresh_from(response, auth_token)
26
26
  self
@@ -5,7 +5,8 @@ module MachineShop
5
5
  def initialize
6
6
  #default values
7
7
  @expiry_time=0
8
- @enable_caching = true
8
+ # default caching is set to false
9
+ @enable_caching = false
9
10
  @base_version = "v0"
10
11
  @custom_endpoints_cache_time = lambda{86400.seconds.ago}
11
12
  #default 1 day
@@ -0,0 +1,28 @@
1
+ #User Defined API for V0
2
+ module MachineShop
3
+ class CustomApi < APIResource
4
+ include MachineShop::APIOperations::List
5
+ include MachineShop::APIOperations::Create
6
+ # include MachineShop::APIOperations::Delete
7
+ # include MachineShop::APIOperations::Update
8
+
9
+
10
+ def self.update(name,auth_token,params={})
11
+ response = MachineShop.gem_put(self.url+"/#{name}", auth_token, params)
12
+ Util.convert_to_machineshop_object(response, auth_token, self.class_name)
13
+ end
14
+
15
+ def self.delete(name,auth_token)
16
+ response = MachineShop.gem_delete(self.url+"/#{name}", auth_token, {})
17
+ end
18
+
19
+ def self.url()
20
+ "/platform/custom"
21
+ end
22
+
23
+ end
24
+
25
+
26
+
27
+ end
28
+
@@ -0,0 +1,21 @@
1
+ #User Defined API for V1
2
+ # deprecated
3
+ module MachineShop
4
+ class CustomApis < APIResource
5
+ include MachineShop::APIOperations::List
6
+ include MachineShop::APIOperations::Create
7
+ # include MachineShop::APIOperations::Delete
8
+ # include MachineShop::APIOperations::Update
9
+
10
+
11
+ def self.update(id,auth_token,params={})
12
+ response = MachineShop.gem_put(self.url+"/#{id}", auth_token, params)
13
+ Util.convert_to_machineshop_object(response, auth_token, self.class_name)
14
+ end
15
+
16
+ def self.delete(id,auth_token)
17
+ response = MachineShop.gem_delete(self.url+"/#{id}", auth_token, {})
18
+ end
19
+ end
20
+ end
21
+
@@ -7,7 +7,7 @@ module MachineShop
7
7
 
8
8
 
9
9
  def self.update(id,auth_token,params={})
10
- response = MachineShop.put(self.url+"/#{id}", auth_token, params)
10
+ response = MachineShop.gem_put(self.url+"/#{id}", auth_token, params)
11
11
  Util.convert_to_machineshop_object(response, auth_token, self.class_name)
12
12
  end
13
13
  end
@@ -0,0 +1,20 @@
1
+ module MachineShop
2
+ class Customers < APIResource
3
+ include MachineShop::APIOperations::List
4
+ include MachineShop::APIOperations::Create
5
+ include MachineShop::APIOperations::Delete
6
+ include MachineShop::APIOperations::Update
7
+
8
+
9
+ def self.update(id,auth_token,params={})
10
+ response = MachineShop.gem_put(self.url+"/#{id}", auth_token, params)
11
+ Util.convert_to_machineshop_object(response, auth_token, self.class_name)
12
+ end
13
+
14
+ def self.delete(id,auth_token)
15
+ MachineShop.gem_delete(self.url+"/#{id}", auth_token)
16
+ end
17
+
18
+ end
19
+ end
20
+
@@ -2,19 +2,29 @@ module MachineShop
2
2
  class DataSourceTypes < APIResource
3
3
  include MachineShop::APIOperations::List
4
4
  include MachineShop::APIOperations::Create
5
+ include MachineShop::APIOperations::Update
5
6
  include MachineShop::APIOperations::Delete
6
7
 
7
8
 
8
- def create_data_source(params)
9
+ def create_data_source(params)
9
10
  params.merge!({:data_source_type => self.id})
10
11
  DataSources.create(params, @auth_token)
11
12
  end
12
13
 
13
- def create_email_data_source(params)
14
+ def create_email_data_source(params)
14
15
  params.merge!({:data_source_type => self.id})
15
16
  MachineShop.gem_post(email_data_source_url, @auth_token, params)
16
17
  end
17
18
 
19
+ def self.update(id,auth_token,params={})
20
+ response = MachineShop.gem_put(self.url+"/#{id}", auth_token, params)
21
+ Util.convert_to_machineshop_object(response, auth_token, self.class_name)
22
+ end
23
+
24
+ def self.delete_data_source_type(id, auth_token)
25
+ MachineShop.gem_delete(self.url + "/#{id}", auth_token, {})
26
+ end
27
+
18
28
  private
19
29
  def self.url
20
30
  '/platform/data_source_types'
@@ -0,0 +1,57 @@
1
+ module MachineShop
2
+ class DataSources < APIResource
3
+ include MachineShop::APIOperations::List
4
+ include MachineShop::APIOperations::Create
5
+ include MachineShop::APIOperations::Update
6
+ include MachineShop::APIOperations::Delete
7
+
8
+ # Specific API calls
9
+
10
+ def report_count(params)
11
+ MachineShop.gem_get(report_count_url, @auth_token, params)
12
+ end
13
+
14
+ def reports(filters={})
15
+ filters.merge!(:device_instance_id => self.id)
16
+ MachineShop::Report.all(filters, @auth_token)
17
+ end
18
+
19
+ def meters(filters={})
20
+ filters.merge!(:device_instance_id => self.id)
21
+ MachineShop::Meter.all(filters, @auth_token)
22
+ end
23
+
24
+ def delete
25
+ MachineShop.gem_delete("/platform/data_sources/#{self.id}", @auth_token,{})
26
+ end
27
+
28
+ def self.delete(id,auth_token)
29
+ MachineShop.gem_delete("/platform/data_sources/#{id}", auth_token)
30
+ end
31
+
32
+ def self.update(id,auth_token,params={})
33
+ response = MachineShop.gem_put(self.url+"/#{id}", auth_token, params)
34
+ Util.convert_to_machineshop_object(response, auth_token, self.class_name)
35
+ end
36
+
37
+ # def self.delete(name,auth_token)
38
+ # response = MachineShop.gem_delete(self.url+"/#{name}", auth_token, {})
39
+ # end
40
+
41
+ def self.create_email_data_source(params, auth_token)
42
+ MachineShop.gem_post('/platform/email_data_sources', auth_token, params)
43
+ end
44
+
45
+ private
46
+
47
+ def self.report_count_url
48
+ url + '/report_count'
49
+ end
50
+
51
+ def self.email_data_source_url
52
+ '/platform/email_data_sources'
53
+ end
54
+
55
+
56
+ end
57
+ end
@@ -0,0 +1,34 @@
1
+ module MachineShop
2
+ class GatewayConfigs < 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.set_gateway_configs(auth_token, params={})
18
+ MachineShop.gem_put('/platform/gateway_data_sources/set_gateway_configs', auth_token, params)
19
+ end
20
+
21
+ def self.set_configs(auth_token, params={})
22
+ MachineShop.gem_put('/platform/gateway_data_sources/set_configs', auth_token, params)
23
+ end
24
+
25
+ def self.reset_group(id, auth_token)
26
+ MachineShop.gem_post("/platform/gateway_configs/#{id}/reset", auth_token, {})
27
+ end
28
+
29
+ def self.send_group_config(id, auth_token)
30
+ MachineShop.gem_post("/platform/gateway_configs/#{id}/send_gateway_config", auth_token, {})
31
+ end
32
+
33
+ end
34
+ end