Class: RazorRisk::Cassini::Applications::Microservices::RESTful::ExternalFacilities::ExternalFacilitiesApp

Inherits:
SecuredMicroservice
  • Object
show all
Includes:
Pantheios, RESTFramework::RouteVerbDispatch, RouteVerbAdaptors::ExternalFacilities, RazorRisk::Core::Diagnostics::Logger
Defined in:
lib/razor_risk/cassini/applications/microservices/restful/externalfacilities/app.rb

Overview

Sinatra Application for the ExternalFacilities Microservice.

Constant Summary collapse

FULL_DESIGNATION =
'ExternalFacilities'
SHORT_DESIGNATION =
'externalfacilities'
SERVICE_TYPE =
:microservice
PROGRAM_FEATURES =
{
    has_web_server:         true,
    has_host_and_port:      true,
    has_razor_connectivity: true,
    authentication:         :with_credentials_algorithm,
    copyright_year:         2019,
}
SUPPORTED_ROUTES =
[
    [ '/externalfacilities/?', :get, 'Get the external facilities.' ],
]
HTTP_ACCEPTS =
%w{
    text/html
    application/json
    application/xml
    text/xml
    text/csv
    text/plain
    text/tab-separated-values
    text/tsv
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.on_init_service(options) ⇒ Object

Raises:

  • (ArgumentError)


80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/razor_risk/cassini/applications/microservices/restful/externalfacilities/app.rb', line 80

def self.on_init_service options

    trace ParamNames[ :options ], options

    raise ArgumentError.new(
        'missing keyword: razor_requester'
    ) unless options.has_key? :razor_requester

    request_options = options[:request_options] || {
        validate: true
    }

    set :razor_requester, options[:razor_requester]
    set :request_options, request_options
end

Instance Method Details

#make_CSV_routes(routes) ⇒ Object

########################################################## routes helpers



163
164
165
166
167
168
169
# File 'lib/razor_risk/cassini/applications/microservices/restful/externalfacilities/app.rb', line 163

def make_CSV_routes routes
    CSV.generate do |csv|
        routes.each do |ar|
            csv << ar
        end
    end
end

#make_HTML_routes(routes, **options) ⇒ Object



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/razor_risk/cassini/applications/microservices/restful/externalfacilities/app.rb', line 171

def make_HTML_routes routes, **options
    routes = routes.map do |ar|
    <<END_OF_tr
   <tr>
<td>#{ar[0]}</td>
<td>#{ar[1]}</td>
<td>#{ar[2]}</td>
   </tr>
END_OF_tr
end

<<END_OF_html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.we.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 <head>
  <title>Razor Risk Web Service API - Internal Microservice - External Facilities</title>
  <meta name="revisit-after" content="24 hours" />
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
 </head>
 <body>
  <h1>Routes</h1>
  <table>
   <tr>
<th>Route</th>
<th>Verb</th>
<th>Description</th>
   </tr>
#{routes.map { |r| r.chomp("\n") }.join("\n")}
  </table>
 </body>
</html>
END_OF_html
end

#make_JSON_routes(routes, **options) ⇒ Object



205
206
207
208
209
210
211
# File 'lib/razor_risk/cassini/applications/microservices/restful/externalfacilities/app.rb', line 205

def make_JSON_routes routes, **options
    r = {
        'routes' => []
    }
    r['routes'] = SUPPORTED_ROUTES.map { |ar| { route: ar[0], verb: ar[1].to_s.upcase, description: ar[2] } }
    r.to_json
end

#make_Plain_routes(routes) ⇒ Object



213
214
215
# File 'lib/razor_risk/cassini/applications/microservices/restful/externalfacilities/app.rb', line 213

def make_Plain_routes routes
    make_TSV_routes routes
end

#make_TSV_routes(routes) ⇒ Object



217
218
219
# File 'lib/razor_risk/cassini/applications/microservices/restful/externalfacilities/app.rb', line 217

def make_TSV_routes routes
    routes.map { |ar| "#{ar[0]}\t#{ar[1]}\t#{ar[2]}\n" }
end

#make_XML_routes(routes) ⇒ Object



221
222
223
224
225
226
227
# File 'lib/razor_risk/cassini/applications/microservices/restful/externalfacilities/app.rb', line 221

def make_XML_routes routes
<<END_OF_xml
<?xml version="1.0">
<routes>#{routes.map { |ar| %Q{  <route route="#{ar[0]}" verb="#{ar[1].to_s.upcase}" description="#{ar[2]}"/>}}.join(%Q{\n})}
</routes>
END_OF_xml
end