web_stat 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6743a3963d79b57d114dc9a8b24db21662e0b3a4c68f35979fc79fd937b7629a
4
- data.tar.gz: 49172adc663e23124ed0c31a422f201495008a5a1a08a409dca5051edb81c901
3
+ metadata.gz: f2eaf23097ccc295a0738b045d11652f1db3fdb1c1c373421a2c67d0e09d847c
4
+ data.tar.gz: c68e883f51d19432ebd8f644c497043a3c7aef6c41a6029423cffe57271a1073
5
5
  SHA512:
6
- metadata.gz: 73cdeede0a73dbb60edcdf236392c2e9c86335e9a78bf6f07742034e0df4e7b8b121c196166a32f3b63c95ce5736e9648a1223f0089d1860c0455ca11568a69c
7
- data.tar.gz: cdf235bd0b36d73e9c0d7a356f352f89d36fd37a97733518ea0277640e19b784b5c366c172c2e5b8395ddecad2dda2e61b1264f3d554e1a4547a5e7561a5732f
6
+ metadata.gz: e779c1c8718b9460f9b5f9caf508e8291086fe6d17ba920af140c0db258f5835fc0f83e360c0cc18c822032a3185ae09b381fc7099ffd96cead65734fae6dc68
7
+ data.tar.gz: 4e93cebd4ccbe0acd9f575a35d5b581fbb172aa0200186894eac9298ca7f0b45f047b3db85be00730f55fe5539e5c38abff14b321c7f8befc46364720afaee0d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- web_stat (0.2.1)
4
+ web_stat (0.2.2)
5
5
  bundler (>= 2.0.2)
6
6
  cld (>= 0.8.0)
7
7
  final_redirect_url (>= 0.1.0)
@@ -1,12 +1,22 @@
1
1
  require 'mechanize'
2
2
  module WebStat
3
+ class INVALID_URL < ::IOError; end
3
4
  class FetchAsWeb < Fetch
4
5
  # initialize class
5
6
  # @param [String] url
6
7
  def initialize(url)
8
+ unless url_valid?(url)
9
+ raise WebStat::INVALID_URL, url
10
+ end
7
11
  @url = original_url(url)
8
12
  @html = get_url(@url)
9
13
  @nokogiri = ::Nokogiri::HTML(@html)
10
14
  end
15
+
16
+ # Validation url
17
+ def url_valid?(url)
18
+ regexp = Regexp.new("^https?://([a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9])\\\.([a-zA-Z]{2,})(/.*)?$", Regexp::IGNORECASE)
19
+ regexp.match?(url)
20
+ end
11
21
  end
12
22
  end
@@ -1,3 +1,3 @@
1
1
  module WebStat
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -87,4 +87,11 @@ RSpec.describe WebStat::Fetch do
87
87
  expect(web_stat[:eyecatch_image_path]).to be_tmp_file_or_nil
88
88
  end
89
89
  end
90
+
91
+ it "invalid url" do
92
+ expect { WebStat.stat_by_url("aaaa") }.to raise_error(WebStat::INVALID_URL)
93
+ expect { WebStat.stat_by_url("http://newsdict/") }.to raise_error(WebStat::INVALID_URL)
94
+ expect { WebStat.stat_by_url("http://newsdict/afsdafasdf") }.to raise_error(WebStat::INVALID_URL)
95
+ expect { WebStat.stat_by_url("p://newsdict/afsdafasdf") }.to raise_error(WebStat::INVALID_URL)
96
+ end
90
97
  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.2.1
4
+ version: 0.2.2
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-01-02 00:00:00.000000000 Z
11
+ date: 2020-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler