amqparty 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d5da03512190acc7740d2ea81063633a39fd7e5d
4
+ data.tar.gz: 01ddc064677659835cd11b1b3274b8147d52b9fd
5
+ SHA512:
6
+ metadata.gz: f2bc2d849584b93ebdcf4a119e578ed6dede21f2198837a5e98fece0f1dbf2cb7ad8272c4d13b74d45cf927cc18422490f5934ac2ee3e0296454a8f70e588e50
7
+ data.tar.gz: f782b39950d4f76eeae2fce9abdd618abc724ee9e2c04e2a3d7a91d43ea98f4650971b853dd9cf131d6a258c53804e9f3c296f4a384dae3c9a9306bd83cff684
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --require emoji-rspec
2
+ --format hearts
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
4
+ - 2.0.0
5
+ - 1.9.3
6
+ - 1.9.2
7
+ - jruby-19mode # JRuby in 1.9 mode
8
+ - ruby-head
9
+ - jruby-head
10
+ - rbx
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # 0.0.2
2
+
3
+ * Initial public version
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in amqparty.gemspec
4
+ #gem "rack-amqp-client", git: "git@github.com:rack-amqp/rack-amqp-client.git"
5
+ gem "rack-amqp-client"
6
+ gemspec
7
+
8
+ platforms :rbx do
9
+ gem 'racc'
10
+ gem 'rubysl', '~> 2.0'
11
+ gem 'psych'
12
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Optoro, Inc
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Joshua Szmajda
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # Amqparty
2
+
3
+ A AMQP-HTTP compliant modification of HTTParty for use with jackalope
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'amqparty'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install amqparty
18
+
19
+ ## Usage
20
+
21
+ First configure AMQParty to connect to your AMQP broker (RabbitMQ or
22
+ other)
23
+
24
+ ```ruby
25
+ AMQParty.configure do |c|
26
+ c.amqp_host = 'localhost'
27
+ end
28
+ ```
29
+
30
+ Then you can use it to talk to your service:
31
+
32
+ ```ruby
33
+ AMQParty.get("amqp://queue.name/path")
34
+ ```
35
+
36
+ Uri scheme must be amqp or amqps. Hostname is actually the queue name.
37
+
38
+ Post and put also work. Delete, head, options are untested.
39
+
40
+ ## Contributing
41
+
42
+ 1. Fork it
43
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
45
+ 4. Push to the branch (`git push origin my-new-feature`)
46
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/amqparty.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'amqparty/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "amqparty"
8
+ spec.version = AMQParty::VERSION
9
+ spec.authors = ["Joshua Szmajda", "John Nestoriak"]
10
+ spec.email = ["josh@optoro.com"]
11
+ spec.description = %q{AMQP-HTTP compliant replacement for HTTParty}
12
+ spec.summary = spec.description
13
+ spec.homepage = "https://github.com/rack-amqp/amqparty"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "httparty", ">=0.10.0"
22
+ spec.add_dependency "rack-amqp-client"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "emoji-rspec"
28
+ spec.add_development_dependency "simplecov"
29
+ spec.add_development_dependency "pry"
30
+ end
@@ -0,0 +1,43 @@
1
+ module AMQParty
2
+ class AMQPartyError < StandardError; end
3
+ class UnsupportedURISchemeError < AMQPartyError; end
4
+ class UnconfiguredError < AMQPartyError; end
5
+
6
+ class Request < HTTParty::Request
7
+ def perform(&block)
8
+ unless %w{amqp}.include? uri.scheme.to_s.downcase
9
+ raise UnsupportedURISchemeError, "#{uri.scheme} must be amqp"
10
+ end
11
+ validate
12
+ setup_raw_request
13
+ chunked_body = nil
14
+
15
+ path = "#{uri.host}#{uri.path}"
16
+ 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
20
+
21
+ Rack::AMQP::Client.with_client(connection_options) do |client|
22
+ method_name = http_method.name.split(/::/).last.upcase
23
+ body = options[:body] || ""
24
+ body = HTTParty::HashConversions.to_params(options[:body]) if body.is_a?(Hash)
25
+ headers = options[:headers] || {}
26
+
27
+ response = client.request(path, {body: body, http_method: method_name, headers: headers, timeout: 5})
28
+
29
+ klass = Net::HTTPResponse.send(:response_class,response.response_code.to_s)
30
+ http_response = klass.new("1.1", response.response_code, "Found")
31
+ response.headers.each_pair do |key, value|
32
+ http_response.add_field key, value
33
+ end
34
+ http_response.body = response.payload
35
+ http_response.send(:instance_eval, "def body; @body; end") # TODO GIANT HACK
36
+ self.last_response = http_response
37
+ end
38
+
39
+ handle_deflation unless http_method == Net::HTTP::Head
40
+ handle_response(chunked_body, &block)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module AMQParty
2
+ VERSION = "0.0.2"
3
+ end
data/lib/amqparty.rb ADDED
@@ -0,0 +1,48 @@
1
+ require 'net/http'
2
+ require 'httparty'
3
+ require 'rack/amqp/client'
4
+
5
+ module AMQParty
6
+
7
+ class << self
8
+ SUPPORTED_HTTP_METHODS = %w{get post put delete head options}
9
+ SUPPORTED_HTTP_METHODS.each do |method|
10
+ eval <<-EOT
11
+ def #{method}(path, options={}, &block)
12
+ perform_request Net::HTTP::#{method.to_s[0...1].upcase}#{method.to_s[1..-1]}, path, options, &block
13
+ end
14
+ EOT
15
+ end
16
+
17
+ def configuration
18
+ @configuration ||= Configuration.new
19
+ end
20
+
21
+ def configure(&block)
22
+ yield configuration
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def self.perform_request(http_method, path, options, &block)
29
+ raise AMQParty::UnconfiguredError.new if configuration.amqp_host.nil?
30
+
31
+ options = default_options.dup.merge(options)
32
+ # TODO cookies support
33
+ path = "#{path}/" if path =~ /\Aamqp?:\/\/([^\/])+\Z/
34
+ Request.new(http_method, path, options).perform(&block)
35
+ end
36
+
37
+ def self.default_options
38
+ {amqp_client_options: {host: configuration.amqp_host}}
39
+ end
40
+
41
+ class Configuration
42
+ attr_accessor :amqp_host
43
+ end
44
+ end
45
+
46
+ require 'amqparty/version'
47
+ require 'amqparty/request'
48
+ #require 'amqparty/connection'
@@ -0,0 +1,81 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples_for 'all request methods' do |meth|
4
+ it 'explodes gracefully when missing a protocol' do
5
+ test = -> {
6
+ AMQParty.send(meth, 'test.simple')
7
+ }
8
+ expect(test).to raise_error(AMQParty::UnsupportedURISchemeError)
9
+ end
10
+
11
+ it 'blows up when not configured to talk to a amqp broker' do
12
+ AMQParty.instance_variable_set('@configuration', AMQParty::Configuration.new)
13
+ test = -> {
14
+ AMQParty.send(meth, 'amqp://test.simple')
15
+ }
16
+ expect(AMQParty.configuration.amqp_host).to be_nil
17
+ expect(test).to raise_error(AMQParty::UnconfiguredError)
18
+ end
19
+ end
20
+
21
+ describe AMQParty do
22
+ describe '#configure' do
23
+ it "yields a configuration object" do
24
+ x = nil
25
+ AMQParty.configure do |c|
26
+ x = c
27
+ end
28
+ expect(x).to_not be_nil
29
+ end
30
+
31
+ it "allows reading the current configuration" do
32
+ expect(AMQParty.configuration).to_not be_nil
33
+ end
34
+
35
+ it "allows configuration of the rabbit host" do
36
+ AMQParty.configure do |c|
37
+ c.amqp_host = 'localhost'
38
+ end
39
+ expect(AMQParty.configuration.amqp_host).to eq('localhost')
40
+ end
41
+ end
42
+
43
+ describe '#get' do
44
+
45
+ it_behaves_like 'all request methods', 'get'
46
+
47
+ it 'calls Rack::AMQP::Client with the proper options' do
48
+ # this method is a lot of stubbing, but I guess it's ok?
49
+ fake_with_client = -> {
50
+ fake_client = double()
51
+ fake_client.should_receive(:request).with('test.simple/users.json', {
52
+ body: '',
53
+ http_method: 'GET',
54
+ headers: {},
55
+ timeout: 5
56
+ }) do
57
+ fake_response = double()
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)
66
+ AMQParty.get('amqp://test.simple/users.json')
67
+ end
68
+
69
+ end
70
+
71
+ it "integrates", brittle: true do
72
+ pending "Some better way to test integrations"
73
+ Timeout.timeout(3) do
74
+ AMQParty.configure do |c|
75
+ c.amqp_host = 'localhost'
76
+ end
77
+ response = AMQParty.get('amqp://test.simple/users.json')
78
+ expect(response.to_json).to eq("[{\"id\":1,\"login\":\"someguy\",\"password\":\"awesomenesssss\",\"created_at\":\"2013-12-07T17:11:45.518Z\",\"updated_at\":\"2013-12-07T17:11:45.518Z\"},{\"id\":2,\"login\":\"Hi\",\"password\":\"There\",\"created_at\":\"2014-03-30T18:31:21.106Z\",\"updated_at\":\"2014-03-30T18:31:21.106Z\"}]")
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe AMQParty do
4
+ it 'exists' do
5
+ AMQParty
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ require 'rspec'
2
+ require 'pry'
3
+ require 'amqparty'
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: amqparty
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Joshua Szmajda
8
+ - John Nestoriak
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-04-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: 0.10.0
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: 0.10.0
28
+ - !ruby/object:Gem::Dependency
29
+ name: rack-amqp-client
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: bundler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: '1.3'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: '1.3'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rake
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
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
+ - - '>='
89
+ - !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'
98
+ - !ruby/object:Gem::Dependency
99
+ name: simplecov
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: pry
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: AMQP-HTTP compliant replacement for HTTParty
127
+ email:
128
+ - josh@optoro.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - .gitignore
134
+ - .rspec
135
+ - .travis.yml
136
+ - CHANGELOG.md
137
+ - Gemfile
138
+ - LICENSE
139
+ - LICENSE.txt
140
+ - README.md
141
+ - Rakefile
142
+ - amqparty.gemspec
143
+ - lib/amqparty.rb
144
+ - lib/amqparty/request.rb
145
+ - lib/amqparty/version.rb
146
+ - spec/amqparty_classmethods_spec.rb
147
+ - spec/amqparty_spec.rb
148
+ - spec/spec_helper.rb
149
+ homepage: https://github.com/rack-amqp/amqparty
150
+ licenses:
151
+ - MIT
152
+ metadata: {}
153
+ post_install_message:
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - '>='
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ requirements: []
168
+ rubyforge_project:
169
+ rubygems_version: 2.2.2
170
+ signing_key:
171
+ specification_version: 4
172
+ summary: AMQP-HTTP compliant replacement for HTTParty
173
+ test_files:
174
+ - spec/amqparty_classmethods_spec.rb
175
+ - spec/amqparty_spec.rb
176
+ - spec/spec_helper.rb