Class: SoftLayer::Messaging::Queue
- Inherits:
-
Object
- Object
- SoftLayer::Messaging::Queue
- Defined in:
- lib/softlayer/messaging/queue.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#resource ⇒ Object
Returns the value of attribute resource.
Instance Method Summary collapse
- #data ⇒ Object (also: #detail)
- #delete(force = false) ⇒ Object
- #delete_message(mid) ⇒ Object
- #expiration ⇒ Object
-
#initialize(parent_resource, options) ⇒ Queue
constructor
A new instance of Queue.
- #load_data ⇒ Object
- #message(id, data = {}) ⇒ Object
- #message_count ⇒ Object
- #modify(properties = {}) ⇒ Object
- #pop(options = {}) ⇒ Object
- #push(msg, options = {}) ⇒ Object
- #tags ⇒ Object
- #to_s ⇒ Object
- #visibility_interval ⇒ Object
- #visible_message_count ⇒ Object
Constructor Details
#initialize(parent_resource, options) ⇒ Queue
Returns a new instance of Queue.
6 7 8 9 10 11 12 13 |
# File 'lib/softlayer/messaging/queue.rb', line 6 def initialize(parent_resource, ) @name = .delete(:name) .delete(:message) if and .any? @data = end @resource = parent_resource["queues/#{@name}"] end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/softlayer/messaging/queue.rb', line 4 def name @name end |
#resource ⇒ Object
Returns the value of attribute resource.
4 5 6 |
# File 'lib/softlayer/messaging/queue.rb', line 4 def resource @resource end |
Instance Method Details
#data ⇒ Object Also known as: detail
41 42 43 |
# File 'lib/softlayer/messaging/queue.rb', line 41 def data @data ||= load_data end |
#delete(force = false) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/softlayer/messaging/queue.rb', line 63 def delete(force = false) force = force ? 1 : 0 result = resource.delete({:params => {:force => force}}) JSON.parse(result, :symbolize_names => true) true end |
#delete_message(mid) ⇒ Object
87 88 89 |
# File 'lib/softlayer/messaging/queue.rb', line 87 def (mid) JSON.parse(resource["messages/#{mid}"].delete, :symbolize_names => true) end |
#expiration ⇒ Object
27 28 29 |
# File 'lib/softlayer/messaging/queue.rb', line 27 def expiration @data[:expiration] end |
#load_data ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/softlayer/messaging/queue.rb', line 46 def load_data response = {} data = JSON.parse(resource.get) data.each do |k,v| response[k.to_sym] = v end return @data = response end |
#message(id, data = {}) ⇒ Object
35 36 37 38 39 |
# File 'lib/softlayer/messaging/queue.rb', line 35 def (id, data={}) data[:id] = id data.delete(:message) Message.new(@resource, data) end |
#message_count ⇒ Object
19 20 21 |
# File 'lib/softlayer/messaging/queue.rb', line 19 def @data[:message_count] end |
#modify(properties = {}) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/softlayer/messaging/queue.rb', line 55 def modify(properties={}) data = properties.to_json result = JSON.parse(resource.put(data, :content_type => :json), :symbolize_names => true) result.delete(:message) @data = result return self end |
#pop(options = {}) ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/softlayer/messaging/queue.rb', line 70 def pop( = {}) [:limit] ||= 1 response = resource["messages?batch=#{options[:limit]}"].get() = [] JSON.parse(response, :symbolize_names => true)[:items].each do |m| << (m[:id], m) end return end |
#push(msg, options = {}) ⇒ Object
80 81 82 83 84 85 |
# File 'lib/softlayer/messaging/queue.rb', line 80 def push(msg, ={}) [:body] = msg body = .to_json result = JSON.parse(resource["messages"].post(body, :content_type => :json), :symbolize_names => true) (result[:id], result) end |
#tags ⇒ Object
31 32 33 |
# File 'lib/softlayer/messaging/queue.rb', line 31 def @data[:tags] end |
#to_s ⇒ Object
91 92 93 |
# File 'lib/softlayer/messaging/queue.rb', line 91 def to_s "Queue<#{@name}>" end |
#visibility_interval ⇒ Object
15 16 17 |
# File 'lib/softlayer/messaging/queue.rb', line 15 def visibility_interval @data[:visibility_interval] end |
#visible_message_count ⇒ Object
23 24 25 |
# File 'lib/softlayer/messaging/queue.rb', line 23 def @data[:visible_message_count] end |