opengraph_parser 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/open_graph.rb +11 -5
  2. metadata +16 -46
@@ -1,6 +1,7 @@
1
1
  require 'nokogiri'
2
2
  require 'redirect_follower'
3
3
  require "addressable/uri"
4
+ require 'uri'
4
5
 
5
6
  class OpenGraph
6
7
  attr_accessor :src, :url, :type, :title, :description, :images, :metadata, :response, :original_images
@@ -11,6 +12,7 @@ class OpenGraph
11
12
  fallback = true
12
13
  end
13
14
  @src = src
15
+ @body = nil
14
16
  @images = []
15
17
  @metadata = {}
16
18
  parse_opengraph(options)
@@ -21,15 +23,19 @@ class OpenGraph
21
23
  private
22
24
  def parse_opengraph(options = {})
23
25
  begin
24
- @response = RedirectFollower.new(@src, options).resolve
26
+ if @src.include? '</html>'
27
+ @body = @src
28
+ else
29
+ @body = RedirectFollower.new(@src, options).resolve.body
30
+ end
25
31
  rescue
26
32
  @title = @url = @src
27
33
  return
28
34
  end
29
35
 
30
- if @response && @response.body
36
+ if @body
31
37
  attrs_list = %w(title url type description)
32
- doc = Nokogiri.parse(@response.body)
38
+ doc = Nokogiri.parse(@body)
33
39
  doc.css('meta').each do |m|
34
40
  if m.attribute('property') && m.attribute('property').to_s.match(/^og:(.+)$/i)
35
41
  m_content = m.attribute('content').to_s.strip
@@ -47,8 +53,8 @@ class OpenGraph
47
53
  end
48
54
 
49
55
  def load_fallback
50
- if @response && @response.body
51
- doc = Nokogiri.parse(@response.body)
56
+ if @body
57
+ doc = Nokogiri.parse(@body)
52
58
 
53
59
  if @title.to_s.empty? && doc.xpath("//head//title").size > 0
54
60
  @title = doc.xpath("//head//title").first.text.to_s.strip
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opengraph_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-02-21 00:00:00.000000000 Z
13
+ date: 2013-05-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: nokogiri
17
- requirement: !ruby/object:Gem::Requirement
17
+ requirement: &70365561662080 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,15 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
- requirements:
28
- - - ! '>='
29
- - !ruby/object:Gem::Version
30
- version: '0'
25
+ version_requirements: *70365561662080
31
26
  - !ruby/object:Gem::Dependency
32
27
  name: addressable
33
- requirement: !ruby/object:Gem::Requirement
28
+ requirement: &70365561661360 !ruby/object:Gem::Requirement
34
29
  none: false
35
30
  requirements:
36
31
  - - ! '>='
@@ -38,15 +33,10 @@ dependencies:
38
33
  version: '0'
39
34
  type: :runtime
40
35
  prerelease: false
41
- version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
- requirements:
44
- - - ! '>='
45
- - !ruby/object:Gem::Version
46
- version: '0'
36
+ version_requirements: *70365561661360
47
37
  - !ruby/object:Gem::Dependency
48
38
  name: rspec
49
- requirement: !ruby/object:Gem::Requirement
39
+ requirement: &70365561660600 !ruby/object:Gem::Requirement
50
40
  none: false
51
41
  requirements:
52
42
  - - ! '>='
@@ -54,15 +44,10 @@ dependencies:
54
44
  version: '0'
55
45
  type: :development
56
46
  prerelease: false
57
- version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
- requirements:
60
- - - ! '>='
61
- - !ruby/object:Gem::Version
62
- version: '0'
47
+ version_requirements: *70365561660600
63
48
  - !ruby/object:Gem::Dependency
64
49
  name: rdoc
65
- requirement: !ruby/object:Gem::Requirement
50
+ requirement: &70365561659860 !ruby/object:Gem::Requirement
66
51
  none: false
67
52
  requirements:
68
53
  - - ! '>='
@@ -70,15 +55,10 @@ dependencies:
70
55
  version: '0'
71
56
  type: :development
72
57
  prerelease: false
73
- version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
- requirements:
76
- - - ! '>='
77
- - !ruby/object:Gem::Version
78
- version: '0'
58
+ version_requirements: *70365561659860
79
59
  - !ruby/object:Gem::Dependency
80
60
  name: bundler
81
- requirement: !ruby/object:Gem::Requirement
61
+ requirement: &70365561659200 !ruby/object:Gem::Requirement
82
62
  none: false
83
63
  requirements:
84
64
  - - ! '>='
@@ -86,15 +66,10 @@ dependencies:
86
66
  version: '0'
87
67
  type: :development
88
68
  prerelease: false
89
- version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
- requirements:
92
- - - ! '>='
93
- - !ruby/object:Gem::Version
94
- version: '0'
69
+ version_requirements: *70365561659200
95
70
  - !ruby/object:Gem::Dependency
96
71
  name: jeweler
97
- requirement: !ruby/object:Gem::Requirement
72
+ requirement: &70365561658400 !ruby/object:Gem::Requirement
98
73
  none: false
99
74
  requirements:
100
75
  - - ! '>='
@@ -102,12 +77,7 @@ dependencies:
102
77
  version: '0'
103
78
  type: :development
104
79
  prerelease: false
105
- version_requirements: !ruby/object:Gem::Requirement
106
- none: false
107
- requirements:
108
- - - ! '>='
109
- - !ruby/object:Gem::Version
110
- version: '0'
80
+ version_requirements: *70365561658400
111
81
  description: A simple Ruby library for parsing Open Graph Protocol information from
112
82
  a website. It also includes a fallback solution when the website has no Open Graph
113
83
  information.
@@ -138,7 +108,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
138
108
  version: '0'
139
109
  segments:
140
110
  - 0
141
- hash: -2567811217494491510
111
+ hash: 1017772970234203575
142
112
  required_rubygems_version: !ruby/object:Gem::Requirement
143
113
  none: false
144
114
  requirements:
@@ -147,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
117
  version: '0'
148
118
  requirements: []
149
119
  rubyforge_project:
150
- rubygems_version: 1.8.24
120
+ rubygems_version: 1.8.10
151
121
  signing_key:
152
122
  specification_version: 3
153
123
  summary: A simple Ruby library for parsing Open Graph Protocol information from a