Class: IronMQ::Messages
- Inherits:
-
Object
- Object
- IronMQ::Messages
- Defined in:
- lib/iron_mq/messages.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
Instance Method Summary collapse
- #delete(message_id, options = {}) ⇒ Object
-
#get(options = {}) ⇒ Object
options: :queue_name => can specify an alternative queue name :timeout => amount of time before message goes back on the queue.
-
#initialize(client) ⇒ Messages
constructor
A new instance of Messages.
- #path(options = {}) ⇒ Object
-
#post(payload, options = {}) ⇒ Object
options: :queue_name => can specify an alternative queue name :delay => time to wait before message will be available on the queue :timeout => The time in seconds to wait after message is taken off the queue, before it is put back on.
- #release(message_id, options = {}) ⇒ Object
Constructor Details
#initialize(client) ⇒ Messages
Returns a new instance of Messages.
8 9 10 |
# File 'lib/iron_mq/messages.rb', line 8 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
6 7 8 |
# File 'lib/iron_mq/messages.rb', line 6 def client @client end |
Instance Method Details
#delete(message_id, options = {}) ⇒ Object
61 62 63 64 65 |
# File 'lib/iron_mq/messages.rb', line 61 def delete(, ={}) path2 = "#{self.path()}/#{}" res = @client.parse_response(@client.delete(path2)) return ResponseBase.new(res) end |
#get(options = {}) ⇒ Object
options:
:queue_name => can specify an alternative queue name
:timeout => amount of time before message goes back on the queue
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/iron_mq/messages.rb', line 19 def get(={}) res = @client.parse_response(@client.get(path(), )) ret = [] res["messages"].each do |m| ret << Message.new(self, m, ) end if [:n] || ['n'] return ret else if ret.size > 0 return ret[0] else return nil end end end |
#path(options = {}) ⇒ Object
12 13 14 |
# File 'lib/iron_mq/messages.rb', line 12 def path(={}) path = "projects/#{@client.project_id}/queues/#{CGI::escape([:queue_name] || ['queue_name'] || @client.queue_name)}/messages" end |
#post(payload, options = {}) ⇒ Object
options:
:queue_name => can specify an alternative queue name
:delay => time to wait before message will be available on the queue
:timeout => The time in seconds to wait after message is taken off the queue, before it is put back on. Delete before :timeout to ensure it does not go back on the queue.
:expires_in => After this time, message will be automatically removed from the queue.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/iron_mq/messages.rb', line 41 def post(payload, ={}) batch = false if payload.is_a?(Array) batch = true msgs = payload else [:body] = payload msgs = [] msgs << end to_send = {} to_send[:messages] = msgs res = @client.parse_response(@client.post(path(), to_send)) if batch return res else return ResponseBase.new({"id"=>res["ids"][0], "msg"=>res["msg"]}) end end |
#release(message_id, options = {}) ⇒ Object
67 68 69 70 71 |
# File 'lib/iron_mq/messages.rb', line 67 def release(, ={}) path2 = "#{self.path()}/#{}/release" res = @client.parse_response(@client.post(path2, )) return ResponseBase.new(res) end |