opengraph 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
data/lib/opengraph.rb CHANGED
@@ -6,13 +6,16 @@ module OpenGraph
6
6
  # Fetch Open Graph data from the specified URI. Makes an
7
7
  # HTTP GET request and returns an OpenGraph::Object if there
8
8
  # is data to be found or <tt>false</tt> if there isn't.
9
- def self.fetch(uri)
10
- parse(RestClient.get(uri).body)
9
+ #
10
+ # Pass <tt>false</tt> for the second argument if you want to
11
+ # see invalid (i.e. missing a required attribute) data.
12
+ def self.fetch(uri, strict = true)
13
+ parse(RestClient.get(uri).body, strict)
11
14
  rescue RestClient::Exception, SocketError
12
15
  false
13
16
  end
14
17
 
15
- def self.parse(html)
18
+ def self.parse(html, strict = true)
16
19
  doc = Nokogiri::HTML.parse(html)
17
20
  page = OpenGraph::Object.new
18
21
  doc.css('meta').each do |m|
@@ -20,7 +23,8 @@ module OpenGraph
20
23
  page[$1.gsub('-','_')] = m.attribute('content').to_s
21
24
  end
22
25
  end
23
- return false unless page.valid?
26
+ return false if page.keys.empty?
27
+ return false unless page.valid? if strict
24
28
  page
25
29
  end
26
30
 
data/opengraph.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{opengraph}
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Michael Bleigh"]
@@ -2,15 +2,24 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe OpenGraph do
4
4
  let(:rotten){ File.open(File.dirname(__FILE__) + '/examples/rottentomatoes.html').read }
5
+ let(:partial){ File.open(File.dirname(__FILE__) + '/examples/partial.html').read }
5
6
 
6
7
  describe '.parse' do
7
8
  it 'should return false if there isnt valid Open Graph info' do
8
9
  OpenGraph.parse("").should be_false
10
+ OpenGraph.parse(partial).should be_false
9
11
  end
10
12
 
11
13
  it 'should otherwise return an OpenGraph::Object' do
12
14
  OpenGraph.parse(rotten).should be_kind_of(OpenGraph::Object)
13
15
  end
16
+
17
+ context ' without strict mode' do
18
+ subject{ OpenGraph.parse(partial, false) }
19
+
20
+ it { should_not be_false }
21
+ it { subject.title.should == 'Partialized' }
22
+ end
14
23
  end
15
24
 
16
25
  describe '.fetch' do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
8
+ - 3
9
+ version: 0.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Michael Bleigh