wireway 202009251743 → 202012021613

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: f94f2c70d3374c7d5012262e2c7c0789bf516dbd37101615a03774be406dbd5d
4
- data.tar.gz: d6235b22333696d6c2dd41824a0f653387ad42ae0c70b9a4b111e18d16f556f0
3
+ metadata.gz: f3560a2e7a16cf646a436dd381ffc4dedb3de1a7b46f332cf95a0f569bad57c4
4
+ data.tar.gz: 2b6c7a4db9d7738ba057bbdb405e0069abe67fef70c7e4bc268e87839e9d86e3
5
5
  SHA512:
6
- metadata.gz: 91c3e345d45b034aad5406994e0b655646e55da42372e635a8dd9e27d30efd46aaf1fdb12ceb4fe8bbb7ad864ae8cb1ded43aff2f5c46766043875d5ba5cab3b
7
- data.tar.gz: 96349bd30a3e1eebd4ac5a6ef7e7fafc5a05228b9165892ed546ceed9235b94a6aa00964db2f1899247c5945d56c834bf34516680863404f831be4815cc35ca5
6
+ metadata.gz: 6ae23df57e3f022fe2f5aa0f0f52ec11323c4bc22298454b0cc636a5c644fe73515ffef6ac2bcc3f370c6827d44cf1e07240fd1e96db33b532e26cb34ae40ed2
7
+ data.tar.gz: f5a2426012577837d8608d2087dbb912537a0ff3c23d1fbc9fe56fed8e3bc154df8f2792924156e4f3efc911de7e0884dc748f4ca5dc66a32b2b6ddaf7e39495
data/README.md CHANGED
@@ -1,3 +1,15 @@
1
+
2
+ <!-- TOC -->
3
+
4
+ - [说明](#说明)
5
+ - [执照](#执照)
6
+ - [插件作用](#插件作用)
7
+ - [行为准则](#行为准则)
8
+ - [关于C919](#关于c919)
9
+ - [使用示例](#使用示例)
10
+
11
+ <!-- /TOC -->
12
+
1
13
  # 说明
2
14
 
3
15
  ## 执照
@@ -27,4 +39,14 @@ C919为系列Gem组件的集合,具体组成部分及相关示例[参考](https:
27
39
  ```ruby
28
40
  Wireway::Spark.satcom(api_code: :finance_fund_base_info, code: '161725')
29
41
  # => [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%", :亏损临界点=>"无", :保收益临界点=>"无", :超额收益临界点=>"无"}]
42
+ ```
43
+
44
+ 或无需引用Gem直接发起Post请求:
45
+
46
+ ```bash
47
+ curl --location --request POST '123.57.155.17:3114/wireway/restful/request_api' \
48
+ --header 'Content-Type: application/x-www-form-urlencoded' \
49
+ --data-urlencode 'platform=satcom' \
50
+ --data-urlencode 'api_code=finance_fund_base_info' \
51
+ --data-urlencode 'code=161725'
30
52
  ```
@@ -1,5 +1,6 @@
1
1
  module Wireway
2
2
  class ApplicationController < ActionController::Base
3
3
  protect_from_forgery with: :exception
4
+ skip_before_action :verify_authenticity_token
4
5
  end
5
6
  end
@@ -0,0 +1,13 @@
1
+ module Wireway
2
+ class RestfulController < ApplicationController
3
+ def request_api
4
+ # TODO 初步了解为rails5的安全机制 去除存在风险 暂时先这样
5
+ args = params.permit!.to_hash.reject!{|key| ["action", "controller"].include?(key)}.deep_symbolize_keys
6
+
7
+ res = Wireway::Spark.send(args[:platform], args)
8
+ tmp = {success: res[0], result: res[1]}
9
+ (tmp.merge!(res[2]) rescue nil) if res[2].present?
10
+ render json: tmp.merge!(tmp)
11
+ end
12
+ end
13
+ end
@@ -11,21 +11,15 @@ module Wireway
11
11
  def node_addresses
12
12
  return $wireway_node_addresses unless $wireway_node_addresses == 404
13
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'
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]]
14
+ nodes = ['123.57.155.17:3113']
15
+ route = '/satcom/other/c919/node_addresses.json'
16
+ res = get(addresses: nodes, route: route) do |result|
17
+ hash = JSON.parse(result[1][:body]).deep_symbolize_keys
18
+ [true, hash]
25
19
  end
26
- raise result[1] unless result[0]
27
20
 
28
- $wireway_node_addresses = result[1].map{|key, value| [key, value[:nodes]]}.to_h
21
+ return res unless res[0]
22
+ $wireway_node_addresses = res[1].map{|key, value| [key, value[:nodes]]}.to_h
29
23
  end
30
24
 
31
25
  def dashboard(**args)
@@ -33,10 +27,11 @@ module Wireway
33
27
  response_type: 'json',
34
28
  }.merge!(args)
35
29
  route = '/dashboard/restful/request_api'
36
-
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
30
+ res = node_addresses
31
+ return res unless res[0]
32
+ post(addresses: res[1][:dashboard], route: route, params: params) do |result|
33
+ return result if (params[:response_type] != 'json')
34
+ body = JSON.parse(result[1][:body]).deep_symbolize_keys
40
35
  return [false, body[:result]] unless body[:success]
41
36
  [true, body[:html_content]]
42
37
  end
@@ -45,43 +40,71 @@ module Wireway
45
40
  def satcom(**args)
46
41
  params = {}.merge!(args)
47
42
  route = '/satcom/restful/request_api'
48
-
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]
43
+ res = node_addresses
44
+ return res unless res[0]
45
+ post(addresses: res[1][:satcom], route: route, params: params) do |result|
46
+ body = JSON.parse(result[1][:body]).deep_symbolize_keys
47
+ return [false, body[:result], body[:errors]].compact unless body[:success]
52
48
  [true, body[:result]]
53
49
  end
54
50
  end
55
51
 
52
+ def wireway(**args)
53
+ params = {
54
+ local: false
55
+ }.merge!(args)
56
+ route = '/wireway/restful/request_api'
57
+ res = node_addresses
58
+ return res unless res[0]
59
+ post(addresses: res[1][:wireway], route: route, params: params) do |result|
60
+ body = JSON.parse(result[1][:body]).deep_symbolize_keys
61
+ return [false, body[:result], body[:errors]].compact unless body[:success]
62
+ [true, body[:result]]
63
+ end
64
+ end
56
65
 
57
- def get(url:, params: {})
58
- get_response do
59
- full_url = [url, URI.encode_www_form(params)]
66
+ def get(addresses:, route:, params: {})
67
+ result = round_robin(addresses: addresses) do |address|
68
+ full_url = [address+route, URI.encode_www_form(params)]
60
69
  full_url.delete_if{|item| !item.present? }
61
70
  RestClient.get(full_url.join("?"))
62
71
  end
72
+ return result unless (result[0] && block_given?)
73
+
74
+ begin
75
+ yield result
76
+ rescue
77
+ return [false, '运行时结果处理异常', {errors: {message: $!.to_s, path: $@}}]
78
+ end
63
79
  end
64
80
 
65
81
  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
-
82
+ result = round_robin(addresses: addresses) do |address|
83
+ RestClient.post "#{address}/#{route}", params
84
+ end
85
+ return result unless (result[0] && block_given?)
86
+
77
87
  begin
78
- yield res
88
+ yield result
79
89
  rescue
80
90
  return [false, '运行时结果处理异常', {errors: {message: $!.to_s, path: $@}}]
81
91
  end
82
92
  end
83
93
 
84
94
  private
95
+ def round_robin(addresses:)
96
+ res = nil
97
+ addresses.each do |address|
98
+ res = get_response do
99
+ yield address
100
+ end
101
+ # TODO: 后期应该优化判断是服务不可以用还是传递参数问题倒是返回false
102
+ # 或者当一定比例节点均无法正常响应时即判定为参数问题
103
+ break if res[0]
104
+ end
105
+ res
106
+ end
107
+
85
108
  def get_response
86
109
  begin
87
110
  response = yield
@@ -3,10 +3,21 @@ module Wireway
3
3
 
4
4
  # Wireway::Spark.dashboard(api_code: :publish_other_request_assets, rely_assets: ["bootstrap_4", "jQuery_3_5_1", "chart_js"])
5
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)
6
+ # Wireway::BusinessLogic::Restful::node_addresses
7
+ # Wireway::Spark.wireway(platform: :satcom, api_code: :finance_fund_base_info, code: '161725')
8
+ def self.method_missing(method_name, local: true, **args)
9
+ begin
10
+ target = Wireway::BusinessLogic::Restful
11
+ return [false, '未找到相关定义方法'] unless target.respond_to?(method_name)
12
+ res = target.send(method_name, args)
13
+ rescue
14
+ error_msg = [false, '请求异常', {errors: {message: $!.to_s, path: $@}}]
15
+ return error_msg unless [true, 'true', 1, '1', 'yes'].include?(local)
16
+ # 当以Gem形式的组件无法处理请求时,尝试请求线上版组件是否可以正常处理请求
17
+ # 即当gem出现问题时会请求线上服务 有利于断点排查
18
+ args.merge!(platform: method_name)
19
+ res = target.wireway(args)
20
+ end
10
21
  end
11
22
 
12
23
  end
@@ -1,2 +1,7 @@
1
1
  Wireway::Engine.routes.draw do
2
+ resources :restful, only:[] do
3
+ collection do
4
+ post :request_api
5
+ end
6
+ end
2
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wireway
3
3
  version: !ruby/object:Gem::Version
4
- version: '202009251743'
4
+ version: '202012021613'
5
5
  platform: ruby
6
6
  authors:
7
7
  - ff4c00
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-25 00:00:00.000000000 Z
11
+ date: 2020-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -86,6 +86,7 @@ files:
86
86
  - app/assets/javascripts/wireway/application.js
87
87
  - app/assets/stylesheets/wireway/application.css
88
88
  - app/controllers/wireway/application_controller.rb
89
+ - app/controllers/wireway/restful_controller.rb
89
90
  - app/helpers/wireway/application_helper.rb
90
91
  - app/jobs/wireway/application_job.rb
91
92
  - app/mailers/wireway/application_mailer.rb