urltest 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 18a06822df8c14a6974ed68931a394cf7fabbda3
4
+ data.tar.gz: 7e0beb9b0c51955368c3ad23638c500da2a168cc
5
+ SHA512:
6
+ metadata.gz: de5db75e70f7a7c975b00662f4eb9d176d2c16fcb496a85eab5bcea9fc3209da9ab06addb256b0d4e761ff571bac107e40cc21e700a708b8127cc8d0d7a42811
7
+ data.tar.gz: 416cdd06936385fc7905eb27700b3b91a3d4ca568eebfb47e0bd0614a2afdaae2daf9d7e36d3e389cab08e3b822b2675c125885b30a0c2b731a58d9814ea94e4
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://ruby.taobao.org'
2
+
3
+ # Specify your gem's dependencies in urltest.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 icyleaf
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,31 @@
1
+ # Urltest
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'urltest'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install urltest
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/urltest/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/urltest ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'urltest'
4
+
5
+
6
+ cmd = Urltest::Commands::Execute.new(ARGV)
7
+ cmd.benchmark
data/lib/urltest.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "urltest/version"
2
+
3
+ require "urltest/commands/options"
4
+ require "urltest/commands"
@@ -0,0 +1,65 @@
1
+ require 'rest_client'
2
+ require 'rainbow'
3
+
4
+
5
+ module Urltest
6
+ module Commands
7
+
8
+ class Execute
9
+ attr_reader :options
10
+
11
+ def initialize(argv)
12
+ @options = Options.new(argv).parse
13
+ end
14
+
15
+ def colorful_text(value)
16
+ color = if value < 0.3
17
+ "green"
18
+ elsif value > 0.8
19
+ "yellow"
20
+ else
21
+ "red"
22
+ end
23
+
24
+ Rainbow(value).send(color)
25
+ end
26
+
27
+ def benchmark
28
+ return unless @options.link
29
+
30
+ min_value = 0
31
+ max_value = 0
32
+ average_value = 0
33
+
34
+ puts '*' * 50
35
+ @options.times.times do |i|
36
+ s = Time.now
37
+ begin
38
+ r = RestClient.get @options.link
39
+ e = Time.now
40
+ diff = e - s
41
+
42
+ if i == 0
43
+ min_value = diff
44
+ max_value = diff
45
+ end
46
+
47
+ average_value += diff
48
+
49
+ min_value = diff if min_value > diff
50
+ max_value = diff if max_value < diff
51
+
52
+ puts "#{i + 1}. Cost #{colorful_text(diff)}s <status #{r.code}, size: #{r.to_s.bytesize} bytes>"
53
+ end
54
+ end
55
+
56
+ average_value = average_value.to_f / @options.times
57
+ puts '*' * 50
58
+ puts "Total:\t\t#{@options.times}"
59
+ puts "Min time:\t#{colorful_text(min_value)}s"
60
+ puts "Max time:\t#{colorful_text(max_value)}s"
61
+ puts "Average time:\t#{colorful_text(average_value)}s"
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,46 @@
1
+ require 'optparse'
2
+ require 'ostruct'
3
+
4
+ module Urltest
5
+ module Commands
6
+ class Options
7
+ attr_reader :options
8
+
9
+ def initialize(args)
10
+ @options = OpenStruct.new
11
+ @options.times = 10
12
+
13
+ opts = OptionParser.new do |opts|
14
+ opts.banner = "\nSpeed test for your url(api)\n\nUsage: urltest [options]"
15
+ opts.version = Urltest::VERSION
16
+
17
+ opts.separator ''
18
+ opts.separator 'Optional:'
19
+
20
+ opts.on_head('-t', '--times [N]', Integer, 'Request times') do |t|
21
+ @options.times = t || 10
22
+ end
23
+ opts.on_head('-l', '--link [URL]', String, 'URL link') do |l|
24
+ @options.link = l
25
+ end
26
+
27
+ opts.on('--version', "Show version") do |v|
28
+ puts opts.version
29
+ exit
30
+ end
31
+
32
+ opts.on('--help', "Show help") do |v|
33
+ puts opts
34
+ exit
35
+ end
36
+ end
37
+
38
+ opts.parse!(args)
39
+ end
40
+
41
+ def parse
42
+ @options
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module Urltest
2
+ VERSION = "0.0.1"
3
+ end
data/urltest.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'urltest/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "urltest"
8
+ spec.version = Urltest::VERSION
9
+ spec.authors = ["icyleaf"]
10
+ spec.email = ["icyleaf.cn@gmail.com"]
11
+ spec.summary = %q{Speed testing for target http url (api)}
12
+ spec.description = %q{Speed testing for target http url (api)}
13
+ spec.homepage = "http://icyleaf.com"
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_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_dependency "commander", "~> 4.2.1"
24
+ spec.add_dependency "rest-client", "~> 1.7.2"
25
+ spec.add_dependency "rainbow", "~> 2.0.0"
26
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: urltest
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - icyleaf
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: commander
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 4.2.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 4.2.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: rest-client
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.7.2
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.7.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: rainbow
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.0.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.0.0
83
+ description: Speed testing for target http url (api)
84
+ email:
85
+ - icyleaf.cn@gmail.com
86
+ executables:
87
+ - urltest
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - bin/urltest
97
+ - lib/urltest.rb
98
+ - lib/urltest/commands.rb
99
+ - lib/urltest/commands/options.rb
100
+ - lib/urltest/version.rb
101
+ - urltest.gemspec
102
+ homepage: http://icyleaf.com
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.4.5
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Speed testing for target http url (api)
126
+ test_files: []