Class: RazorRisk::Razor::Connectivity::Razor3::HeaderMaker
- Inherits:
-
Object
- Object
- RazorRisk::Razor::Connectivity::Razor3::HeaderMaker
- Includes:
- Pantheios, Xqsr3::Quality::ParameterChecking
- Defined in:
- lib/razor_risk/razor/connectivity/razor_3/header_maker.rb
Defined Under Namespace
Modules: HeaderMaker_Constants
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#isdodiffallow ⇒ Object
readonly
Returns the value of attribute isdodiffallow.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
-
.prepare_inbound_header(environment, isdodiffallow = true, **options) ⇒ String, ...
Prepares a Razor inbound (XML) header, returned as either a string or an XML node.
Instance Method Summary collapse
-
#initialize(environment, isdodiffallow = true, **options) ⇒ HeaderMaker
constructor
A new instance of HeaderMaker.
-
#prepare_inbound_header(**options) ⇒ Object
See class method for explanation for options.
Constructor Details
#initialize(environment, isdodiffallow = true, **options) ⇒ HeaderMaker
Returns a new instance of HeaderMaker.
80 81 82 83 84 85 86 87 |
# File 'lib/razor_risk/razor/connectivity/razor_3/header_maker.rb', line 80 def initialize environment, isdodiffallow = true, ** trace ParamNames[ :environment, :isdodiffallow, :options ], environment, isdodiffallow, @environment = environment @isdodiffallow = isdodiffallow @options = .clone end |
Instance Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
89 90 91 |
# File 'lib/razor_risk/razor/connectivity/razor_3/header_maker.rb', line 89 def environment @environment end |
#isdodiffallow ⇒ Object (readonly)
Returns the value of attribute isdodiffallow.
90 91 92 |
# File 'lib/razor_risk/razor/connectivity/razor_3/header_maker.rb', line 90 def isdodiffallow @isdodiffallow end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
91 92 93 |
# File 'lib/razor_risk/razor/connectivity/razor_3/header_maker.rb', line 91 def @options end |
Class Method Details
.prepare_inbound_header(environment, isdodiffallow = true, **options) ⇒ String, ...
Prepares a Razor inbound (XML) header, returned as either a string or an XML node
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 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 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/razor_risk/razor/connectivity/razor_3/header_maker.rb', line 146 def self.prepare_inbound_header environment, isdodiffallow = true, ** trace ParamNames[ :environment, :isdodiffallow, :options ], environment, isdodiffallow, raise ArgumentError, "option :request is no longer supported; use :request_name instead" if .has_key? :request unrecognised = .keys.find { |k| !HeaderMaker_Constants::AcceptedOptions.include?(k) } and raise ArgumentError, "option #{::Symbol === unrecognised ? ':' : ''}#{unrecognised} is not recognised" request_name = check_option , :request_name, types: [ ::Symbol, ::String ], reject_empty: true request_type = check_option , :request_type, types: [ ::Symbol, ::String ], values: HeaderMaker_Constants::RequestTypes, reject_empty: true response_mode = check_option , :response_mode, types: [ ::Symbol, ::String ], reject_empty: true return_type = check_option , :return_type, types: [ ::String, ::Symbol ], values: [ :string, :string_array, :xml ] || :string body = check_option , :body, types: [ ::Nokogiri::XML::Element, ::String ], allow_nil: true, reject_empty: false body_attributes = check_option , :body_attributes, type: ::Hash, allow_nil: true caller_name = check_option , :caller, types: [ ::Symbol, ::String ], allow_nil: true, reject_empty: true body ||= '' if body_attributes server = check_option , :server, types: [ ::Symbol, ::String ], allow_nil: true, reject_empty: true server ||= '' user_id = check_option , :user_id, types: [ ::String ], allow_nil: true, reject_empty: true attributes = HeaderMaker_Constants.DefaultAttributes(**) attributes[:environment] = environment attributes[:request] = request_name attributes[:responseMode] = response_mode attributes[:caller] = caller_name if caller_name attributes[:server] = server if server attributes[:userId] = user_id if user_id attributes[:doDiffs] = isdodiffallow attributes = Hash[attributes.sort_by { |k, v| k }] attributes = attributes.map do |name, value| %Q< #{name}="#{value}"> end.join "\n" case return_type when :string, :xml r = [] r << <<END_OF_first <?xml version="1.0" encoding="utf-8"?> <#{request_type} #{attributes} END_OF_first case body when ::Nokogiri::XML::Element r << <<END_OF_last > END_OF_last r << body.to_xml r << <<END_OF_last </#{request_type}> END_OF_last when ::String b_a = body_attributes ? body_attributes.map { |n, v| %Q< #{n}="#{v}"> }.join('') : '' if body.empty? r << <<END_OF_last > <body#{b_a} /> </#{request_type}> END_OF_last else r << <<END_OF_last > <body#{b_a}> #{body} </body> </#{request_type}> END_OF_last end else r << <<END_OF_last /> END_OF_last end r = r.join "\n" r = ::Nokogiri.XML(r) if return_type == :xml r when :string_array r = [] r << <<END_OF_first <?xml version="1.0" encoding="utf-8"?> <#{request_type} #{attributes}> END_OF_first r << body if body r << <<END_OF_last </#{request_type} END_OF_last r end end |
Instance Method Details
#prepare_inbound_header(**options) ⇒ Object
See class method for explanation for options
94 95 96 97 98 99 100 101 |
# File 'lib/razor_risk/razor/connectivity/razor_3/header_maker.rb', line 94 def prepare_inbound_header ** trace opts = self..merge self.class.prepare_inbound_header environment, isdodiffallow, **opts end |