ogp 0.2.0 → 0.3.0

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
- SHA1:
3
- metadata.gz: ca2fa62d7e09874c7999112994aa53385734c2b1
4
- data.tar.gz: e44b5cb9f6eebf69a0a1e03f931f9502af687f10
2
+ SHA256:
3
+ metadata.gz: ac04b68e554119d27453a1d23849c99eafa72199ecac95e34deded14824e9894
4
+ data.tar.gz: 16b167b85c8cffbf3df3292fe7f41a7b00a2f57f731806786a67679585b5ac5b
5
5
  SHA512:
6
- metadata.gz: 824aee85a548ab9eb7cbcf46369567f238b01bac1a2d9969d82bad2b5b182a004e071c91a33bab8cb9045bc0a5052c91c5647362e666a7bf528f75e928fde6ae
7
- data.tar.gz: 9b16c4795d015b03fe307dc98a0ce4830d8ae70c85de99a7072d2f5943f1f85ae1b0174926ce14a83d35c9bc910a9300224582f586dedaae1d929b4c28914bed
6
+ metadata.gz: f27db8019f8e34d972c859e9bec5ddc8365e3ab5fe77c0aebeedbfa81c2d243627af0b5b3e85dd9b67de0a2f5d7cd159d95c7ea8bb0a78f7ed0a7e9efdbe9c31
7
+ data.tar.gz: d7b980adaa3d90df2409795e6e3e20474fc3f8b19956ebe73c340b11a79bf68813633ae341462c1264489f96bcf0d0a3e34c3aecb4838ccd6fe452cd2dbb55e8
data/README.md CHANGED
@@ -1,13 +1,11 @@
1
1
  <p align="center">
2
- <a href="https://github.com/mirego/ogp">
2
+ <a href="https://github.com/jcouture/ogp">
3
3
  <img src="https://i.imgur.com/qZrMsLq.png" alt="ogp" />
4
4
  </a>
5
5
  <br />
6
6
  OGP is a minimalist Ruby library that does only one thing: parse Open Graph protocol information. For more information: <a href="http://ogp.me">http://ogp.me</a>.
7
7
  <br /><br />
8
8
  <a href="https://rubygems.org/gems/ogp"><img src="http://img.shields.io/gem/v/ogp.svg" /></a>
9
- <a href="https://codeclimate.com/github/jcouture/ogp"><img src="http://img.shields.io/codeclimate/github/jcouture/ogp.svg" /></a>
10
- <a href="https://gemnasium.com/jcouture/ogp"><img src="http://img.shields.io/gemnasium/jcouture/ogp.svg" /></a>
11
9
  <a href="https://travis-ci.org/jcouture/ogp"><img src="http://img.shields.io/travis/jcouture/ogp.svg" /></a>
12
10
  </p>
13
11
 
@@ -22,6 +22,8 @@ module OGP
22
22
 
23
23
  raise MalformedSourceError unless source.include?('</html>')
24
24
 
25
+ source.force_encoding('UTF-8') if source.encoding != 'UTF-8'
26
+
25
27
  self.images = []
26
28
  self.audios = []
27
29
  self.locales = []
@@ -45,6 +47,7 @@ module OGP
45
47
  end
46
48
  end
47
49
 
50
+ # rubocop:disable Metrics/CyclomaticComplexity
48
51
  def parse_attributes(document)
49
52
  document.xpath('//head/meta[starts-with(@property, \'og:\')]').each do |attribute|
50
53
  attribute_name = attribute.get('property').downcase.gsub('og:', '')
@@ -52,16 +55,19 @@ module OGP
52
55
  when /^image$/i
53
56
  images << OpenStruct.new(url: attribute.get('content').to_s)
54
57
  when /^image:(.+)/i
58
+ images << OpenStruct.new unless images.last
55
59
  images.last[Regexp.last_match[1].gsub('-', '_')] = attribute.get('content').to_s
56
60
  when /^audio$/i
57
61
  audios << OpenStruct.new(url: attribute.get('content').to_s)
58
62
  when /^audio:(.+)/i
63
+ audios << OpenStruct.new unless audios.last
59
64
  audios.last[Regexp.last_match[1].gsub('-', '_')] = attribute.get('content').to_s
60
65
  when /^locale/i
61
66
  locales << attribute.get('content').to_s
62
67
  when /^video$/i
63
68
  videos << OpenStruct.new(url: attribute.get('content').to_s)
64
69
  when /^video:(.+)/i
70
+ videos << OpenStruct.new unless videos.last
65
71
  videos.last[Regexp.last_match[1].gsub('-', '_')] = attribute.get('content').to_s
66
72
  else
67
73
  instance_variable_set("@#{attribute_name}", attribute.get('content'))
@@ -1,3 +1,3 @@
1
1
  module OGP
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
21
  spec.require_paths = ['lib']
22
22
 
23
- spec.add_dependency 'oga', '~> 2.10'
23
+ spec.add_dependency 'oga', '~> 2.15'
24
24
 
25
25
  spec.add_development_dependency 'bundler', '~> 1.13'
26
26
  spec.add_development_dependency 'rake', '~> 10.0'
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta content="Hello 世界" property="og:title">
5
+ <meta content="website" property="og:type">
6
+ <meta content="Быстрая коричневая лиса прыгает через ленивую собаку." property="og:description">
7
+ <meta content="https://www.example.com" property="og:url">
8
+ <meta content="https://www.example.com/image.jpg" property="og:image">
9
+ <title></title>
10
+ </head>
11
+ <body>
12
+ </body>
13
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta content="The Rock" property="og:title">
5
+ <meta content="video.movie" property="og:type">
6
+ <meta content="http://www.imdb.com/title/tt0117500/" property="og:url">
7
+ <meta content="http://example.com/ogp.jpg" property="og:image:url">
8
+ <meta content="https://secure.example.com/ogp.jpg" property="og:image:secure_url">
9
+ <meta content="image/jpeg" property="og:image:type">
10
+ <meta content="400" property="og:image:width">
11
+ <meta content="300" property="og:image:height">
12
+ <meta content="A shiny red apple with a bite taken out" property="og:image:alt">
13
+ <meta content="http://example.com/ogp.jpg" property="og:image">
14
+ <meta content="http://example.com/movie.swf" property="og:video:url">
15
+ <meta content="https://secure.example.com/movie.swf" property="og:video:secure_url">
16
+ <meta content="application/x-shockwave-flash" property="og:video:type">
17
+ <meta content="400" property="og:video:width">
18
+ <meta content="300" property="og:video:height">
19
+ <meta content="http://example.com/sound.ogg" property="og:audio:url">
20
+ <meta content="https://secure.example.com/sound.ogg" property="og:audio:secure_url">
21
+
22
+ <title></title>
23
+ </head>
24
+ <body>
25
+ </body>
26
+ </html>
@@ -107,5 +107,39 @@ describe OGP::OpenGraph do
107
107
  expect(open_graph.images[1].height).to eql('500')
108
108
  end
109
109
  end
110
+
111
+ context 'with no root video attributes' do
112
+ it 'should create a proper OpenGraph object' do
113
+ content = File.read("#{File.dirname(__FILE__)}/../fixtures/no_root_attributes.html")
114
+ open_graph = OGP::OpenGraph.new(content)
115
+
116
+ expect(open_graph.images[0].url).to eql('http://example.com/ogp.jpg')
117
+ expect(open_graph.images[0].secure_url).to eql('https://secure.example.com/ogp.jpg')
118
+ expect(open_graph.images[0].type).to eql('image/jpeg')
119
+ expect(open_graph.images[0].width).to eql('400')
120
+ expect(open_graph.images[0].height).to eql('300')
121
+ expect(open_graph.images[0].alt).to eql('A shiny red apple with a bite taken out')
122
+ expect(open_graph.videos[0].url).to eql('http://example.com/movie.swf')
123
+ expect(open_graph.videos[0].secure_url).to eql('https://secure.example.com/movie.swf')
124
+ expect(open_graph.videos[0].type).to eql('application/x-shockwave-flash')
125
+ expect(open_graph.videos[0].width).to eql('400')
126
+ expect(open_graph.videos[0].height).to eql('300')
127
+ expect(open_graph.audios[0].url).to eql('http://example.com/sound.ogg')
128
+ expect(open_graph.audios[0].secure_url).to eql('https://secure.example.com/sound.ogg')
129
+ end
130
+ end
131
+
132
+ context 'with internationalization and unexpected encoding' do
133
+ it 'should create a proper OpenGraph object' do
134
+ content = File.read("#{File.dirname(__FILE__)}/../fixtures/i18n_encoding.html", encoding: 'ASCII-8BIT')
135
+ open_graph = OGP::OpenGraph.new(content)
136
+
137
+ expect(open_graph.title).to eql('Hello 世界')
138
+ expect(open_graph.description).to eql('Быстрая коричневая лиса прыгает через ленивую собаку.')
139
+ expect(open_graph.type).to eql('website')
140
+ expect(open_graph.url).to eql('https://www.example.com')
141
+ expect(open_graph.image.url).to eql('https://www.example.com/image.jpg')
142
+ end
143
+ end
110
144
  end
111
145
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ogp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean-Philippe Couture
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-15 00:00:00.000000000 Z
11
+ date: 2019-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oga
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.10'
19
+ version: '2.15'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.10'
26
+ version: '2.15'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -102,9 +102,11 @@ files:
102
102
  - lib/ogp/version.rb
103
103
  - ogp.gemspec
104
104
  - spec/fixtures/audio_structured_attributes.html
105
+ - spec/fixtures/i18n_encoding.html
105
106
  - spec/fixtures/image_structured_attributes.html
106
107
  - spec/fixtures/missing_required_attributes.html
107
108
  - spec/fixtures/multiple_images_attributes.html
109
+ - spec/fixtures/no_root_attributes.html
108
110
  - spec/fixtures/optional_attributes.html
109
111
  - spec/fixtures/required_attributes.html
110
112
  - spec/fixtures/video_structured_attributes.html
@@ -129,16 +131,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
131
  - !ruby/object:Gem::Version
130
132
  version: '0'
131
133
  requirements: []
132
- rubyforge_project:
133
- rubygems_version: 2.5.1
134
+ rubygems_version: 3.0.3
134
135
  signing_key:
135
136
  specification_version: 4
136
137
  summary: Simple Ruby library for parsing Open Graph prototocol information.
137
138
  test_files:
138
139
  - spec/fixtures/audio_structured_attributes.html
140
+ - spec/fixtures/i18n_encoding.html
139
141
  - spec/fixtures/image_structured_attributes.html
140
142
  - spec/fixtures/missing_required_attributes.html
141
143
  - spec/fixtures/multiple_images_attributes.html
144
+ - spec/fixtures/no_root_attributes.html
142
145
  - spec/fixtures/optional_attributes.html
143
146
  - spec/fixtures/required_attributes.html
144
147
  - spec/fixtures/video_structured_attributes.html