ironmq 1.2.7 → 1.2.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,7 +6,7 @@ Getting Started
6
6
 
7
7
  Install the gem:
8
8
 
9
- gem install ironmq
9
+ gem install iron_mq
10
10
 
11
11
  Create an IronMQ client object:
12
12
 
@@ -26,7 +26,7 @@ The Basics
26
26
  **Pop** a message off the queue:
27
27
 
28
28
  msg = @ironmq.messages.get()
29
- p res
29
+ p msg
30
30
 
31
31
  When you pop/get a message from the queue, it will NOT be deleted. It will eventually go back onto the queue after
32
32
  a timeout if you don't delete it (default timeout is 10 minutes).
data/Rakefile CHANGED
@@ -10,7 +10,9 @@ begin
10
10
  gem.email = "travis@iron.io"
11
11
  gem.homepage = "http://www.iron.io"
12
12
  gem.authors = ["Travis Reeder"]
13
- gem.add_dependency 'typhoeus'
13
+ gem.add_dependency 'rest-client'
14
+ gem.add_dependency 'rest'
15
+ #gem.add_dependency 'typhoeus'
14
16
  gem.required_ruby_version = '>= 1.9'
15
17
  end
16
18
  Jeweler::GemcutterTasks.new
@@ -32,7 +34,7 @@ Rake::RDocTask.new do |rdoc|
32
34
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
33
35
 
34
36
  rdoc.rdoc_dir = 'doc'
35
- rdoc.title = "ironmq_gem #{version}"
37
+ rdoc.title = "iron_mq #{version}"
36
38
  rdoc.rdoc_files.include('README*')
37
39
  rdoc.rdoc_files.include('lib/**/*.rb')
38
40
  end
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 1
3
3
  :minor: 2
4
- :patch: 7
4
+ :patch: 8
5
5
  :build:
@@ -4,12 +4,12 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = "ironmq"
8
- s.version = "1.2.7"
7
+ s.name = "iron_mq"
8
+ s.version = "1.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Travis Reeder"]
12
- s.date = "2011-12-08"
12
+ s.date = "2011-12-18"
13
13
  s.description = "Ruby client for IronMQ"
14
14
  s.email = "travis@iron.io"
15
15
  s.extra_rdoc_files = [
@@ -19,15 +19,15 @@ Gem::Specification.new do |s|
19
19
  "README.markdown",
20
20
  "Rakefile",
21
21
  "VERSION.yml",
22
- "ironmq.gemspec",
23
- "lib/ironmq.rb",
24
- "lib/ironmq/client.rb",
25
- "lib/ironmq/messages.rb",
26
- "lib/ironmq/queues.rb",
22
+ "iron_mq.gemspec",
23
+ "lib/iron_mq.rb",
24
+ "lib/iron_mq/client.rb",
25
+ "lib/iron_mq/messages.rb",
26
+ "lib/iron_mq/queues.rb",
27
27
  "test/long_run.rb",
28
28
  "test/quick_run.rb",
29
29
  "test/test_base.rb",
30
- "test/test_ironmq.rb"
30
+ "test/test_iron_mq.rb"
31
31
  ]
32
32
  s.homepage = "http://www.iron.io"
33
33
  s.require_paths = ["lib"]
@@ -39,15 +39,21 @@ Gem::Specification.new do |s|
39
39
  s.specification_version = 3
40
40
 
41
41
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
42
- s.add_runtime_dependency(%q<typhoeus>, [">= 0"])
43
- s.add_runtime_dependency(%q<typhoeus>, [">= 0"])
42
+ s.add_runtime_dependency(%q<rest-client>, [">= 0"])
43
+ s.add_runtime_dependency(%q<rest>, [">= 0"])
44
+ s.add_runtime_dependency(%q<rest-client>, [">= 0"])
45
+ s.add_runtime_dependency(%q<rest>, [">= 0"])
44
46
  else
45
- s.add_dependency(%q<typhoeus>, [">= 0"])
46
- s.add_dependency(%q<typhoeus>, [">= 0"])
47
+ s.add_dependency(%q<rest-client>, [">= 0"])
48
+ s.add_dependency(%q<rest>, [">= 0"])
49
+ s.add_dependency(%q<rest-client>, [">= 0"])
50
+ s.add_dependency(%q<rest>, [">= 0"])
47
51
  end
48
52
  else
49
- s.add_dependency(%q<typhoeus>, [">= 0"])
50
- s.add_dependency(%q<typhoeus>, [">= 0"])
53
+ s.add_dependency(%q<rest-client>, [">= 0"])
54
+ s.add_dependency(%q<rest>, [">= 0"])
55
+ s.add_dependency(%q<rest-client>, [">= 0"])
56
+ s.add_dependency(%q<rest>, [">= 0"])
51
57
  end
52
58
  end
53
59
 
@@ -1,3 +1 @@
1
- require_relative 'ironmq/queues'
2
- require_relative 'ironmq/messages'
3
- require_relative 'ironmq/client'
1
+ raise "The ironmq gem is deprecated. Please change to iron_mq instead. Same usage, different name."
@@ -1,13 +1,13 @@
1
1
  require 'yaml'
2
2
  require 'concur'
3
3
  begin
4
- require File.join(File.dirname(__FILE__), '..', 'lib', 'ironmq')
4
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'iron_mq')
5
5
  rescue Exception => ex
6
- puts "Could NOT load current ironmq: " + ex.message
6
+ puts "Could NOT load current iron_mq: " + ex.message
7
7
  raise ex
8
8
  end
9
9
 
10
- @config = YAML::load_file(File.expand_path(File.join("~", "Dropbox", "configs", "ironmq_gem", "test", "config.yml")))
10
+ @config = YAML::load_file(File.expand_path(File.join("~", "Dropbox", "configs", "iron_mq_ruby", "test", "config.yml")))
11
11
  @client = IronMQ::Client.new(@config['ironmq'])
12
12
  @client.queue_name = 'ironmq-gem-long'
13
13
  @num_to_add = @config['count']
@@ -2,27 +2,32 @@
2
2
  require_relative 'test_base'
3
3
 
4
4
  class QuickRun < TestBase
5
-
6
- def setup
7
- super
8
- @client.queue_name = 'ironmq-gem-quick'
9
- end
5
+
6
+ def setup
7
+ super
8
+ @client.queue_name = 'ironmq-gem-quick'
9
+ end
10
10
 
11
11
  def test_basics
12
12
  res = @client.messages.post("hello world!")
13
+ assert res.id
14
+ assert res.msg
13
15
  p res
14
16
 
15
17
  res = @client.messages.get()
18
+ assert res.id
19
+ assert res.body
16
20
  p res
17
21
 
18
22
  res = @client.messages.delete(res["id"])
23
+ assert res.msg
19
24
  p res
20
25
 
21
26
  res = @client.messages.get()
22
27
  p res
23
-
28
+
24
29
  end
25
30
 
26
-
31
+
27
32
  end
28
33
 
@@ -2,7 +2,7 @@ gem 'test-unit'
2
2
  require 'test/unit'
3
3
  require 'yaml'
4
4
  begin
5
- require File.join(File.dirname(__FILE__), '../lib/ironmq')
5
+ require File.join(File.dirname(__FILE__), '../lib/iron_mq')
6
6
  rescue Exception => ex
7
7
  puts "Could NOT load current ironmq: " + ex.message
8
8
  raise ex
@@ -10,12 +10,28 @@ end
10
10
 
11
11
 
12
12
  class TestBase < Test::Unit::TestCase
13
- def setup
13
+ def setup
14
14
  puts 'setup'
15
- @config = YAML::load_file(File.expand_path(File.join("~", "Dropbox", "configs", "ironmq_gem", "test", "config.yml")))
16
- @client = IronMQ::Client.new(@config['ironmq'])
15
+ # check multiple config locations
16
+ @config = load_config
17
+ puts "config=" + @config.inspect
18
+ @client = IronMQ::Client.new(@config['iron_mq'])
17
19
  @client.logger.level = Logger::DEBUG
18
20
  @client.queue_name = 'ironmq-ruby-tests'
19
21
 
20
22
  end
23
+
24
+ def load_config
25
+ # check for config
26
+ if defined? $abt_config
27
+ @config = $abt_config
28
+ return @config
29
+ end
30
+ cf = File.expand_path(File.join("~", "Dropbox", "configs", "iron_mq_ruby", "test", "config.yml"))
31
+ if File.exist?(cf)
32
+ @config = YAML::load_file(cf)
33
+ return @config
34
+ end
35
+
36
+ end
21
37
  end
@@ -1,5 +1,7 @@
1
1
  # Put config.yml file in ~/Dropbox/configs/ironmq_gem/test/config.yml
2
2
 
3
+ #$abt_config = {:hello=>'abt_config_ya'}
4
+
3
5
  gem 'test-unit'
4
6
  require 'test/unit'
5
7
  require 'yaml'
@@ -93,8 +95,8 @@ class IronMQTests < TestBase
93
95
  end
94
96
  assert res.size > 0
95
97
 
96
- res = @client.queues.list(:page=>2)
97
- puts "res.size=" + res.size.to_s
98
+ res = @client.queues.list(:page=>5)
99
+ puts "res.size 2=" + res.size.to_s
98
100
  res.each do |q|
99
101
  p q.name
100
102
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ironmq
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.7
4
+ version: 1.2.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-08 00:00:00.000000000 Z
12
+ date: 2011-12-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: typhoeus
16
- requirement: &16958660 !ruby/object:Gem::Requirement
15
+ name: rest-client
16
+ requirement: &13083060 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *16958660
24
+ version_requirements: *13083060
25
25
  - !ruby/object:Gem::Dependency
26
- name: typhoeus
27
- requirement: &16958160 !ruby/object:Gem::Requirement
26
+ name: rest
27
+ requirement: &13082540 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,29 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *16958160
35
+ version_requirements: *13082540
36
+ - !ruby/object:Gem::Dependency
37
+ name: rest-client
38
+ requirement: &13082000 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *13082000
47
+ - !ruby/object:Gem::Dependency
48
+ name: rest
49
+ requirement: &13081420 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *13081420
36
58
  description: Ruby client for IronMQ
37
59
  email: travis@iron.io
38
60
  executables: []
@@ -43,15 +65,12 @@ files:
43
65
  - README.markdown
44
66
  - Rakefile
45
67
  - VERSION.yml
46
- - ironmq.gemspec
68
+ - iron_mq.gemspec
47
69
  - lib/ironmq.rb
48
- - lib/ironmq/client.rb
49
- - lib/ironmq/messages.rb
50
- - lib/ironmq/queues.rb
51
70
  - test/long_run.rb
52
71
  - test/quick_run.rb
53
72
  - test/test_base.rb
54
- - test/test_ironmq.rb
73
+ - test/test_iron_mq.rb
55
74
  homepage: http://www.iron.io
56
75
  licenses: []
57
76
  post_install_message:
@@ -1,126 +0,0 @@
1
- require 'json'
2
- require 'typhoeus'
3
- require 'logger'
4
-
5
- module IronMQ
6
-
7
- class Client
8
-
9
- attr_accessor :token, :project_id, :queue_name, :logger
10
-
11
- def initialize(options={})
12
- @logger = Logger.new(STDOUT)
13
- @logger.level=Logger::INFO
14
-
15
- @token = options[:token] || options['token']
16
- @project_id = options[:project_id] || options['project_id']
17
- @queue_name = options[:queue_name] || options['queue_name'] || "default"
18
- @scheme = options[:scheme] || options['scheme'] || "https"
19
- @host = options[:host] || options['host'] || "mq-aws-us-east-1.iron.io"
20
- @port = options[:port] || options['port'] || 443
21
-
22
- @base_url = "#{@scheme}://#{@host}:#{@port}/1"
23
-
24
- end
25
-
26
- def messages
27
- return Messages.new(self)
28
- end
29
-
30
- def queues
31
- return Queues.new(self)
32
- end
33
-
34
- def base_url
35
- #"#{scheme}://#{host}:#{port}/1"
36
- @base_url
37
- end
38
-
39
- def full_url(path)
40
- url = "#{base_url}#{path}"
41
- url
42
- end
43
-
44
- def common_req_hash
45
- {
46
- :headers=>{"Content-Type" => 'application/json',
47
- "Authorization"=>"OAuth #{@token}",
48
- "User-Agent"=>"IronMQ Ruby Client"}
49
- }
50
- end
51
-
52
- def post(path, params={})
53
- url = full_url(path)
54
- @logger.debug 'url=' + url
55
- #response = @http_sess.post(path + "?oauth=#{@token}", {'oauth' => @token}.merge(params).to_json, {"Content-Type" => 'application/json'})
56
- req_hash = common_req_hash
57
- req_hash[:body] = params.to_json
58
- response = Typhoeus::Request.post(url, req_hash)
59
- @logger.debug 'typhoeus response=' + response.inspect
60
- res = check_response(response)
61
- #@logger.debug 'response: ' + res.inspect
62
- #body = response.body
63
- #res = JSON.parse(body)
64
- return res, response.code
65
- end
66
-
67
- def get(path, params={})
68
- url = full_url(path)
69
- @logger.debug 'url=' + url
70
- req_hash = common_req_hash
71
- req_hash[:params] = params
72
- @logger.debug 'req_hash=' + req_hash.inspect
73
- response = Typhoeus::Request.get(url, req_hash)
74
- res = check_response(response)
75
- return res, response.code
76
- end
77
-
78
- def delete(path, params={})
79
- url = "#{base_url}#{path}"
80
- @logger.debug 'url=' + url
81
- req_hash = common_req_hash
82
- req_hash[:params] = params
83
- response = Typhoeus::Request.delete(url, req_hash)
84
- res = check_response(response)
85
- #body = response.body
86
- #res = JSON.parse(body)
87
- #@logger.debug 'response: ' + res.inspect
88
- return res, response.code
89
- end
90
-
91
- def check_response(response)
92
- # response.code # http status code
93
- #response.time # time in seconds the request took
94
- #response.headers # the http headers
95
- #response.headers_hash # http headers put into a hash
96
- #response.body # the response body
97
- status = response.code
98
- body = response.body
99
- # todo: check content-type == application/json before parsing
100
- @logger.debug "response code=" + status.to_s
101
- @logger.debug "response body=" + body.inspect
102
- res = JSON.parse(body)
103
- if status < 400
104
-
105
- else
106
- raise IronMQ::Error.new(res["msg"], :status=>status)
107
- end
108
- res
109
- end
110
-
111
- end
112
-
113
- class Error < StandardError
114
- def initialize(msg, options={})
115
- super(msg)
116
- @options = options
117
- end
118
-
119
- def status
120
- @options[:status]
121
- end
122
- end
123
-
124
-
125
- end
126
-
@@ -1,78 +0,0 @@
1
- module IronMQ
2
- class Messages
3
-
4
- attr_accessor :client
5
-
6
- def initialize(client)
7
- @client = client
8
- end
9
-
10
- def path(options={})
11
- path = "/projects/#{@client.project_id}/queues/#{options[:queue_name] || @client.queue_name}/messages"
12
- end
13
-
14
- # options:
15
- # :queue_name => can specify an alternative queue name
16
- # :timeout => amount of time before message goes back on the queue
17
- def get(options={})
18
- begin
19
- params = nil
20
- if options[:timeout]
21
- params = {:timeout => options[:timeout]}
22
- end
23
- res, status = @client.get(path(options), params)
24
- return Message.new(self, res)
25
- rescue IronMQ::Error => ex
26
- if ex.status == 404
27
- return nil
28
- end
29
- raise ex
30
- end
31
-
32
-
33
- end
34
-
35
- # options:
36
- # :queue_name => can specify an alternative queue name
37
- def post(payload, options={})
38
- res, status = @client.post(path(options), :body=>payload)
39
- return Message.new(self, res)
40
- end
41
-
42
- def delete(message_id, options={})
43
- path2 = "#{self.path(options)}/#{message_id}"
44
- res, status = @client.delete(path2)
45
- res
46
- end
47
-
48
- end
49
-
50
- class Message
51
-
52
- def initialize(messages, res)
53
- @messages = messages
54
- @data = res
55
- end
56
-
57
- def raw
58
- @data
59
- end
60
-
61
- def [](key)
62
- raw[key]
63
- end
64
-
65
- def id
66
- raw["id"]
67
- end
68
-
69
- def body
70
- raw["body"]
71
- end
72
-
73
- def delete
74
- @messages.delete(self.id)
75
- end
76
- end
77
-
78
- end
@@ -1,72 +0,0 @@
1
- module IronMQ
2
- class Queues
3
-
4
- attr_accessor :client
5
-
6
- def initialize(client)
7
- @client = client
8
- end
9
-
10
- def path(options={})
11
- path = "/projects/#{@client.project_id}/queues"
12
- end
13
-
14
- def list(options={})
15
- ret = []
16
- res, status = @client.get("#{path(options)}", options)
17
- res.each do |q|
18
- #p q
19
- q = Queue.new(self, q)
20
- ret << q
21
- end
22
- ret
23
- end
24
-
25
- # options:
26
- # :name => can specify an alternative queue name
27
- def get(options={})
28
- res, status = @client.get("#{path(options)}/#{options[:name]}")
29
- return Queue.new(self, res)
30
- end
31
-
32
-
33
- end
34
-
35
- class Queue
36
-
37
- def initialize(queues, res)
38
- @queues = queues
39
- @data = res
40
- end
41
-
42
- def raw
43
- @data
44
- end
45
-
46
- def [](key)
47
- raw[key]
48
- end
49
-
50
- def id
51
- raw["id"]
52
- end
53
-
54
- def name
55
- raw["name"]
56
- end
57
-
58
- def size
59
- return raw["size"] if raw["size"]
60
- return @size if @size
61
- q = @queues.get(:name=>name)
62
- @size = q.size
63
- return @size
64
- end
65
-
66
- # def delete
67
- # @messages.delete(self.id)
68
- # end
69
- end
70
-
71
- end
72
-