Class: Jungle::SQSResponseFactory
- Inherits:
-
Object
- Object
- Jungle::SQSResponseFactory
- Defined in:
- lib/jungle/client.rb
Class Method Summary collapse
- .create_queue_response(operation, response) ⇒ Object
- .delete_message_response(operation, response) ⇒ Object
- .list_queues_response(operation, response) ⇒ Object
- .manufacture(operation, response, options = nil) ⇒ Object
- .peek_message_response(operation, response) ⇒ Object
- .receive_message_response(operation, response, options) ⇒ Object
- .send_message_response(operation, response) ⇒ Object
Class Method Details
.create_queue_response(operation, response) ⇒ Object
530 531 532 533 534 535 536 537 538 |
# File 'lib/jungle/client.rb', line 530 def self.create_queue_response(operation, response) if response.is_a? Net::HTTPSuccess xml = response.read_body m, queue_url = *xml.match(/<QueueUrl>http:\/\/.*?\/(.*?)<\/QueueUrl>/) Struct::SQSCreateQueueResponse.new(operation, response.code.to_i, xml, queue_url) else Struct::SQSErrorResponse.new(operation, response.code.to_i, response.read_body) end end |
.delete_message_response(operation, response) ⇒ Object
570 571 572 573 574 575 576 577 |
# File 'lib/jungle/client.rb', line 570 def self.(operation, response) if response.is_a? Net::HTTPSuccess xml = response.read_body Struct::SQSDeleteMessageResponse.new(operation, response.code.to_i, xml) else Struct::SQSErrorResponse.new(operation, response.code.to_i, response.read_body) end end |
.list_queues_response(operation, response) ⇒ Object
540 541 542 543 544 545 546 547 548 |
# File 'lib/jungle/client.rb', line 540 def self.list_queues_response(operation, response) if response.is_a? Net::HTTPSuccess xml = response.read_body queue_urls = xml.scan(/<QueueUrl>(.+?)<\/QueueUrl>/m).flatten Struct::SQSListQueuesResponse.new(operation, response.code.to_i, xml, queue_urls) else Struct::SQSErrorResponse.new(operation, response.code.to_i, response.read_body) end end |
.manufacture(operation, response, options = nil) ⇒ Object
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 |
# File 'lib/jungle/client.rb', line 509 def self.manufacture(operation, response, = nil) begin if self.send(operation.to_s + "_response", operation, response, ) else self.send(operation.to_s + "_response", operation, response) end rescue raise raise(InternalError, "operation #{operation} not implemented") end # case operation # when :create_queue: self.create_queue_response(operation, response) # when :list_queues: self.list_queues_response(operation, response) # when :send_message: self.send_message_response(operation, response) # when :receive_message: self.receive_message_response(operation, response) # else raise(InternalError, "operation #{operation} not implemented") # end end |
.peek_message_response(operation, response) ⇒ Object
579 580 581 582 583 584 585 586 587 588 |
# File 'lib/jungle/client.rb', line 579 def self.(operation, response) if response.is_a? Net::HTTPSuccess xml = response.read_body m, = *xml.match(/<Message>.*?<\/Message>/) = SQSMessage.new() Struct::SQSPeekMessageResponse.new(operation, response.code.to_i, xml, ) else Struct::SQSErrorResponse.new(operation, response.code.to_i, response.read_body) end end |
.receive_message_response(operation, response, options) ⇒ Object
560 561 562 563 564 565 566 567 568 |
# File 'lib/jungle/client.rb', line 560 def self.(operation, response, ) if response.is_a? Net::HTTPSuccess xml = response.read_body = xml.scan(/<Message>.*?<\/Message>/m).map { || SQSMessage.new([:queue_path], ) } Struct::SQSReceiveMessageResponse.new(operation, response.code.to_i, xml, ) else Struct::SQSErrorResponse.new(operation, response.code.to_i, response.read_body) end end |
.send_message_response(operation, response) ⇒ Object
550 551 552 553 554 555 556 557 558 |
# File 'lib/jungle/client.rb', line 550 def self.(operation, response) if response.is_a? Net::HTTPSuccess xml = response.read_body m, = *xml.match(/<MessageId>(.*?)<\/MessageId>/) Struct::SQSCreateQueueResponse.new(operation, response.code.to_i, xml, ) else Struct::SQSErrorResponse.new(operation, response.code.to_i, response.read_body) end end |