Class: RazorRisk::Cassini::Applications::RouteVerbAdaptors::Portfolios::ItemPut
- Inherits:
-
RESTFramework::VerbHandler
- Object
- RESTFramework::VerbHandler
- RazorRisk::Cassini::Applications::RouteVerbAdaptors::Portfolios::ItemPut
- Includes:
- Pantheios, Utilities::Portfolios, RazorRisk::Core::Diagnostics::Logger, Razor::Connectivity::Razor3::EntityConnectors
- Defined in:
- lib/razor_risk/cassini/applications/route_verb_adaptors/portfolios/item_put.rb
Overview
########################################################################## classes
Constant Summary collapse
- HTTP_VERB =
:put
- HTTP_CONTENT_TYPES =
%w{ application/xml text/xml }
- HTTP_ACCEPTS =
%w{ application/xml application/json text/xml }
- ROUTE_VARIABLES =
%w{ id }
- QUERY_PARAMETERS =
[]
Instance Method Summary collapse
Methods included from Utilities::Portfolios
Instance Method Details
#handle(env, params, request, response) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/razor_risk/cassini/applications/route_verb_adaptors/portfolios/item_put.rb', line 60 def handle env, params, request, response # trace trace ParamNames[ :env, :params, :request, :response ], env, params, request, response # parameters id = Integer(params['id']) { halt *[ 404, {}, 'invalid identifier for PUT verb - must be an integer' ] } # read request body (XML) # # NOTE: For this handler, the input is required to be XML, and it # is required that the document has a single top-level node # 'portfolios' request.body.rewind body_text = request.body.read rq_body = nil case request.content_type when 'application/xml', 'text/xml' rq_body = ::Nokogiri.XML body_text else log :violation, "unexpected content-type '#{request.content_type}'" end rq_body = validate_request_body rq_body, require_id: true # get credentials cr = get_required_credentials # get requester rr = settings.razor_requester # get connector ec = PortfoliosConnector.new(rr, credentials: cr) # issue request qr = ec.update_portfolio id, rq_body, indicate_result_by: :qualified_result unless qr.succeeded? log :warning, "failed to put portfolio with id '#{id}': #{qr.failure_qualifier.reasons.join(':')}" if r = qr.failure_qualifier.reasons.lookup?('RZ0011') halt *[ 404, {}, "#{r.message}: #{r.details}" ] else halt *[ 422, {}, "failed to put portfolio" ] =begin halt *[ 500, {}, qr.failure_qualifier.reasons.join("\n") ] =end end end end |