web_stat 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f62b7ce2720dcd1851a3c0620af8da6e00313e1b5de918e8b1e23ceeeacee89
4
- data.tar.gz: 1a52579415bf2a4f96efd39931ef41849751f693658f5cfbcd88202c680a446c
3
+ metadata.gz: bf6e7c6f1461adb76d15e934bbcb4866350dbef5ee45dc36ab5bac44cac88ce5
4
+ data.tar.gz: 3f788539423a476ba805b5cc023320fbd9e16b5ef3cffe476f8c7c9a9c6bcedf
5
5
  SHA512:
6
- metadata.gz: 51b5d4fbc2e0969913cec3c1ae4b745cca8a790b4f9638d9a920d844840500424c69f18e7d3f58d2d870b8391e0817f06781699b302f36b2a68d81467608a867
7
- data.tar.gz: 2d4ba4bfac9c5d5c76fcc48ba0202b7dbf223b4f42b7d6a649cce22c0742d6b7605c3386c93be2cb29487308714fc94fd2bf1063faf78bdcd5b7b6c5ab060d8b
6
+ metadata.gz: 77787d2811e56d7e7db5d78c378204ff83fb44252a38c41e5843e8abf98e5c06dc5e5763f5e877202557294ea480c065f541f05ae9bd944e28433d9f46be5520
7
+ data.tar.gz: ed612a3a5bb29330c08876736e834a166f658db6f4ca75c7d93c120a60ddeb25695f98416efaeb5d42693b2278b74ca22ab83b77235135b962ce0f9ed956fd6a
@@ -1,28 +1,30 @@
1
- class WebDriverHelper
2
- class << self
3
- # Get last url
4
- # @param [String] url
5
- # @param [Integer] delay
6
- def get_last_url(url, delay=nil)
7
- Selenium::WebDriver.logger.output = File.join("/tmp", "selenium.log")
8
- Selenium::WebDriver.logger.level = :info
9
- options = Selenium::WebDriver::Chrome::Options.new(args: [
10
- 'headless',
11
- 'no-sandbox',
12
- 'disable-gpu',
13
- 'start-maximized',
14
- 'window-size=1920,1080'
15
- ])
16
- driver = Selenium::WebDriver.for(:chrome, options: options)
17
- driver.manage.timeouts.implicit_wait = 10
18
- Selenium::WebDriver::Wait.new(timeout: 10)
19
- driver.get(url)
20
- if delay.is_a?(Integer)
21
- sleep delay
1
+ module WebStat
2
+ class WebDriverHelper
3
+ class << self
4
+ # Get last url
5
+ # @param [String] url
6
+ # @param [Integer] delay
7
+ def get_last_url(url, delay=nil)
8
+ Selenium::WebDriver.logger.output = File.join("/tmp", "selenium.log")
9
+ Selenium::WebDriver.logger.level = :info
10
+ options = Selenium::WebDriver::Chrome::Options.new(args: [
11
+ 'headless',
12
+ 'no-sandbox',
13
+ 'disable-gpu',
14
+ 'start-maximized',
15
+ 'window-size=1920,1080'
16
+ ])
17
+ driver = Selenium::WebDriver.for(:chrome, options: options)
18
+ driver.manage.timeouts.implicit_wait = 10
19
+ Selenium::WebDriver::Wait.new(timeout: 10)
20
+ driver.get(url)
21
+ if delay.is_a?(Integer)
22
+ sleep delay
23
+ end
24
+ last_url = driver.current_url
25
+ driver.quit
26
+ last_url
22
27
  end
23
- last_url = driver.current_url
24
- driver.quit
25
- last_url
26
28
  end
27
29
  end
28
30
  end
@@ -122,7 +122,7 @@ module WebStat
122
122
  # Get original url
123
123
  # @param [String] url
124
124
  def original_url(url)
125
- last_url = FinalRedirectUrl.final_redirect_url(url)
125
+ last_url = WebStat::FinalRedirectUrl.final_redirect_url(url)
126
126
  unless last_url.nil? || last_url.scrub('').empty?
127
127
  last_url
128
128
  else
@@ -1,50 +1,50 @@
1
1
  # ref) https://github.com/indyarocks/final_redirect_url
2
2
  # customize
3
3
  # Changed
4
-
5
- module FinalRedirectUrl
6
-
7
- def self.final_redirect_url(url, options={})
8
- final_url = ''
9
- if is_valid_url?(url)
10
- begin
11
- redirect_lookup_depth = options[:depth].to_i > 0 ? options[:depth].to_i : 10
12
- response_uri = get_final_redirect_url(url, redirect_lookup_depth)
13
- final_url = url_string_from_uri(response_uri)
14
- rescue Exception => ex
15
- # nothing
4
+ module WebStat
5
+ class FinalRedirectUrl
6
+ class << self
7
+ def final_redirect_url(url, options={})
8
+ final_url = ''
9
+ if is_valid_url?(url)
10
+ begin
11
+ redirect_lookup_depth = options[:depth].to_i > 0 ? options[:depth].to_i : 10
12
+ response_uri = get_final_redirect_url(url, redirect_lookup_depth)
13
+ final_url = url_string_from_uri(response_uri)
14
+ rescue Exception => ex
15
+ # nothing
16
+ end
17
+ end
18
+ final_url
16
19
  end
17
- end
18
- final_url
19
- end
20
-
21
- private
22
- def self.is_valid_url?(url)
23
- url.to_s.match? URI::regexp(['http', 'https'])
24
- end
25
-
26
- def self.get_final_redirect_url(url, limit = 10)
27
- return url if limit <= 0
28
- uri = URI.parse(url)
29
- response = ::Net::HTTP.get_response(uri)
30
- if response.class == Net::HTTPOK
31
- return URI.parse(WebDriverHelper.get_last_url(uri))
32
- else
33
- redirect_location = response['location']
34
- location_uri = URI.parse(redirect_location)
35
- if location_uri.host.nil?
36
- redirect_location = uri.scheme + '://' + uri.host + redirect_location
20
+
21
+ private
22
+ def is_valid_url?(url)
23
+ url.to_s.match? URI::regexp(['http', 'https'])
24
+ end
25
+ def get_final_redirect_url(url, limit = 10)
26
+ return url if limit <= 0
27
+ uri = URI.parse(url)
28
+ response = ::Net::HTTP.get_response(uri)
29
+ if response.class == Net::HTTPOK
30
+ return URI.parse(WebStat::WebDriverHelper.get_last_url(uri))
31
+ else
32
+ redirect_location = response['location']
33
+ location_uri = URI.parse(redirect_location)
34
+ if location_uri.host.nil?
35
+ redirect_location = uri.scheme + '://' + uri.host + redirect_location
36
+ end
37
+ warn "redirected to #{redirect_location}"
38
+ get_final_redirect_url(redirect_location, limit - 1)
39
+ end
40
+ end
41
+ def url_string_from_uri(uri)
42
+ url_str = "#{uri.scheme}://#{uri.host}#{uri.request_uri}"
43
+ if uri.fragment
44
+ url_str = url_str + "##{uri.fragment}"
45
+ end
46
+ url_str
37
47
  end
38
- warn "redirected to #{redirect_location}"
39
- get_final_redirect_url(redirect_location, limit - 1)
40
- end
41
- end
42
-
43
- def self.url_string_from_uri(uri)
44
- url_str = "#{uri.scheme}://#{uri.host}#{uri.request_uri}"
45
- if uri.fragment
46
- url_str = url_str + "##{uri.fragment}"
47
48
  end
48
- url_str
49
49
  end
50
- end
50
+ end
@@ -1,3 +1,3 @@
1
1
  module WebStat
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web_stat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - yusuke abe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-11 00:00:00.000000000 Z
11
+ date: 2020-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler