Class: SoftLayer::Messaging::Queue

Inherits:
Object
  • Object
show all
Defined in:
lib/softlayer/messaging/queue.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options)
  @name = options.delete(:name)
  options.delete(:message)
  if options and options.any?
    @data = options
  end
  @resource = parent_resource["queues/#{@name}"]
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/softlayer/messaging/queue.rb', line 4

def name
  @name
end

#resourceObject

Returns the value of attribute resource.



4
5
6
# File 'lib/softlayer/messaging/queue.rb', line 4

def resource
  @resource
end

Instance Method Details

#dataObject 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 delete_message(mid)
  JSON.parse(resource["messages/#{mid}"].delete, :symbolize_names => true)
end

#expirationObject



27
28
29
# File 'lib/softlayer/messaging/queue.rb', line 27

def expiration
  @data[:expiration]
end

#load_dataObject



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 message(id, data={})
  data[:id] = id
  data.delete(:message)
  Message.new(@resource, data)
end

#message_countObject



19
20
21
# File 'lib/softlayer/messaging/queue.rb', line 19

def message_count
  @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(options = {})
  options[:limit] ||= 1
  response = resource["messages?batch=#{options[:limit]}"].get()
  messages = []
  JSON.parse(response, :symbolize_names => true)[:items].each do |m|
    messages << message(m[:id], m)
  end
  return messages
end

#push(msg, options = {}) ⇒ Object



80
81
82
83
84
85
# File 'lib/softlayer/messaging/queue.rb', line 80

def push(msg, options={})
  options[:body] = msg
  body = options.to_json
  result = JSON.parse(resource["messages"].post(body, :content_type => :json), :symbolize_names => true)
  message(result[:id], result)
end

#tagsObject



31
32
33
# File 'lib/softlayer/messaging/queue.rb', line 31

def tags
  @data[:tags]
end

#to_sObject



91
92
93
# File 'lib/softlayer/messaging/queue.rb', line 91

def to_s
  "Queue<#{@name}>"
end

#visibility_intervalObject



15
16
17
# File 'lib/softlayer/messaging/queue.rb', line 15

def visibility_interval
  @data[:visibility_interval]
end

#visible_message_countObject



23
24
25
# File 'lib/softlayer/messaging/queue.rb', line 23

def visible_message_count
  @data[:visible_message_count]
end