hypermq-ruby-client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6166b7042a62e7de27ffde40074b886b0fbbbee3
4
+ data.tar.gz: 124a9b4b7b5e0e24d109c0fece5ef7c18c30c1e8
5
+ SHA512:
6
+ metadata.gz: d56233c67e6077d853eae6a8c7aa13078b8e88ffd24b9bbc55309e3e7098bf888c7e06a778a6f5318002a3a3e9f2963f322e0b8749fb6e5a941f4c926c2547dc
7
+ data.tar.gz: a6e44006b871562855cb0c80677d555bac3e5b214f9861ad127eba8b56c1c769a4e1fe45a8e691596904859774220c409421931d6e2165b29ea2480bb6260a35
@@ -0,0 +1 @@
1
+ /coverage
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
@@ -0,0 +1,89 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ hypermq-ruby-client (0.0.1)
5
+ faraday
6
+ id
7
+ yajl-ruby
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activemodel (4.1.1)
13
+ activesupport (= 4.1.1)
14
+ builder (~> 3.1)
15
+ activesupport (4.1.1)
16
+ i18n (~> 0.6, >= 0.6.9)
17
+ json (~> 1.7, >= 1.7.7)
18
+ minitest (~> 5.1)
19
+ thread_safe (~> 0.1)
20
+ tzinfo (~> 1.1)
21
+ addressable (2.3.6)
22
+ builder (3.2.2)
23
+ coveralls (0.7.0)
24
+ multi_json (~> 1.3)
25
+ rest-client
26
+ simplecov (>= 0.7)
27
+ term-ansicolor
28
+ thor
29
+ crack (0.4.2)
30
+ safe_yaml (~> 1.0.0)
31
+ diff-lcs (1.2.5)
32
+ docile (1.1.3)
33
+ faraday (0.9.0)
34
+ multipart-post (>= 1.2, < 3)
35
+ i18n (0.6.9)
36
+ id (0.1)
37
+ activemodel
38
+ activesupport
39
+ money
40
+ optional
41
+ json (1.8.1)
42
+ metaclass (0.0.4)
43
+ mime-types (2.2)
44
+ minitest (5.3.3)
45
+ mocha (1.0.0)
46
+ metaclass (~> 0.0.1)
47
+ money (6.1.1)
48
+ i18n (~> 0.6.4)
49
+ multi_json (1.10.0)
50
+ multipart-post (2.0.0)
51
+ optional (0.0.7)
52
+ rest-client (1.6.7)
53
+ mime-types (>= 1.16)
54
+ rspec (2.14.1)
55
+ rspec-core (~> 2.14.0)
56
+ rspec-expectations (~> 2.14.0)
57
+ rspec-mocks (~> 2.14.0)
58
+ rspec-core (2.14.8)
59
+ rspec-expectations (2.14.5)
60
+ diff-lcs (>= 1.1.3, < 2.0)
61
+ rspec-mocks (2.14.6)
62
+ safe_yaml (1.0.3)
63
+ simplecov (0.8.2)
64
+ docile (~> 1.1.0)
65
+ multi_json
66
+ simplecov-html (~> 0.8.0)
67
+ simplecov-html (0.8.0)
68
+ term-ansicolor (1.3.0)
69
+ tins (~> 1.0)
70
+ thor (0.19.1)
71
+ thread_safe (0.3.3)
72
+ tins (1.1.0)
73
+ tzinfo (1.1.0)
74
+ thread_safe (~> 0.1)
75
+ webmock (1.17.4)
76
+ addressable (>= 2.2.7)
77
+ crack (>= 0.3.2)
78
+ yajl-ruby (1.2.0)
79
+
80
+ PLATFORMS
81
+ ruby
82
+
83
+ DEPENDENCIES
84
+ coveralls
85
+ hypermq-ruby-client!
86
+ mocha
87
+ rspec
88
+ simplecov
89
+ webmock
@@ -0,0 +1 @@
1
+ # HyperMQ Ruby Client
@@ -0,0 +1,26 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'hypermq-ruby-client'
3
+ s.version = '0.0.1'
4
+ s.date = '2014-05-07'
5
+ s.summary = "Ruby client for hypermq restful message queue"
6
+ s.description = "Provides a simple interface to hypermq"
7
+ s.authors = ["Russell Dunphy"]
8
+ s.email = ['rssll@rsslldnphy.com']
9
+ s.files = `git ls-files`.split($\)
10
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
11
+ s.require_paths = ["lib"]
12
+ s.homepage = 'http://github.com/uswitch/hypermq-ruby-client'
13
+ s.license = 'MIT'
14
+
15
+ s.add_dependency "id"
16
+ s.add_dependency "faraday"
17
+ s.add_dependency "yajl-ruby"
18
+
19
+ s.add_development_dependency "rspec"
20
+ s.add_development_dependency "webmock"
21
+ s.add_development_dependency "mocha"
22
+ s.add_development_dependency "simplecov"
23
+ s.add_development_dependency "coveralls"
24
+
25
+ end
26
+
@@ -0,0 +1,51 @@
1
+ require 'faraday'
2
+ require 'yajl'
3
+ require 'id'
4
+
5
+ module HyperMQ
6
+ class Client
7
+
8
+ def initialize(name, host, port=80)
9
+ @name = name
10
+ @host = host
11
+ @port = port
12
+ end
13
+
14
+ def domain
15
+ "http://#{host}:#{port}"
16
+ end
17
+
18
+ def push(queue, message)
19
+ url = [domain, 'q', queue].join('/')
20
+ Faraday.post(url) do |req|
21
+ req.headers['Content-Type'] = 'application/json'
22
+ req.body = Yajl::Encoder.encode(producer: name, body: message)
23
+ end.env[:status] == 201
24
+ end
25
+
26
+ def fetch(queue, message_id=nil)
27
+ url = [domain, 'q', queue, message_id].compact.join('/')
28
+ response = Faraday.get(url).env[:body]
29
+ Yajl::Parser.parse(response)
30
+ end
31
+
32
+ def acknowledge(queue, message_id)
33
+ url = [domain, 'ack', queue, name].join('/')
34
+ status = Faraday.post(url) do |req|
35
+ req.headers['Content-Type'] = 'application/json'
36
+ req.body = %-{"id":"#{message_id}"}-
37
+ end.env[:status]
38
+ status.to_i == 201
39
+ end
40
+
41
+ def last_seen(queue)
42
+ url = [domain, 'ack', queue, name].join('/')
43
+ response = Faraday.get(url).env[:body]
44
+ Yajl::Parser.parse(response).fetch('message')
45
+ end
46
+
47
+ private
48
+ attr_reader :name, :host, :port
49
+
50
+ end
51
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe HyperMQ::Client do
4
+
5
+ let (:client) { HyperMQ::Client.new('test-client', 'hypermq.yourdomain.com') }
6
+
7
+ before do
8
+ stub_request(:get, "http://hypermq.yourdomain.com/q/myqueue").to_return(File.read('spec/support/myqueue-from-beginning.json'))
9
+ stub_request(:get, "http://hypermq.yourdomain.com/q/myqueue/c35e12a0-d502-11e3-a3db-7831c1b71f12").to_return(File.read('spec/support/myqueue-next.json'))
10
+ stub_request(:post, "http://hypermq.yourdomain.com/ack/myqueue/test-client").to_return(File.read('spec/support/myqueue-ack.json'))
11
+ stub_request(:get, "http://hypermq.yourdomain.com/ack/myqueue/test-client").to_return(File.read('spec/support/myqueue-last-seen.json'))
12
+ stub_request(:post, "http://hypermq.yourdomain.com/q/myqueue").
13
+ with(:body => "{\"producer\":\"test-client\",\"body\":{\"some\":\"data\"}}").
14
+ to_return(File.read('spec/support/myqueue-create.json'))
15
+ end
16
+
17
+
18
+ describe "#fetch" do
19
+ it "requests the first page of messages when called without a second argument" do
20
+ expect(client.fetch('myqueue')).to eq ({
21
+ "queue"=>"myqueue",
22
+ "_embedded"=>{"message"=>[{
23
+ "created"=>1399369359563,
24
+ "body"=>{"some"=>"data"},
25
+ "producer"=>"myproducer",
26
+ "queue"=>"myqueue",
27
+ "id"=>"c35e12a0-d502-11e3-a3db-7831c1b71f12"
28
+ }]},
29
+ "_links"=>{"self"=>{"href"=>"http://hypermq.yourdomain.com/q/myqueue"}}})
30
+ end
31
+
32
+ it "requests the page of messages after a given id when called with that id as its second argument" do
33
+ expect(client.fetch('myqueue', "c35e12a0-d502-11e3-a3db-7831c1b71f12")).to eq ({
34
+ "queue"=>"myqueue",
35
+ "_embedded"=>{"message"=>[{"created"=>1399473341221, "body"=>{"msg"=>1},
36
+ "producer"=>"myproducer", "queue"=>"myqueue", "id"=>"dd441550-d5f4-11e3-b17b-7831c1b71f12"}]},
37
+ "_links"=>{"prev"=>{"href"=>"http://hypermq.yourdomain.com/q/myqueue"},
38
+ "self"=>{"href"=>"http://hypermq.yourdomain.com/q/myqueue/c35e12a0-d502-11e3-a3db-7831c1b71f12"
39
+ }}})
40
+ end
41
+ end
42
+
43
+ describe "#acknowledge" do
44
+ it 'acknowledges receipt of a message' do
45
+ expect(client.acknowledge('myqueue', 'c35e12a0-d502-11e3-a3db-7831c1b71f12')).to be_true
46
+ end
47
+ end
48
+
49
+ describe "#last_seen" do
50
+ it 'returns the id of the last acknowledged message' do
51
+ expect(client.last_seen('myqueue')).to eq 'a35e12a0-d502-11e3-a3db-831c1b71f112'
52
+ end
53
+ end
54
+
55
+ describe "#push" do
56
+ it 'pushes a message onto the queue' do
57
+ expect(client.push('myqueue', some: 'data')).to be_true
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,14 @@
1
+ require 'rspec'
2
+ require 'simplecov'
3
+ require 'webmock/rspec'
4
+
5
+ SimpleCov.start do
6
+ add_filter 'spec'
7
+ end
8
+
9
+ require 'hypermq/client'
10
+
11
+ RSpec.configure do |c|
12
+ c.order = :rand
13
+ c.mock_with :mocha
14
+ end
@@ -0,0 +1,8 @@
1
+ HTTP/1.1 201 Created
2
+ Server: nginx/1.4.4
3
+ Date: Wed, 07 May 2014 14:46:00 GMT
4
+ Content-Type: text/plain;charset=ISO-8859-1
5
+ Content-Length: 36
6
+ Connection: keep-alive
7
+
8
+ c35e12a0-d502-11e3-a3db-7831c1b71f11
@@ -0,0 +1,7 @@
1
+ HTTP/1.1 201 Created
2
+ Server: nginx/1.4.4
3
+ Date: Wed, 07 May 2014 15:32:23 GMT
4
+ Content-Type: text/plain
5
+ Content-Length: 0
6
+ Connection: keep-alive
7
+
@@ -0,0 +1,11 @@
1
+ HTTP/1.1 200 OK
2
+ Server: nginx/1.4.4
3
+ Date: Wed, 07 May 2014 10:47:08 GMT
4
+ Content-Type: application/json;charset=UTF-8
5
+ Content-Length: 253
6
+ Connection: keep-alive
7
+ Vary: Accept
8
+ Last-Modified: Tue, 06 May 2014 09:42:39 GMT
9
+ ETag: "c35e12a0-d502-11e3-a3db-7831c1b71f12"
10
+
11
+ {"queue":"myqueue","_embedded":{"message":[{"created":1399369359563,"body":{"some":"data"},"producer":"myproducer","queue":"myqueue","id":"c35e12a0-d502-11e3-a3db-7831c1b71f12"}]},"_links":{"self":{"href":"http:\/\/hypermq.yourdomain.com\/q\/myqueue"}}}
@@ -0,0 +1,9 @@
1
+ HTTP/1.1 200 OK
2
+ Server: nginx/1.4.4
3
+ Date: Wed, 07 May 2014 14:58:27 GMT
4
+ Content-Type: application/json;charset=UTF-8
5
+ Content-Length: 50
6
+ Connection: keep-alive
7
+ Vary: Accept
8
+
9
+ {"message":"a35e12a0-d502-11e3-a3db-831c1b71f112"}
@@ -0,0 +1,11 @@
1
+ HTTP/1.1 200 OK
2
+ Server: nginx/1.4.4
3
+ Date: Wed, 07 May 2014 14:35:41 GMT
4
+ Content-Type: application/json;charset=UTF-8
5
+ Content-Length: 347
6
+ Connection: keep-alive
7
+ Vary: Accept
8
+ Last-Modified: Wed, 07 May 2014 14:35:41 GMT
9
+ ETag: "dd441550-d5f4-11e3-b17b-7831c1b71f12"
10
+
11
+ {"queue":"myqueue","_embedded":{"message":[{"created":1399473341221,"body":{"msg":1},"producer":"myproducer","queue":"myqueue","id":"dd441550-d5f4-11e3-b17b-7831c1b71f12"}]},"_links":{"prev":{"href":"http:\/\/hypermq.yourdomain.com\/q\/myqueue"},"self":{"href":"http:\/\/hypermq.yourdomain.com\/q\/myqueue\/c35e12a0-d502-11e3-a3db-7831c1b71f12"}}}
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hypermq-ruby-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Russell Dunphy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: id
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: yajl-ruby
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: mocha
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: coveralls
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Provides a simple interface to hypermq
126
+ email:
127
+ - rssll@rsslldnphy.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - .gitignore
133
+ - Gemfile
134
+ - Gemfile.lock
135
+ - README.md
136
+ - hypermq-ruby-client.gemspec
137
+ - lib/hypermq/client.rb
138
+ - spec/lib/hypermq/client_spec.rb
139
+ - spec/spec_helper.rb
140
+ - spec/support/myqueue-ack.json
141
+ - spec/support/myqueue-create.json
142
+ - spec/support/myqueue-from-beginning.json
143
+ - spec/support/myqueue-last-seen.json
144
+ - spec/support/myqueue-next.json
145
+ homepage: http://github.com/uswitch/hypermq-ruby-client
146
+ licenses:
147
+ - MIT
148
+ metadata: {}
149
+ post_install_message:
150
+ rdoc_options: []
151
+ require_paths:
152
+ - lib
153
+ required_ruby_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ required_rubygems_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - '>='
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ requirements: []
164
+ rubyforge_project:
165
+ rubygems_version: 2.0.14
166
+ signing_key:
167
+ specification_version: 4
168
+ summary: Ruby client for hypermq restful message queue
169
+ test_files:
170
+ - spec/lib/hypermq/client_spec.rb
171
+ - spec/spec_helper.rb
172
+ - spec/support/myqueue-ack.json
173
+ - spec/support/myqueue-create.json
174
+ - spec/support/myqueue-from-beginning.json
175
+ - spec/support/myqueue-last-seen.json
176
+ - spec/support/myqueue-next.json