browsing_facade 1.0.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
+ SHA256:
3
+ metadata.gz: 6f618d662f68388c6bbc65fc0231ecfda2e2851a2fe409dd354430ade87a6cbc
4
+ data.tar.gz: 76ce30b884e8028553b990ead6283896a0c5bbeea272b584d3b2724bd912e77c
5
+ SHA512:
6
+ metadata.gz: 20eb3612975cbb96e74fd9af1662db3f46bb25dc866560c93120b93c2d7253f759c07eab3e95da3cb51d497bdc8da49912f7b056a1b1d51ab8dbb42f5264b408
7
+ data.tar.gz: cb76efa5ba8cc305e4c9dfcc3557012ced2a1fe9cf163f5dec0732131a3c26a2417d4c5b1e5c59e66c3b89f3635179bffa70ccb3cf4d917f313f714bf9012015
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format documentation
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Main]
2
+
3
+ ## [1.0.0] - 2023-08-30
4
+
5
+ - First version.
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,49 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ browsing_facade (1.0.0)
5
+ ferrum
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.8.4)
11
+ public_suffix (>= 2.0.2, < 6.0)
12
+ concurrent-ruby (1.2.2)
13
+ diff-lcs (1.5.0)
14
+ ferrum (0.13)
15
+ addressable (~> 2.5)
16
+ concurrent-ruby (~> 1.1)
17
+ webrick (~> 1.7)
18
+ websocket-driver (>= 0.6, < 0.8)
19
+ public_suffix (5.0.3)
20
+ rake (13.0.6)
21
+ rspec (3.12.0)
22
+ rspec-core (~> 3.12.0)
23
+ rspec-expectations (~> 3.12.0)
24
+ rspec-mocks (~> 3.12.0)
25
+ rspec-core (3.12.2)
26
+ rspec-support (~> 3.12.0)
27
+ rspec-expectations (3.12.3)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.12.0)
30
+ rspec-mocks (3.12.6)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.12.0)
33
+ rspec-support (3.12.1)
34
+ webrick (1.8.1)
35
+ websocket-driver (0.7.6)
36
+ websocket-extensions (>= 0.1.0)
37
+ websocket-extensions (0.1.5)
38
+
39
+ PLATFORMS
40
+ arm64-darwin-22
41
+ x86_64-linux
42
+
43
+ DEPENDENCIES
44
+ browsing_facade!
45
+ rake
46
+ rspec (>= 3.12.0)
47
+
48
+ BUNDLED WITH
49
+ 2.4.10
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Martin Moen Wulffeld
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # browsing_facade
2
+
3
+ [![Gem Version](http://img.shields.io/gem/v/browsing_facade.svg)](https://rubygems.org/gems/browsing_facade)
4
+ [![Build Status](https://github.com/wulffeld/browsing_facade/workflows/CI/badge.svg?branch=main)](https://github.com/wulffeld/browsing_facade/actions?query=workflow%3ACI)
5
+ [![Gem Downloads](https://img.shields.io/gem/dt/browsing_facade.svg)](https://rubygems.org/gems/browsing_facade)
6
+ [![Maintainability](https://api.codeclimate.com/v1/badges/7b3c646f87ca2d6d691c/maintainability)](https://codeclimate.com/github/wulffeld/browsing_facade)
7
+
8
+ ## Installation
9
+
10
+ Include the gem in your Gemfile:
11
+
12
+ ```ruby
13
+ gem "browsing_facade"
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ```ruby
19
+ browse = BrowsingFacade.instance
20
+ browse.visit(url: "http://www.example.com")
21
+ puts browse.code
22
+ ```
23
+
24
+ ## Support
25
+
26
+ Submit suggestions or feature requests as a GitHub Issue or Pull
27
+ Request (preferred). If you send a pull request, remember to update the
28
+ corresponding unit tests. In fact, I prefer new features to be submitted in the
29
+ form of new unit tests.
30
+
31
+ ## Versioning
32
+
33
+ Semantic Versioning 2.0 as defined at <http://semver.org>.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,32 @@
1
+ require_relative "lib/browsing_facade/version"
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "browsing_facade"
5
+ spec.version = BrowsingFacade::VERSION
6
+ spec.authors = ["Martin Moen Wulffeld"]
7
+ spec.email = ["martin@wulffeld.dk"]
8
+
9
+ spec.summary = "A facade for browsing"
10
+ spec.homepage = "https://github.com/wulffeld/browsing_facade"
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = ">= 3.0"
13
+
14
+ spec.metadata["homepage_uri"] = spec.homepage
15
+ spec.metadata["source_code_uri"] = "https://github.com/wulffeld/browsing_facade"
16
+ spec.metadata["changelog_uri"] = "https://github.com/wulffeld/browsing_facade/CHANGELOG.md"
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
+ `git ls-files -z`.split("\x0").reject do |f|
22
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
23
+ end
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_runtime_dependency "ferrum"
30
+ spec.add_development_dependency "rspec", ">= 3.12.0"
31
+ spec.add_development_dependency "rake"
32
+ end
@@ -0,0 +1,3 @@
1
+ class BrowsingFacade
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,42 @@
1
+ require "ferrum"
2
+
3
+ class BrowsingFacade
4
+ include Singleton
5
+
6
+ def visit(url:)
7
+ @override_status = nil
8
+ browser.go_to(url)
9
+ rescue Ferrum::PendingConnectionsError,
10
+ Ferrum::TimeoutError,
11
+ Ferrum::StatusError
12
+ @override_status = 500
13
+ end
14
+
15
+ def code
16
+ return @override_status if @override_status
17
+
18
+ if browser.network.traffic[0]&.response&.status == 301
19
+ 301
20
+ else
21
+ browser.network.status
22
+ end
23
+ end
24
+
25
+ def cleanup
26
+ browser.reset
27
+ end
28
+
29
+ # If code was 301 then redirect_to will return the new url.
30
+ def redirect_to
31
+ browser.network.traffic[0].response.headers["Location"]
32
+ end
33
+
34
+ def quit
35
+ browser.quit
36
+ @browser = nil
37
+ end
38
+
39
+ def browser
40
+ @browser ||= Ferrum::Browser.new(timeout: 30)
41
+ end
42
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: browsing_facade
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Martin Moen Wulffeld
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-09-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ferrum
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: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 3.12.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 3.12.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - martin@wulffeld.dk
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".rspec"
63
+ - CHANGELOG.md
64
+ - Gemfile
65
+ - Gemfile.lock
66
+ - LICENSE
67
+ - README.md
68
+ - Rakefile
69
+ - browsing_facade.gemspec
70
+ - lib/browsing_facade.rb
71
+ - lib/browsing_facade/version.rb
72
+ homepage: https://github.com/wulffeld/browsing_facade
73
+ licenses:
74
+ - MIT
75
+ metadata:
76
+ homepage_uri: https://github.com/wulffeld/browsing_facade
77
+ source_code_uri: https://github.com/wulffeld/browsing_facade
78
+ changelog_uri: https://github.com/wulffeld/browsing_facade/CHANGELOG.md
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '3.0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubygems_version: 3.4.18
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: A facade for browsing
98
+ test_files: []