amqparty 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +0 -2
- data/.travis.yml +2 -2
- data/README.md +17 -0
- data/amqparty.gemspec +2 -3
- data/lib/amqparty.rb +27 -5
- data/lib/amqparty/request.rb +22 -8
- data/lib/amqparty/version.rb +1 -1
- data/spec/amqparty_classmethods_spec.rb +63 -17
- metadata +25 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24f1ff05a43649e133ef937f72d0a87abcb3940f
|
4
|
+
data.tar.gz: be5500567394b7cdbc674dda48efc8be80a59bb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5912b578d5d002737d15d5abe83314e58aa470f688fd28f14e935801adf6bbf4263c3712d58ca7d20257d120baf05c28d2ffdad34b23b12c1481e63bd2fb05d6
|
7
|
+
data.tar.gz: 297bf404bc4cac06adbbcc3fc86a2904538385722e287ce2ea43e055e8b3c96c385436c1b1b5aa193db78af6716b88b0e848bf280458727c5a7597305738e7d3
|
data/.rspec
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
A AMQP-HTTP compliant modification of HTTParty for use with jackalope
|
4
4
|
|
5
|
+
![Travis CI](https://travis-ci.org/rack-amqp/amqparty.svg?branch=master)
|
6
|
+
|
5
7
|
## Installation
|
6
8
|
|
7
9
|
Add this line to your application's Gemfile:
|
@@ -37,6 +39,21 @@ Uri scheme must be amqp or amqps. Hostname is actually the queue name.
|
|
37
39
|
|
38
40
|
Post and put also work. Delete, head, options are untested.
|
39
41
|
|
42
|
+
Valid configuration parameters are shown below:
|
43
|
+
|
44
|
+
| Parameters | Description | Default Value |
|
45
|
+
|-----------------------|:----------------------------------------------------------------------:|--------------:|
|
46
|
+
| amqp\_host | host name or IP address of the rabbitmq server | localhost |
|
47
|
+
| port | rabbitmq server port | 5672 |
|
48
|
+
| username | username to use for the rabbitmq server connection | guest |
|
49
|
+
| password | password to use for the rabbitmq server connection | guest |
|
50
|
+
| tls | use TLS when connecting to the rabbitmq server | false |
|
51
|
+
| tls\_ca\_certificates | an array of paths to CA certificates in pem format | [] |
|
52
|
+
| tls\_cert | path to the client certificate for SSL connections in pem format | nil |
|
53
|
+
| tls\_key | path to the client private key for SSL connections in pem format | nil |
|
54
|
+
| verify\_peer | disable/enable peer verification (used with TLS) | false |
|
55
|
+
| request\_timeout | value in seconds indicating the reply wait timeout for an amqp request | 5 |
|
56
|
+
|
40
57
|
## Contributing
|
41
58
|
|
42
59
|
1. Fork it
|
data/amqparty.gemspec
CHANGED
@@ -19,12 +19,11 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_dependency "httparty", ">=0.10.0"
|
22
|
-
spec.add_dependency "rack-amqp-client"
|
22
|
+
spec.add_dependency "rack-amqp-client", ">=0.0.3"
|
23
23
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.3"
|
25
25
|
spec.add_development_dependency "rake"
|
26
|
-
spec.add_development_dependency "rspec"
|
27
|
-
spec.add_development_dependency "emoji-rspec"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
28
27
|
spec.add_development_dependency "simplecov"
|
29
28
|
spec.add_development_dependency "pry"
|
30
29
|
end
|
data/lib/amqparty.rb
CHANGED
@@ -28,18 +28,40 @@ module AMQParty
|
|
28
28
|
def self.perform_request(http_method, path, options, &block)
|
29
29
|
raise AMQParty::UnconfiguredError.new if configuration.amqp_host.nil?
|
30
30
|
|
31
|
-
options = default_options.dup.merge(options)
|
31
|
+
options = configuration.default_options.dup.merge(options)
|
32
32
|
# TODO cookies support
|
33
33
|
path = "#{path}/" if path =~ /\Aamqp?:\/\/([^\/])+\Z/
|
34
34
|
Request.new(http_method, path, options).perform(&block)
|
35
35
|
end
|
36
36
|
|
37
|
-
def self.default_options
|
38
|
-
{amqp_client_options: {host: configuration.amqp_host}}
|
39
|
-
end
|
40
|
-
|
41
37
|
class Configuration
|
42
38
|
attr_accessor :amqp_host
|
39
|
+
attr_accessor :port
|
40
|
+
attr_accessor :request_timeout
|
41
|
+
attr_accessor :tls_ca_certificates
|
42
|
+
attr_accessor :verify_peer
|
43
|
+
attr_accessor :tls
|
44
|
+
attr_accessor :tls_key
|
45
|
+
attr_accessor :tls_cert
|
46
|
+
attr_accessor :username
|
47
|
+
attr_accessor :password
|
48
|
+
|
49
|
+
def default_options
|
50
|
+
{
|
51
|
+
amqp_client_options: {
|
52
|
+
host: amqp_host,
|
53
|
+
port: port || 5672,
|
54
|
+
tls_ca_certificates: tls_ca_certificates || [],
|
55
|
+
verify_peer: verify_peer || false,
|
56
|
+
tls: tls || false,
|
57
|
+
tls_key: tls_key,
|
58
|
+
tls_cert: tls_cert,
|
59
|
+
username: username || 'guest',
|
60
|
+
password: password || 'guest'
|
61
|
+
},
|
62
|
+
request_timeout: request_timeout || 5
|
63
|
+
}
|
64
|
+
end
|
43
65
|
end
|
44
66
|
end
|
45
67
|
|
data/lib/amqparty/request.rb
CHANGED
@@ -13,26 +13,40 @@ module AMQParty
|
|
13
13
|
chunked_body = nil
|
14
14
|
|
15
15
|
path = "#{uri.host}#{uri.path}"
|
16
|
+
path = "#{path}?#{uri.query}" if uri.query
|
16
17
|
connection_options = options[:amqp_client_options]
|
17
|
-
|
18
|
-
#connection_options[:user] = uri.user if uri.user
|
19
|
-
#connection_options[:password] = uri.password if uri.password
|
18
|
+
async = options[:async]
|
20
19
|
|
21
20
|
Rack::AMQP::Client.with_client(connection_options) do |client|
|
22
21
|
method_name = http_method.name.split(/::/).last.upcase
|
23
22
|
body = options[:body] || ""
|
24
|
-
|
23
|
+
|
24
|
+
if body.is_a?(Hash)
|
25
|
+
body = HTTParty::HashConversions.to_params(options[:body])
|
26
|
+
end
|
27
|
+
|
25
28
|
headers = options[:headers] || {}
|
29
|
+
timeout = options[:request_timeout]
|
26
30
|
|
27
|
-
response = client.request(path, {
|
31
|
+
response = client.request(path, {
|
32
|
+
body: body,
|
33
|
+
http_method: method_name,
|
34
|
+
headers: headers,
|
35
|
+
timeout: timeout,
|
36
|
+
async: !!async
|
37
|
+
}
|
38
|
+
)
|
28
39
|
|
29
|
-
|
30
|
-
|
40
|
+
response_code = response.response_code
|
41
|
+
klass = Net::HTTPResponse.send(:response_class, response_code.to_s)
|
42
|
+
http_response = klass.new("1.1", response_code, "Found")
|
31
43
|
response.headers.each_pair do |key, value|
|
32
44
|
http_response.add_field key, value
|
33
45
|
end
|
34
46
|
http_response.body = response.payload
|
35
|
-
|
47
|
+
|
48
|
+
# TODO GIANT HACK
|
49
|
+
http_response.send(:instance_eval, "def body; @body; end")
|
36
50
|
self.last_response = http_response
|
37
51
|
end
|
38
52
|
|
data/lib/amqparty/version.rb
CHANGED
@@ -38,34 +38,80 @@ describe AMQParty do
|
|
38
38
|
end
|
39
39
|
expect(AMQParty.configuration.amqp_host).to eq('localhost')
|
40
40
|
end
|
41
|
+
|
42
|
+
it "allows configuration of a request timeout" do
|
43
|
+
AMQParty.configure do |c|
|
44
|
+
c.request_timeout = 10
|
45
|
+
end
|
46
|
+
expect(AMQParty.configuration.request_timeout).to eq(10)
|
47
|
+
end
|
48
|
+
|
41
49
|
end
|
42
50
|
|
43
51
|
describe '#get' do
|
44
52
|
|
53
|
+
before :each do
|
54
|
+
AMQParty.configure do |c|
|
55
|
+
c.amqp_host = 'localhost'
|
56
|
+
c.request_timeout = 55
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
let(:client) { double('Rack::AMQP::Client') }
|
61
|
+
let(:params) {
|
62
|
+
{
|
63
|
+
body: '',
|
64
|
+
http_method: 'GET',
|
65
|
+
headers: {},
|
66
|
+
timeout: 55,
|
67
|
+
async: false
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
let(:client_params) {
|
72
|
+
{
|
73
|
+
host: 'localhost',
|
74
|
+
port: 5672,
|
75
|
+
tls_ca_certificates: [],
|
76
|
+
verify_peer: false,
|
77
|
+
tls: false,
|
78
|
+
tls_key: nil,
|
79
|
+
tls_cert: nil,
|
80
|
+
username: 'guest',
|
81
|
+
password: 'guest'
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
45
85
|
it_behaves_like 'all request methods', 'get'
|
46
86
|
|
47
87
|
it 'calls Rack::AMQP::Client with the proper options' do
|
48
88
|
# this method is a lot of stubbing, but I guess it's ok?
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
fake_response.stub(:response_code) { 200 }
|
59
|
-
fake_response.stub(:headers) { {'response_header' => 'foo'} }
|
60
|
-
fake_response.stub(:payload) { 'Hello World' }
|
61
|
-
fake_response
|
62
|
-
end
|
63
|
-
fake_client
|
64
|
-
}
|
65
|
-
expect(Rack::AMQP::Client).to receive(:client).with({host: 'localhost'}).and_return(&fake_with_client)
|
89
|
+
expect(client).to receive(:request).with('test.simple/users.json', params) do
|
90
|
+
response = double()
|
91
|
+
allow(response).to receive(:response_code) { 200 }
|
92
|
+
allow(response).to receive(:headers) { {'response_header' => 'foo'} }
|
93
|
+
allow(response).to receive(:payload) { 'Hello World' }
|
94
|
+
response
|
95
|
+
end
|
96
|
+
|
97
|
+
expect(Rack::AMQP::Client).to receive(:client).with(client_params).and_return(client)
|
66
98
|
AMQParty.get('amqp://test.simple/users.json')
|
67
99
|
end
|
68
100
|
|
101
|
+
it 'calls Rack::AMQP::Client with the correct path' do
|
102
|
+
# this mthod is a lot of stubbing, but I guess it's ok?
|
103
|
+
expect(client).to receive(:request).with('test.simple/users.json?login=foo', params) do
|
104
|
+
response = double()
|
105
|
+
allow(response).to receive(:response_code) { 200 }
|
106
|
+
allow(response).to receive(:headers) { {'response_header' => 'foo'} }
|
107
|
+
allow(response).to receive(:payload) { 'Hello World' }
|
108
|
+
response
|
109
|
+
end
|
110
|
+
|
111
|
+
expect(Rack::AMQP::Client).to receive(:client).with(client_params).and_return(client)
|
112
|
+
AMQParty.get('amqp://test.simple/users.json?login=foo')
|
113
|
+
end
|
114
|
+
|
69
115
|
end
|
70
116
|
|
71
117
|
it "integrates", brittle: true do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amqparty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Szmajda
|
@@ -9,118 +9,104 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-11-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- -
|
18
|
+
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: 0.10.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- -
|
25
|
+
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: 0.10.0
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: rack-amqp-client
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- -
|
32
|
+
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
34
|
+
version: 0.0.3
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- -
|
39
|
+
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
41
|
+
version: 0.0.3
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: bundler
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- - ~>
|
46
|
+
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
48
|
version: '1.3'
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- - ~>
|
53
|
+
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '1.3'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: rake
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- -
|
60
|
+
- - ">="
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '0'
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- -
|
67
|
+
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '0'
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: rspec
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- -
|
74
|
+
- - "~>"
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version: '0'
|
76
|
+
version: '3.0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
|
-
- -
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
version: '0'
|
84
|
-
- !ruby/object:Gem::Dependency
|
85
|
-
name: emoji-rspec
|
86
|
-
requirement: !ruby/object:Gem::Requirement
|
87
|
-
requirements:
|
88
|
-
- - '>='
|
81
|
+
- - "~>"
|
89
82
|
- !ruby/object:Gem::Version
|
90
|
-
version: '0'
|
91
|
-
type: :development
|
92
|
-
prerelease: false
|
93
|
-
version_requirements: !ruby/object:Gem::Requirement
|
94
|
-
requirements:
|
95
|
-
- - '>='
|
96
|
-
- !ruby/object:Gem::Version
|
97
|
-
version: '0'
|
83
|
+
version: '3.0'
|
98
84
|
- !ruby/object:Gem::Dependency
|
99
85
|
name: simplecov
|
100
86
|
requirement: !ruby/object:Gem::Requirement
|
101
87
|
requirements:
|
102
|
-
- -
|
88
|
+
- - ">="
|
103
89
|
- !ruby/object:Gem::Version
|
104
90
|
version: '0'
|
105
91
|
type: :development
|
106
92
|
prerelease: false
|
107
93
|
version_requirements: !ruby/object:Gem::Requirement
|
108
94
|
requirements:
|
109
|
-
- -
|
95
|
+
- - ">="
|
110
96
|
- !ruby/object:Gem::Version
|
111
97
|
version: '0'
|
112
98
|
- !ruby/object:Gem::Dependency
|
113
99
|
name: pry
|
114
100
|
requirement: !ruby/object:Gem::Requirement
|
115
101
|
requirements:
|
116
|
-
- -
|
102
|
+
- - ">="
|
117
103
|
- !ruby/object:Gem::Version
|
118
104
|
version: '0'
|
119
105
|
type: :development
|
120
106
|
prerelease: false
|
121
107
|
version_requirements: !ruby/object:Gem::Requirement
|
122
108
|
requirements:
|
123
|
-
- -
|
109
|
+
- - ">="
|
124
110
|
- !ruby/object:Gem::Version
|
125
111
|
version: '0'
|
126
112
|
description: AMQP-HTTP compliant replacement for HTTParty
|
@@ -130,9 +116,9 @@ executables: []
|
|
130
116
|
extensions: []
|
131
117
|
extra_rdoc_files: []
|
132
118
|
files:
|
133
|
-
- .gitignore
|
134
|
-
- .rspec
|
135
|
-
- .travis.yml
|
119
|
+
- ".gitignore"
|
120
|
+
- ".rspec"
|
121
|
+
- ".travis.yml"
|
136
122
|
- CHANGELOG.md
|
137
123
|
- Gemfile
|
138
124
|
- LICENSE
|
@@ -156,12 +142,12 @@ require_paths:
|
|
156
142
|
- lib
|
157
143
|
required_ruby_version: !ruby/object:Gem::Requirement
|
158
144
|
requirements:
|
159
|
-
- -
|
145
|
+
- - ">="
|
160
146
|
- !ruby/object:Gem::Version
|
161
147
|
version: '0'
|
162
148
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
163
149
|
requirements:
|
164
|
-
- -
|
150
|
+
- - ">="
|
165
151
|
- !ruby/object:Gem::Version
|
166
152
|
version: '0'
|
167
153
|
requirements: []
|