restful-trades 0.8.7
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 +7 -0
- data/bin/razorrisk-microservice-trades +392 -0
- data/lib/razor_risk/cassini/applications/microservices/restful/trades/version.rb +59 -0
- data/lib/razor_risk/cassini/applications/microservices/restful/trades.rb +2 -0
- data/lib/razor_risk/cassini/applications/route_verb_adaptors/trades/collection_get.rb +266 -0
- data/lib/razor_risk/cassini/applications/route_verb_adaptors/trades/collection_post.rb +204 -0
- data/lib/razor_risk/cassini/applications/route_verb_adaptors/trades/item_delete.rb +182 -0
- data/lib/razor_risk/cassini/applications/route_verb_adaptors/trades/item_get.rb +175 -0
- data/lib/razor_risk/cassini/applications/route_verb_adaptors/trades/item_post.rb +271 -0
- data/lib/razor_risk/cassini/applications/route_verb_adaptors/trades/item_put.rb +249 -0
- data/lib/razor_risk/cassini/applications/route_verb_adaptors/trades.rb +8 -0
- metadata +260 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 62ac6e8e67358970cc32da5c78097870d2b4185d
|
4
|
+
data.tar.gz: 5f0a6f5ba2f8e72c586b30fbaaaf185e0a4bbaea
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: da19ba8eb43a4bb3ef39920460e47d1d9284bb58f78b141c21faf029687e5252b2cc1ff1994e9c73cd5aa9accbc9d2d763e035a377542abd4e520eb3e79f5b27
|
7
|
+
data.tar.gz: a11df3126317a46423523fbf067b50a4faeca1e332a962cae863672c57be68b396340e885f48fb24adadbab582a7d7dbbece655b7cdd76606fb6a166f6856cd2
|
@@ -0,0 +1,392 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
# ######################################################################## #
|
5
|
+
# File: tools/servers/restful/trades/ws.rb
|
6
|
+
#
|
7
|
+
# Purpose: Main module/entry file for the Trades Microservice
|
8
|
+
#
|
9
|
+
# Author: Matthew Wilson
|
10
|
+
#
|
11
|
+
# Copyright (c) 2018, Razor Risk Technologies Pty Ltd
|
12
|
+
# All rights reserved.
|
13
|
+
#
|
14
|
+
# ######################################################################## #
|
15
|
+
|
16
|
+
|
17
|
+
# ##########################################################################
|
18
|
+
|
19
|
+
# Microservices: Trades (trades)
|
20
|
+
#
|
21
|
+
# Supported:
|
22
|
+
#
|
23
|
+
# - [GET] / {Unsecured}
|
24
|
+
# - [DELETE] /delete/:sysId {Secured}
|
25
|
+
# - [GET] /get {Secured}
|
26
|
+
# - [GET] /get/:id {Secured}
|
27
|
+
# - [POST] /post {Secured}
|
28
|
+
# - [PUT] /put/:id {Secured}
|
29
|
+
|
30
|
+
# ##########################################################################
|
31
|
+
# requires
|
32
|
+
|
33
|
+
require 'razor_risk/cassini/diagnostics/zeroth_include'
|
34
|
+
|
35
|
+
require 'razor_risk/cassini/applications/microservices/restful/trades'
|
36
|
+
|
37
|
+
require 'razor_risk/cassini/applications/route_verb_adaptors/trades'
|
38
|
+
|
39
|
+
require 'razor_risk/cassini/main'
|
40
|
+
|
41
|
+
require 'razor_risk/cassini/applications/rest_framework/route_verb_dispatcher'
|
42
|
+
require 'razor_risk/cassini/applications/secured_microservice'
|
43
|
+
require 'razor_risk/cassini/authorisation'
|
44
|
+
require 'razor_risk/cassini/common/version'
|
45
|
+
require 'razor_risk/cassini/util/version_util'
|
46
|
+
|
47
|
+
require 'razor_risk/razor/connectivity/razor_3/header_maker'
|
48
|
+
require 'razor_risk/razor/connectivity/razor_3/razor_requester'
|
49
|
+
require 'razor_risk/razor/connectivity/version'
|
50
|
+
|
51
|
+
require 'razor_risk/core/diagnostics/extensions/libclimate'
|
52
|
+
require 'razor_risk/core/diagnostics/logger'
|
53
|
+
|
54
|
+
require 'active_support/core_ext/hash'
|
55
|
+
require 'pantheios'
|
56
|
+
require 'xqsr3/version'
|
57
|
+
|
58
|
+
require 'csv'
|
59
|
+
require 'json'
|
60
|
+
require 'nokogiri'
|
61
|
+
|
62
|
+
# ##########################################################################
|
63
|
+
# includes
|
64
|
+
|
65
|
+
include ::RazorRisk::Cassini::Applications
|
66
|
+
include ::RazorRisk::Cassini::Applications::RESTFramework
|
67
|
+
include ::RazorRisk::Cassini::Applications::RouteVerbAdaptors
|
68
|
+
include ::RazorRisk::Cassini::Authorisation::SecurityModelHelpers
|
69
|
+
include ::RazorRisk::Cassini::Constants
|
70
|
+
include ::RazorRisk::Cassini::Util::SecretsUtil
|
71
|
+
include ::RazorRisk::Cassini::Util::VersionUtil
|
72
|
+
|
73
|
+
include ::RazorRisk::Razor::Connectivity::Razor3
|
74
|
+
|
75
|
+
include ::RazorRisk::Cassini::Diagnostics
|
76
|
+
include ::RazorRisk::Core::Diagnostics::Logger
|
77
|
+
|
78
|
+
include ::Pantheios
|
79
|
+
|
80
|
+
# ##########################################################################
|
81
|
+
# constants
|
82
|
+
|
83
|
+
PROGRAM_VERSION = ::RazorRisk::Cassini::Applications::Microservices::RESTful::Trades::VERSION
|
84
|
+
|
85
|
+
SUPPORTED_ROUTES = [
|
86
|
+
|
87
|
+
[ '/delete/:sysId', :delete, 'deletes the specified trade', ],
|
88
|
+
[ '/get', :get, 'gets the collection of trades', ],
|
89
|
+
[ '/get/:id', :get, 'gets the specified trade', ],
|
90
|
+
[ '/post', :post, 'posts a specified trade', ],
|
91
|
+
[ '/put/:id', :put, 'puts a specified trade', ],
|
92
|
+
[ '/post/getTradeContribution/?', :post, 'puts a specified trade', ],
|
93
|
+
]
|
94
|
+
|
95
|
+
HTTP_ACCEPTS = %w{ text/html application/json application/xml text/xml text/csv text/plain text/tab-separated-values text/tsv }
|
96
|
+
|
97
|
+
# ##########################################################################
|
98
|
+
# compatibility checks
|
99
|
+
|
100
|
+
check_version_compatibility ::RazorRisk::Cassini::Common, [ 0, 21 ], 'RazorRisk.Cassini.Common'
|
101
|
+
check_version_compatibility ::RazorRisk::Razor::Connectivity, [ 0, 11, 2 ], 'RazorRisk.Razor.Connectivity'
|
102
|
+
check_version_compatibility ::LibCLImate, '0.10'
|
103
|
+
check_version_compatibility ::Pantheios, '0.20'
|
104
|
+
check_version_compatibility ::Xqsr3::VERSION, '0.30'
|
105
|
+
|
106
|
+
# ##########################################################################
|
107
|
+
# functions
|
108
|
+
|
109
|
+
def make_CSV_routes routes
|
110
|
+
|
111
|
+
CSV.generate do |csv|
|
112
|
+
|
113
|
+
routes.each do |ar|
|
114
|
+
|
115
|
+
csv << ar
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def make_HTML_routes routes, **options
|
121
|
+
|
122
|
+
# TODO: use erb
|
123
|
+
|
124
|
+
routes = routes.map do |ar|
|
125
|
+
|
126
|
+
<<END_OF_tr
|
127
|
+
<tr>
|
128
|
+
<td>#{ar[0]}</td>
|
129
|
+
<td>#{ar[1]}</td>
|
130
|
+
<td>#{ar[2]}</td>
|
131
|
+
</tr>
|
132
|
+
END_OF_tr
|
133
|
+
end
|
134
|
+
|
135
|
+
<<END_OF_html
|
136
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.we.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
137
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
138
|
+
<head>
|
139
|
+
<title>Razor Risk Web Service API - Internal Microservice - trade</title>
|
140
|
+
<meta name="revisit-after" content="24 hours" />
|
141
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
142
|
+
</head>
|
143
|
+
<body>
|
144
|
+
<h1>Routes</h1>
|
145
|
+
<table>
|
146
|
+
<tr>
|
147
|
+
<th>Route</th>
|
148
|
+
<th>Verb</th>
|
149
|
+
<th>Description</th>
|
150
|
+
</tr>
|
151
|
+
#{routes.map { |r| r.chomp("\n") }.join("\n")}
|
152
|
+
</table>
|
153
|
+
</body>
|
154
|
+
</html>
|
155
|
+
END_OF_html
|
156
|
+
end
|
157
|
+
|
158
|
+
def make_JSON_routes routes, **options
|
159
|
+
|
160
|
+
r = {
|
161
|
+
|
162
|
+
'routes' => []
|
163
|
+
}
|
164
|
+
|
165
|
+
r['routes'] = SUPPORTED_ROUTES.map { |ar| { route: ar[0], verb: ar[1].to_s.upcase, description: ar[2] } }
|
166
|
+
|
167
|
+
r.to_json
|
168
|
+
end
|
169
|
+
|
170
|
+
def make_Plain_routes routes
|
171
|
+
|
172
|
+
make_TSV_routes routes
|
173
|
+
end
|
174
|
+
|
175
|
+
def make_TSV_routes routes
|
176
|
+
|
177
|
+
routes.map { |ar| "#{ar[0]}\t#{ar[1]}\t#{ar[2]}\n" }
|
178
|
+
end
|
179
|
+
|
180
|
+
def make_XML_routes routes
|
181
|
+
|
182
|
+
<<END_OF_xml
|
183
|
+
<?xml version="1.0">
|
184
|
+
<routes>#{routes.map { |ar| %Q{ <route route="#{ar[0]}" verb="#{ar[1].to_s.upcase}" description="#{ar[2]}"/>}}.join(%Q{\n})}
|
185
|
+
</routes>
|
186
|
+
END_OF_xml
|
187
|
+
end
|
188
|
+
|
189
|
+
# ##########################################################################
|
190
|
+
# static set-up
|
191
|
+
|
192
|
+
# ##########################################################################
|
193
|
+
# lambdas
|
194
|
+
|
195
|
+
Lambdas_XML_to_JSON = lambda do |xml|
|
196
|
+
|
197
|
+
ConversionUtil.convert_XML_to_JSON xml
|
198
|
+
end
|
199
|
+
|
200
|
+
# ##########################################################################
|
201
|
+
# application
|
202
|
+
|
203
|
+
class TradesApp < SecuredMicroservice
|
204
|
+
|
205
|
+
include RouteVerbDispatch
|
206
|
+
|
207
|
+
include ::Pantheios
|
208
|
+
|
209
|
+
|
210
|
+
FULL_DESIGNATION = 'Trades'
|
211
|
+
SHORT_DESIGNATION = 'trades'
|
212
|
+
SERVICE_TYPE = :microservice
|
213
|
+
|
214
|
+
PROGRAM_FEATURES = {
|
215
|
+
|
216
|
+
has_web_server: true,
|
217
|
+
|
218
|
+
has_host_and_port: true,
|
219
|
+
|
220
|
+
has_razor_connectivity: true,
|
221
|
+
|
222
|
+
authentication: :with_credentials_algorithm,
|
223
|
+
|
224
|
+
copyright_year: 2017,
|
225
|
+
}
|
226
|
+
|
227
|
+
|
228
|
+
def self.on_init_service options
|
229
|
+
|
230
|
+
trace ParamNames[ :options ], options
|
231
|
+
|
232
|
+
raise ArgumentError, 'missing keyword: razor_requester' unless options.has_key? :razor_requester
|
233
|
+
|
234
|
+
set :razor_requester, options[:razor_requester]
|
235
|
+
end
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
private
|
240
|
+
def sec
|
241
|
+
|
242
|
+
return '' if credentials.empty?
|
243
|
+
" (for #{credentials.join(':')})"
|
244
|
+
end
|
245
|
+
public
|
246
|
+
|
247
|
+
|
248
|
+
# functional routes (DELETE, GET, POST, PUT)
|
249
|
+
|
250
|
+
delete '/delete/:sysId/?' do
|
251
|
+
|
252
|
+
# trace
|
253
|
+
|
254
|
+
trace ParamNames[ :request, :params ], request, params
|
255
|
+
|
256
|
+
dispatch Trades::ItemDelete
|
257
|
+
end
|
258
|
+
|
259
|
+
# params:
|
260
|
+
# +result-form+:: Specifies the form of the result: +default+ gets the
|
261
|
+
# full Razor body, and is the default if none specified; +summary+ gets
|
262
|
+
# the trade-summary form; +trade+ gets the trade form
|
263
|
+
get '/get/:id/?' do
|
264
|
+
|
265
|
+
# trace
|
266
|
+
|
267
|
+
trace ParamNames[ :request, :params ], request, params
|
268
|
+
|
269
|
+
dispatch Trades::ItemGet
|
270
|
+
end
|
271
|
+
|
272
|
+
# params:
|
273
|
+
# +page-base+:: Specifies the (0-based) index index of the first element
|
274
|
+
# to be presented. Defaults to 0 if not specified
|
275
|
+
# +page-extent+:: Specifies the number of records to return in the
|
276
|
+
# retrieval window. Defaults to 1000 if not specified
|
277
|
+
# +quick-search+:: Specifies a quick-search string
|
278
|
+
get '/get/?' do
|
279
|
+
|
280
|
+
trace ParamNames[ :request, :params ], request, params
|
281
|
+
|
282
|
+
dispatch Trades::CollectionGet
|
283
|
+
end
|
284
|
+
|
285
|
+
# params:
|
286
|
+
# +result-form+:: Specifies the form of the result: +id+ gets the
|
287
|
+
# ID of the trade, and is the default if none specified; +body+ gets
|
288
|
+
# the XML body response
|
289
|
+
post '/post/?' do
|
290
|
+
|
291
|
+
trace ParamNames[ :request, :params ], request, params
|
292
|
+
|
293
|
+
dispatch Trades::ItemPost
|
294
|
+
end
|
295
|
+
|
296
|
+
post '/post/getTradeContribution/?' do
|
297
|
+
trace ParamNames[ :request, :params ], request, params
|
298
|
+
dispatch Trades::CollectionPost
|
299
|
+
end
|
300
|
+
|
301
|
+
# params:
|
302
|
+
# +result-form+:: Specifies the form of the result: +id+ gets the
|
303
|
+
# ID of the trade, and is the default if none specified; +body+ gets
|
304
|
+
# the XML body response
|
305
|
+
put '/put/:id/?' do
|
306
|
+
|
307
|
+
trace ParamNames[ :request, :params ], request, params
|
308
|
+
|
309
|
+
dispatch Trades::ItemPut
|
310
|
+
end
|
311
|
+
|
312
|
+
get '/' do
|
313
|
+
|
314
|
+
HTTP_ACCEPTS.each do |accept_type|
|
315
|
+
|
316
|
+
if request.accept? accept_type
|
317
|
+
|
318
|
+
content_type accept_type
|
319
|
+
|
320
|
+
case accept_type
|
321
|
+
when 'application/json'
|
322
|
+
|
323
|
+
r = make_JSON_routes SUPPORTED_ROUTES
|
324
|
+
when 'application/xml', 'text/xml'
|
325
|
+
|
326
|
+
r = make_XML_routes SUPPORTED_ROUTES
|
327
|
+
when 'text/csv'
|
328
|
+
|
329
|
+
r = make_CSV_routes SUPPORTED_ROUTES
|
330
|
+
when 'text/html'
|
331
|
+
|
332
|
+
r = make_HTML_routes SUPPORTED_ROUTES
|
333
|
+
when 'text/plain'
|
334
|
+
|
335
|
+
r = make_Plain_routes SUPPORTED_ROUTES
|
336
|
+
when 'text/tsv', 'text/tab-separated-values'
|
337
|
+
|
338
|
+
r = make_TSV_routes SUPPORTED_ROUTES
|
339
|
+
else
|
340
|
+
|
341
|
+
log :violation, 'unrecognised accept type \'', accept_type, '\''
|
342
|
+
|
343
|
+
halt *[ 500, {}, 'internal server failure' ]
|
344
|
+
end
|
345
|
+
|
346
|
+
return r
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
halt *[ 406, {}, "supports only the Accept types #{HTTP_ACCEPTS.map { |t| %Q<'#{t}'> }.join(', ')}" ]
|
351
|
+
end
|
352
|
+
|
353
|
+
define_catch_all_handlers
|
354
|
+
end
|
355
|
+
|
356
|
+
TheApp = TradesApp
|
357
|
+
|
358
|
+
# now define the OPTIONS support
|
359
|
+
|
360
|
+
supported_routes = Hash.new { |h, k| h[k] = [] }
|
361
|
+
|
362
|
+
SUPPORTED_ROUTES.each do |ar|
|
363
|
+
|
364
|
+
supported_routes[ar[0]].push ar[1]
|
365
|
+
end
|
366
|
+
|
367
|
+
supported_routes.each do |k, v|
|
368
|
+
|
369
|
+
if k =~ /:id(?:\/\?)?$/
|
370
|
+
|
371
|
+
route = "#$`*"
|
372
|
+
else
|
373
|
+
|
374
|
+
route = k
|
375
|
+
end
|
376
|
+
|
377
|
+
TheApp.options route do
|
378
|
+
|
379
|
+
verbs = v.map { |t| t.upcase }.join(',')
|
380
|
+
|
381
|
+
halt *[200, { 'Allow' => verbs }, [ verbs ] ]
|
382
|
+
end
|
383
|
+
end
|
384
|
+
|
385
|
+
TheApp.options '/' do
|
386
|
+
|
387
|
+
halt *[200, { 'Allow' => 'GET' }, '' ]
|
388
|
+
end
|
389
|
+
|
390
|
+
# ############################## end of file ############################# #
|
391
|
+
|
392
|
+
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# ######################################################################## #
|
4
|
+
# File: razor_risk/cassini/applications/microservices/restful/trades/version.rb
|
5
|
+
#
|
6
|
+
# Purpose: Version for RazorRisk.Cassini.Microservices.RESTful.Trades library
|
7
|
+
#
|
8
|
+
# Created: 7th January 2019
|
9
|
+
# Updated: 16th January 2019
|
10
|
+
#
|
11
|
+
# Copyright (c) 2019, Razor Risk Technologies Pty Ltd
|
12
|
+
# All rights reserved.
|
13
|
+
#
|
14
|
+
# ######################################################################## #
|
15
|
+
|
16
|
+
|
17
|
+
=begin
|
18
|
+
=end
|
19
|
+
|
20
|
+
module RazorRisk
|
21
|
+
module Cassini
|
22
|
+
module Applications
|
23
|
+
module Microservices
|
24
|
+
module RESTful
|
25
|
+
|
26
|
+
module Trades
|
27
|
+
|
28
|
+
# Current version of the RazorRisk.Cassini.Microservices.RESTful.Trades library
|
29
|
+
VERSION = '0.8.7'
|
30
|
+
|
31
|
+
private
|
32
|
+
VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
|
33
|
+
public
|
34
|
+
# Major version of the RazorRisk.Cassini.Microservices.RESTful.Trades library
|
35
|
+
VERSION_MAJOR = VERSION_PARTS_[0] # :nodoc:
|
36
|
+
# Minor version of the RazorRisk.Cassini.Microservices.RESTful.Trades library
|
37
|
+
VERSION_MINOR = VERSION_PARTS_[1] # :nodoc:
|
38
|
+
# Patch version of the RazorRisk.Cassini.Microservices.RESTful.Trades library
|
39
|
+
VERSION_PATCH = VERSION_PARTS_[2] # :nodoc:
|
40
|
+
# Commit version of the RazorRisk.Cassini.Microservices.RESTful.Trades library
|
41
|
+
VERSION_COMMIT = VERSION_PARTS_[3] || 0 # :nodoc:
|
42
|
+
|
43
|
+
|
44
|
+
# The description of the framework
|
45
|
+
DESCRIPTION = "Razor Risk's Cassini Web-framework's Trades RESTful microservice"
|
46
|
+
|
47
|
+
# [DEPRECATED] Instead use +DESCRIPTION+
|
48
|
+
FRAMEWORK_DESCRIPTION = DESCRIPTION
|
49
|
+
end # module Trades
|
50
|
+
|
51
|
+
end # module RESTful
|
52
|
+
end # module Microservices
|
53
|
+
end # module Applications
|
54
|
+
end # module Cassini
|
55
|
+
end # module RazorRisk
|
56
|
+
|
57
|
+
# ############################## end of file ############################# #
|
58
|
+
|
59
|
+
|