wireway 202009261101 → 202009261823

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: b9237eaee0fd2deb0be287b9fbdc82c055547985a059d4f60c36f22ca6ebd56c
4
- data.tar.gz: f524f667e4a0c2b4feb00fc4194c2647ceeaee07dcfeb8a5b4961b526e48caa2
3
+ metadata.gz: fe78d0e055c3c3f939469f26705ad12ce8279b73831d7ccb269b805c590bdfd4
4
+ data.tar.gz: 0c6b60c52344c59943ed2a9dda5ad7eba360839f0505f49b72d567e999622615
5
5
  SHA512:
6
- metadata.gz: 2b72a87f14671df8d89f55673f3321f27f27742fb848d293a7880f7e038f526ae7f90a8aab5cfe9f0de9f9f54dd6615a6fcac97baff50fd157cd059673029bbf
7
- data.tar.gz: 3d3e2e50c7bef6c6e0ccb1a8990b0f0fe6d94d6a6d47db85e4067dd3461fe094226277a1f04b2c17ce14404b29c39d19e3145bf925cff60a4ed85dc4b2f30e49
6
+ metadata.gz: 451e827ce40582528b4d0b0f900f46f5e11598d566327c1c8ef1ec20c8253679263b5dd5a297e0a057cae3894aa05ffb0e1cfda092879c9680fc86d37e7c1f86
7
+ data.tar.gz: 16edffb414030b9225ba1158fd25b8311bd23ed59b004f8c7cca35275143e93cac9ee98723a53c1ba71898d750387e8e272303ca3f7468324b6f75cbbd0ec3d1
data/README.md CHANGED
@@ -27,4 +27,14 @@ C919为系列Gem组件的集合,具体组成部分及相关示例[参考](https:
27
27
  ```ruby
28
28
  Wireway::Spark.satcom(api_code: :finance_fund_base_info, code: '161725')
29
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
+ ```
31
+
32
+ 或无需引用Gem直接发起Post请求:
33
+
34
+ ```bash
35
+ curl --location --request POST '123.57.155.17:3114/wireway/restful/request_api' \
36
+ --header 'Content-Type: application/x-www-form-urlencoded' \
37
+ --data-urlencode 'platform=satcom' \
38
+ --data-urlencode 'api_code=finance_fund_base_info' \
39
+ --data-urlencode 'code=161725'
30
40
  ```
@@ -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,9 +11,9 @@ 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']
14
+ nodes = ['123.57.155.17:3113']
15
15
  route = '/satcom/other/c919/node_addresses.json'
16
- res = get(addresses: hosts, route: route) do |result|
16
+ res = get(addresses: nodes, route: route) do |result|
17
17
  hash = JSON.parse(result[1][:body]).deep_symbolize_keys
18
18
  [true, hash]
19
19
  end
@@ -41,11 +41,23 @@ module Wireway
41
41
 
42
42
  post(addresses: node_addresses[:satcom], route: route, params: params) do |result|
43
43
  body = JSON.parse(result[1][:body]).deep_symbolize_keys
44
- return [false, body[:result]] unless body[:success]
44
+ return [false, body[:result], body[:errors]].compact unless body[:success]
45
45
  [true, body[:result]]
46
46
  end
47
47
  end
48
48
 
49
+ def wireway(**args)
50
+ params = {
51
+ local: false
52
+ }.merge!(args)
53
+ route = '/wireway/restful/request_api'
54
+
55
+ post(addresses: node_addresses[:wireway], route: route, params: params) do |result|
56
+ body = JSON.parse(result[1][:body]).deep_symbolize_keys
57
+ return [false, body[:result], body[:errors]].compact unless body[:success]
58
+ [true, body[:result]]
59
+ end
60
+ end
49
61
 
50
62
  def get(addresses:, route:, params: {})
51
63
  result = round_robin(addresses: addresses) do |address|
@@ -3,13 +3,20 @@ 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)
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)
7
9
  begin
8
10
  target = Wireway::BusinessLogic::Restful
9
11
  return [false, '未找到相关定义方法'] unless target.respond_to?(method_name)
10
12
  res = target.send(method_name, args)
11
13
  rescue
12
- return [false, '请求异常', {errors: {message: $!.to_s, path: $@}}]
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)
13
20
  end
14
21
  end
15
22
 
@@ -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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wireway
3
3
  version: !ruby/object:Gem::Version
4
- version: '202009261101'
4
+ version: '202009261823'
5
5
  platform: ruby
6
6
  authors:
7
7
  - ff4c00
@@ -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