opengraph 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/README.rdoc +26 -2
- data/VERSION +1 -1
- data/lib/opengraph.rb +2 -2
- data/opengraph.gemspec +68 -0
- data/spec/opengraph_spec.rb +7 -0
- metadata +4 -3
data/LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -1,6 +1,30 @@
|
|
1
1
|
= OpenGraph
|
2
2
|
|
3
|
-
OpenGraph is a very simple library for parsing Open Graph
|
3
|
+
OpenGraph is a very simple library for parsing Open Graph protocol
|
4
|
+
information from web sites. Learn more about the protocol at:
|
5
|
+
|
6
|
+
http://opengraphprotocol.org
|
7
|
+
|
8
|
+
== Installation
|
9
|
+
|
10
|
+
gem install opengraph
|
11
|
+
|
12
|
+
== Usage
|
13
|
+
|
14
|
+
require 'opengraph'
|
15
|
+
|
16
|
+
movie = OpenGraph.fetch('http://www.rottentomatoes.com/m/1217700-kick_ass/')
|
17
|
+
|
18
|
+
movie.title # => 'Kick-Ass'
|
19
|
+
movie.movie? # => true
|
20
|
+
movie.image # => 'http://images.rottentomatoes.com/images/movie/custom/00/1217700.jpg'
|
21
|
+
|
22
|
+
If you try to fetch Open Graph information for a URL that doesn't
|
23
|
+
have any, the <tt>fetch</tt> method will return <tt>false.</tt>.
|
24
|
+
The OpenGraph::Object that is returned is just a Hash with accessors
|
25
|
+
built into it, so you can examine what properties you've retrieved like so:
|
26
|
+
|
27
|
+
movie.keys # => ['type','image','title','url']
|
4
28
|
|
5
29
|
== Note on Patches/Pull Requests
|
6
30
|
|
@@ -14,4 +38,4 @@ OpenGraph is a very simple library for parsing Open Graph information from web s
|
|
14
38
|
|
15
39
|
== Copyright
|
16
40
|
|
17
|
-
Copyright (c) 2010 Michael Bleigh. See LICENSE for details.
|
41
|
+
Copyright (c) 2010 Intridea, Inc. and Michael Bleigh. See LICENSE for details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/lib/opengraph.rb
CHANGED
@@ -8,6 +8,8 @@ module OpenGraph
|
|
8
8
|
# is data to be found or <tt>false</tt> if there isn't.
|
9
9
|
def self.fetch(uri)
|
10
10
|
parse(RestClient.get(uri).body)
|
11
|
+
rescue RestClient::Exception, SocketError
|
12
|
+
false
|
11
13
|
end
|
12
14
|
|
13
15
|
def self.parse(html)
|
@@ -20,8 +22,6 @@ module OpenGraph
|
|
20
22
|
end
|
21
23
|
return false unless page.valid?
|
22
24
|
page
|
23
|
-
rescue RestClient::Exception
|
24
|
-
false
|
25
25
|
end
|
26
26
|
|
27
27
|
TYPES = {
|
data/opengraph.gemspec
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{opengraph}
|
8
|
+
s.version = "0.0.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Michael Bleigh"]
|
12
|
+
s.date = %q{2010-04-24}
|
13
|
+
s.description = %q{A very simple Ruby library for parsing Open Graph prototocol information from websites. See http://opengraphprotocol.org for more information.}
|
14
|
+
s.email = %q{michael@intridea.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/opengraph.rb",
|
27
|
+
"opengraph.gemspec",
|
28
|
+
"spec/examples/rottentomatoes.html",
|
29
|
+
"spec/opengraph_spec.rb",
|
30
|
+
"spec/spec.opts",
|
31
|
+
"spec/spec_helper.rb"
|
32
|
+
]
|
33
|
+
s.homepage = %q{http://github.com/intridea/opengraph}
|
34
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
s.rubygems_version = %q{1.3.6}
|
37
|
+
s.summary = %q{A very simple Ruby library for parsing Open Graph prototocol information from websites.}
|
38
|
+
s.test_files = [
|
39
|
+
"spec/opengraph_spec.rb",
|
40
|
+
"spec/spec_helper.rb"
|
41
|
+
]
|
42
|
+
|
43
|
+
if s.respond_to? :specification_version then
|
44
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
45
|
+
s.specification_version = 3
|
46
|
+
|
47
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
48
|
+
s.add_runtime_dependency(%q<hashie>, [">= 0"])
|
49
|
+
s.add_runtime_dependency(%q<nokogiri>, ["~> 1.4.0"])
|
50
|
+
s.add_runtime_dependency(%q<rest-client>, ["~> 1.4.0"])
|
51
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
52
|
+
s.add_development_dependency(%q<webmock>, [">= 0"])
|
53
|
+
else
|
54
|
+
s.add_dependency(%q<hashie>, [">= 0"])
|
55
|
+
s.add_dependency(%q<nokogiri>, ["~> 1.4.0"])
|
56
|
+
s.add_dependency(%q<rest-client>, ["~> 1.4.0"])
|
57
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
58
|
+
s.add_dependency(%q<webmock>, [">= 0"])
|
59
|
+
end
|
60
|
+
else
|
61
|
+
s.add_dependency(%q<hashie>, [">= 0"])
|
62
|
+
s.add_dependency(%q<nokogiri>, ["~> 1.4.0"])
|
63
|
+
s.add_dependency(%q<rest-client>, ["~> 1.4.0"])
|
64
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
65
|
+
s.add_dependency(%q<webmock>, [">= 0"])
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
data/spec/opengraph_spec.rb
CHANGED
@@ -19,6 +19,13 @@ describe OpenGraph do
|
|
19
19
|
OpenGraph.fetch('http://www.rottentomatoes.com/m/1217700-kick_ass/').title.should == 'Kick-Ass'
|
20
20
|
WebMock.should have_requested(:get, 'http://www.rottentomatoes.com/m/1217700-kick_ass/')
|
21
21
|
end
|
22
|
+
|
23
|
+
it 'should catch errors' do
|
24
|
+
stub_request(:get, 'http://example.com').to_return(:status => 404)
|
25
|
+
OpenGraph.fetch('http://example.com').should be_false
|
26
|
+
RestClient.should_receive(:get).with('http://example.com').and_raise(SocketError)
|
27
|
+
OpenGraph.fetch('http://example.com').should be_false
|
28
|
+
end
|
22
29
|
end
|
23
30
|
end
|
24
31
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Michael Bleigh
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-24 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -100,6 +100,7 @@ files:
|
|
100
100
|
- Rakefile
|
101
101
|
- VERSION
|
102
102
|
- lib/opengraph.rb
|
103
|
+
- opengraph.gemspec
|
103
104
|
- spec/examples/rottentomatoes.html
|
104
105
|
- spec/opengraph_spec.rb
|
105
106
|
- spec/spec.opts
|