Class: SoftLayer::Messaging::Topic
- Inherits:
-
Object
- Object
- SoftLayer::Messaging::Topic
- Defined in:
- lib/softlayer/messaging/topic.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
- #create_subscription(type, properties = {}) ⇒ Object
- #data ⇒ Object (also: #detail)
- #delete(force = false) ⇒ Object
- #delete_subscription(subscription_name) ⇒ Object
-
#initialize(parent_resource, options) ⇒ Topic
constructor
A new instance of Topic.
- #load_data ⇒ Object
- #modify(properties = {}) ⇒ Object
- #publish(msg, tags = []) ⇒ Object
- #subscription(id, data = {}) ⇒ Object
- #subscriptions ⇒ Object
- #tags ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(parent_resource, options) ⇒ Topic
Returns a new instance of Topic.
6 7 8 9 10 11 12 13 |
# File 'lib/softlayer/messaging/topic.rb', line 6 def initialize(parent_resource, ) @name = .delete(:name) .delete(:message) if and .any? @data = end @resource = parent_resource["topics/#{@name}"] end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/softlayer/messaging/topic.rb', line 4 def name @name end |
#resource ⇒ Object
Returns the value of attribute resource.
4 5 6 |
# File 'lib/softlayer/messaging/topic.rb', line 4 def resource @resource end |
Instance Method Details
#create_subscription(type, properties = {}) ⇒ Object
68 69 70 71 72 |
# File 'lib/softlayer/messaging/topic.rb', line 68 def create_subscription(type, properties={}) sub = {:endpoint_type => type, :endpoint => properties} results = JSON.parse(@resource["/subscriptions"].post(sub.to_json, :content_type => :json), :symbolize_names => true) Subscription.new @resource, results end |
#data ⇒ Object Also known as: detail
24 25 26 |
# File 'lib/softlayer/messaging/topic.rb', line 24 def data @data ||= load_data end |
#delete(force = false) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/softlayer/messaging/topic.rb', line 46 def delete(force = false) force = force ? 1 : 0 result = @resource.delete({:params => {:force => force}}) JSON.parse(result, :symbolize_names => true) true end |
#delete_subscription(subscription_name) ⇒ Object
74 75 76 77 |
# File 'lib/softlayer/messaging/topic.rb', line 74 def delete_subscription(subscription_name) JSON.parse(@resource["/subscriptions/#{subscription_name}"].delete(), :symbolize_names => true) true end |
#load_data ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/softlayer/messaging/topic.rb', line 29 def load_data response = {} data = JSON.parse(@resource.get, :symbolize_names => true) data.each do |k,v| response[k.to_sym] = v end return @data = response end |
#modify(properties = {}) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/softlayer/messaging/topic.rb', line 38 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 |
#publish(msg, tags = []) ⇒ Object
53 54 55 56 57 |
# File 'lib/softlayer/messaging/topic.rb', line 53 def publish(msg, = []) = {:body => msg, :tags => }.to_json JSON.parse(@resource["/messages"].post(, :content_type => :json), :symbolize_names => true) true end |
#subscription(id, data = {}) ⇒ Object
19 20 21 22 |
# File 'lib/softlayer/messaging/topic.rb', line 19 def subscription(id, data={}) data[:id] = id Subscription.new(@resource, data) end |
#subscriptions ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/softlayer/messaging/topic.rb', line 59 def subscriptions results = JSON.parse(@resource["/subscriptions"].get, :symbolize_names => true) subs = [] results[:items].each { |result| subs << Subscription.new(@resource, result) } subs end |
#tags ⇒ Object
15 16 17 |
# File 'lib/softlayer/messaging/topic.rb', line 15 def @data[:tags] end |
#to_s ⇒ Object
79 80 81 |
# File 'lib/softlayer/messaging/topic.rb', line 79 def to_s "Topic<#{@name}>" end |