Class: RazorRisk::Razor::Connectivity::Razor3::HeaderMaker

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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, **options

    trace ParamNames[ :environment, :isdodiffallow, :options ], environment, isdodiffallow, options

    @environment    =   environment
    @isdodiffallow  =   isdodiffallow
    @options        =   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
  @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

Parameters:

  • environment (String) —

    The environment name. May not be nil

  • options (Hash) —

    Options that alter the behaviour

  • +:request_type+ (Hash) —

    a customizable set of options

  • +:return_type+ (Hash) —

    a customizable set of options

  • +:request+ (Hash) —

    a customizable set of options

  • +:request_name+ (Hash) —

    a customizable set of options

  • +:response_mode+ (Hash) —

    a customizable set of options

  • +:body+ (Hash) —

    a customizable set of options

  • +:body_attributes+ (Hash) —

    a customizable set of options

  • +:caller+ (Hash) —

    a customizable set of options

  • +:server+ (Hash) —

    a customizable set of options

  • +:no_caller_name+ (Hash) —

    a customizable set of options

  • +:no_caller_pid+ (Hash) —

    a customizable set of options

  • +:no_caller_thread+ (Hash) —

    a customizable set of options

  • +:no_caller_version+ (Hash) —

    a customizable set of options

  • +:no_replicate+ (Hash) —

    a customizable set of options

Returns:

  • (String, Array[String, String], Nokogiri::XML::Node) —

    The inbound header, which will be a string, a pair of strings (in an array), or an XML node

Raises:

  • (ArgumentError)


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, **options

    trace ParamNames[ :environment, :isdodiffallow, :options ], environment, isdodiffallow, options

    raise ArgumentError, "option :request is no longer supported; use :request_name instead" if options.has_key? :request

    unrecognised    =   options.keys.find { |k| !HeaderMaker_Constants::AcceptedOptions.include?(k) } and raise ArgumentError, "option #{::Symbol === unrecognised ? ':' : ''}#{unrecognised} is not recognised"

    request_name    =   check_option options, :request_name, types: [ ::Symbol, ::String ], reject_empty: true

    request_type    =   check_option options, :request_type, types: [ ::Symbol, ::String ], values: HeaderMaker_Constants::RequestTypes, reject_empty: true

    response_mode   =   check_option options, :response_mode, types: [ ::Symbol, ::String ], reject_empty: true

    return_type     =   check_option options, :return_type, types: [ ::String, ::Symbol ], values: [ :string, :string_array, :xml ] || :string

    body            =   check_option options, :body, types: [ ::Nokogiri::XML::Element, ::String ], allow_nil: true, reject_empty: false
    body_attributes =   check_option options, :body_attributes, type: ::Hash, allow_nil: true
    caller_name     =   check_option options, :caller, types: [ ::Symbol, ::String ], allow_nil: true, reject_empty: true

    body            ||= '' if body_attributes

    server          =   check_option options, :server, types: [ ::Symbol, ::String ], allow_nil: true, reject_empty: true
    server          ||= ''
    user_id         =   check_option options, :user_id, types: [ ::String ], allow_nil: true, reject_empty: true

    attributes      =   HeaderMaker_Constants.DefaultAttributes(**options)

    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 **options

    trace

    opts = self.options.merge options

    self.class.prepare_inbound_header environment, isdodiffallow, **opts
end