wireway 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: de44bf149733f3105823eecc87f0b9b120fc9380f93bbac7182a3766b6be529b
4
+ data.tar.gz: 92067746481272029ba0a9e10ef473403d98bd52f6501835086187cf559210e2
5
+ SHA512:
6
+ metadata.gz: 1f85c0a7225e7be7463108a06269f6dd1f0108a8ab1ec1f6389aeb4c337d48c7e428f9c97baeb073cc155e2c04f316e89d8b7fa4e772cb22d24851cf47aa0f80
7
+ data.tar.gz: 95eb22ae3434dfa438c46e4d4cf57349875ade2dbb5786cb6f229c37abfd98112b607d69cac0f5c10b2da6979a482065c0a320446dfefb850a356f128e93ad46
@@ -0,0 +1,20 @@
1
+ Copyright 2020
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,37 @@
1
+ # 说明
2
+
3
+ ## 行为准则
4
+
5
+ 0. 集成该Gem后可实现各组件任意调用.
6
+ 0. 各组件的端口,地址等配置工作应由本Gem负责维护,宿主无需进行任何额外配置即可使用.
7
+ 0. 各组件的具体配置信息可以通过Satcom实时获取最新配置内容.
8
+ 0. 后期应允许符合某种安全机制的节点自主加入并注册允许发现.
9
+
10
+ # Wireway
11
+ Short description and motivation.
12
+
13
+ ## Usage
14
+ How to use my plugin.
15
+
16
+ ## Installation
17
+ Add this line to your application's Gemfile:
18
+
19
+ ```ruby
20
+ gem 'wireway'
21
+ ```
22
+
23
+ And then execute:
24
+ ```bash
25
+ $ bundle
26
+ ```
27
+
28
+ Or install it yourself as:
29
+ ```bash
30
+ $ gem install wireway
31
+ ```
32
+
33
+ ## Contributing
34
+ Contribution directions go here.
35
+
36
+ ## License
37
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,32 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Wireway'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+ load 'rails/tasks/statistics.rake'
21
+
22
+ require 'bundler/gem_tasks'
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'test'
28
+ t.pattern = 'test/**/*_test.rb'
29
+ t.verbose = false
30
+ end
31
+
32
+ task default: :test
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts/wireway .js
2
+ //= link_directory ../stylesheets/wireway .css
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require rails-ujs
14
+ //= require activestorage
15
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,5 @@
1
+ module Wireway
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ module Wireway
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Wireway
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module Wireway
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: 'from@example.com'
4
+ layout 'mailer'
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Wireway
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,90 @@
1
+ module Wireway
2
+ module BusinessLogic
3
+ module Restful
4
+ extend self
5
+
6
+ def request_path
7
+ {
8
+ # url路径不需要动态获取,只有ip和端口是动态的,如果请求路径都不一致,不能认为是正常的节点.
9
+ dashboard: '/dashboard/restful/request_api',
10
+ satcom: '/satcom/restful/request_api',
11
+ }
12
+ end
13
+
14
+ def dashboard(**args)
15
+ params = {
16
+ response_type: 'json',
17
+ }.merge!(args)
18
+
19
+ url = 'http://172.28.81.156:3111/dashboard/restful/request_api'
20
+
21
+ res = post(url: url, params: params)
22
+ return res unless res[0]
23
+
24
+ body = (JSON.parse(res[1][:body]) rescue (return [false, '接口返回内容JSON格式化异常']))
25
+ return [false, body['result']] unless body["success"]
26
+
27
+ [true, body['html_content']]
28
+ end
29
+
30
+ def satcom(**args)
31
+ params = {
32
+ }.merge!(args)
33
+
34
+ url = 'http://172.28.81.156:3113/satcom/restful/request_api'
35
+
36
+ res = post(url: url, params: params)
37
+ return res unless res[0]
38
+
39
+ body = (JSON.parse(res[1][:body]).deep_symbolize_keys rescue (return [false, '接口返回内容JSON格式化异常']))
40
+ return [false, body[:result]] unless body[:success]
41
+
42
+ [true, body[:result]]
43
+ end
44
+
45
+
46
+ def get(url:, params: {})
47
+ get_response do
48
+ full_url = [url, URI.encode_www_form(params)]
49
+ full_url.delete_if{|item| !item.present? }
50
+ RestClient.get(full_url.join("?"))
51
+ end
52
+ end
53
+
54
+ def post(url:, params: {})
55
+ get_response do
56
+ RestClient.post url, params
57
+ end
58
+ end
59
+
60
+ private
61
+ def get_response
62
+ begin
63
+ response = yield
64
+ return [false, "响应码异常:#{response.code}", {response: response}] unless (response.code == 200)
65
+
66
+ hash = {code: 200}
67
+ res = handle_body_encode(body: response.body)
68
+ return res unless res[0]
69
+
70
+ hash.merge!({body: res[1]})
71
+ rescue
72
+ return [false, '请求异常', {errors: {message: $!.to_s, path: $@}}]
73
+ end
74
+
75
+ [true, hash]
76
+ end
77
+
78
+ def handle_body_encode(body: )
79
+ body = case body.encoding.to_s
80
+ when 'UTF-8', 'ASCII-8BIT'
81
+ body
82
+ else
83
+ body.encode('utf-8','gbk', :undef => :replace, :replace => "?", :invalid => :replace).chars.select{|i| i.valid_encoding?}.join
84
+ end
85
+
86
+ [true, body]
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,13 @@
1
+ module Wireway
2
+ module Spark
3
+
4
+ # Wireway::Spark.dashboard(api_code: :publish_other_request_assets, rely_assets: ["bootstrap_4", "jQuery_3_5_1", "chart_js"])
5
+ # Wireway::Spark.satcom(api_code: :finance_fund_base_info, code: '161725')
6
+ def self.method_missing(method_name, **args)
7
+ target = Wireway::BusinessLogic::Restful
8
+ return [false, '未找到相关定义方法'] unless target.respond_to?(method_name)
9
+ res = target.send(method_name, args)
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Wireway</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+
8
+ <%= stylesheet_link_tag "wireway/application", media: "all" %>
9
+ <%= javascript_include_tag "wireway/application" %>
10
+ </head>
11
+ <body>
12
+
13
+ <%= yield %>
14
+
15
+ </body>
16
+ </html>
@@ -0,0 +1,2 @@
1
+ Wireway::Engine.routes.draw do
2
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :wireway do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,5 @@
1
+ require "wireway/engine"
2
+
3
+ module Wireway
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,6 @@
1
+ module Wireway
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Wireway
4
+ require 'rest-client'
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module Wireway
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wireway
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ff4c00
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-09-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.2.4
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 5.2.4.3
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: 5.2.4
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 5.2.4.3
33
+ - !ruby/object:Gem::Dependency
34
+ name: rest-client
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '='
38
+ - !ruby/object:Gem::Version
39
+ version: 2.1.0
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - '='
45
+ - !ruby/object:Gem::Version
46
+ version: 2.1.0
47
+ - !ruby/object:Gem::Dependency
48
+ name: sqlite3
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: pry-byebug
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 3.9.0
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 3.9.0
75
+ description: 用于C919各组件间相互调用,组网协助.
76
+ email:
77
+ - ff4c00@gmail.com
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - MIT-LICENSE
83
+ - README.md
84
+ - Rakefile
85
+ - app/assets/config/wireway_manifest.js
86
+ - app/assets/javascripts/wireway/application.js
87
+ - app/assets/stylesheets/wireway/application.css
88
+ - app/controllers/wireway/application_controller.rb
89
+ - app/helpers/wireway/application_helper.rb
90
+ - app/jobs/wireway/application_job.rb
91
+ - app/mailers/wireway/application_mailer.rb
92
+ - app/models/wireway/application_record.rb
93
+ - app/models/wireway/business_logic/restful.rb
94
+ - app/models/wireway/spark.rb
95
+ - app/views/layouts/wireway/application.html.erb
96
+ - config/routes.rb
97
+ - lib/tasks/wireway_tasks.rake
98
+ - lib/wireway.rb
99
+ - lib/wireway/engine.rb
100
+ - lib/wireway/version.rb
101
+ homepage: https://gitlab.com/ff4c00/space/-/tree/master/%E7%9F%A5%E8%AF%86%E4%BD%93%E7%B3%BB/%E5%BA%94%E7%94%A8%E7%A7%91%E5%AD%A6/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%A7%91%E5%AD%A6/%E8%BD%AF%E4%BB%B6%E5%B7%A5%E7%A8%8B/Rails/C919/wireway
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubygems_version: 3.0.6
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: 用于联接各组件
124
+ test_files: []