brocli 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 872cb465247ad0eefbe268990e1649de6b9643b6
4
+ data.tar.gz: ba451f4a3dc5f6c7aee49a341ac6a41ff390c0d6
5
+ SHA512:
6
+ metadata.gz: 12a63373627a8892fa61a6771c5d6aabe21b4fd33428b5fda8c694ed15ddf024e0fb804ed0dba2bf743f9dc091ea2e061fdd787ec6ad2e036dbe62e5a9bbabaf
7
+ data.tar.gz: 83eb4969830e9f075c86184232f5f341f346d16b23012fbedd70ef1a480eed2aaa33ca99a8507df86c5eef768bdbb12a02c3b53196ae0b53b96269703e5e1a98
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'brocli'
4
+
5
+ Brocli::Initiate.start( ARGV )
@@ -0,0 +1,2 @@
1
+ require "brocli/version"
2
+ require "brocli/cli"
@@ -0,0 +1,42 @@
1
+ require 'thor'
2
+ require_relative 'sanitizer'
3
+ require_relative 'defaults'
4
+ require_relative 'ping'
5
+ require_relative 'string'
6
+
7
+ module Brocli
8
+ class Initiate < Thor
9
+ desc "hit [URL] [TIME_LIMIT] [TIME_INTERVAL]", "use brocli hit to ping the url. by default url is set to www.gitlab.com."
10
+ long_desc <<-HIT
11
+ brocli hit [URL] [TOTAL_TIME] [TIME_INTERVAL]
12
+
13
+ check the average response time for www.gitlab.com after pinging it for 1 minute every 10 seconds
14
+
15
+ ** FOR CUSTOM HIT PLEASE PROVIDE ALL THE ARGUMENTS **
16
+
17
+ **example: brocli hit 'www.your_domain_name.com' 60 10
18
+
19
+ --URL provide url as an option if you want to hit to a specified url
20
+ --TOTAL_TIME provide total_time_limit in seconds as an option if you want to specify the total time limit for hitting the url
21
+ --TIME_INTERVAL provide time_interval in seconds to specify the time interval after which the next hit will occur
22
+ HIT
23
+
24
+ include Sanitizer
25
+ include Ping
26
+
27
+ def hit(url = Brocli::DEFAULT_URL, time_limit = Brocli::EXECUTION_TIME_LIMIT, time_interval = Brocli::TIME_INTERVAL)
28
+ begin
29
+ average_time = client.ping(client.sanitizer(url), time_limit.to_f, time_interval.to_f)
30
+ raise 'There is some error' unless average_time != nil
31
+ puts "Average response time for #{url} is #{(average_time).round(Brocli::DEFAULT_ROUNDING)}s".green
32
+ rescue Exception => e
33
+ puts e.message.red
34
+ end
35
+ end
36
+
37
+ private
38
+ def client
39
+ @client ||= Brocli::Initiate.new
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,13 @@
1
+ module Brocli
2
+
3
+ #contains the defaults to the brcoli gem add any other gem related defaults here
4
+
5
+ DEFAULT_URL = 'https://www.gitlab.com' #default url
6
+
7
+ EXECUTION_TIME_LIMIT = 60 #total execution time of pinging loop in seconds
8
+
9
+ TIME_INTERVAL = 10 #time intervals between hits in seconds
10
+
11
+ DEFAULT_ROUNDING = 2 #default value of final rounding off the response time
12
+
13
+ end
@@ -0,0 +1,25 @@
1
+ require 'httparty'
2
+ require 'benchmark'
3
+ require_relative 'defaults'
4
+ require_relative 'string'
5
+
6
+ module Ping
7
+
8
+ def ping(url, time_limit, time_interval)
9
+ begin
10
+ time_elapsed = 0
11
+ loop_times = (time_limit/time_interval).ceil #in case of decimal values ceil will ensure that we do not lack intended no. of hits
12
+ loop_times.times do |i|
13
+ sleep(time_interval) unless (i == 0)
14
+ puts "Hitting url #{url}".brown
15
+ real_time = Benchmark.realtime { HTTParty.get(url) } #we call realtime method of Benchmark module to get the real time only. modify it if you want to access any other attributes as well
16
+ puts "Real time for this hit is #{real_time}s".cyan
17
+ time_elapsed += real_time
18
+ end
19
+ return (time_elapsed/loop_times) #returnig the average time of all hits in seconds
20
+ rescue Exception => e
21
+ puts "#{e.message}, make sure you provided the correct url".red
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1,14 @@
1
+ module Sanitizer
2
+
3
+ #check for the scheme of url passed and append a scheme if not present since httparty requires scheme as well
4
+ def sanitizer(url)
5
+ uri = URI.parse(url)
6
+ if not uri.scheme
7
+ link = "https://#{url}"
8
+ uri = URI(link)
9
+ end
10
+ uri
11
+ end
12
+
13
+ #add any other url sanitizers here
14
+ end
@@ -0,0 +1,29 @@
1
+ class String
2
+
3
+ #defining custom color schemes for the bash output string, feel free to add more color unix codes
4
+ #calling all the methods to the String class itself.
5
+
6
+ def black; "\e[30m#{self}\e[0m" end
7
+ def red; "\e[31m#{self}\e[0m" end
8
+ def green; "\e[32m#{self}\e[0m" end
9
+ def brown; "\e[33m#{self}\e[0m" end
10
+ def blue; "\e[34m#{self}\e[0m" end
11
+ def magenta; "\e[35m#{self}\e[0m" end
12
+ def cyan; "\e[36m#{self}\e[0m" end
13
+ def gray; "\e[37m#{self}\e[0m" end
14
+
15
+ def bg_black; "\e[40m#{self}\e[0m" end
16
+ def bg_red; "\e[41m#{self}\e[0m" end
17
+ def bg_green; "\e[42m#{self}\e[0m" end
18
+ def bg_brown; "\e[43m#{self}\e[0m" end
19
+ def bg_blue; "\e[44m#{self}\e[0m" end
20
+ def bg_magenta; "\e[45m#{self}\e[0m" end
21
+ def bg_cyan; "\e[46m#{self}\e[0m" end
22
+ def bg_gray; "\e[47m#{self}\e[0m" end
23
+
24
+ def bold; "\e[1m#{self}\e[22m" end
25
+ def italic; "\e[3m#{self}\e[23m" end
26
+ def underline; "\e[4m#{self}\e[24m" end
27
+ def blink; "\e[5m#{self}\e[25m" end
28
+ def reverse_color; "\e[7m#{self}\e[27m" end
29
+ end
@@ -0,0 +1,3 @@
1
+ module Brocli
2
+ VERSION = "0.0.5"
3
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: brocli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ platform: ruby
6
+ authors:
7
+ - suman saurabh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-01-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
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.15'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.15'
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.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
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.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description:
84
+ email:
85
+ - sumansaurabh93s@gmail.com
86
+ executables:
87
+ - brocli
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - bin/brocli
92
+ - lib/brocli.rb
93
+ - lib/brocli/cli.rb
94
+ - lib/brocli/defaults.rb
95
+ - lib/brocli/ping.rb
96
+ - lib/brocli/sanitizer.rb
97
+ - lib/brocli/string.rb
98
+ - lib/brocli/version.rb
99
+ homepage: https://rubygems.org/profiles/suman_ruby
100
+ licenses:
101
+ - MIT
102
+ metadata: {}
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 2.5.1
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: Ruby gem to expose a CLI to calculate average response time of an HTTP request.
123
+ test_files: []