http_machinegun 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
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
+ coverage
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in http_machinegun.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem "pry-debugger", "~> 0.2.1"
8
+ gem 'rspec'
9
+ gem 'webmock'
10
+
11
+ gem 'rb-fsevent'
12
+ gem 'guard-rspec'
13
+ gem 'growl'
14
+
15
+ gem 'simplecov', :require => false
16
+ gem 'simplecov-rcov', :require => false
17
+ end
data/Guardfile ADDED
@@ -0,0 +1,24 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec' do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+
17
+ # Capybara features specs
18
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
19
+
20
+ # Turnip features and steps
21
+ watch(%r{^spec/acceptance/(.+)\.feature$})
22
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23
+ end
24
+
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 y.fujii
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,48 @@
1
+ HttpMachinegun
2
+ ======================
3
+ It sends data (or get data) via http with The number-of-times thread.
4
+
5
+ install
6
+ ------
7
+ `gem install http_machinegun`
8
+
9
+ usage
10
+ ------
11
+ ```ruby
12
+ http_machinegun fire -u #{url}
13
+ ```
14
+ ###example
15
+
16
+ ```ruby
17
+ #simple get request by one times
18
+ http_machinegun fire -u localhost
19
+
20
+ #get request to 3000 port option by one times
21
+ http_machinegun fire -u localhost -p 3000
22
+
23
+ #post request with data by one times
24
+ http_machinegun fire -u localhost -d abc -m post
25
+ #or
26
+ http_machinegun fire -u localhost -d data.txt
27
+
28
+ #get request with data by ten times
29
+ http_machinegun fire -u localhost -t 10
30
+ ```
31
+
32
+ ###options
33
+ * -u, --url
34
+ target url
35
+
36
+ * -p, --port
37
+ target port
38
+
39
+ * -d, --data_or_file
40
+ string or file path
41
+
42
+ * -m, --method
43
+ http method (get,post,put,delete )
44
+
45
+ * -t, --thread_number
46
+ request number of times you want
47
+
48
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'http_machinegun'
4
+ HttpMachinegun::Machinegun.start
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/http_machinegun/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["y.fujii"]
6
+ gem.email = ["ishikurasakura@gmail.com"]
7
+ gem.description = %q{http client with thread}
8
+ gem.summary = %q{send data with thread}
9
+ gem.homepage = "https://github.com/YoshitsuguFujii/http_machinegun"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "http_machinegun"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = HttpMachinegun::VERSION
17
+
18
+ gem.add_dependency 'thor'
19
+ gem.add_dependency 'parallel'
20
+ end
@@ -0,0 +1,44 @@
1
+ require "thor"
2
+ require "pry"
3
+ #require 'benchmark'
4
+ require 'parallel'
5
+ require "http_machinegun/data"
6
+ require "http_machinegun/client"
7
+ require "http_machinegun/version"
8
+
9
+ # 引数 url port threadcount data
10
+ module HttpMachinegun
11
+
12
+ class Machinegun < Thor
13
+ desc "fire", "send data A number of specified thread "
14
+ method_option :url , :type => :string, :required => true, :aliases => "-u"
15
+ method_option :port, :type => :numeric, :aliases => "-p"
16
+ method_option :data_or_file_path, :type => :string, :default => "", :aliases => "-d"
17
+ method_option :method, :type => :string, :default => "get", :aliases => "-m"
18
+ method_option :thread_number , :type => :numeric, :default => 1, :aliases => "-t"
19
+
20
+ ##
21
+ #
22
+ def fire
23
+ data = Data.new(options[:data_or_file_path])
24
+ client = Client.new(options[:url], options[:port], data)
25
+ client.http_method(options[:method])
26
+ client.set_body
27
+
28
+ clients = Array.new( options[:thread_number] , client)
29
+ results = Parallel.each(clients, :in_threads => Parallel.processor_count) {|url|
30
+ res = client.execute
31
+ if res.code =~ /^[^2]..$/
32
+ say("http_status_code:" + res.code, :red)
33
+ else
34
+ say("http_status_code:" + res.code, :green)
35
+ end
36
+
37
+ res
38
+ }
39
+
40
+ results
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,82 @@
1
+ # coding: utf-8
2
+
3
+ require 'net/http'
4
+ require 'uri'
5
+ require 'json'
6
+
7
+ module HttpMachinegun
8
+ class Client
9
+ DEFAULT_PORT = 80
10
+
11
+ BASE_HEADERS = {
12
+ #'content-type'=>'application/json'
13
+ 'content-type'=>'text/plain'
14
+ }
15
+
16
+ def initialize(url, port, send_data = "")
17
+ raise ArgumentError if url.nil?
18
+
19
+ @url = URI.parse(url)
20
+ @port = port || @url.port || DEFAULT_PORT
21
+ @send_data = send_data
22
+ end
23
+
24
+ def basic_auth(username, password)
25
+ if username && password
26
+ @request_body.basic_auth username, password
27
+ else
28
+ raise ArgumentError
29
+ end
30
+
31
+ self
32
+ rescue NoMethodError => ex
33
+ puts "【error】set http medhod type before call"
34
+ #@request_body = Net::HTTP::Get.new('/')
35
+ #retry
36
+ raise ex
37
+ end
38
+
39
+ def http_method(method)
40
+ path = @url.path.empty? ? "/" : @url.path
41
+ case method.to_sym
42
+ when :get
43
+ @request_body = Net::HTTP::Get.new(path)
44
+ when :post
45
+ @request_body = Net::HTTP::Post.new(path, BASE_HEADERS)
46
+ when :put
47
+ @request_body = Net::HTTP::Put.new(path, BASE_HEADERS)
48
+ when :delete
49
+ @request_body = Net::HTTP::Delete.new(path)
50
+ else
51
+ @request_body = Net::HTTP::Get.new(path)
52
+ end
53
+
54
+ self
55
+ end
56
+
57
+ def set_body
58
+ @request_body.body = @send_data.to_json
59
+
60
+ self
61
+ end
62
+
63
+ def execute()
64
+ Net::HTTP.start(@url.host, @port) do |http|
65
+ response = http.request(@request_body)
66
+ if response.code =~ /^[^2]..$/
67
+ case response.code
68
+ when '400'
69
+ "BadRequestException"
70
+ when '401'
71
+ "UnauthorizedException"
72
+ when '404'
73
+ "NotFoundException"
74
+ else
75
+ end
76
+ end
77
+
78
+ response
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+
3
+ module HttpMachinegun
4
+ class Data
5
+
6
+ attr_accessor :data
7
+
8
+ def initialize(_data)
9
+ file = Pathname.new(_data)
10
+ self.data = if file.exist?
11
+ file.open.read
12
+ else
13
+ _data
14
+ end
15
+ end
16
+
17
+ def to_s
18
+ self.data
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module HttpMachinegun
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,87 @@
1
+ # coding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe HttpMachinegun::Client do
5
+ let(:url) { "http://example.com" }
6
+ let(:url_fully) { "http://example.com:8080/" }
7
+ let(:port) { 8080 }
8
+ let(:send_data) { "abcdefg" }
9
+ before do
10
+ @client = HttpMachinegun::Client.new(url, port, send_data)
11
+ stub_request(:get , url_fully).to_return(:body => 'succeed get request')
12
+ stub_request(:post , url_fully).to_return{|req| { :body => "succeed post request and request body #{send_data}" } }
13
+ stub_request(:put , url_fully).to_return{|req| { :body => "succeed put request and request body #{send_data}" } }
14
+ stub_request(:delete , url_fully).to_return(:body => 'succeed delete request')
15
+ end
16
+
17
+ context "base header" do
18
+ it { HttpMachinegun::Client::BASE_HEADERS["content-type"].should eql "text/plain" }
19
+ end
20
+
21
+ context "initialize" do
22
+ it "raise error due to no args" do
23
+ lambda{ HttpMachinegun::Client.new }.should raise_error ArgumentError
24
+ end
25
+
26
+ context "normal" do
27
+ it { @client.instance_variable_get("@url").to_s.should eql url }
28
+ it { @client.instance_variable_get("@port").should eql port }
29
+ it { @client.instance_variable_get("@send_data").should eql send_data }
30
+ end
31
+ end
32
+
33
+ context "basic_auth" do
34
+ it "raise error if no args" do
35
+ expect { @client.basic_auth }.to raise_error(ArgumentError)
36
+ end
37
+
38
+ it "raise error if called before set http_method" do
39
+ expect { @client.basic_auth("hoge", "fuga") }.to raise_error(NoMethodError)
40
+ end
41
+
42
+ it do
43
+ @client.http_method("get").basic_auth("hoge","fuga")
44
+ @client.instance_variable_get("@request_body").instance_variable_get("@header")['authorization'] == Net::HTTP::Get.new('/').send(:basic_encode , "hoge","fuga")
45
+ end
46
+ end
47
+
48
+ context "http_method" do
49
+
50
+ %w(get post put delete).each do |method|
51
+ it {@client.http_method(method).instance_variable_get("@request_body").should be_instance_of(eval("Net::HTTP::#{method.capitalize}")) }
52
+ end
53
+
54
+ it { expect{ @client.http_method}.to raise_error }
55
+ end
56
+
57
+ context "set_body" do
58
+ subject { @client.http_method(:get).set_body.instance_variable_get("@request_body") }
59
+ its(:body){should eql "abcdefg".to_json }
60
+ end
61
+
62
+ context "execute" do
63
+ context "get request" do
64
+ subject { @client.http_method(:get).set_body.execute }
65
+ it { subject.code.should eql "200" }
66
+ it { subject.body.should eql "succeed get request" }
67
+ end
68
+
69
+ context "post request" do
70
+ subject { @client.http_method(:post).set_body.execute }
71
+ it { subject.code.should eql "200" }
72
+ it { subject.body.should eql "succeed post request and request body #{send_data}" }
73
+ end
74
+
75
+ context "post request" do
76
+ subject { @client.http_method(:put).set_body.execute }
77
+ it { subject.code.should eql "200" }
78
+ it { subject.body.should eql "succeed put request and request body #{send_data}" }
79
+ end
80
+
81
+ context "delete request" do
82
+ subject { @client.http_method(:delete).set_body.execute }
83
+ it { subject.code.should eql "200" }
84
+ it { subject.body.should eql "succeed delete request" }
85
+ end
86
+ end
87
+ end
data/spec/data_spec.rb ADDED
@@ -0,0 +1,17 @@
1
+ # coding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe HttpMachinegun::Data do
5
+
6
+ context "when argument is string" do
7
+ it{ HttpMachinegun::Data.new("abcdef").to_s.should eql "abcdef" }
8
+ end
9
+
10
+ context "when argument is file path" do
11
+ it do
12
+ file_path = "#{File.dirname(__FILE__)}/resources/data_fixture.txt"
13
+ HttpMachinegun::Data.new(file_path).to_s.should eql File.read(file_path)
14
+ end
15
+ end
16
+
17
+ end
@@ -0,0 +1,198 @@
1
+ # coding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe HttpMachinegun do
5
+ let(:url) { "http://example.com" }
6
+ let(:url_fully) { "http://example.com:80/" }
7
+ let(:port) { 3000 }
8
+ let(:send_data) { "abcdefg" }
9
+
10
+ let(:default_port) { 80 }
11
+ let(:default_send_data) { "" }
12
+
13
+ before do
14
+ @client = HttpMachinegun::Client.new(url, port, send_data)
15
+ stub_request(:get , url_fully).to_return(:body => 'succeed get request')
16
+ stub_request(:post , url_fully).to_return{|req| { :body => "succeed post request and request body #{send_data}" } }
17
+ stub_request(:put , url_fully).to_return{|req| { :body => "succeed put request and request body #{send_data}" } }
18
+ stub_request(:delete , url_fully).to_return(:body => 'succeed delete request')
19
+ stub_request(:get , url + ":" + port.to_s + "/").to_return(:body => 'succeed get request')
20
+ end
21
+
22
+ context "argument" do
23
+ context "url" do
24
+ subject { HttpMachinegun::Machinegun }
25
+ it "is empty" do
26
+ output = capture(:stdout) {
27
+ subject.start(["fire"])
28
+ }
29
+ output.should_not include("http_status_code:200")
30
+ end
31
+
32
+ it "only" do
33
+ output = capture(:stdout) {
34
+ subject.start(["fire","--url", url])
35
+ }
36
+ output.should include("http_status_code:200")
37
+ end
38
+
39
+ context "parameter is correct" do
40
+ subject{ HttpMachinegun::Machinegun.start(["fire","--url", url]) }
41
+
42
+ it { subject.first.instance_variable_get("@url").to_s.should eq url }
43
+ it { subject.first.instance_variable_get("@port").should eq default_port }
44
+ it { subject.first.instance_variable_get("@request_body").should be_instance_of(Net::HTTP::Get) }
45
+ it { subject.first.instance_variable_get("@send_data").should be_instance_of(HttpMachinegun::Data) }
46
+ it { subject.first.instance_variable_get("@send_data").to_s.should eq default_send_data }
47
+ its(:length){ should eq 1}
48
+ end
49
+ end
50
+
51
+ context "port" do
52
+ subject { HttpMachinegun::Machinegun }
53
+ it "is empty" do
54
+ output = capture(:stdout) {
55
+ subject.start(["fire","--url", url])
56
+ }
57
+ output.should include("http_status_code:200")
58
+ end
59
+
60
+ it "only" do
61
+ output = capture(:stdout) {
62
+ subject.start(["fire","--port", port])
63
+ }
64
+ output.should_not include("http_status_code:200")
65
+ end
66
+
67
+ context "parameter is correct" do
68
+ subject{ HttpMachinegun::Machinegun.start(["fire","--url", url, "--port", port]) }
69
+
70
+ it { subject.first.instance_variable_get("@url").to_s.should eq url }
71
+ it { subject.first.instance_variable_get("@port").should eq port }
72
+ it { subject.first.instance_variable_get("@request_body").should be_instance_of(Net::HTTP::Get) }
73
+ it { subject.first.instance_variable_get("@send_data").should be_instance_of(HttpMachinegun::Data) }
74
+ it { subject.first.instance_variable_get("@send_data").to_s.should eq default_send_data }
75
+ its(:length){ should eq 1}
76
+ end
77
+ end
78
+
79
+ context "data_or_file_path" do
80
+ subject { HttpMachinegun::Machinegun }
81
+ it "is empty" do
82
+ output = capture(:stdout) {
83
+ subject.start(["fire","--url", url])
84
+ }
85
+ output.should include("http_status_code:200")
86
+ end
87
+
88
+ it "only" do
89
+ output = capture(:stdout) {
90
+ subject.start(["fire","--data_or_file_path", send_data])
91
+ }
92
+ output.should_not include("http_status_code:200")
93
+ end
94
+
95
+ context "parameter is correct" do
96
+ subject{ HttpMachinegun::Machinegun.start(["fire","--url", url, "--port", port, "--data_or_file_path", send_data]) }
97
+
98
+ it { subject.first.instance_variable_get("@url").to_s.should eq url }
99
+ it { subject.first.instance_variable_get("@port").should eq port }
100
+ it { subject.first.instance_variable_get("@request_body").should be_instance_of(Net::HTTP::Get) }
101
+ it { subject.first.instance_variable_get("@send_data").should be_instance_of(HttpMachinegun::Data) }
102
+ it { subject.first.instance_variable_get("@send_data").to_s.should eq send_data }
103
+ its(:length){ should eq 1}
104
+ end
105
+ end
106
+
107
+ context "method" do
108
+ subject { HttpMachinegun::Machinegun }
109
+ it "is empty" do
110
+ output = capture(:stdout) {
111
+ subject.start(["fire","--url", url])
112
+ }
113
+ output.should include("http_status_code:200")
114
+ end
115
+
116
+ it "only" do
117
+ output = capture(:stdout) {
118
+ subject.start(["fire","--method", :get])
119
+ }
120
+ output.should_not include("http_status_code:200")
121
+ end
122
+
123
+ context "parameter is correct" do
124
+ context "get session" do
125
+ subject{ HttpMachinegun::Machinegun.start(["fire","--url", url, "--port", port, "--data_or_file_path", send_data, "--method", :get]) }
126
+
127
+ it { subject.first.instance_variable_get("@url").to_s.should eq url }
128
+ it { subject.first.instance_variable_get("@port").should eq port }
129
+ it { subject.first.instance_variable_get("@request_body").should be_instance_of(Net::HTTP::Get) }
130
+ it { subject.first.instance_variable_get("@send_data").should be_instance_of(HttpMachinegun::Data) }
131
+ it { subject.first.instance_variable_get("@send_data").to_s.should eq send_data }
132
+ its(:length){ should eq 1}
133
+ end
134
+
135
+ context "post session" do
136
+ subject{ HttpMachinegun::Machinegun.start(["fire","--url", url, "--data_or_file_path", send_data, "--method", :post]) }
137
+
138
+ it { subject.first.instance_variable_get("@url").to_s.should eq url }
139
+ it { subject.first.instance_variable_get("@port").should eq default_port }
140
+ it { subject.first.instance_variable_get("@request_body").should be_instance_of(Net::HTTP::Post) }
141
+ it { subject.first.instance_variable_get("@send_data").should be_instance_of(HttpMachinegun::Data) }
142
+ it { subject.first.instance_variable_get("@send_data").to_s.should eq send_data }
143
+ its(:length){ should eq 1}
144
+ end
145
+
146
+ context "put session" do
147
+ subject{ HttpMachinegun::Machinegun.start(["fire","--url", url, "--data_or_file_path", send_data, "--method", :put]) }
148
+
149
+ it { subject.first.instance_variable_get("@url").to_s.should eq url }
150
+ it { subject.first.instance_variable_get("@port").should eq default_port }
151
+ it { subject.first.instance_variable_get("@request_body").should be_instance_of(Net::HTTP::Put) }
152
+ it { subject.first.instance_variable_get("@send_data").should be_instance_of(HttpMachinegun::Data) }
153
+ it { subject.first.instance_variable_get("@send_data").to_s.should eq send_data }
154
+ its(:length){ should eq 1}
155
+ end
156
+
157
+ context "delete session" do
158
+ subject{ HttpMachinegun::Machinegun.start(["fire","--url", url, "--data_or_file_path", send_data, "--method", :delete]) }
159
+
160
+ it { subject.first.instance_variable_get("@url").to_s.should eq url }
161
+ it { subject.first.instance_variable_get("@port").should eq default_port }
162
+ it { subject.first.instance_variable_get("@request_body").should be_instance_of(Net::HTTP::Delete) }
163
+ it { subject.first.instance_variable_get("@send_data").should be_instance_of(HttpMachinegun::Data) }
164
+ it { subject.first.instance_variable_get("@send_data").to_s.should eq send_data }
165
+ its(:length){ should eq 1}
166
+ end
167
+ end
168
+ end
169
+
170
+ context "thread_number" do
171
+ subject { HttpMachinegun::Machinegun }
172
+ it "is empty" do
173
+ output = capture(:stdout) {
174
+ subject.start(["fire","--url", url])
175
+ }
176
+ output.should include("http_status_code:200")
177
+ end
178
+
179
+ it "only" do
180
+ output = capture(:stdout) {
181
+ subject.start(["fire","--thread_number", 1])
182
+ }
183
+ output.should_not include("http_status_code:200")
184
+ end
185
+
186
+ context "parameter is correct" do
187
+ subject{ HttpMachinegun::Machinegun.start(["fire","--url", url, "--thread_number", 10, "--data_or_file_path", send_data]) }
188
+
189
+ it { subject.first.instance_variable_get("@url").to_s.should eq url }
190
+ it { subject.first.instance_variable_get("@port").should eq default_port }
191
+ it { subject.first.instance_variable_get("@request_body").should be_instance_of(Net::HTTP::Get) }
192
+ it { subject.first.instance_variable_get("@send_data").should be_instance_of(HttpMachinegun::Data) }
193
+ it { subject.first.instance_variable_get("@send_data").to_s.should eq send_data }
194
+ its(:length){ should eq 10}
195
+ end
196
+ end
197
+ end
198
+ end
@@ -0,0 +1,2 @@
1
+ このGemは特定のサイトにHTTPをなげるためのタスクを提供します
2
+ スレッドを使っているため、少しは早いはずです。
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+ require 'rubygems'
3
+ require 'http_machinegun'
4
+ require 'webmock/rspec'
5
+ require 'stringio'
6
+ require 'simplecov'
7
+ require 'simplecov-rcov'
8
+ SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
9
+ SimpleCov.start
10
+
11
+ # Set shell to basic
12
+ $0 = "thor"
13
+ $thor_runner = true
14
+ ARGV.clear
15
+ Thor::Base.shell = Thor::Shell::Basic
16
+
17
+ RSpec.configure do |config|
18
+ # Captures the output for analysis later
19
+ #
20
+ # @example Capture `$stderr`
21
+ #
22
+ # output = capture(:stderr) { $stderr.puts "this is captured" }
23
+ #
24
+ # @param [Symbol] stream `:stdout` or `:stderr`
25
+ # @yield The block to capture stdout/stderr for.
26
+ # @return [String] The contents of $stdout or $stderr
27
+ def capture(stream)
28
+ begin
29
+ stream = stream.to_s
30
+ eval "$#{stream} = StringIO.new"
31
+ yield
32
+ result = eval("$#{stream}").string
33
+ ensure
34
+ eval("$#{stream} = #{stream.upcase}")
35
+ end
36
+
37
+ result
38
+ end
39
+
40
+ alias :silence :capture
41
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: http_machinegun
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - y.fujii
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: parallel
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: http client with thread
47
+ email:
48
+ - ishikurasakura@gmail.com
49
+ executables:
50
+ - http_machinegun
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - .rspec
56
+ - Gemfile
57
+ - Guardfile
58
+ - LICENSE
59
+ - README.md
60
+ - Rakefile
61
+ - bin/http_machinegun
62
+ - http_machinegun.gemspec
63
+ - lib/http_machinegun.rb
64
+ - lib/http_machinegun/client.rb
65
+ - lib/http_machinegun/data.rb
66
+ - lib/http_machinegun/version.rb
67
+ - spec/client_spec.rb
68
+ - spec/data_spec.rb
69
+ - spec/http_machingun_spec.rb
70
+ - spec/resources/data_fixture.txt
71
+ - spec/spec_helper.rb
72
+ homepage: https://github.com/YoshitsuguFujii/http_machinegun
73
+ licenses: []
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 1.8.24
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: send data with thread
96
+ test_files:
97
+ - spec/client_spec.rb
98
+ - spec/data_spec.rb
99
+ - spec/http_machingun_spec.rb
100
+ - spec/resources/data_fixture.txt
101
+ - spec/spec_helper.rb