apiotics 0.1.22

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 (70) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +260 -0
  4. data/Rakefile +33 -0
  5. data/lib/apiotics.rb +57 -0
  6. data/lib/apiotics/client.rb +20 -0
  7. data/lib/apiotics/configuration.rb +22 -0
  8. data/lib/apiotics/extract.rb +87 -0
  9. data/lib/apiotics/insert.rb +105 -0
  10. data/lib/apiotics/parse.rb +20 -0
  11. data/lib/apiotics/portal.rb +156 -0
  12. data/lib/apiotics/railtie.rb +14 -0
  13. data/lib/apiotics/server.rb +236 -0
  14. data/lib/apiotics/version.rb +3 -0
  15. data/lib/generators/apiotics/channel/USAGE +10 -0
  16. data/lib/generators/apiotics/channel/channel_generator.rb +35 -0
  17. data/lib/generators/apiotics/channel/templates/apiotics_channel.rb.erb +9 -0
  18. data/lib/generators/apiotics/channel/templates/apiotics_channel_client.coffee.erb +16 -0
  19. data/lib/generators/apiotics/channel/templates/apiotics_channel_initializer.rb.erb +3 -0
  20. data/lib/generators/apiotics/controller/USAGE +8 -0
  21. data/lib/generators/apiotics/controller/controller_generator.rb +24 -0
  22. data/lib/generators/apiotics/controller/templates/apiotics_scaffold.rb.erb +60 -0
  23. data/lib/generators/apiotics/create_model/USAGE +10 -0
  24. data/lib/generators/apiotics/create_model/create_model_generator.rb +76 -0
  25. data/lib/generators/apiotics/create_model/templates/apiotics_logs_model.rb.erb +7 -0
  26. data/lib/generators/apiotics/create_model/templates/apiotics_model.rb.erb +49 -0
  27. data/lib/generators/apiotics/create_model/templates/apiotics_module.rb.erb +10 -0
  28. data/lib/generators/apiotics/create_model/templates/apiotics_module_model.rb.erb +8 -0
  29. data/lib/generators/apiotics/create_model/templates/create_module_model_table.rb.erb +8 -0
  30. data/lib/generators/apiotics/create_table/USAGE +9 -0
  31. data/lib/generators/apiotics/create_table/create_table_generator.rb +52 -0
  32. data/lib/generators/apiotics/create_table/templates/create_logs_table.rb.erb +14 -0
  33. data/lib/generators/apiotics/create_table/templates/create_table.rb.erb +16 -0
  34. data/lib/generators/apiotics/initializer/USAGE +8 -0
  35. data/lib/generators/apiotics/initializer/initializer_generator.rb +27 -0
  36. data/lib/generators/apiotics/initializer/templates/apiotics.rb.erb +10 -0
  37. data/lib/generators/apiotics/initializer/templates/apiotics_module.rb.erb +6 -0
  38. data/lib/generators/apiotics/initializer/templates/apiotics_settings.rb.erb +9 -0
  39. data/lib/generators/apiotics/initializer/templates/apiotics_targets.rb.erb +3 -0
  40. data/lib/generators/apiotics/initializer/templates/setting.rb.erb +3 -0
  41. data/lib/generators/apiotics/install/USAGE +11 -0
  42. data/lib/generators/apiotics/install/install_generator.rb +11 -0
  43. data/lib/generators/apiotics/migration/USAGE +10 -0
  44. data/lib/generators/apiotics/migration/migration_generator.rb +54 -0
  45. data/lib/generators/apiotics/migration/templates/create_logs_table.rb.erb +14 -0
  46. data/lib/generators/apiotics/migration/templates/migrate_table.rb.erb +12 -0
  47. data/lib/generators/apiotics/model/USAGE +11 -0
  48. data/lib/generators/apiotics/model/model_generator.rb +58 -0
  49. data/lib/generators/apiotics/script/USAGE +8 -0
  50. data/lib/generators/apiotics/script/script_generator.rb +44 -0
  51. data/lib/generators/apiotics/script/templates/comm_server.rake +19 -0
  52. data/lib/generators/apiotics/script/templates/dev_comm_server.rake +19 -0
  53. data/lib/generators/apiotics/script/templates/dev_server.rb +8 -0
  54. data/lib/generators/apiotics/script/templates/dev_server_control.rb +7 -0
  55. data/lib/generators/apiotics/script/templates/publish_script.rake +6 -0
  56. data/lib/generators/apiotics/script/templates/script.rb.erb +12 -0
  57. data/lib/generators/apiotics/script/templates/server.rb +8 -0
  58. data/lib/generators/apiotics/script/templates/server_control.rb +7 -0
  59. data/lib/generators/apiotics/script/templates/test_comm_server.rake +19 -0
  60. data/lib/generators/apiotics/script/templates/test_server.rb +8 -0
  61. data/lib/generators/apiotics/script/templates/test_server_control.rb +7 -0
  62. data/lib/generators/apiotics/view/USAGE +12 -0
  63. data/lib/generators/apiotics/view/templates/default.css.erb +18 -0
  64. data/lib/generators/apiotics/view/templates/edit.html.erb +6 -0
  65. data/lib/generators/apiotics/view/templates/form.html.erb +36 -0
  66. data/lib/generators/apiotics/view/templates/index.html.erb +57 -0
  67. data/lib/generators/apiotics/view/templates/show.html.erb +47 -0
  68. data/lib/generators/apiotics/view/view_generator.rb +26 -0
  69. data/lib/tasks/simbiotes_tasks.rake +4 -0
  70. metadata +237 -0
@@ -0,0 +1,8 @@
1
+ Description:
2
+ This generator creates an apiotics.rb initializer file at config/initializers
3
+
4
+ Example:
5
+ rails generate apiotics_initializer
6
+
7
+ This will create:
8
+ config/initializers/apiotics.rb
@@ -0,0 +1,27 @@
1
+ module Apiotics
2
+ class InitializerGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+ argument :portal, :type => :string, :required => false
5
+
6
+ def copy_initializer_file
7
+ if portal == "true"
8
+ @c = Apiotics::Portal.parse_all_interfaces
9
+ template "apiotics_targets.rb.erb", "config/initializers/apiotics_targets.rb"
10
+ else
11
+ template "apiotics.rb.erb", "config/initializers/apiotics.rb"
12
+ template "apiotics_settings.rb.erb", "db/migrate/#{date_string}_create_apiotics_settings.rb"
13
+ template "setting.rb.erb", "app/models/apiotics_setting.rb"
14
+ #template "apiotics_module.rb.erb", "app/models/apiotics.rb"
15
+ end
16
+ end
17
+
18
+
19
+
20
+ private
21
+
22
+ def date_string
23
+ date_string = DateTime.now.strftime("%Y%m%d%H%M%S")
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,10 @@
1
+ Apiotics.configure do |config|
2
+ config.public_key = nil #set this to an Environment variable
3
+ config.private_key = nil #set this to an Environment variable
4
+ config.local_port = 8001
5
+ config.server_port = 8000
6
+ config.tls = true
7
+ config.verify_peer = true
8
+ config.handshake = true
9
+ config.local_logging = true
10
+ end
@@ -0,0 +1,6 @@
1
+ module Apiotics
2
+ def self.table_name_prefix
3
+ 'apiotics_'
4
+ end
5
+
6
+ end
@@ -0,0 +1,9 @@
1
+ class CreateApioticsSettings < ActiveRecord::Migration[5.1]
2
+ def change
3
+ create_table :apiotics_settings do |t|
4
+ t.string :key
5
+ t.text :value
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ Apiotics.configure do |config|
2
+ config.targets = <%= @c %>
3
+ end
@@ -0,0 +1,3 @@
1
+ class ApioticsSetting < ApplicationRecord
2
+
3
+ end
@@ -0,0 +1,11 @@
1
+ Description:
2
+ Install the initial files for the Apiotics gem.
3
+
4
+ Example:
5
+ rails g apiotics:install
6
+
7
+ This will create:
8
+ config/initializers/apiotics.rb
9
+ lib/scripts/server.rb
10
+ lib/scripts/server_control.rb
11
+ lib/tasks/comm_server.rake
@@ -0,0 +1,11 @@
1
+ module Apiotics
2
+ class InstallGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def install
6
+ generate "apiotics:initializer"
7
+ generate "apiotics:script"
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ Description:
2
+ Creates database migrations for Apiotics tables
3
+
4
+ Example:
5
+ rails generate apiotics:migration AddAttributeToTableName attribute:type attribute:type ... attribute:type
6
+
7
+ This will create:
8
+ db/migrate/{datetime_string}_migration_name.rb
9
+
10
+ The AddAttributeToTableName argument is flexible, but expects an existing Apiotics table name after the "To" portion of the name.
@@ -0,0 +1,54 @@
1
+ module Apiotics
2
+ class MigrationGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+ argument :name, :type => :string
5
+ argument :attributes, :type => :hash, :required => true
6
+
7
+ def copy_create_table_files
8
+ template "migrate_table.rb.erb", "db/migrate/#{date_string}_#{underscore_name}.rb"
9
+ sleep 1
10
+ attributes.each do |k,v|
11
+ @k = k
12
+ @v = v
13
+ template "create_logs_table.rb.erb", "db/migrate/#{date_string}_#{underscore_name}_logs.rb"
14
+ sleep 1
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def date_string
21
+ date_string = DateTime.now.strftime("%Y%m%d%H%M%S")
22
+ end
23
+
24
+ def table_name
25
+ array = name.underscore.split('_')
26
+ i = 0
27
+ new_array = Array.new
28
+ marker = false
29
+ while i < array.length
30
+ if marker == true
31
+ new_array << array[i]
32
+ end
33
+ if array[i] == "to"
34
+ marker = true
35
+ end
36
+ i += 1
37
+ end
38
+ new_array.join('_')
39
+ end
40
+
41
+ def underscore_name
42
+ name.underscore
43
+ end
44
+
45
+ def class_name
46
+ name.classify
47
+ end
48
+
49
+ def logs_table_name(k)
50
+ table_name + "_" + k.underscore + "_" + "logs"
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,14 @@
1
+ class <%= class_name %>Logs < ActiveRecord::Migration[5.1]
2
+ def change
3
+ create_table :<%= logs_table_name(@k) %> do |t|
4
+ t.<%= @v %> :<%= @k %>
5
+ t.boolean :<%= @k %>_ack
6
+ t.boolean :<%= @k %>_complete
7
+ t.string :<%= @k %>_timestamp
8
+ t.string :<%= @k %>_status
9
+ t.string :<%= @k %>_action
10
+ t.integer :<%= table_name %>_id
11
+ t.timestamps
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ class <%= class_name %> < ActiveRecord::Migration[5.1]
2
+ def change
3
+ <% attributes.each do |k,v| %>
4
+ add_column :<%= table_name %>, :<%= k %>, :<%= v %>
5
+ add_column :<%= table_name %>, :<%= k %>_ack, :boolean
6
+ add_column :<%= table_name %>, :<%= k %>_complete, :boolean
7
+ add_column :<%= table_name %>, :<%= k %>_timestamp, :string
8
+ add_column :<%= table_name %>, :<%= k %>_status, :string
9
+ add_column :<%= table_name %>, :<%= k %>_action, :string
10
+ <% end %>
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ Description:
2
+ Creates a model and associated database table with the attributes specified. If using data from the portal (recommended) Worker should be the name of a worker defined in your Hive, and Model should be the name of a Driver or Script in that Worker.
3
+
4
+ Example:
5
+ rails generate apiotics:model Worker Model attribute:type attribute:type ... attribute:type
6
+
7
+ This will create:
8
+ app/models/worker.rb
9
+ app/models/worker/model.rb
10
+ db/migrate/{datetime_stamp}_create_table.rb
11
+ db/migrate/{datetime_stamp}_create_table_attribute_logs.rb
@@ -0,0 +1,58 @@
1
+ module Apiotics
2
+ class ModelGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+ argument :parent, :type => :string
5
+ argument :name, :type => :string
6
+ argument :attributes, :type => :hash, :required => false
7
+
8
+ def run_generators
9
+ generate "apiotics:create_table", arguments
10
+ if @c == nil
11
+ generate "apiotics:create_model", "#{parent} #{name}"
12
+ else
13
+ generate "apiotics:create_model", thorify
14
+ generate "apiotics:initializer", "true"
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def arguments
21
+ if attributes == nil
22
+ return get_attributes
23
+ else
24
+ return parent.to_s + " " + name.to_s + " " + stringify
25
+ end
26
+ end
27
+
28
+ def stringify
29
+ string = String.new
30
+ attributes.each do |k,v|
31
+ string = string + k + ":" + v + " "
32
+ end
33
+ string
34
+ end
35
+
36
+ def get_attributes
37
+ @c = Apiotics.get_attributes(parent, name)
38
+ if @c[:kind] == "script"
39
+ generate "apiotics:script", "#{parent} #{name}"
40
+ end
41
+ string = String.new
42
+ @c[:attributes].each do |k,v|
43
+ if v[:type] == "enum"
44
+ string = string + k.gsub(" ", "_").downcase + ":" + "integer" + " "
45
+ else
46
+ string = string + k.gsub(" ", "_").downcase + ":" + v[:type] + " "
47
+ end
48
+ end
49
+ return parent.to_s + " " + name.to_s + " " + string
50
+ end
51
+
52
+ def thorify
53
+ string = String.new
54
+ string = parent.to_s + " " + name.to_s + " " + "true"
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Generate a stub script to run on a device
3
+
4
+ Example:
5
+ rails generate apiotics:script Thing
6
+
7
+ This will create:
8
+ lib/scripts/apiotics/thing.rb
@@ -0,0 +1,44 @@
1
+ module Apiotics
2
+ class ScriptGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+ argument :parent, :type => :string, :required => false
5
+ argument :name, :type => :string, :required => false
6
+
7
+ def create_script
8
+ if name != nil
9
+ @c = Apiotics::Portal.get_attributes(parent, name)
10
+ template "script.rb.erb", "lib/scripts/apiotics/#{parent_file_name}/#{file_name}.rb"
11
+ end
12
+ copy_file "server.rb", "lib/scripts/server.rb"
13
+ copy_file "test_server.rb", "lib/scripts/test_server.rb"
14
+ copy_file "dev_server.rb", "lib/scripts/dev_server.rb"
15
+ copy_file "server_control.rb", "lib/scripts/server_control.rb"
16
+ copy_file "test_server_control.rb", "lib/scripts/test_server_control.rb"
17
+ copy_file "dev_server_control.rb", "lib/scripts/dev_server_control.rb"
18
+ copy_file "comm_server.rake", "lib/tasks/comm_server.rake"
19
+ copy_file "test_comm_server.rake", "lib/tasks/test_comm_server.rake"
20
+ copy_file "dev_comm_server.rake", "lib/tasks/dev_comm_server.rake"
21
+ copy_file "publish_script.rake", "lib/tasks/publish_script.rake"
22
+ FileUtils.chmod 0775, "lib/scripts/server_control.rb"
23
+ end
24
+
25
+ private
26
+
27
+ def file_name
28
+ name.underscore
29
+ end
30
+
31
+ def class_name
32
+ name.classify
33
+ end
34
+
35
+ def parent_class_name
36
+ parent.classify
37
+ end
38
+
39
+ def parent_file_name
40
+ parent.underscore
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,19 @@
1
+ namespace :comms do
2
+ desc "Start local communication server"
3
+ task start: :environment do
4
+ system("ruby", "#{Rails.root}/lib/scripts/server_control.rb", "start")
5
+ puts $?
6
+ end
7
+
8
+ desc "Stop local communication server"
9
+ task stop: :environment do
10
+ system("ruby", "#{Rails.root}/lib/scripts/server_control.rb", "stop")
11
+ puts $?
12
+ end
13
+
14
+ desc "Restart local communication server"
15
+ task restart: :environment do
16
+ system("ruby", "#{Rails.root}/lib/scripts/server_control.rb", "restart")
17
+ puts $?
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ namespace :dev_comms do
2
+ desc "Start local communication server"
3
+ task start: :environment do
4
+ system("ruby", "#{Rails.root}/lib/scripts/dev_server_control.rb", "start")
5
+ puts $?
6
+ end
7
+
8
+ desc "Stop local communication server"
9
+ task stop: :environment do
10
+ system("ruby", "#{Rails.root}/lib/scripts/dev_server_control.rb", "stop")
11
+ puts $?
12
+ end
13
+
14
+ desc "Restart local communication server"
15
+ task restart: :environment do
16
+ system("ruby", "#{Rails.root}/lib/scripts/dev_server_control.rb", "restart")
17
+ puts $?
18
+ end
19
+ end
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Load Rails
4
+ ENV['RAILS_ENV'] = ARGV[0] || 'development'
5
+ DIR = File.dirname(__FILE__)
6
+ require DIR + '/../../config/environment'
7
+
8
+ Apiotics::Server.new
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # add the ontop: true option to see the output of the server in the console in which you run rake comms:start
4
+
5
+ require 'daemons'
6
+
7
+ Daemons.run("lib/scripts/dev_server.rb", ontop: false)
@@ -0,0 +1,6 @@
1
+ namespace :script do
2
+ desc "Publish script to the hive."
3
+ task :publish, [:worker, :name] => [:environment] do |task, args|
4
+ Apiotics::Portal.upload_script(args[:worker], args[:name])
5
+ end
6
+ end
@@ -0,0 +1,12 @@
1
+ #######
2
+ # This script will be deployed to your device.
3
+ # The $global variables below represent the values your script will receive/needs to provide to/from its various interfaces and inputs.
4
+ # Your script should change the value of these variables to what they should be, and they will then get passed back.
5
+ # You can also add additional global variables. If you do, these will be passed back to the script along with the
6
+ # interface and input variables the next time the script is invoked. These are useful for keeping state across script
7
+ # invocations.
8
+ <% @c[:attributes].each do |k,v|%>
9
+ $<%= k.gsub(" ","_") %><% end %><% @c[:inputs].each do |k,v|%>
10
+ $<%= "#{k.gsub(" ","_")}_#{v.gsub(" ","_")}" %><% end %>
11
+
12
+ # put your logic here.
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Load Rails
4
+ ENV['RAILS_ENV'] = ARGV[0] || 'production'
5
+ DIR = File.dirname(__FILE__)
6
+ require DIR + '/../../config/environment'
7
+
8
+ Apiotics::Server.new
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # add the ontop: true option to see the output of the server in the console in which you run rake comms:start
4
+
5
+ require 'daemons'
6
+
7
+ Daemons.run('lib/scripts/server.rb', ontop: false)
@@ -0,0 +1,19 @@
1
+ namespace :test_comms do
2
+ desc "Start local communication server"
3
+ task start: :environment do
4
+ system("ruby", "#{Rails.root}/lib/scripts/dev_server_control.rb", "start")
5
+ puts $?
6
+ end
7
+
8
+ desc "Stop local communication server"
9
+ task stop: :environment do
10
+ system("ruby", "#{Rails.root}/lib/scripts/dev_server_control.rb", "stop")
11
+ puts $?
12
+ end
13
+
14
+ desc "Restart local communication server"
15
+ task restart: :environment do
16
+ system("ruby", "#{Rails.root}/lib/scripts/dev_server_control.rb", "restart")
17
+ puts $?
18
+ end
19
+ end