ogo 0.0.1 → 0.0.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 +4 -4
- data/.gitignore +1 -0
- data/README.md +3 -1
- data/lib/ogo.rb +3 -0
- data/lib/ogo/opengraph.rb +51 -11
- data/lib/ogo/utils/redirect_follower.rb +15 -6
- data/lib/ogo/version.rb +1 -1
- data/ogo.gemspec +2 -0
- data/spec/lib/ogo/opengraph_spec.rb +133 -0
- data/spec/lib/ogo/utils/redirect_follower_spec.rb +83 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/view/euc-jp.html +23 -0
- data/spec/view/opengraph.html +22 -0
- data/spec/view/opengraph_no_meta_nor_description.html +12 -0
- data/spec/view/opengraph_no_metadata.html +12 -0
- data/spec/view/shift_jis.html +23 -0
- metadata +38 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41df5206b948578ceb2d31a306c73f84f35b837e
|
4
|
+
data.tar.gz: f871b617057c6b54f11dd2aa255880d6a623db8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ddeef19fba2db90c1f70729e9d99ed8d7c2f908eafb83b2b791139262a88d66d096cf8b855e695ad6608112f6652f27fc5a21a579e135b067caf0fdb784117e6
|
7
|
+
data.tar.gz: 1b714a39fece5216852e31eadfbcf9822e50cd3233c98871015b55d0d99ceeed3587132bd6cb96129cef644a62374ff5102654730931eb938f16f12ef96b9fb3
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -3,7 +3,9 @@
|
|
3
3
|
## Information
|
4
4
|
|
5
5
|
Implementation of first verion of this gem based mostly on @huyha85's opengraph_parser
|
6
|
-
https://github.com/huyha85/opengraph_parser and its forks
|
6
|
+
https://github.com/huyha85/opengraph_parser and its forks:
|
7
|
+
|
8
|
+
Charset support taken from @codefist fork: https://github.com/codefirst/opengraph_parser
|
7
9
|
|
8
10
|
I prefer to make my own repo for this gem as origin repo is seemingly-abandoned and
|
9
11
|
I need more functionality than just opengraph (ogp.me) tags parsing.
|
data/lib/ogo.rb
CHANGED
data/lib/ogo/opengraph.rb
CHANGED
@@ -1,18 +1,17 @@
|
|
1
|
-
require 'nokogiri'
|
2
|
-
require 'utils/redirect_follower'
|
3
|
-
require "addressable/uri"
|
4
|
-
require 'uri'
|
5
|
-
|
6
1
|
module Ogo
|
7
2
|
class Opengraph
|
8
3
|
|
9
|
-
attr_accessor :src, :url, :type, :title, :description,
|
4
|
+
attr_accessor :src, :url, :type, :title, :description,
|
5
|
+
:images, :metadata, :response, :body, :charset, :original_images,
|
6
|
+
:error
|
10
7
|
|
11
8
|
def initialize(src, options = {})
|
12
9
|
@src = src
|
13
10
|
@body = nil
|
14
11
|
@images = []
|
15
12
|
@metadata = {}
|
13
|
+
@charset = 'utf-8'
|
14
|
+
@error = nil
|
16
15
|
|
17
16
|
@_fallback = options[:fallback] || true
|
18
17
|
@_options = options
|
@@ -22,6 +21,22 @@ module Ogo
|
|
22
21
|
parse_opengraph(@_options)
|
23
22
|
load_fallback if @_fallback
|
24
23
|
check_images_path
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
def parse!
|
28
|
+
parse
|
29
|
+
error ? raise(error) : self
|
30
|
+
end
|
31
|
+
|
32
|
+
def inspect
|
33
|
+
str = "<Ogo::Opengraph:0x00#{'%x' % (self.object_id << 1)}\nurl=\"#{url}\",\nmetadata=#{metadata},\n"
|
34
|
+
str << "images=#{images},\ntype=\"#{type}\",\ntitle=\"#{title}\">"
|
35
|
+
str
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_s
|
39
|
+
inspect
|
25
40
|
end
|
26
41
|
|
27
42
|
private
|
@@ -31,16 +46,19 @@ module Ogo
|
|
31
46
|
if src.include? '</html>'
|
32
47
|
self.body = src
|
33
48
|
else
|
34
|
-
|
49
|
+
resolved = Ogo::Utils::RedirectFollower.new(src, options).resolve
|
50
|
+
self.body = resolved.body
|
51
|
+
self.charset = resolved.charset if resolved.charset
|
35
52
|
end
|
36
|
-
rescue
|
53
|
+
rescue => e
|
37
54
|
self.title = self.url = src
|
55
|
+
self.error = e
|
38
56
|
return
|
39
57
|
end
|
40
58
|
|
41
59
|
if body
|
42
60
|
attrs_list = %w(title url type description)
|
43
|
-
doc =
|
61
|
+
doc = parse_html
|
44
62
|
doc.css('meta').each do |m|
|
45
63
|
if m.attribute('property') && m.attribute('property').to_s.match(/^og:(.+)$/i)
|
46
64
|
m_content = m.attribute('content').to_s.strip
|
@@ -59,7 +77,7 @@ module Ogo
|
|
59
77
|
|
60
78
|
def load_fallback
|
61
79
|
if body
|
62
|
-
doc =
|
80
|
+
doc = parse_html
|
63
81
|
|
64
82
|
if title.to_s.empty? && doc.xpath("//head//title").size > 0
|
65
83
|
self.title = doc.xpath("//head//title").first.text.to_s.strip
|
@@ -82,7 +100,7 @@ module Ogo
|
|
82
100
|
|
83
101
|
def check_images_path
|
84
102
|
self.original_images = images.dup
|
85
|
-
uri = Addressable::URI.parse(
|
103
|
+
uri = Addressable::URI.parse(url)
|
86
104
|
imgs = images.dup
|
87
105
|
self.images = []
|
88
106
|
imgs.each do |img|
|
@@ -135,5 +153,27 @@ module Ogo
|
|
135
153
|
metadata_container
|
136
154
|
end
|
137
155
|
end
|
156
|
+
|
157
|
+
def parse_html
|
158
|
+
unless charset
|
159
|
+
doc = Nokogiri.parse(body.scrub)
|
160
|
+
self.charset = guess_encoding(doc)
|
161
|
+
end
|
162
|
+
Nokogiri::HTML(body, nil, charset)
|
163
|
+
end
|
164
|
+
|
165
|
+
def guess_encoding(doc)
|
166
|
+
_charset = doc.xpath('//meta/@charset').first
|
167
|
+
return _charset.value.to_s if charset
|
168
|
+
|
169
|
+
_charset = doc.xpath('//meta').each do |m|
|
170
|
+
if m.attribute('http-equiv') && m.attribute('content') && m.attribute('http-equiv').value.casecmp('Content-Type')
|
171
|
+
return m.attribute('content').value.split('charset=').last.strip
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
'UTF-8'
|
176
|
+
end
|
177
|
+
|
138
178
|
end
|
139
179
|
end
|
@@ -6,22 +6,23 @@ module Ogo
|
|
6
6
|
REDIRECT_DEFAULT_LIMIT = 5
|
7
7
|
|
8
8
|
class TooManyRedirects < StandardError; end
|
9
|
+
class EmptyURLError < ArgumentError; end
|
9
10
|
|
10
|
-
attr_accessor :url, :body, :redirect_limit, :response, :headers
|
11
|
+
attr_accessor :url, :body, :charset, :redirect_limit, :response, :headers
|
11
12
|
|
12
13
|
def initialize(url, options = {})
|
13
|
-
|
14
|
+
raise EmptyURLError if url.to_s.empty?
|
15
|
+
@redirect_limit = options[:limit] || REDIRECT_DEFAULT_LIMIT
|
14
16
|
@headers = options[:headers] || {}
|
15
|
-
@url = url
|
17
|
+
@url = url.start_with?('http') ? url : "http://#{url}"
|
16
18
|
end
|
17
19
|
|
18
20
|
def resolve
|
19
21
|
raise TooManyRedirects if redirect_limit < 0
|
20
22
|
|
21
|
-
|
22
|
-
uri = Addressable::URI.parse(URI.escape(url))
|
23
|
+
uri = Addressable::URI.parse(url).normalize
|
23
24
|
|
24
|
-
http = Net::HTTP.new(uri.host, uri.
|
25
|
+
http = Net::HTTP.new(uri.host, uri.inferred_port)
|
25
26
|
if uri.scheme == 'https'
|
26
27
|
http.use_ssl = true
|
27
28
|
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
@@ -35,6 +36,14 @@ module Ogo
|
|
35
36
|
resolve
|
36
37
|
end
|
37
38
|
|
39
|
+
charset = nil
|
40
|
+
if content_type = response['content-type']
|
41
|
+
if content_type =~ /charset=(.+)/i
|
42
|
+
charset = $1
|
43
|
+
end
|
44
|
+
end
|
45
|
+
self.charset = charset
|
46
|
+
|
38
47
|
self.body = response.body
|
39
48
|
self
|
40
49
|
end
|
data/lib/ogo/version.rb
CHANGED
data/ogo.gemspec
CHANGED
@@ -19,5 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.add_dependency 'nokogiri', '>= 1.6'
|
20
20
|
s.add_dependency 'addressable', '>= 2.4.0'
|
21
21
|
s.add_development_dependency 'rspec', '>= 3.0'
|
22
|
+
s.add_development_dependency 'pry'
|
23
|
+
s.add_development_dependency 'byebug'
|
22
24
|
s.add_development_dependency 'rake'
|
23
25
|
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe Ogo::Opengraph do
|
4
|
+
describe "#initialize" do
|
5
|
+
context "with invalid src" do
|
6
|
+
it "set title and url the same as src" do
|
7
|
+
og = Ogo::Opengraph.new("invalid")
|
8
|
+
og.parse
|
9
|
+
expect(og.src).to eq "invalid"
|
10
|
+
expect(og.title).to eq "invalid"
|
11
|
+
expect(og.url).to eq "invalid"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "with no fallback" do
|
16
|
+
it "should get values from opengraph metadata" do
|
17
|
+
response = double(charset: 'UTF-8', body: File.open("#{File.dirname(__FILE__)}/../../view/opengraph.html", 'r') { |f| f.read })
|
18
|
+
Ogo::Utils::RedirectFollower.stub(:new) { double(resolve: response) }
|
19
|
+
|
20
|
+
og = Ogo::Opengraph.new("http://test.host", fallback: false)
|
21
|
+
og.parse
|
22
|
+
og.src.should == "http://test.host"
|
23
|
+
og.title.should == "OpenGraph Title"
|
24
|
+
og.type.should == "article"
|
25
|
+
og.url.should == "http://test.host"
|
26
|
+
og.description.should == "My OpenGraph sample site for Rspec"
|
27
|
+
og.images.should == ["http://test.host/images/rock1.jpg", "http://test.host/images/rock2.jpg"]
|
28
|
+
og.original_images.should == ["http://test.host/images/rock1.jpg", "/images/rock2.jpg"]
|
29
|
+
og.metadata.should == {
|
30
|
+
title: [{_value: "OpenGraph Title"}],
|
31
|
+
type: [{_value: "article"}],
|
32
|
+
url: [{_value: "http://test.host"}],
|
33
|
+
description: [{_value: "My OpenGraph sample site for Rspec"}],
|
34
|
+
image: [
|
35
|
+
{
|
36
|
+
_value: "http://test.host/images/rock1.jpg",
|
37
|
+
width: [{ _value: "300" }],
|
38
|
+
height: [{ _value: "300" }]
|
39
|
+
},
|
40
|
+
{
|
41
|
+
_value: "/images/rock2.jpg",
|
42
|
+
height: [{ _value: "1000" }]
|
43
|
+
}
|
44
|
+
],
|
45
|
+
locale: [
|
46
|
+
{
|
47
|
+
_value: "en_GB",
|
48
|
+
alternate: [
|
49
|
+
{ _value: "fr_FR" },
|
50
|
+
{ _value: "es_ES" }
|
51
|
+
]
|
52
|
+
}
|
53
|
+
]
|
54
|
+
}
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "with fallback" do
|
59
|
+
context "when website has opengraph metadata" do
|
60
|
+
it "should get values from opengraph metadata" do
|
61
|
+
response = double(charset: 'UTF-8', body: File.open("#{File.dirname(__FILE__)}/../../view/opengraph.html", 'r') { |f| f.read })
|
62
|
+
Ogo::Utils::RedirectFollower.stub(:new) { double(resolve: response) }
|
63
|
+
|
64
|
+
og = Ogo::Opengraph.new("http://test.host")
|
65
|
+
og.parse
|
66
|
+
og.src.should == "http://test.host"
|
67
|
+
og.title.should == "OpenGraph Title"
|
68
|
+
og.type.should == "article"
|
69
|
+
og.url.should == "http://test.host"
|
70
|
+
og.description.should == "My OpenGraph sample site for Rspec"
|
71
|
+
og.images.should == ["http://test.host/images/rock1.jpg", "http://test.host/images/rock2.jpg"]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "when website has no opengraph metadata" do
|
76
|
+
it "should lookup for other data from website" do
|
77
|
+
response = double(charset: 'UTF-8', body: File.open("#{File.dirname(__FILE__)}/../../view/opengraph_no_metadata.html", 'r') { |f| f.read })
|
78
|
+
Ogo::Utils::RedirectFollower.stub(:new) { double(resolve: response) }
|
79
|
+
|
80
|
+
og = Ogo::Opengraph.new("http://test.host/child_page")
|
81
|
+
og.parse
|
82
|
+
og.src.should == "http://test.host/child_page"
|
83
|
+
og.title.should == "OpenGraph Title Fallback"
|
84
|
+
og.type.should be_nil
|
85
|
+
og.url.should == "http://test.host/child_page"
|
86
|
+
og.description.should == "Short Description Fallback"
|
87
|
+
og.images.should == ["http://test.host/images/wall1.jpg", "http://test.host/images/wall2.jpg"]
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context "with body" do
|
93
|
+
it "should parse body instead of downloading it" do
|
94
|
+
content = File.read("#{File.dirname(__FILE__)}/../../view/opengraph.html")
|
95
|
+
Ogo::Utils::RedirectFollower.should_not_receive(:new)
|
96
|
+
|
97
|
+
og = Ogo::Opengraph.new(content)
|
98
|
+
og.parse
|
99
|
+
og.src.should == content
|
100
|
+
og.title.should == "OpenGraph Title"
|
101
|
+
og.type.should == "article"
|
102
|
+
og.url.should == "http://test.host"
|
103
|
+
og.description.should == "My OpenGraph sample site for Rspec"
|
104
|
+
og.images.should == ["http://test.host/images/rock1.jpg", "http://test.host/images/rock2.jpg"]
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context "with Shift_JIS" do
|
109
|
+
it "should get values from opengraph metadata" do
|
110
|
+
pending 'Not working'
|
111
|
+
response = double(charset: 'euc-jp', body: File.open("#{File.dirname(__FILE__)}/../../view/shift_jis.html", 'r') { |f| f.read })
|
112
|
+
Ogo::Utils::RedirectFollower.stub(:new) { double(resolve: response) }
|
113
|
+
|
114
|
+
og = Ogo::Opengraph.new("http://test.host", fallback: false)
|
115
|
+
og.parse
|
116
|
+
og.src.should == "http://test.host"
|
117
|
+
og.title.should == "日本語"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
context "with EUC-JP" do
|
121
|
+
it "should get values from opengraph metadata" do
|
122
|
+
pending 'Not working'
|
123
|
+
response = double(charset: 'euc-jp', body: File.open("#{File.dirname(__FILE__)}/../../view/euc-jp.html", 'r') { |f| f.read })
|
124
|
+
Ogo::Utils::RedirectFollower.stub(:new) { double(resolve: response) }
|
125
|
+
|
126
|
+
og = Ogo::Opengraph.new("http://test.host", fallback: false)
|
127
|
+
og.parse
|
128
|
+
og.src.should == "http://test.host"
|
129
|
+
og.title.should == "日本語"
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
|
2
|
+
|
3
|
+
describe Ogo::Utils::RedirectFollower do
|
4
|
+
describe "#resolve" do
|
5
|
+
let(:url) { "http://test.host" }
|
6
|
+
let(:https_url) { "https://test.host" }
|
7
|
+
let(:mock_res) { double(body: "Body is here.") }
|
8
|
+
let(:mock_redirect) {
|
9
|
+
m = double(body: %Q{<body><a href="http://new.test.host"></a></body>}, kind_of?: Net::HTTPRedirection)
|
10
|
+
m.stub(:[]).and_return(nil)
|
11
|
+
m
|
12
|
+
}
|
13
|
+
|
14
|
+
context "with no redirection" do
|
15
|
+
it "should return the response" do
|
16
|
+
uri = URI.parse(URI.escape(url))
|
17
|
+
|
18
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
19
|
+
Net::HTTP.should_receive(:new).with(uri.host, uri.port).and_return(http)
|
20
|
+
http.should_receive(:request_get).and_return(mock_res)
|
21
|
+
|
22
|
+
res = Ogo::Utils::RedirectFollower.new(url).resolve
|
23
|
+
res.body.should == "Body is here."
|
24
|
+
res.redirect_limit.should == Ogo::Utils::RedirectFollower::REDIRECT_DEFAULT_LIMIT
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "and uri scheme is HTTPS" do
|
28
|
+
it "should use https method to retrieve the uri" do
|
29
|
+
uri = URI.parse(URI.escape(https_url))
|
30
|
+
|
31
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
32
|
+
Net::HTTP.should_receive(:new).with(uri.host, uri.port).and_return(https)
|
33
|
+
https.should_receive(:request_get).and_return(mock_res)
|
34
|
+
|
35
|
+
res = Ogo::Utils::RedirectFollower.new(https_url).resolve
|
36
|
+
res.body.should == "Body is here."
|
37
|
+
res.redirect_limit.should == Ogo::Utils::RedirectFollower::REDIRECT_DEFAULT_LIMIT
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "and has headers option" do
|
42
|
+
it "should add headers when retrieve the uri" do
|
43
|
+
uri = URI.parse(URI.escape(url))
|
44
|
+
|
45
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
46
|
+
Net::HTTP.should_receive(:new).with(uri.host, uri.port).and_return(http)
|
47
|
+
http.should_receive(:request_get).and_return(mock_res)
|
48
|
+
res = Ogo::Utils::RedirectFollower.new(url, {:headers => {'User-Agent' => 'My Custom User-Agent'}}).resolve
|
49
|
+
res.body.should == "Body is here."
|
50
|
+
res.redirect_limit.should == Ogo::Utils::RedirectFollower::REDIRECT_DEFAULT_LIMIT
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "with redirection" do
|
56
|
+
it "should follow the link in redirection" do
|
57
|
+
uri = URI.parse(URI.escape(url))
|
58
|
+
|
59
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
60
|
+
Net::HTTP.should_receive(:new).twice.and_return(http)
|
61
|
+
http.should_receive(:request_get).twice.and_return(mock_redirect, mock_res)
|
62
|
+
|
63
|
+
res = Ogo::Utils::RedirectFollower.new(url).resolve
|
64
|
+
res.body.should == "Body is here."
|
65
|
+
res.redirect_limit.should == Ogo::Utils::RedirectFollower::REDIRECT_DEFAULT_LIMIT - 1
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "with unlimited redirection" do
|
70
|
+
it "should raise TooManyRedirects error" do
|
71
|
+
uri = URI.parse(URI.escape(url))
|
72
|
+
|
73
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
74
|
+
Net::HTTP.stub(:new).and_return(http)
|
75
|
+
http.stub(:request_get).and_return(mock_redirect)
|
76
|
+
|
77
|
+
lambda {
|
78
|
+
Ogo::Utils::RedirectFollower.new(url).resolve
|
79
|
+
}.should raise_error(Ogo::Utils::RedirectFollower::TooManyRedirects)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'ogo'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<meta http-equiv="Content-Type" content="text/html; charset=euc-jp">
|
4
|
+
<title>OpenGraph Title Fallback</title>
|
5
|
+
<meta property="og:title" content="ÆüËܸì" />
|
6
|
+
<meta property="og:type" content="article" />
|
7
|
+
<meta property="og:url" content="http://test.host" />
|
8
|
+
<meta property="og:description" content="My OpenGraph sample site for Rspec" />
|
9
|
+
<meta property="og:image" content="http://test.host/images/rock1.jpg" />
|
10
|
+
<meta property="og:image:width" content="300" />
|
11
|
+
<meta property="og:image:height" content="300" />
|
12
|
+
<meta property="og:image" content="/images/rock2.jpg" />
|
13
|
+
<meta property="og:image:height" content="1000" />
|
14
|
+
<meta property="og:locale" content="en_GB" />
|
15
|
+
<meta property="og:locale:alternate" content="fr_FR" />
|
16
|
+
<meta property="og:locale:alternate" content="es_ES" />
|
17
|
+
<meta name="description" content="Short Description Fallback" />
|
18
|
+
</head>
|
19
|
+
<body>
|
20
|
+
<img src="http://test.host/images/wall1.jpg" />
|
21
|
+
<img src="http://test.host/images/wall2.jpg" />
|
22
|
+
</body>
|
23
|
+
</html>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title>OpenGraph Title Fallback</title>
|
4
|
+
<meta property="og:title" content="OpenGraph Title" />
|
5
|
+
<meta property="og:type" content="article" />
|
6
|
+
<meta property="og:url" content="http://test.host" />
|
7
|
+
<meta property="og:description" content="My OpenGraph sample site for Rspec" />
|
8
|
+
<meta property="og:image" content="http://test.host/images/rock1.jpg" />
|
9
|
+
<meta property="og:image:width" content="300" />
|
10
|
+
<meta property="og:image:height" content="300" />
|
11
|
+
<meta property="og:image" content="/images/rock2.jpg" />
|
12
|
+
<meta property="og:image:height" content="1000" />
|
13
|
+
<meta property="og:locale" content="en_GB" />
|
14
|
+
<meta property="og:locale:alternate" content="fr_FR" />
|
15
|
+
<meta property="og:locale:alternate" content="es_ES" />
|
16
|
+
<meta name="description" content="Short Description Fallback" />
|
17
|
+
</head>
|
18
|
+
<body>
|
19
|
+
<img src="http://test.host/images/wall1.jpg" />
|
20
|
+
<img src="http://test.host/images/wall2.jpg" />
|
21
|
+
</body>
|
22
|
+
</html>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title>OpenGraph Title Fallback</title>
|
4
|
+
<meta property="og:type" content="" />
|
5
|
+
<meta property="og:url" content="" />
|
6
|
+
</head>
|
7
|
+
<body>
|
8
|
+
<img src="/images/wall1.jpg" />
|
9
|
+
<img src="../images/wall2.jpg" />
|
10
|
+
<p>No description meta here.</p>
|
11
|
+
</body>
|
12
|
+
</html>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title>OpenGraph Title Fallback</title>
|
4
|
+
<meta name="description" content="Short Description Fallback" />
|
5
|
+
<meta property="og:type" content="" />
|
6
|
+
<meta property="og:url" content="" />
|
7
|
+
</head>
|
8
|
+
<body>
|
9
|
+
<img src="/images/wall1.jpg" />
|
10
|
+
<img src="../images/wall2.jpg" />
|
11
|
+
</body>
|
12
|
+
</html>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<meta charset="Shift_JIS" />
|
4
|
+
<title>OpenGraph Title Fallback</title>
|
5
|
+
<meta property="og:title" content="“ú–{Œê" />
|
6
|
+
<meta property="og:type" content="article" />
|
7
|
+
<meta property="og:url" content="http://test.host" />
|
8
|
+
<meta property="og:description" content="My OpenGraph sample site for Rspec" />
|
9
|
+
<meta property="og:image" content="http://test.host/images/rock1.jpg" />
|
10
|
+
<meta property="og:image:width" content="300" />
|
11
|
+
<meta property="og:image:height" content="300" />
|
12
|
+
<meta property="og:image" content="/images/rock2.jpg" />
|
13
|
+
<meta property="og:image:height" content="1000" />
|
14
|
+
<meta property="og:locale" content="en_GB" />
|
15
|
+
<meta property="og:locale:alternate" content="fr_FR" />
|
16
|
+
<meta property="og:locale:alternate" content="es_ES" />
|
17
|
+
<meta name="description" content="Short Description Fallback" />
|
18
|
+
</head>
|
19
|
+
<body>
|
20
|
+
<img src="http://test.host/images/wall1.jpg" />
|
21
|
+
<img src="http://test.host/images/wall2.jpg" />
|
22
|
+
</body>
|
23
|
+
</html>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ogo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- gazay
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -52,6 +52,34 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
84
|
name: rake
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -83,6 +111,14 @@ files:
|
|
83
111
|
- lib/ogo/utils/redirect_follower.rb
|
84
112
|
- lib/ogo/version.rb
|
85
113
|
- ogo.gemspec
|
114
|
+
- spec/lib/ogo/opengraph_spec.rb
|
115
|
+
- spec/lib/ogo/utils/redirect_follower_spec.rb
|
116
|
+
- spec/spec_helper.rb
|
117
|
+
- spec/view/euc-jp.html
|
118
|
+
- spec/view/opengraph.html
|
119
|
+
- spec/view/opengraph_no_meta_nor_description.html
|
120
|
+
- spec/view/opengraph_no_metadata.html
|
121
|
+
- spec/view/shift_jis.html
|
86
122
|
homepage: https://github.com/gazay/ogo
|
87
123
|
licenses:
|
88
124
|
- MIT
|