Class: ActiveMessaging::Adapters::Sqs::SQSResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/activemessaging/adapters/sqs.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ SQSResponse

Returns a new instance of SQSResponse.



376
377
378
379
380
381
# File 'lib/activemessaging/adapters/sqs.rb', line 376

def initialize response
  # puts "response.body = #{response.body}"
  @http_response = response
  @headers = response.to_hash()
  @doc = REXML::Document.new(response.body)
end

Instance Attribute Details

#docObject

Returns the value of attribute doc.



374
375
376
# File 'lib/activemessaging/adapters/sqs.rb', line 374

def doc
  @doc
end

#headersObject

Returns the value of attribute headers.



374
375
376
# File 'lib/activemessaging/adapters/sqs.rb', line 374

def headers
  @headers
end

#http_responseObject

Returns the value of attribute http_response.



374
375
376
# File 'lib/activemessaging/adapters/sqs.rb', line 374

def http_response
  @http_response
end

Instance Method Details

#each_node(xp) ⇒ Object



411
412
413
# File 'lib/activemessaging/adapters/sqs.rb', line 411

def each_node(xp)
  REXML::XPath.each(doc.root, xp) {|n| yield n}
end

#errorsObject



391
392
393
394
395
396
397
398
399
400
401
402
403
404
# File 'lib/activemessaging/adapters/sqs.rb', line 391

def errors
  return "HTTP Error: #{http_response.code} : #{http_response.message}" unless http_response.kind_of?(Net::HTTPSuccess)

  msg = nil
  each_node('//Error') { |n|
    msg ||= ""
    c = n.elements['Code'].text
    m = n.elements['Message'].text
    msg << ", " if msg != ""
    msg << "#{c} : #{m}"
  }

  return msg
end

#errors?Boolean

Returns:

  • (Boolean)


387
388
389
# File 'lib/activemessaging/adapters/sqs.rb', line 387

def errors?
  (not http_response.kind_of?(Net::HTTPSuccess)) or (message_type == 'ErrorResponse')
end

#get_text(xpath, default = '') ⇒ Object



406
407
408
409
# File 'lib/activemessaging/adapters/sqs.rb', line 406

def get_text(xpath,default='')
  e = REXML::XPath.first( doc, xpath)
  e.nil? ? default : e.text
end

#message_typeObject



383
384
385
# File 'lib/activemessaging/adapters/sqs.rb', line 383

def message_type
  return doc ? doc.root.name : ''
end

#nodes(xp) ⇒ Object



415
416
417
# File 'lib/activemessaging/adapters/sqs.rb', line 415

def nodes(xp)
  doc.elements.to_a(xp)
end