Class: IronMQ::Message

Inherits:
ResponseBase show all
Defined in:
lib/iron_mq/messages.rb

Instance Attribute Summary collapse

Attributes inherited from ResponseBase

#code, #raw

Instance Method Summary collapse

Methods inherited from ResponseBase

#[], #id, #msg

Constructor Details

#initialize(queue, data) ⇒ Message

Returns a new instance of Message.



8
9
10
11
# File 'lib/iron_mq/messages.rb', line 8

def initialize(queue, data)
  @queue = queue
  super(data, 200)
end

Instance Attribute Details

#queueObject (readonly)

Returns the value of attribute queue.



6
7
8
# File 'lib/iron_mq/messages.rb', line 6

def queue
  @queue
end

Instance Method Details

#bodyObject



13
14
15
# File 'lib/iron_mq/messages.rb', line 13

def body
  @raw['body']
end

#call_api_and_parse_response(meth, ext_path = "", options = {}, instantiate = true) ⇒ Object



60
61
62
# File 'lib/iron_mq/messages.rb', line 60

def call_api_and_parse_response(meth, ext_path = "", options = {}, instantiate = true)
  @queue.call_api_and_parse_response(meth, "#{path(ext_path)}", options, instantiate)
end

#delayObject



25
26
27
# File 'lib/iron_mq/messages.rb', line 25

def delay
  @raw['delay']
end

#deleteObject



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/iron_mq/messages.rb', line 48

def delete
  call_api_and_parse_response(:delete)
rescue Rest::HttpError => ex
  #if ex.code == 404
  #  Rest.logger.info("Delete got 404, safe to ignore.")
  #  # return ResponseBase as normal
  #  ResponseBase.new({"msg" => "Deleted"}, 404)
  #else
    raise ex
  #end
end

#expires_inObject



21
22
23
# File 'lib/iron_mq/messages.rb', line 21

def expires_in
  @raw['expires_in']
end

#release(options = {}) ⇒ Object



37
38
39
# File 'lib/iron_mq/messages.rb', line 37

def release(options = {})
  call_api_and_parse_response(:post, "/release", options)
end

#reserved_countObject



29
30
31
# File 'lib/iron_mq/messages.rb', line 29

def reserved_count
  @raw['reserved_count']
end

#subscribers(options = {}) ⇒ Object

‘options` was kept for backward compatibility



42
43
44
45
46
# File 'lib/iron_mq/messages.rb', line 42

def subscribers(options = {})
  response = call_api_and_parse_response(:get, "/subscribers", {}, false)

  response['subscribers'].map { |s| Subscriber.new(s, self, options) }
end

#timeoutObject



17
18
19
# File 'lib/iron_mq/messages.rb', line 17

def timeout
  @raw['timeout']
end

#touchObject



33
34
35
# File 'lib/iron_mq/messages.rb', line 33

def touch
  call_api_and_parse_response(:post, "/touch")
end