Class: QBWC::Request
- Inherits:
-
Object
- Object
- QBWC::Request
- Defined in:
- lib/qbwc/request.rb
Instance Attribute Summary collapse
-
#error ⇒ Object
Returns the value of attribute error.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
Returns the value of attribute response.
-
#response_proc ⇒ Object
readonly
Returns the value of attribute response_proc.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(request, response_proc) ⇒ Request
constructor
A new instance of Request.
- #process_response ⇒ Object
- #to_hash ⇒ Object
- #to_qbxml ⇒ Object
Constructor Details
#initialize(request, response_proc) ⇒ Request
Returns a new instance of Request.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/qbwc/request.rb', line 6 def initialize(request, response_proc) #Handle Cases for a request passed in as a Hash or String #If it's a hash verify that it is properly wrapped with qbxml_msg_rq and xml_attributes for on_error events #Allow strings of QBXML to be passed in directly. case when request.is_a?(Hash) unless request.keys.include?(:qbxml_msgs_rq) wrapped_request = { :qbxml_msgs_rq => {:xml_attributes => {"onError"=> QBWC::on_error } } } wrapped_request[:qbxml_msgs_rq] = wrapped_request[:qbxml_msgs_rq].merge(request) request = wrapped_request end @request = QBWC.parser.hash_to_qbxml(request) when request.is_a?(String) @request = request end @response_proc = response_proc end |
Instance Attribute Details
#error ⇒ Object
Returns the value of attribute error.
4 5 6 |
# File 'lib/qbwc/request.rb', line 4 def error @error end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
3 4 5 |
# File 'lib/qbwc/request.rb', line 3 def request @request end |
#response ⇒ Object
Returns the value of attribute response.
4 5 6 |
# File 'lib/qbwc/request.rb', line 4 def response @response end |
#response_proc ⇒ Object (readonly)
Returns the value of attribute response_proc.
3 4 5 |
# File 'lib/qbwc/request.rb', line 3 def response_proc @response_proc end |
Class Method Details
.from_array(requests, response_proc) ⇒ Object
40 41 42 |
# File 'lib/qbwc/request.rb', line 40 def from_array(requests, response_proc) Array(requests).map { |r| new(r, response_proc) } end |
Instance Method Details
#process_response ⇒ Object
26 27 28 |
# File 'lib/qbwc/request.rb', line 26 def process_response @response_proc && @response && @response_proc.call(response) end |
#to_hash ⇒ Object
34 35 36 |
# File 'lib/qbwc/request.rb', line 34 def to_hash QBWC.parser.qbxml_to_hash @request.to_s end |
#to_qbxml ⇒ Object
30 31 32 |
# File 'lib/qbwc/request.rb', line 30 def to_qbxml QBWC.parser.hash_to_qbxml(request) end |