Class: IronMQ::Client
- Inherits:
-
IronCore::Client
- Object
- IronCore::Client
- IronMQ::Client
- Defined in:
- lib/iron_mq/client.rb
Constant Summary collapse
- AWS_US_EAST_HOST =
'mq-aws-us-east-1-1.iron.io'
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#queue_name ⇒ Object
Returns the value of attribute queue_name.
Instance Method Summary collapse
- #base_url ⇒ Object
- #create_queue(queue_name, options) ⇒ Object
-
#get(*args) ⇒ Object
Backward compatibility for client.queues.get(name: ‘my_queue’) client.queues.get(‘name’ => ‘my_queue’).
- #headers ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
-
#queues ⇒ Object
Backward compatibility, adds possibility to call client.queues.all client.queues.list client.queues.queue(name).
- #queues_get(name) ⇒ Object (also: #queue)
- #queues_list(options = {}) ⇒ Object (also: #list, #all)
- #update_queue(queue_name, options) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/iron_mq/client.rb', line 12 def initialize(={}) = { scheme: 'https', host: IronMQ::Client::AWS_US_EAST_HOST, port: 443, api_version: 3, user_agent: 'iron_mq_ruby-' + IronMQ::VERSION + ' (iron_core_ruby-' + IronCore.version + ')' } super('iron', 'mq', , , [:project_id, :token, :api_version]) if @keystone.nil? if @token.nil? IronCore::Logger.error 'IronMQ', 'Token is not set', IronCore::Error end check_id(@project_id, 'project_id') end @logger = Logger.new(STDOUT) @logger.level = Logger::INFO end |
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
10 11 12 |
# File 'lib/iron_mq/client.rb', line 10 def logger @logger end |
#queue_name ⇒ Object
Returns the value of attribute queue_name.
10 11 12 |
# File 'lib/iron_mq/client.rb', line 10 def queue_name @queue_name end |
Instance Method Details
#base_url ⇒ Object
41 42 43 |
# File 'lib/iron_mq/client.rb', line 41 def base_url @base_url ||= "#{super}#{@api_version}/projects/#{@project_id}/queues" end |
#create_queue(queue_name, options) ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/iron_mq/client.rb', line 87 def create_queue(queue_name, ) response = self.put("/#{CGI::escape(queue_name).gsub('+', '%20')}", {queue: }) queue_hash = JSON.parse(response.body.to_s) ResponseBase.new(queue_hash['queue']) end |
#get(*args) ⇒ Object
Backward compatibility for
client.queues.get(name: 'my_queue')
client.queues.get('name' => 'my_queue')
70 71 72 73 74 75 76 77 |
# File 'lib/iron_mq/client.rb', line 70 def get(*args) if args.size == 1 && args[0].is_a?(Hash) queue_name = (args[0][:name] || args[0]['name']).to_s queue_name.empty? ? super : queues_get(queue_name) else super end end |
#headers ⇒ Object
37 38 39 |
# File 'lib/iron_mq/client.rb', line 37 def headers super.merge({'Authorization' => "OAuth #{@token_provider.nil? ? @token : @token_provider.token}"}) end |
#queues ⇒ Object
Backward compatibility, adds possibility to call
client.queues.all
client.queues.list
client.queues.queue(name)
83 84 85 |
# File 'lib/iron_mq/client.rb', line 83 def queues self end |
#queues_get(name) ⇒ Object Also known as: queue
61 62 63 |
# File 'lib/iron_mq/client.rb', line 61 def queues_get(name) IronMQ::Queue.new(self, name) end |
#queues_list(options = {}) ⇒ Object Also known as: list, all
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/iron_mq/client.rb', line 45 def queues_list( = {}) is_raw = [.delete(:raw), .delete('raw')].compact.first response = parse_response(get('', )) # GET base_url # p response # returns list of evaluated queues if is_raw response.map{ |q_info| ResponseBase.new(q_info) } else response['queues'].map { |q_info| Queue.new(self, q_info['name']) } end end |
#update_queue(queue_name, options) ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/iron_mq/client.rb', line 95 def update_queue(queue_name, ) response = self.patch("/#{CGI::escape(queue_name).gsub('+', '%20')}", {queue: }) queue_hash = JSON.parse(response.body.to_s) ResponseBase.new(queue_hash['queue']) end |