Class: IronMQ::Messages
- Inherits:
-
Object
- Object
- IronMQ::Messages
- Defined in:
- lib/iron_mq/messages.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
Class Method Summary collapse
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, queue = nil) ⇒ 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, queue = nil) ⇒ Messages
Returns a new instance of Messages.
8 9 10 11 |
# File 'lib/iron_mq/messages.rb', line 8 def initialize(client, queue=nil) @client = client @queue = queue end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/iron_mq/messages.rb', line 6 def client @client end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
6 7 8 |
# File 'lib/iron_mq/messages.rb', line 6 def queue @queue end |
Class Method Details
Instance Method Details
#delete(message_id, options = {}) ⇒ Object
81 82 83 84 85 |
# File 'lib/iron_mq/messages.rb', line 81 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
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/iron_mq/messages.rb', line 31 def get(={}) if .is_a?(String) # assume it's an id puts 'get_by_id' return Message.new(self, {'id'=>}, ) #r = @client.get(path(:msg_id=>options)) #p r #return r end 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
14 15 16 17 18 |
# File 'lib/iron_mq/messages.rb', line 14 def path(={}) [:queue_name] ||= ((@queue ? @queue.name : nil) || @client.queue_name) [:project_id] = @client.project_id Messages.path() 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.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/iron_mq/messages.rb', line 61 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
87 88 89 90 91 |
# File 'lib/iron_mq/messages.rb', line 87 def release(, ={}) path2 = "#{self.path()}/#{}/release" res = @client.parse_response(@client.post(path2, )) return ResponseBase.new(res) end |