Class: IronMQ::Client

Inherits:
IronCore::Client
  • Object
show all
Defined in:
lib/iron_mq/client.rb

Constant Summary collapse

AWS_US_EAST_HOST =
'mq-aws-us-east-1.iron.io'

Instance Attribute Summary collapse

Instance Method Summary collapse

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
# File 'lib/iron_mq/client.rb', line 12

def initialize(options={})
  default_options = {
      :scheme => 'https',
      :host => IronMQ::Client::AWS_US_EAST_HOST,
      :port => 443,
      :api_version => 1,
      :user_agent => 'iron_mq_ruby-' + IronMQ::VERSION + ' (iron_core_ruby-' + IronCore.version + ')'
  }

  super('iron', 'mq', options, default_options, [:project_id, :token, :api_version])

  IronCore::Logger.error 'IronMQ', "Token is not set", IronCore::Error if @token.nil?

  check_id(@project_id, 'project_id')

  @logger = Logger.new(STDOUT)
  @logger.level = Logger::INFO
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



10
11
12
# File 'lib/iron_mq/client.rb', line 10

def logger
  @logger
end

#queue_nameObject

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_urlObject



35
36
37
# File 'lib/iron_mq/client.rb', line 35

def base_url
  @base_url = "#{super}#{@api_version}/projects/#{@project_id}/queues"
end

#get(*args) ⇒ Object

Backward compatibility for

client.queues.get(:name => "my_queue")
client.queues.get("name" => "my_queue")


63
64
65
66
67
68
69
70
# File 'lib/iron_mq/client.rb', line 63

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

#headersObject



31
32
33
# File 'lib/iron_mq/client.rb', line 31

def headers
  super.merge({'Authorization' => "OAuth #{@token}"})
end

#queuesObject

Backward compatibility, adds possibility to call

client.queues.all
client.queues.list
client.queues.queue(name)


76
77
78
# File 'lib/iron_mq/client.rb', line 76

def queues
  self
end

#queues_get(name) ⇒ Object Also known as: queue



54
55
56
# File 'lib/iron_mq/client.rb', line 54

def queues_get(name)
  IronMQ::Queue.new(self, name)
end

#queues_list(options = {}) ⇒ Object Also known as: list, all



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/iron_mq/client.rb', line 39

def queues_list(options = {})
  is_raw = [options.delete(:raw),
            options.delete('raw')].compact.first
  response = parse_response(get('', options)) # GET base_url
  # returns list of evaluated queues
  if is_raw
    response.map{ |q_info| ResponseBase.new(q_info) }
  else
    response.map{ |q_info| Queue.new(self, q_info["name"]) }
  end
end