Class: Jungle::SQSResponseFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/jungle/client.rb

Class Method Summary collapse

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.delete_message_response(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, options = nil)
  begin
    if options
      self.send(operation.to_s + "_response", operation, response, options)
    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.peek_message_response(operation, response)
  if response.is_a? Net::HTTPSuccess
    xml = response.read_body
    m, message_xml = *xml.match(/<Message>.*?<\/Message>/)
    message = SQSMessage.new(message_xml)
    Struct::SQSPeekMessageResponse.new(operation, response.code.to_i, xml, message)
  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.receive_message_response(operation, response, options)
  if response.is_a? Net::HTTPSuccess
    xml = response.read_body
    messages = xml.scan(/<Message>.*?<\/Message>/m).map { |message_xml| SQSMessage.new(options[:queue_path], message_xml) }
    Struct::SQSReceiveMessageResponse.new(operation, response.code.to_i, xml, messages)
  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.send_message_response(operation, response)
  if response.is_a? Net::HTTPSuccess
    xml = response.read_body
    m, message_id = *xml.match(/<MessageId>(.*?)<\/MessageId>/)
    Struct::SQSCreateQueueResponse.new(operation, response.code.to_i, xml, message_id)
  else
    Struct::SQSErrorResponse.new(operation, response.code.to_i, response.read_body)
  end
end