wireway 202009260916 → 202012021617

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: cc36a1205a1ce8c38095ccac73fcff1807c07434105769785a2b7db98450ff60
4
- data.tar.gz: f5a4cd7ecbce2efab9f053ed8fe28abc535e46ae494c81ecb2bd5ff862f4e11d
3
+ metadata.gz: 2d07a6ca738f27ad3c9fd623c8bdbce18acb7860e27f3afc1410de25ec57496f
4
+ data.tar.gz: 49e48b8cbe49c109dbfa937ba7104908dabc559d38e3e72db457fb46e55f79cd
5
5
  SHA512:
6
- metadata.gz: 9a679323899c8252c4a9d09e5d6f82b42d6e291f08d64d7af73bb495fcf67370ef5c1046d6b514d9b02cda4a22d0f75801cb32a87b3c88f6966b62340713ed59
7
- data.tar.gz: 593a2e97789b881197610b6a737ec07afc53506d587f2ceac862e54062dcc2441b6fe67008fc2aaf8545fc61c67ca7138f9519ccb63983c9d88d41e882165292
6
+ metadata.gz: 83fcb9122548dcd969db7524ae4dc1cddd325d27ab9476a0403df1079dc9908d3edfa4ea0e9228227b1e5e8df0ad326bfef23379981cf92bb7bf5c12e35364b8
7
+ data.tar.gz: ae11a93a1377341c08f7e1c31f27300d48e20402541a5cd49a1eb05c0a704624a4558fdef54c6f56c0de48bb46fadb4b03623dab47a6a629ffab91d4a7eb9eda
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,14 +11,16 @@ 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
20
- raise res[1] unless res[0]
21
- $wireway_node_addresses = res[1].map{|key, value| [key, value[:nodes]]}.to_h
20
+
21
+ return res unless res[0]
22
+ nodes = res[1].map{|key, value| [key, value[:nodes]]}.to_h
23
+ $wireway_node_addresses = [true, nodes]
22
24
  end
23
25
 
24
26
  def dashboard(**args)
@@ -26,9 +28,10 @@ module Wireway
26
28
  response_type: 'json',
27
29
  }.merge!(args)
28
30
  route = '/dashboard/restful/request_api'
29
-
30
- post(addresses: node_addresses[:dashboard], route: route, params: params) do |result|
31
- return res if (params[:response_type] != 'json')
31
+ res = node_addresses
32
+ return res unless res[0]
33
+ post(addresses: res[1][:dashboard], route: route, params: params) do |result|
34
+ return result if (params[:response_type] != 'json')
32
35
  body = JSON.parse(result[1][:body]).deep_symbolize_keys
33
36
  return [false, body[:result]] unless body[:success]
34
37
  [true, body[:html_content]]
@@ -38,14 +41,28 @@ module Wireway
38
41
  def satcom(**args)
39
42
  params = {}.merge!(args)
40
43
  route = '/satcom/restful/request_api'
41
-
42
- post(addresses: node_addresses[:satcom], route: route, params: params) do |result|
44
+ res = node_addresses
45
+ return res unless res[0]
46
+ post(addresses: res[1][:satcom], route: route, params: params) do |result|
43
47
  body = JSON.parse(result[1][:body]).deep_symbolize_keys
44
- return [false, body[:result]] unless body[:success]
48
+ return [false, body[:result], body[:errors]].compact unless body[:success]
45
49
  [true, body[:result]]
46
50
  end
47
51
  end
48
52
 
53
+ def wireway(**args)
54
+ params = {
55
+ local: false
56
+ }.merge!(args)
57
+ route = '/wireway/restful/request_api'
58
+ res = node_addresses
59
+ return res unless res[0]
60
+ post(addresses: res[1][:wireway], route: route, params: params) do |result|
61
+ body = JSON.parse(result[1][:body]).deep_symbolize_keys
62
+ return [false, body[:result], body[:errors]].compact unless body[:success]
63
+ [true, body[:result]]
64
+ end
65
+ end
49
66
 
50
67
  def get(addresses:, route:, params: {})
51
68
  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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wireway
3
3
  version: !ruby/object:Gem::Version
4
- version: '202009260916'
4
+ version: '202012021617'
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-26 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