http_find 0.1.0

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: 20cd3400333198c6a692fe8418f0648e3c5278c2
4
+ data.tar.gz: 7eacec0e4e24d158bf5fec2f132713a4d255c569
5
+ SHA512:
6
+ metadata.gz: be7eb9eb7cde160e0575ca9c2453ada0f96b49640990706e2a615401d800cd785bd4a4404ecaa813fa56821fe8b0ae74b1a6efb397fa55b216c8a8a0161fd002
7
+ data.tar.gz: 3197a99c3c5692e3223495a8480adb7fcad2356939e9ec4b1e0f1b4e987369d19d8bca13d5695bf5ba80ee66ba1760d0af5e560b24876128d5d3b66aa3017d25
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,11 @@
1
+ Style/Documentation:
2
+ Enabled: false
3
+
4
+ Style/DotPosition:
5
+ EnforcedStyle: trailing
6
+
7
+ Style/StringLiterals:
8
+ EnforcedStyle: double_quotes
9
+
10
+ Style/ClassAndModuleChildren:
11
+ Enabled: false
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 2.3.1
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at nick@scheurich.me. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in http_search.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Nicholas Scheurich
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/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # HTTP Find
2
+
3
+ [![Build Status](https://travis-ci.org/ngscheurich/http_search.svg?branch=master)](https://travis-ci.org/ngscheurich/http_search)
4
+ [![Coverage Status](https://coveralls.io/repos/github/ngscheurich/http_search/badge.svg?branch=master)](https://coveralls.io/github/ngscheurich/http_search?branch=master)
5
+
6
+ Searches the contents of an HTTP response for a specified term or pattern.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'http_find'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install http_find
23
+
24
+ Installing this gem will add the executable `httpfind` to your system.
25
+
26
+ ## Usage
27
+
28
+ With `httpfind` in your $PATH, usage looks like:
29
+
30
+ ```
31
+ $ httpfind [URI] [TERM]
32
+ ```
33
+
34
+ This will search the HTTP GET response from `URI` for the specified `TERM`.
35
+
36
+ `TERM` may be either a simple string or a regular expression in the form
37
+ `$ httpfind -e http://example.com '\d.{2} one'` (note the `-e` flag).
38
+ Check `$httpfind help` for more info.
39
+
40
+ ## Development
41
+
42
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
43
+ `rake test` to run the tests. You can also run `bin/console` for an interactive
44
+ prompt that will allow you to experiment.
45
+
46
+ To install this gem onto your local machine, run `bundle exec rake install`.
47
+ To release a new version, update the version number in `version.rb`, and then
48
+ run `bundle exec rake release`, which will create a git tag for the version,
49
+ push git commits and tags, and push the `.gem` file to
50
+ [rubygems.org](https://rubygems.org).
51
+
52
+ ## Contributing
53
+
54
+ Bug reports and pull requests are welcome on GitHub at
55
+ https://github.com/ngscheurich/http_find. This project is intended to be a safe,
56
+ welcoming space for collaboration, and contributors are expected to adhere to
57
+ the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
58
+
59
+ ## License
60
+
61
+ The gem is available as open source under the terms of the
62
+ [MIT License](http://opensource.org/licenses/MIT).
63
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "http_find"
5
+
6
+ require "pry"
7
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/httpfind ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "pathname"
4
+
5
+ source_path = (Pathname(__dir__) + "../lib").expand_path
6
+ $LOAD_PATH << source_path
7
+
8
+ require "http_find"
9
+ HttpFind::Cli.start(ARGV)
data/http_find.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "http_find/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "http_find"
8
+ spec.version = HttpFind::VERSION
9
+ spec.authors = ["Nicholas Scheurich"]
10
+ spec.email = ["nick@scheurich.me"]
11
+
12
+ spec.summary = "HTTP response searcher"
13
+ spec.description = "Searches the contents of an HTTP response for a specified term or pattern."
14
+ spec.homepage = "https://github.com/ngscheurich/http_find"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency "httparty", "~> 0.13"
23
+ spec.add_runtime_dependency "colorize", "~> 0.8"
24
+ spec.add_runtime_dependency "thor", "~> 0.19"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.12"
27
+ spec.add_development_dependency "coveralls", "~> 0.8"
28
+ spec.add_development_dependency "pry", "~> 0.10"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "minitest", "~> 5.0"
31
+ spec.add_development_dependency "minitest-reporters", "~> 1.1"
32
+ spec.add_development_dependency "webmock", "~> 2.1"
33
+ end
data/lib/http_find.rb ADDED
@@ -0,0 +1,14 @@
1
+ require "http_find/version"
2
+ require "http_find/response"
3
+ require "http_find/matcher"
4
+ require "http_find/output"
5
+ require "http_find/cli"
6
+
7
+ module HttpFind
8
+ def self.find(uri, subject)
9
+ response = HttpFind::Response.new(uri)
10
+ matcher = HttpFind::Matcher.new(response.body)
11
+ output = HttpFind::Output.new(matcher.match(subject))
12
+ output.lines
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ require "thor"
2
+
3
+ module HttpFind
4
+ class Cli < Thor
5
+ option :regexp, type: :boolean, default: false, aliases: "-e",
6
+ desc: "Indicate that TERM is a regular expression"
7
+ desc "find URI TERM", "searches the HTTP GET response of URI for TERM"
8
+ def find(uri, term)
9
+ subject = options[:regexp] ? /#{term}/ : term
10
+ HttpFind.find(uri, subject).each { |l| puts l }
11
+ end
12
+
13
+ default_task :find
14
+ end
15
+ end
@@ -0,0 +1,63 @@
1
+ require "httparty"
2
+ require "colorize"
3
+
4
+ module HttpFind
5
+ class Matcher
6
+ MATCH_COLOR = :yellow
7
+
8
+ attr_reader :text
9
+
10
+ def initialize(text)
11
+ @text = text
12
+ end
13
+
14
+ def match(subj)
15
+ if subj.class == Regexp
16
+ regexp_match(subj)
17
+ else
18
+ string_match(subj.to_s)
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def lines
25
+ @text.split("\n")
26
+ end
27
+
28
+ def base_match
29
+ matches = []
30
+
31
+ lines.each_with_index do |line, i|
32
+ yield(line, i, matches)
33
+ end
34
+
35
+ matches
36
+ end
37
+
38
+ def regexp_match(regexp)
39
+ base_match do |line, i, matches|
40
+ regexp_matches = line.scan(regexp)
41
+ unless regexp_matches.empty?
42
+ regexp_matches.each { |m| line.sub!(m, m.colorize(MATCH_COLOR)) }
43
+ matches << result(i + 1, line)
44
+ end
45
+ end
46
+ end
47
+
48
+ def string_match(str)
49
+ base_match do |line, i, matches|
50
+ if line.include?(str)
51
+ matches << result(i + 1, line.gsub(str, str.colorize(MATCH_COLOR)))
52
+ end
53
+ end
54
+ end
55
+
56
+ def result(line_num, text)
57
+ {
58
+ line: line_num,
59
+ text: text
60
+ }
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,16 @@
1
+ module HttpFind
2
+ class Output
3
+ def initialize(matches)
4
+ @matches = matches
5
+ end
6
+
7
+ def lines
8
+ justlen = @matches.map { |m| m[:line] }.sort.last.to_s.length
9
+ @matches.map do |m|
10
+ line = m[:line].to_s
11
+ text = m[:text]
12
+ "#{line.rjust(justlen)} | #{text}"
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ require "httparty"
2
+
3
+ module HttpFind
4
+ class Response
5
+ attr_reader :code
6
+ attr_reader :body
7
+
8
+ def initialize(uri)
9
+ furi = uri.start_with?("http") ? uri : "http://#{uri}"
10
+ party = HTTParty.get(furi)
11
+ @code = party.response.code.to_i
12
+ @body = @code == 200 ? party.response.body : nil
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module HttpFind
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,205 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: http_find
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nicholas Scheurich
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-10-04 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.13'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: colorize
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.19'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.19'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.12'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.12'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.8'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.8'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.10'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.10'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: minitest
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '5.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '5.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: minitest-reporters
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.1'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.1'
139
+ - !ruby/object:Gem::Dependency
140
+ name: webmock
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '2.1'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '2.1'
153
+ description: Searches the contents of an HTTP response for a specified term or pattern.
154
+ email:
155
+ - nick@scheurich.me
156
+ executables:
157
+ - httpfind
158
+ extensions: []
159
+ extra_rdoc_files: []
160
+ files:
161
+ - ".coveralls.yml"
162
+ - ".gitignore"
163
+ - ".rubocop.yml"
164
+ - ".tool-versions"
165
+ - ".travis.yml"
166
+ - CODE_OF_CONDUCT.md
167
+ - Gemfile
168
+ - LICENSE.txt
169
+ - README.md
170
+ - Rakefile
171
+ - bin/console
172
+ - bin/setup
173
+ - exe/httpfind
174
+ - http_find.gemspec
175
+ - lib/http_find.rb
176
+ - lib/http_find/cli.rb
177
+ - lib/http_find/matcher.rb
178
+ - lib/http_find/output.rb
179
+ - lib/http_find/response.rb
180
+ - lib/http_find/version.rb
181
+ homepage: https://github.com/ngscheurich/http_find
182
+ licenses:
183
+ - MIT
184
+ metadata: {}
185
+ post_install_message:
186
+ rdoc_options: []
187
+ require_paths:
188
+ - lib
189
+ required_ruby_version: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ required_rubygems_version: !ruby/object:Gem::Requirement
195
+ requirements:
196
+ - - ">="
197
+ - !ruby/object:Gem::Version
198
+ version: '0'
199
+ requirements: []
200
+ rubyforge_project:
201
+ rubygems_version: 2.5.1
202
+ signing_key:
203
+ specification_version: 4
204
+ summary: HTTP response searcher
205
+ test_files: []