Class: SoftLayer::Messaging::Client
- Inherits:
-
Object
- Object
- SoftLayer::Messaging::Client
- Defined in:
- lib/softlayer/messaging/client.rb
Instance Attribute Summary collapse
-
#auth ⇒ Object
Returns the value of attribute auth.
-
#resource ⇒ Object
Returns the value of attribute resource.
Instance Method Summary collapse
- #authenticate(username, api_key, options = {}) ⇒ Object
- #create_queue(name, properties = {}) ⇒ Object
- #create_topic(name, properties = {}) ⇒ Object
- #delete_queue(name, force = false) ⇒ Object
- #delete_topic(name, force = false) ⇒ Object
- #get_queue(name) ⇒ Object
- #get_topic(name) ⇒ Object
-
#initialize(account, options = {}) ⇒ Client
constructor
A new instance of Client.
- #list_queues(options = {}) ⇒ Object (also: #queues)
- #list_topics(options = {}) ⇒ Object (also: #topics)
- #ping ⇒ Object
- #queue(name, options = {}) ⇒ Object
-
#stats(type = 'day') ⇒ Object
Types: day, week, month.
- #to_s ⇒ Object
- #topic(name, options = {}) ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(account, options = {}) ⇒ Client
Returns a new instance of Client.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/softlayer/messaging/client.rb', line 7 def initialize(account, ={}) @account = account [:datacenter] ||= 'dal05' [:network] ||= 'public' if not [:endpoint] [:endpoint] = "https://#{SoftLayer.endpoints[[:datacenter].to_s][[:network].to_s]}" end @base_resource = RestClient::Resource.new([:endpoint]) @endpoint = "#{[:endpoint]}/v1/#{account}" [:endpoint] = @endpoint @resource = AuthedResource.new([:endpoint], {:headers => {:accept => :json}}) end |
Instance Attribute Details
#auth ⇒ Object
Returns the value of attribute auth.
6 7 8 |
# File 'lib/softlayer/messaging/client.rb', line 6 def auth @auth end |
#resource ⇒ Object
Returns the value of attribute resource.
6 7 8 |
# File 'lib/softlayer/messaging/client.rb', line 6 def resource @resource end |
Instance Method Details
#authenticate(username, api_key, options = {}) ⇒ Object
21 22 23 24 25 |
# File 'lib/softlayer/messaging/client.rb', line 21 def authenticate(username, api_key, ={}) auth_endpoint = "#{@endpoint}/auth" @resource.auth = Auth.new(auth_endpoint, username, api_key, ) @resource.auth. end |
#create_queue(name, properties = {}) ⇒ Object
101 102 103 104 105 |
# File 'lib/softlayer/messaging/client.rb', line 101 def create_queue(name, properties={}) data = properties.to_json result = JSON.parse(resource["queues/#{name}"].put(data, :content_type => :json), :symbolize_names => true) return Queue.new(@resource, result) end |
#create_topic(name, properties = {}) ⇒ Object
107 108 109 110 111 |
# File 'lib/softlayer/messaging/client.rb', line 107 def create_topic(name, properties={}) data = properties.to_json result = JSON.parse(resource["topics/#{name}"].put(data, :content_type => :json), :symbolize_names => true) return Topic.new(@resource, result) end |
#delete_queue(name, force = false) ⇒ Object
89 90 91 92 93 |
# File 'lib/softlayer/messaging/client.rb', line 89 def delete_queue(name, force = false) force = force ? 1 : 0 JSON.parse(resource["queues/#{name}?force=#{force}"].delete(), :symbolize_names => true) true end |
#delete_topic(name, force = false) ⇒ Object
95 96 97 98 99 |
# File 'lib/softlayer/messaging/client.rb', line 95 def delete_topic(name, force = false) force = force ? 1 : 0 JSON.parse(resource["topics/#{name}?force=#{force}"].delete(), :symbolize_names => true) true end |
#get_queue(name) ⇒ Object
77 78 79 80 81 |
# File 'lib/softlayer/messaging/client.rb', line 77 def get_queue(name) return Queue.new(@resource, :name => name).tap{ |q| q.load_data } end |
#get_topic(name) ⇒ Object
83 84 85 86 87 |
# File 'lib/softlayer/messaging/client.rb', line 83 def get_topic(name) return Topic.new(@resource, :name => name).tap{ |q| q.load_data } end |
#list_queues(options = {}) ⇒ Object Also known as: queues
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/softlayer/messaging/client.rb', line 40 def list_queues(={}) = [:tags] params = {} params[:tags] = .join(',').to_s if queues = [] result = JSON.parse(resource['queues'].get({:params => params}), :symbolize_names => true)[:items] result.each do |q| queues << Queue.new(@resource, q) end queues end |
#list_topics(options = {}) ⇒ Object Also known as: topics
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/softlayer/messaging/client.rb', line 53 def list_topics(={}) = [:tags] params = {} params[:tags] = .join(',').to_s if topics = [] result = JSON.parse(resource['topics'].get({:params => params}), :symbolize_names => true)[:items] result.each do |q| topics << Topic.new(@resource, q) end topics end |
#ping ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/softlayer/messaging/client.rb', line 31 def ping begin @base_resource['v1/ping'].get true rescue false end end |
#queue(name, options = {}) ⇒ Object
67 68 69 70 |
# File 'lib/softlayer/messaging/client.rb', line 67 def queue(name, ={}) [:name] = name return Queue.new(@resource, ) end |
#stats(type = 'day') ⇒ Object
Types: day, week, month
114 115 116 |
# File 'lib/softlayer/messaging/client.rb', line 114 def stats(type='day') JSON.parse(resource["stats/#{type}"].get, :symbolize_names => true) end |
#to_s ⇒ Object
118 119 120 |
# File 'lib/softlayer/messaging/client.rb', line 118 def to_s "QueueClient<#{@resource.url}>" end |
#topic(name, options = {}) ⇒ Object
72 73 74 75 |
# File 'lib/softlayer/messaging/client.rb', line 72 def topic(name, ={}) [:name] = name return Topic.new(@resource, ) end |
#url ⇒ Object
27 28 29 |
# File 'lib/softlayer/messaging/client.rb', line 27 def url @resource.url end |