web_stat 0.1.4 → 0.1.5

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: 7d345b565a961f56aed9c6d8066d0e30d277709fc1db322955a22593c8ad274d
4
- data.tar.gz: 41839683fc9f346fba303f15b15db5ee8544c4525ad506c7f35544d7d5290372
3
+ metadata.gz: 4d0d937e282be9703078c9d3020ae5234109fd313d85bfeae2238d46cf77d0cb
4
+ data.tar.gz: fa312d255074eaf53e4af3c16400d783a390e73ebe2e35d545891a2e40010f66
5
5
  SHA512:
6
- metadata.gz: 4b1fffc06896ed0b6ba91bfd765f05be10b53d77c735474a45b9780f5661c8e4ffed66e47666dfe49ed57aaa643e0e24c509ae1b71398ce1eb0358d6b4073966
7
- data.tar.gz: c0829dbc658f6c3a40e08b248be139f79ad6acb5a880c237122cd096238cf10333c19c147974338c021ac64fd52e35d6bb071080c8043f7f27ac8d5cae439923
6
+ metadata.gz: e54007687bf53813bd08e11bec1e14812abda574f3129d0123676c5e7729eca943fddf7e5995342c179c6ca2c135bcbbaffa0657952c52d1c57d52c368f3b9af
7
+ data.tar.gz: a69e0fc7e9a1b0c1b7b0360514ac96f9dd8d02ddef37ef9d2ea9a7cd8e05e7543b6cb0c36f62eef705f13c9d6812d9933e812a466f03925f9fc379110a60eeb0
data/.gitignore CHANGED
@@ -13,3 +13,6 @@
13
13
  # builded gems
14
14
  *.gem
15
15
  /config
16
+
17
+ # jetbrain
18
+ /.idea
@@ -11,10 +11,15 @@ require "web_stat/fetch/fetch_as_web"
11
11
  module WebStat
12
12
  class << self
13
13
  # Get web page's stat by url
14
- def stat_by_url(url)
14
+ def stat_by_web(url)
15
15
  web_stat = WebStat::FetchAsWeb.new(url)
16
16
  web_stat.stat
17
17
  end
18
+
19
+ # Get web page's stat by url
20
+ def stat_by_url(url)
21
+ stat_by_web(url)
22
+ end
18
23
 
19
24
  # Get web page's stat by html
20
25
  def stat_by_html(html)
@@ -2,6 +2,7 @@ require 'uri'
2
2
  require 'digest'
3
3
  require 'sanitize'
4
4
  require 'nokogiri'
5
+ require 'open-uri'
5
6
  require 'ruby-readability'
6
7
  require 'final_redirect_url'
7
8
  module WebStat
@@ -61,8 +62,10 @@ module WebStat
61
62
  def save_local_path(url)
62
63
  return nil if url.nil? || !url.match(/^http/)
63
64
  tmp_file = "/tmp/#{Digest::SHA1.hexdigest(url)}"
64
- File.open(tmp_file, "w") do |_file|
65
- _file.puts(get_url(url))
65
+ open(original_url(url)) do |remote_file|
66
+ File.open(tmp_file, "w+b") do |_file|
67
+ _file.puts(remote_file.read)
68
+ end
66
69
  end
67
70
  tmp_file
68
71
  end
@@ -83,10 +86,22 @@ module WebStat
83
86
  title: title,
84
87
  site_name: site_name,
85
88
  content: content,
86
- url: original_url,
89
+ url: @url,
87
90
  eyecatch_image_path: save_local_path(eyecatch_image_path),
88
91
  tags: tag.nouns
89
92
  }
90
93
  end
94
+
95
+ private
96
+
97
+ # Get original url
98
+ # @param [String] url
99
+ def original_url(url)
100
+ if url.match(/^http/)
101
+ FinalRedirectUrl.final_redirect_url(url)
102
+ else
103
+ url
104
+ end
105
+ end
91
106
  end
92
107
  end
@@ -6,18 +6,9 @@ module WebStat
6
6
  # initialize class
7
7
  # @param [String] url
8
8
  def initialize(url)
9
- @url = url
10
- @html = get_url(url).force_encoding("utf-8")
9
+ @url = original_url(url)
10
+ @html = get_url(url)
11
11
  @nokogiri = ::Nokogiri::HTML(@html)
12
12
  end
13
-
14
- # Get original url
15
- def original_url
16
- if @url.match(/^http/)
17
- FinalRedirectUrl.final_redirect_url(@url)
18
- else
19
- @url
20
- end
21
- end
22
13
  end
23
14
  end
@@ -1,3 +1,3 @@
1
1
  module WebStat
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
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.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - yusuke abe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-14 00:00:00.000000000 Z
11
+ date: 2019-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler