ironmq 1.2.4 → 1.2.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,6 +4,10 @@ IronMQ Ruby Client
4
4
  Getting Started
5
5
  ==============
6
6
 
7
+ Install the gem:
8
+
9
+ gem install ironmq
10
+
7
11
  Create an IronMQ client object:
8
12
 
9
13
  @client = IronMQ::Client.new('token'=>'MYTOKEN', 'project_id'=>'MYPROJECTID')
data/Rakefile CHANGED
@@ -10,7 +10,7 @@ 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 'patron'
13
+ gem.add_dependency 'typhoeus'
14
14
  gem.required_ruby_version = '>= 1.9'
15
15
  end
16
16
  Jeweler::GemcutterTasks.new
@@ -27,12 +27,12 @@ end
27
27
 
28
28
  task :default => :test
29
29
 
30
- require 'rake/rdoctask'
30
+ require 'rdoc/task'
31
31
  Rake::RDocTask.new do |rdoc|
32
32
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
33
33
 
34
34
  rdoc.rdoc_dir = 'doc'
35
- rdoc.title = "beanstalk-client #{version}"
35
+ rdoc.title = "ironmq_gem #{version}"
36
36
  rdoc.rdoc_files.include('README*')
37
37
  rdoc.rdoc_files.include('lib/**/*.rb')
38
38
  end
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 1
3
3
  :minor: 2
4
- :patch: 4
4
+ :patch: 5
5
5
  :build:
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ironmq}
8
- s.version = "1.2.4"
8
+ s.version = "1.2.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Travis Reeder}]
12
- s.date = %q{2011-10-14}
12
+ s.date = %q{2011-11-01}
13
13
  s.description = %q{Ruby client for IronMQ}
14
14
  s.email = %q{travis@iron.io}
15
15
  s.extra_rdoc_files = [
@@ -22,7 +22,8 @@ Gem::Specification.new do |s|
22
22
  "ironmq.gemspec",
23
23
  "lib/ironmq.rb",
24
24
  "lib/ironmq/client.rb",
25
- "test/ironmq_tests.rb"
25
+ "test/ironmq_tests.rb",
26
+ "test/long_run.rb"
26
27
  ]
27
28
  s.homepage = %q{http://www.iron.io}
28
29
  s.require_paths = [%q{lib}]
@@ -34,12 +35,12 @@ Gem::Specification.new do |s|
34
35
  s.specification_version = 3
35
36
 
36
37
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
37
- s.add_runtime_dependency(%q<patron>, [">= 0"])
38
+ s.add_runtime_dependency(%q<typhoeus>, [">= 0"])
38
39
  else
39
- s.add_dependency(%q<patron>, [">= 0"])
40
+ s.add_dependency(%q<typhoeus>, [">= 0"])
40
41
  end
41
42
  else
42
- s.add_dependency(%q<patron>, [">= 0"])
43
+ s.add_dependency(%q<typhoeus>, [">= 0"])
43
44
  end
44
45
  end
45
46
 
@@ -1,12 +1,12 @@
1
1
  require 'json'
2
- require 'patron'
2
+ require 'typhoeus'
3
3
  require 'logger'
4
4
 
5
5
  module IronMQ
6
6
 
7
7
  class Client
8
8
 
9
- attr_accessor :token, :project_id, :queue_name, :base_url, :logger
9
+ attr_accessor :token, :project_id, :queue_name, :logger
10
10
 
11
11
  def initialize(options={})
12
12
  @logger = Logger.new(STDOUT)
@@ -15,18 +15,11 @@ module IronMQ
15
15
  @token = options[:token] || options['token']
16
16
  @project_id = options[:project_id] || options['project_id']
17
17
  @queue_name = options[:queue_name] || options['queue_name'] || "default"
18
- @scheme = options[:scheme] || options['scheme'] || "http"
18
+ @scheme = options[:scheme] || options['scheme'] || "https"
19
19
  @host = options[:host] || options['host'] || "mq-aws-us-east-1.iron.io"
20
- @port = options[:port] || options['port'] || 80
21
- # todo: default https
22
- @base_url = "#{@scheme}://#{@host}:#{@port}/1"
20
+ @port = options[:port] || options['port'] || 443
23
21
 
24
- sess = Patron::Session.new
25
- sess.timeout = 10
26
- sess.base_url = @base_url
27
- sess.headers['User-Agent'] = 'IronMQ Ruby Client'
28
- #sess.enable_debug "/tmp/patron.debug"
29
- @http_sess = sess
22
+ @base_url = "#{@scheme}://#{@host}:#{@port}/1"
30
23
 
31
24
  end
32
25
 
@@ -34,48 +27,74 @@ module IronMQ
34
27
  return Messages.new(self)
35
28
  end
36
29
 
30
+ def base_url
31
+ #"#{scheme}://#{host}:#{port}/1"
32
+ @base_url
33
+ end
34
+
35
+ def full_url(path)
36
+ url = "#{base_url}#{path}"
37
+ url
38
+ end
39
+
40
+ def common_req_hash
41
+ {
42
+ :headers=>{"Content-Type" => 'application/json',
43
+ "Authorization"=>"OAuth #{@token}"}
44
+ }
45
+ end
37
46
 
38
47
  def post(path, params={})
39
- url = "#{@base_url}#{path}"
48
+ url = full_url(path)
40
49
  @logger.debug 'url=' + url
41
- response = @http_sess.post(path + "?oauth=#{@token}", {'oauth' => @token}.merge(params).to_json, {"Content-Type" => 'application/json'})
50
+ #response = @http_sess.post(path + "?oauth=#{@token}", {'oauth' => @token}.merge(params).to_json, {"Content-Type" => 'application/json'})
51
+ req_hash = common_req_hash
52
+ req_hash[:body] = params.to_json
53
+ response = Typhoeus::Request.post(url, req_hash)
42
54
  check_response(response)
43
55
  @logger.debug 'response: ' + response.inspect
44
56
  body = response.body
45
57
  res = JSON.parse(body)
46
- return res, response.status
58
+ return res, response.code
47
59
  end
48
60
 
49
61
  def get(path, params={})
50
- url = "#{@base_url}#{path}"
62
+ url = full_url(path)
51
63
  @logger.debug 'url=' + url
52
- response = @http_sess.request(:get, path,
53
- {},
54
- :query=>{'oauth'=>@token}.merge(params))
64
+ req_hash = common_req_hash
65
+ req_hash[:params] = params
66
+ response = Typhoeus::Request.get(url, req_hash)
55
67
  res = check_response(response)
56
-
57
- return res, response.status
68
+ return res, response.code
58
69
  end
59
70
 
60
71
  def delete(path, params={})
61
- url = "#{@base_url}#{path}"
72
+ url = "#{base_url}#{path}"
62
73
  @logger.debug 'url=' + url
63
- response = @http_sess.request(:delete, path,
64
- {},
65
- :query=>{'oauth'=>@token}.merge(params))
74
+ req_hash = common_req_hash
75
+ req_hash[:params] = params
76
+ response = Typhoeus::Request.delete(url, req_hash)
66
77
  check_response(response)
67
78
  body = response.body
68
79
  res = JSON.parse(body)
69
80
  @logger.debug 'response: ' + res.inspect
70
- return res, response.status
81
+ return res, response.code
71
82
  end
72
83
 
73
84
  def check_response(response)
74
- status = response.status
85
+ # response.code # http status code
86
+ #response.time # time in seconds the request took
87
+ #response.headers # the http headers
88
+ #response.headers_hash # http headers put into a hash
89
+ #response.body # the response body
90
+ status = response.code
75
91
  body = response.body
92
+ # todo: check content-type == application/json before parsing
93
+ @logger.debug "response code=" + status.to_s
94
+ @logger.debug "response body=" + body.inspect
76
95
  res = JSON.parse(body)
77
96
  if status < 400
78
-
97
+
79
98
  else
80
99
  raise IronMQ::Error.new(res["msg"], :status=>status)
81
100
  end
@@ -117,6 +136,7 @@ module IronMQ
117
136
  if ex.status == 404
118
137
  return nil
119
138
  end
139
+ raise ex
120
140
  end
121
141
 
122
142
 
@@ -126,6 +146,7 @@ module IronMQ
126
146
  # :queue_name => can specify an alternative queue name
127
147
  def post(payload, options={})
128
148
  res, status = @client.post(path(options), :body=>payload)
149
+ return Message.new(self, res)
129
150
  end
130
151
 
131
152
  def delete(message_id, options={})
@@ -0,0 +1,37 @@
1
+ require 'yaml'
2
+ begin
3
+ require File.join(File.dirname(__FILE__), '../lib/ironmq')
4
+ rescue Exception => ex
5
+ puts "Could NOT load current ironmq: " + ex.message
6
+ raise ex
7
+ end
8
+
9
+ @config = YAML::load_file(File.expand_path(File.join("~", "Dropbox", "configs", "ironmq_gem", "test", "config.yml")))
10
+ @client = IronMQ::Client.new(@config['ironmq'])
11
+ @client.queue_name = 'ironmq-gem-tests'
12
+ @num_to_add = @config['count']
13
+
14
+ start = Time.now
15
+ puts "Queuing #{@num_to_add} items at #{start}..."
16
+ @num_to_add.times do |i|
17
+ puts "POST #{i}..."
18
+ res = @client.messages.post("hello world! #{i}")
19
+ p res
20
+ end
21
+ put_time = (Time.now.to_f - start.to_f)
22
+ puts "Finished pushing in #{put_time} seconds"
23
+
24
+ start = Time.now
25
+ puts "Getting and deleting #{@num_to_add} items at #{start}..."
26
+ @num_to_add.times do |i|
27
+ puts "GET #{i}..."
28
+ res = @client.messages.get()
29
+ p res
30
+ puts "DELETE #{i}..."
31
+ res = @client.messages.delete(res["id"])
32
+ p res
33
+ end
34
+
35
+ puts "Finished pushing #{@num_to_add} items in #{put_time} seconds."
36
+ puts "Finished getting and deleting #{@num_to_add} items in #{(Time.now.to_f - start.to_f)} seconds."
37
+
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: ironmq
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.2.4
5
+ version: 1.2.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Travis Reeder
@@ -10,10 +10,10 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-10-14 00:00:00 Z
13
+ date: 2011-11-01 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: patron
16
+ name: typhoeus
17
17
  prerelease: false
18
18
  requirement: &id001 !ruby/object:Gem::Requirement
19
19
  none: false
@@ -39,6 +39,7 @@ files:
39
39
  - lib/ironmq.rb
40
40
  - lib/ironmq/client.rb
41
41
  - test/ironmq_tests.rb
42
+ - test/long_run.rb
42
43
  homepage: http://www.iron.io
43
44
  licenses: []
44
45