wireway 0.1.0 → 202009251743

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: de44bf149733f3105823eecc87f0b9b120fc9380f93bbac7182a3766b6be529b
4
- data.tar.gz: 92067746481272029ba0a9e10ef473403d98bd52f6501835086187cf559210e2
3
+ metadata.gz: f94f2c70d3374c7d5012262e2c7c0789bf516dbd37101615a03774be406dbd5d
4
+ data.tar.gz: d6235b22333696d6c2dd41824a0f653387ad42ae0c70b9a4b111e18d16f556f0
5
5
  SHA512:
6
- metadata.gz: 1f85c0a7225e7be7463108a06269f6dd1f0108a8ab1ec1f6389aeb4c337d48c7e428f9c97baeb073cc155e2c04f316e89d8b7fa4e772cb22d24851cf47aa0f80
7
- data.tar.gz: 95eb22ae3434dfa438c46e4d4cf57349875ade2dbb5786cb6f229c37abfd98112b607d69cac0f5c10b2da6979a482065c0a320446dfefb850a356f128e93ad46
6
+ metadata.gz: 91c3e345d45b034aad5406994e0b655646e55da42372e635a8dd9e27d30efd46aaf1fdb12ceb4fe8bbb7ad864ae8cb1ded43aff2f5c46766043875d5ba5cab3b
7
+ data.tar.gz: 96349bd30a3e1eebd4ac5a6ef7e7fafc5a05228b9165892ed546ceed9235b94a6aa00964db2f1899247c5945d56c834bf34516680863404f831be4815cc35ca5
data/README.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # 说明
2
2
 
3
+ ## 执照
4
+
5
+ 根据以下条款,该Gem可作为开源软件使用 [MIT License](https://opensource.org/licenses/MIT).
6
+
7
+ ## 插件作用
8
+
9
+ 该Gem主要起到反向代理作用,通过该Gem可实现C919系列插件的调用.
10
+
11
+ 该Gem本身并不实现任何具体功能,只是将请求转发给具体的服务接口.<br>
12
+ 因此,具体可用功能以及参数格式以各组件示例页面为准.
13
+
3
14
  ## 行为准则
4
15
 
5
16
  0. 集成该Gem后可实现各组件任意调用.
@@ -7,31 +18,13 @@
7
18
  0. 各组件的具体配置信息可以通过Satcom实时获取最新配置内容.
8
19
  0. 后期应允许符合某种安全机制的节点自主加入并注册允许发现.
9
20
 
10
- # Wireway
11
- Short description and motivation.
21
+ ## 关于C919
12
22
 
13
- ## Usage
14
- How to use my plugin.
23
+ C919为系列Gem组件的集合,具体组成部分及相关示例[参考](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)
15
24
 
16
- ## Installation
17
- Add this line to your application's Gemfile:
25
+ ## 使用示例
18
26
 
19
27
  ```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).
28
+ Wireway::Spark.satcom(api_code: :finance_fund_base_info, code: '161725')
29
+ # => [true, {:基金全称=>"招商中证白酒指数分级证券投资基金", :基金简称=>"招商中证白酒指数分级", :基金代码=>"161725(前端)", :基金类型=>"股票指数", :发行日期=>"2015年05月12日", :"成立日期/规模"=>"2015年05月27日 / 3.965亿份", :资产规模=>"129.25亿元(截止至:2020年06月30日)", :份额规模=>"184.0866亿份(截止至:2020年08月26日)", :基金经理人=>"侯昊", :基金托管人=>"中国银行", :成立来分红=>"每份累计0.00元(0次)", :管理费率=>"1.00%(每年)", :托管费率=>"0.22%(每年)", :销售服务费率=>"---(每年)", :最高认购费率=>"0.80%(前端)", :业绩比较基准=>"中证白酒指数收益率×95%+金融机构人民币活期存款基准利率(税后)×5%", :跟踪标的=>"中证白酒指数", :母子基金=>"161725(母)150269 150270(子)", :是否配对转换=>"是", :是否转LOF=>"否", :封闭期=>"无", :提前结束条款=>"无", :定期折算日=>"每个会计年度的12月15日(遇节假日顺延)", :不定期折算条件=>"当招商中证白酒份额的基金份额净值达到1.500元;当招商中证白酒B份额的基金份额参考净值达到0.250元。", :固定收益份额年化收益率=>"一年期定期存款利率(税后)+3%", :亏损临界点=>"无", :保收益临界点=>"无", :超额收益临界点=>"无"}]
30
+ ```
@@ -3,43 +3,54 @@ module Wireway
3
3
  module Restful
4
4
  extend self
5
5
 
6
- def request_path
7
- {
8
- # url路径不需要动态获取,只有ip和端口是动态的,如果请求路径都不一致,不能认为是正常的节点.
9
- dashboard: '/dashboard/restful/request_api',
10
- satcom: '/satcom/restful/request_api',
6
+ $wireway_node_addresses = 404
7
+
8
+ # 后期应由专门组件对于已登记地址信息进行活跃验证,并将可用节点信息回传给Satcom
9
+ # 后期当某一节点调用不通过时将常量赋值为404进行更新
10
+ # url路径不需要动态获取,只有ip和端口是动态的,如果请求路径都不一致,不能认为是合规的节点.
11
+ def node_addresses
12
+ return $wireway_node_addresses unless $wireway_node_addresses == 404
13
+
14
+ hosts = ['172.28.81.156:3113']
15
+ route = '/satcom/restful/request_api'
16
+ params = {
17
+ api_code: 'other_c919_node_addresses',
18
+ key_type: 'en'
11
19
  }
20
+
21
+ result = post(addresses: hosts, route: route, params: params) do |res|
22
+ body = JSON.parse(res[1][:body]).deep_symbolize_keys
23
+ return [false, body[:result]] unless body[:success]
24
+ [true, body[:result]]
25
+ end
26
+ raise result[1] unless result[0]
27
+
28
+ $wireway_node_addresses = result[1].map{|key, value| [key, value[:nodes]]}.to_h
12
29
  end
13
30
 
14
31
  def dashboard(**args)
15
32
  params = {
16
33
  response_type: 'json',
17
34
  }.merge!(args)
18
-
19
- url = 'http://172.28.81.156:3111/dashboard/restful/request_api'
35
+ route = '/dashboard/restful/request_api'
20
36
 
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']]
37
+ post(addresses: node_addresses[:dashboard], route: route, params: params) do |res|
38
+ return res if (params[:response_type] != 'json')
39
+ body = JSON.parse(res[1][:body]).deep_symbolize_keys
40
+ return [false, body[:result]] unless body[:success]
41
+ [true, body[:html_content]]
42
+ end
28
43
  end
29
44
 
30
45
  def satcom(**args)
31
- params = {
32
- }.merge!(args)
33
-
34
- url = 'http://172.28.81.156:3113/satcom/restful/request_api'
46
+ params = {}.merge!(args)
47
+ route = '/satcom/restful/request_api'
35
48
 
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]]
49
+ post(addresses: node_addresses[:satcom], route: route, params: params) do |res|
50
+ body = JSON.parse(res[1][:body]).deep_symbolize_keys
51
+ return [false, body[:result]] unless body[:success]
52
+ [true, body[:result]]
53
+ end
43
54
  end
44
55
 
45
56
 
@@ -51,9 +62,22 @@ module Wireway
51
62
  end
52
63
  end
53
64
 
54
- def post(url:, params: {})
55
- get_response do
56
- RestClient.post url, params
65
+ def post(addresses:, route:, params: {})
66
+ res = nil
67
+ addresses.each do |addresses|
68
+ res = get_response do
69
+ RestClient.post "#{addresses}/#{route}", params
70
+ end
71
+ # TODO: 后期应该优化判断是服务不可以用还是传递参数问题倒是返回false
72
+ # 或者当一定比例节点均无法正常响应时即判定为参数问题
73
+ break if res[0]
74
+ end
75
+ return res unless (block_given? || res[0])
76
+
77
+ begin
78
+ yield res
79
+ rescue
80
+ return [false, '运行时结果处理异常', {errors: {message: $!.to_s, path: $@}}]
57
81
  end
58
82
  end
59
83
 
@@ -1,3 +1,3 @@
1
1
  module Wireway
2
- VERSION = '0.1.0'
2
+ VERSION = Time.now.strftime("%Y%m%d%H%M")
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wireway
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: '202009251743'
5
5
  platform: ruby
6
6
  authors:
7
7
  - ff4c00
@@ -72,7 +72,7 @@ dependencies:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
74
  version: 3.9.0
75
- description: 用于C919各组件间相互调用,组网协助.
75
+ description: 用于反向代理C919各组件,实现组件间组网协作.
76
76
  email:
77
77
  - ff4c00@gmail.com
78
78
  executables: []