ogp 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +46 -0
- data/Rakefile +6 -0
- data/lib/ogp.rb +6 -0
- data/lib/ogp/open_graph.rb +86 -0
- data/lib/ogp/version.rb +3 -0
- data/ogp.gemspec +27 -0
- data/spec/fixtures/audio_structured_attributes.html +15 -0
- data/spec/fixtures/image_structured_attributes.html +17 -0
- data/spec/fixtures/missing_required_attributes.html +11 -0
- data/spec/fixtures/multiple_images_attributes.html +19 -0
- data/spec/fixtures/optional_attributes.html +20 -0
- data/spec/fixtures/required_attributes.html +12 -0
- data/spec/fixtures/video_structured_attributes.html +17 -0
- data/spec/ogp/open_graph_spec.rb +111 -0
- data/spec/spec_helper.rb +7 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 76a5e1d09ecf649ed6ae42c9210670fc975e97dc
|
4
|
+
data.tar.gz: 5b3247e18f9d7dcbad25d56772fdf89da37c2ac0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e7bad59e8dd573ab9ff01753c6f846be1faad91870162b90c924849694aff9f548aa6163e113e440e4703635c18eb53e4826548136e77e0e4ea7f7c92448845a
|
7
|
+
data.tar.gz: b92431e1f01c0233bda839f3a3a165dc14c53c59ee1222109046a56e0e178359060a264c41b5fa6866191bdb8f23b8748d4c5ee54a5ce227ca6e9af186b3f698
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at jcouture@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Jean-Philippe Couture
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# OGP
|
2
|
+
|
3
|
+
OGP is a minimalist Ruby library that does only one thing: parse Open Graph protocol information from web sites. For more information: http://ogp.me.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application’s Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'ogp'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install ogp
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
In order to keep OGP very simple, it does not perform any HTTP operations. As such, in this example, [Faraday](https://github.com/lostisland/faraday) is used to achieve this functionality.
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'faraday'
|
27
|
+
require 'ogp'
|
28
|
+
|
29
|
+
response = Faraday.get('http://ogp.me')
|
30
|
+
|
31
|
+
open_graph = OGP::OpenGraph.new(response.body)
|
32
|
+
open_graph.title # => "Open Graph protocol"
|
33
|
+
open_graph.type # => "website"
|
34
|
+
open_graph.image.url # => "http://ogp.me/logo.png"
|
35
|
+
open_graph.url # => "http://ogp.me/"
|
36
|
+
```
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jcouture/ogp. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
41
|
+
|
42
|
+
|
43
|
+
## License
|
44
|
+
|
45
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
46
|
+
|
data/Rakefile
ADDED
data/lib/ogp.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'oga'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
REQUIRED_ATTRIBUTES = %w(title type image url)
|
5
|
+
|
6
|
+
module OGP
|
7
|
+
class OpenGraph
|
8
|
+
# Required Accessors
|
9
|
+
attr_accessor :title, :type, :url
|
10
|
+
attr_accessor :images
|
11
|
+
|
12
|
+
# Optional Accessors
|
13
|
+
attr_accessor :description, :determiner, :site_name
|
14
|
+
attr_accessor :audios
|
15
|
+
attr_accessor :locales
|
16
|
+
attr_accessor :videos
|
17
|
+
|
18
|
+
def initialize(source)
|
19
|
+
if source.nil? || source.empty?
|
20
|
+
raise ArgumentError.new('`source` cannot be nil or empty.')
|
21
|
+
end
|
22
|
+
|
23
|
+
if !source.include?('</html>')
|
24
|
+
raise MalformedSourceError
|
25
|
+
end
|
26
|
+
|
27
|
+
self.images = []
|
28
|
+
self.audios = []
|
29
|
+
self.locales = []
|
30
|
+
self.videos = []
|
31
|
+
|
32
|
+
document = Oga.parse_html(source)
|
33
|
+
check_required_attributes(document)
|
34
|
+
parse_attributes(document)
|
35
|
+
end
|
36
|
+
|
37
|
+
def image
|
38
|
+
return if self.images.nil?
|
39
|
+
return self.images.first
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def check_required_attributes(document)
|
45
|
+
REQUIRED_ATTRIBUTES.each do |attribute_name|
|
46
|
+
if !attribute_exists(document, attribute_name)
|
47
|
+
raise MissingAttributeError.new("Missing required attribute: #{attribute_name}")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def parse_attributes(document)
|
53
|
+
document.xpath('//head/meta[starts-with(@property, \'og:\')]').each do |attribute|
|
54
|
+
attribute_name = attribute.get('property').downcase.gsub('og:', '')
|
55
|
+
case attribute_name
|
56
|
+
when /^image$/i
|
57
|
+
self.images << OpenStruct.new(url: attribute.get('content').to_s)
|
58
|
+
when /^image:(.+)/i
|
59
|
+
self.images.last[$1.gsub('-','_')] = attribute.get('content').to_s
|
60
|
+
when /^audio$/i
|
61
|
+
self.audios << OpenStruct.new(url: attribute.get('content').to_s)
|
62
|
+
when /^audio:(.+)/i
|
63
|
+
self.audios.last[$1.gsub('-','_')] = attribute.get('content').to_s
|
64
|
+
when /^locale/i
|
65
|
+
self.locales << attribute.get('content').to_s
|
66
|
+
when /^video$/i
|
67
|
+
self.videos << OpenStruct.new(url: attribute.get('content').to_s)
|
68
|
+
when /^video:(.+)/i
|
69
|
+
self.videos.last[$1.gsub('-','_')] = attribute.get('content').to_s
|
70
|
+
else
|
71
|
+
instance_variable_set("@#{attribute_name}", attribute.get('content'))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def attribute_exists(document, name)
|
77
|
+
document.at_xpath("boolean(//head/meta[@property='og:#{name}'])")
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
class MissingAttributeError < StandardError
|
82
|
+
end
|
83
|
+
|
84
|
+
class MalformedSourceError < StandardError
|
85
|
+
end
|
86
|
+
end
|
data/lib/ogp/version.rb
ADDED
data/ogp.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ogp/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'ogp'
|
8
|
+
spec.version = OGP::VERSION
|
9
|
+
spec.authors = ['Jean-Philippe Couture']
|
10
|
+
spec.email = ['jcouture@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = spec.description
|
13
|
+
spec.description = %q{Simple Ruby library for parsing Open Graph prototocol information from websites. See http://ogp.me for more information.}
|
14
|
+
spec.homepage = 'https://github.com/jcouture/ogp'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files`.split("\n")
|
18
|
+
spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_dependency 'oga', '~> 2.10'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
26
|
+
spec.add_development_dependency 'rspec', '~> 3.6'
|
27
|
+
end
|
@@ -0,0 +1,15 @@
|
|
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">
|
8
|
+
<meta content="http://example.com/sound.ogg" property="og:audio">
|
9
|
+
<meta content="https://secure.example.com/sound.ogg" property="og:audio:secure_url">
|
10
|
+
<meta content="audio/ogg" property="og:audio:type">
|
11
|
+
<title></title>
|
12
|
+
</head>
|
13
|
+
<body>
|
14
|
+
</body>
|
15
|
+
</html>
|
@@ -0,0 +1,17 @@
|
|
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">
|
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
|
+
<title></title>
|
14
|
+
</head>
|
15
|
+
<body>
|
16
|
+
</body>
|
17
|
+
</html>
|
@@ -0,0 +1,11 @@
|
|
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
|
+
<title></title>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
</body>
|
11
|
+
</html>
|
@@ -0,0 +1,19 @@
|
|
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/ogp1.jpg" property="og:image">
|
8
|
+
<meta content="image/jpeg" property="og:image:type">
|
9
|
+
<meta content="400" property="og:image:width">
|
10
|
+
<meta content="300" property="og:image:height">
|
11
|
+
<meta content="http://example.com/ogp2.jpg" property="og:image">
|
12
|
+
<meta content="image/jpeg" property="og:image:type">
|
13
|
+
<meta content="600" property="og:image:width">
|
14
|
+
<meta content="500" property="og:image:height">
|
15
|
+
<title></title>
|
16
|
+
</head>
|
17
|
+
<body>
|
18
|
+
</body>
|
19
|
+
</html>
|
@@ -0,0 +1,20 @@
|
|
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://ia.media-imdb.com/images/rock.jpg" property="og:image">
|
8
|
+
<meta content="http://example.com/bond/theme.mp3" property="og:audio">
|
9
|
+
<meta content="Sean Connery found fame and fortune as the suave, sophisticated British agent, James Bond." property="og:description">
|
10
|
+
<meta content="the" property="og:determiner">
|
11
|
+
<meta content="en_GB" property="og:locale">
|
12
|
+
<meta content="fr_FR" property="og:locale:alternate">
|
13
|
+
<meta content="es_ES" property="og:locale:alternate">
|
14
|
+
<meta content="IMDb" property="og:site_name">
|
15
|
+
<meta content="http://example.com/bond/trailer.swf" property="og:video">
|
16
|
+
<title></title>
|
17
|
+
</head>
|
18
|
+
<body>
|
19
|
+
</body>
|
20
|
+
</html>
|
@@ -0,0 +1,12 @@
|
|
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://ia.media-imdb.com/images/rock.jpg" property="og:image">
|
8
|
+
<title></title>
|
9
|
+
</head>
|
10
|
+
<body>
|
11
|
+
</body>
|
12
|
+
</html>
|
@@ -0,0 +1,17 @@
|
|
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">
|
8
|
+
<meta content="http://example.com/movie.swf" property="og:video">
|
9
|
+
<meta content="https://secure.example.com/movie.swf" property="og:video:secure_url">
|
10
|
+
<meta content="application/x-shockwave-flash" property="og:video:type">
|
11
|
+
<meta content="400" property="og:video:width">
|
12
|
+
<meta content="300" property="og:video:height">
|
13
|
+
<title></title>
|
14
|
+
</head>
|
15
|
+
<body>
|
16
|
+
</body>
|
17
|
+
</html>
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OGP::OpenGraph do
|
4
|
+
describe '#initialize' do
|
5
|
+
context 'with strictly the required attributes' do
|
6
|
+
it 'should create a proper OpenGraph object' do
|
7
|
+
content = File.read("#{File.dirname(__FILE__)}/../fixtures/required_attributes.html")
|
8
|
+
open_graph = OGP::OpenGraph.new(content)
|
9
|
+
|
10
|
+
expect(open_graph.title).to eql('The Rock')
|
11
|
+
expect(open_graph.type).to eql('video.movie')
|
12
|
+
expect(open_graph.url).to eql('http://www.imdb.com/title/tt0117500/')
|
13
|
+
expect(open_graph.image.url).to eql('http://ia.media-imdb.com/images/rock.jpg')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'with missing one of the required attributes' do
|
18
|
+
it 'should raise an error' do
|
19
|
+
content = File.read("#{File.dirname(__FILE__)}/../fixtures/missing_required_attributes.html")
|
20
|
+
|
21
|
+
expect{OGP::OpenGraph.new(content)}.to raise_error(OGP::MissingAttributeError)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'with nil source' do
|
26
|
+
it 'should raise an error' do
|
27
|
+
expect{OGP::OpenGraph.new(nil)}.to raise_error(ArgumentError)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'with empty source' do
|
32
|
+
it 'should raise an error' do
|
33
|
+
expect{OGP::OpenGraph.new('')}.to raise_error(ArgumentError)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'with malformed source' do
|
38
|
+
it 'should raise an error' do
|
39
|
+
expect{OGP::OpenGraph.new('Lorem ipsum dolor sit amet, consectetur adipiscing elit.')}.to raise_error(OGP::MalformedSourceError)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'with optional attributes' do
|
44
|
+
it 'should create a proper OpenGraph object' do
|
45
|
+
content = File.read("#{File.dirname(__FILE__)}/../fixtures/optional_attributes.html")
|
46
|
+
open_graph = OGP::OpenGraph.new(content)
|
47
|
+
|
48
|
+
expect(open_graph.audios[0].url).to eql('http://example.com/bond/theme.mp3')
|
49
|
+
expect(open_graph.description).to eql('Sean Connery found fame and fortune as the suave, sophisticated British agent, James Bond.')
|
50
|
+
expect(open_graph.determiner).to eql('the')
|
51
|
+
expect(open_graph.locales).to match_array(%w(en_GB fr_FR es_ES))
|
52
|
+
expect(open_graph.site_name).to eql('IMDb')
|
53
|
+
expect(open_graph.videos[0].url).to eql('http://example.com/bond/trailer.swf')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'with image structured attributes' do
|
58
|
+
it 'should create a proper OpenGraph object' do
|
59
|
+
content = File.read("#{File.dirname(__FILE__)}/../fixtures/image_structured_attributes.html")
|
60
|
+
open_graph = OGP::OpenGraph.new(content)
|
61
|
+
|
62
|
+
expect(open_graph.image.url).to eql('http://example.com/ogp.jpg')
|
63
|
+
expect(open_graph.image.secure_url).to eql('https://secure.example.com/ogp.jpg')
|
64
|
+
expect(open_graph.image.type).to eql('image/jpeg')
|
65
|
+
expect(open_graph.image.width).to eql('400')
|
66
|
+
expect(open_graph.image.height).to eql('300')
|
67
|
+
expect(open_graph.image.alt).to eql('A shiny red apple with a bite taken out')
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'with audio structured attributes' do
|
72
|
+
it 'should create a proper OpenGraph object' do
|
73
|
+
content = File.read("#{File.dirname(__FILE__)}/../fixtures/audio_structured_attributes.html")
|
74
|
+
open_graph = OGP::OpenGraph.new(content)
|
75
|
+
|
76
|
+
expect(open_graph.audios[0].url).to eql('http://example.com/sound.ogg')
|
77
|
+
expect(open_graph.audios[0].secure_url).to eql('https://secure.example.com/sound.ogg')
|
78
|
+
expect(open_graph.audios[0].type).to eql('audio/ogg')
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'with video structured attributes' do
|
83
|
+
it 'should create a proper OpenGraph object' do
|
84
|
+
content = File.read("#{File.dirname(__FILE__)}/../fixtures/video_structured_attributes.html")
|
85
|
+
open_graph = OGP::OpenGraph.new(content)
|
86
|
+
|
87
|
+
expect(open_graph.videos[0].url).to eql('http://example.com/movie.swf')
|
88
|
+
expect(open_graph.videos[0].secure_url).to eql('https://secure.example.com/movie.swf')
|
89
|
+
expect(open_graph.videos[0].type).to eql('application/x-shockwave-flash')
|
90
|
+
expect(open_graph.videos[0].width).to eql('400')
|
91
|
+
expect(open_graph.videos[0].height).to eql('300')
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'with multiples image attributes' do
|
96
|
+
it 'should create a proper OpenGraph object' do
|
97
|
+
content = File.read("#{File.dirname(__FILE__)}/../fixtures/multiple_images_attributes.html")
|
98
|
+
open_graph = OGP::OpenGraph.new(content)
|
99
|
+
|
100
|
+
expect(open_graph.images[0].url).to eql('http://example.com/ogp1.jpg')
|
101
|
+
expect(open_graph.images[0].type).to eql('image/jpeg')
|
102
|
+
expect(open_graph.images[0].width).to eql('400')
|
103
|
+
expect(open_graph.images[0].height).to eql('300')
|
104
|
+
expect(open_graph.images[1].url).to eql('http://example.com/ogp2.jpg')
|
105
|
+
expect(open_graph.images[1].type).to eql('image/jpeg')
|
106
|
+
expect(open_graph.images[1].width).to eql('600')
|
107
|
+
expect(open_graph.images[1].height).to eql('500')
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ogp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jean-Philippe Couture
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-09-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: oga
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.10'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.13'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.13'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.6'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.6'
|
69
|
+
description: Simple Ruby library for parsing Open Graph prototocol information from
|
70
|
+
websites. See http://ogp.me for more information.
|
71
|
+
email:
|
72
|
+
- jcouture@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- CODE_OF_CONDUCT.md
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- lib/ogp.rb
|
85
|
+
- lib/ogp/open_graph.rb
|
86
|
+
- lib/ogp/version.rb
|
87
|
+
- ogp.gemspec
|
88
|
+
- spec/fixtures/audio_structured_attributes.html
|
89
|
+
- spec/fixtures/image_structured_attributes.html
|
90
|
+
- spec/fixtures/missing_required_attributes.html
|
91
|
+
- spec/fixtures/multiple_images_attributes.html
|
92
|
+
- spec/fixtures/optional_attributes.html
|
93
|
+
- spec/fixtures/required_attributes.html
|
94
|
+
- spec/fixtures/video_structured_attributes.html
|
95
|
+
- spec/ogp/open_graph_spec.rb
|
96
|
+
- spec/spec_helper.rb
|
97
|
+
homepage: https://github.com/jcouture/ogp
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
metadata: {}
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
requirements: []
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 2.5.1
|
118
|
+
signing_key:
|
119
|
+
specification_version: 4
|
120
|
+
summary: ''
|
121
|
+
test_files:
|
122
|
+
- spec/fixtures/audio_structured_attributes.html
|
123
|
+
- spec/fixtures/image_structured_attributes.html
|
124
|
+
- spec/fixtures/missing_required_attributes.html
|
125
|
+
- spec/fixtures/multiple_images_attributes.html
|
126
|
+
- spec/fixtures/optional_attributes.html
|
127
|
+
- spec/fixtures/required_attributes.html
|
128
|
+
- spec/fixtures/video_structured_attributes.html
|
129
|
+
- spec/ogp/open_graph_spec.rb
|
130
|
+
- spec/spec_helper.rb
|