muxer 0.0.3

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: d719948cdb50146fa727e57fce8edd5fe2782369
4
+ data.tar.gz: 08f76ec167b1d6865ff23184a0c147b8e0f989a6
5
+ SHA512:
6
+ metadata.gz: 4ee194b036ffa44f81dd862001ae9d4cc22b12e18c3f8560b8973aa03fbdaa09a45e284725de3ef3edaf877ec521d6bb4b89bd0b4c596cf9b587dcbe13c553de
7
+ data.tar.gz: e81632546f0b0a47bb7cb539607060358f3d853886f9c4c03ac6ae9cf9e34b9ab14c14f274e7752b2a0bd2a4df5bd9d2829e34daf4f91e0428491bff7890f644
data/.gitignore ADDED
@@ -0,0 +1,22 @@
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
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in muxer.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Chris MacNaughton
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,29 @@
1
+ # Muxer
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'muxer'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install muxer
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/muxer/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,24 @@
1
+ module Muxer
2
+ class Multiplexer
3
+
4
+ def initialize
5
+ @requests = []
6
+ end
7
+
8
+ def add_url(url)
9
+ @requests << Request.new do
10
+ url = url
11
+ end
12
+ end
13
+
14
+ def execute
15
+ responses = []
16
+ looping = true
17
+ EventMachine.run do
18
+ EM.stop
19
+ end
20
+
21
+ responses
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,29 @@
1
+ module Muxer
2
+ class Request
3
+ attr_accessor :url, :timeout, :headers
4
+ attr_reader :method
5
+
6
+ def initialize
7
+ @method = :GET
8
+ @timeout = nil
9
+ @headers = {}
10
+ end
11
+
12
+ def method=(method)
13
+ method = method.downcase.to_sym
14
+
15
+ @method = method.upcase if [:get, :post, :head, :options, :put, :delete].include? method
16
+ end
17
+
18
+ def process!
19
+ http = EventMachine::HttpRequest.new(url)
20
+ http.public_send(method,
21
+ head: headers,
22
+ connect_timeout: timeout,
23
+ inactivity_timeout: timeout
24
+ )
25
+
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module Muxer
2
+ VERSION = '0.0.3'
3
+ end
data/lib/muxer.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'eventmachine'
2
+ require 'em-http'
3
+
4
+ require 'muxer/version'
5
+ require 'muxer/request'
6
+ require 'muxer/multiplexer'
7
+
8
+ module Muxer
9
+ def self.execute
10
+ multiplexer = Multiplexer.new
11
+
12
+ yield multiplexer if block_given?
13
+
14
+ multiplexer.execute
15
+ end
16
+ end
data/muxer.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'muxer/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "muxer"
8
+ spec.version = Muxer::VERSION
9
+ spec.authors = ["Chris MacNaughton"]
10
+ spec.email = ["chmacnaughton@gmail.com"]
11
+ spec.summary = %q{Muxer is a web request multiplexer}
12
+ spec.description = %q{Muxer allows timeouts to be set for each request made in addition to a global timeout for a set of requests.}
13
+ spec.homepage = "https://github.com/ChrisMacNaughton/muxer"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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_runtime_dependency "eventmachine", "~>1.0"
22
+ spec.add_runtime_dependency "em-http-request", "~>1.1"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.6"
25
+ spec.add_development_dependency "rake", "~>10.4"
26
+ spec.add_development_dependency "rspec", "~>3.2"
27
+ spec.add_development_dependency "vcr", "~>2.9"
28
+ spec.add_development_dependency "pry", "~>0.10"
29
+ end
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Muxer::Multiplexer do
4
+ let(:request) { Muxer::Multiplexer.new }
5
+
6
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Muxer::Request do
4
+ let(:request) { Muxer::Request.new }
5
+
6
+ it 'has a url' do
7
+ request.url = 'https://www.google.com'
8
+
9
+ expect(request.url).to eq('https://www.google.com')
10
+ end
11
+
12
+ it 'has a timeout' do
13
+ request.timeout = 10
14
+
15
+ expect(request.timeout).to eq(10)
16
+ end
17
+
18
+ it 'has headers' do
19
+ request.headers[:api_key] = "test1234"
20
+
21
+ expect(request.headers).to be_kind_of(Hash)
22
+ expect(request.headers).to eq({api_key: 'test1234'})
23
+ end
24
+
25
+ describe :method do
26
+ it 'has a valid method' do
27
+ request.method = 'POST'
28
+
29
+ expect(request.method).to eq(:POST)
30
+ end
31
+
32
+ it 'does not have an invalid method' do
33
+ request.method = "WRONG"
34
+
35
+ expect(request.method).to eq(:GET)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Muxer, "execute" do
4
+
5
+ it 'can make a web request' do
6
+ response = Muxer.execute do |muxer|
7
+ muxer.add_url "https://www.google.com"
8
+ end
9
+
10
+ expect(response).to be_kind_of(Array)
11
+ end
12
+
13
+
14
+ end
@@ -0,0 +1,81 @@
1
+ require 'vcr'
2
+ require File.join(__FILE__, "..","..","lib","muxer")
3
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
4
+ RSpec.configure do |config|
5
+ # rspec-expectations config goes here. You can use an alternate
6
+ # assertion/expectation library such as wrong or the stdlib/minitest
7
+ # assertions if you prefer.
8
+ config.expect_with :rspec do |expectations|
9
+ # This option will default to `true` in RSpec 4. It makes the `description`
10
+ # and `failure_message` of custom matchers include text for helper methods
11
+ # defined using `chain`, e.g.:
12
+ # be_bigger_than(2).and_smaller_than(4).description
13
+ # # => "be bigger than 2 and smaller than 4"
14
+ # ...rather than:
15
+ # # => "be bigger than 2"
16
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
17
+ end
18
+
19
+ # rspec-mocks config goes here. You can use an alternate test double
20
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
21
+ config.mock_with :rspec do |mocks|
22
+ # Prevents you from mocking or stubbing a method that does not exist on
23
+ # a real object. This is generally recommended, and will default to
24
+ # `true` in RSpec 4.
25
+ mocks.verify_partial_doubles = true
26
+ end
27
+
28
+
29
+ VCR.configure do |c|
30
+ c.cassette_library_dir = 'spec/cassettes'
31
+ # c.hook_into :webmock
32
+ end
33
+ # The settings below are suggested to provide a good initial experience
34
+ # with RSpec, but feel free to customize to your heart's content.
35
+
36
+ # These two settings work together to allow you to limit a spec run
37
+ # to individual examples or groups you care about by tagging them with
38
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
39
+ # get run.
40
+ config.filter_run :focus
41
+ config.run_all_when_everything_filtered = true
42
+
43
+ # Limits the available syntax to the non-monkey patched syntax that is
44
+ # recommended. For more details, see:
45
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
46
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
47
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
48
+ config.disable_monkey_patching!
49
+
50
+ # This setting enables warnings. It's recommended, but in some cases may
51
+ # be too noisy due to issues in dependencies.
52
+ config.warnings = true
53
+
54
+ # Many RSpec users commonly either run the entire suite or an individual
55
+ # file, and it's useful to allow more verbose output when running an
56
+ # individual spec file.
57
+ if config.files_to_run.one?
58
+ # Use the documentation formatter for detailed output,
59
+ # unless a formatter has already been configured
60
+ # (e.g. via a command-line flag).
61
+ config.default_formatter = 'doc'
62
+ end
63
+
64
+ # Print the 10 slowest examples and example groups at the
65
+ # end of the spec run, to help surface which specs are running
66
+ # particularly slow.
67
+ config.profile_examples = 10
68
+
69
+ # Run specs in random order to surface order dependencies. If you find an
70
+ # order dependency and want to debug it, you can fix the order by providing
71
+ # the seed, which is printed after each run.
72
+ # --seed 1234
73
+ config.order = :random
74
+
75
+ # Seed global randomization in this process using the `--seed` CLI option.
76
+ # Setting this allows you to use `--seed` to deterministically reproduce
77
+ # test failures related to randomization by passing the same `--seed` value
78
+ # as the one that triggered the failure.
79
+ Kernel.srand config.seed
80
+
81
+ end
metadata ADDED
@@ -0,0 +1,162 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: muxer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Chris MacNaughton
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: eventmachine
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: em-http-request
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '10.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '10.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '3.2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '3.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '2.9'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '2.9'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: '0.10'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: '0.10'
111
+ description: Muxer allows timeouts to be set for each request made in addition to
112
+ a global timeout for a set of requests.
113
+ email:
114
+ - chmacnaughton@gmail.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - .gitignore
120
+ - .rspec
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - lib/muxer.rb
126
+ - lib/muxer/multiplexer.rb
127
+ - lib/muxer/request.rb
128
+ - lib/muxer/version.rb
129
+ - muxer.gemspec
130
+ - spec/muxer/multiplexer_spec.rb
131
+ - spec/muxer/request_spec.rb
132
+ - spec/muxer_spec.rb
133
+ - spec/spec_helper.rb
134
+ homepage: https://github.com/ChrisMacNaughton/muxer
135
+ licenses:
136
+ - MIT
137
+ metadata: {}
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - '>='
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.2.2
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: Muxer is a web request multiplexer
158
+ test_files:
159
+ - spec/muxer/multiplexer_spec.rb
160
+ - spec/muxer/request_spec.rb
161
+ - spec/muxer_spec.rb
162
+ - spec/spec_helper.rb