opengraph_parser 0.1.0 → 0.1.1

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 +17 -4
  2. metadata +24 -13
data/lib/open_graph.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'nokogiri'
2
2
  require 'redirect_follower'
3
+ require "addressable/uri"
3
4
 
4
5
  class OpenGraph
5
6
  attr_accessor :src, :url, :type, :title, :description, :images, :metadata, :response
@@ -13,6 +14,7 @@ class OpenGraph
13
14
  check_images_path
14
15
  end
15
16
 
17
+ private
16
18
  def parse_opengraph
17
19
  begin
18
20
  @response = RedirectFollower.new(@src).resolve
@@ -60,19 +62,19 @@ class OpenGraph
60
62
  end
61
63
 
62
64
  def check_images_path
63
- uri = URI.parse(URI.escape(@src))
65
+ uri = Addressable::URI.parse(@src)
64
66
  imgs = @images.dup
65
67
  @images = []
66
68
  imgs.each do |img|
67
- if URI.parse(URI.escape(img)).host.nil?
68
- add_image("#{uri.scheme}://#{uri.host}:#{uri.port}#{img}")
69
+ if Addressable::URI.parse(img).host.nil?
70
+ full_path = generate_path(img, uri)
71
+ add_image(full_path)
69
72
  else
70
73
  add_image(img)
71
74
  end
72
75
  end
73
76
  end
74
77
 
75
- private
76
78
  def add_image(image_url)
77
79
  @images << image_url unless @images.include?(image_url) || image_url.to_s.empty?
78
80
  end
@@ -82,4 +84,15 @@ class OpenGraph
82
84
  add_image(link.attribute(attr).to_s.strip)
83
85
  end
84
86
  end
87
+
88
+ def generate_path(relative_path, uri)
89
+ host = "#{uri.scheme}://#{uri.host}#{':' + uri.port.to_s if uri.port}"
90
+ if relative_path.start_with?('/')
91
+ "#{host}#{relative_path}"
92
+ elsif uri.path.to_s.end_with?('/')
93
+ "#{host}#{uri.path}#{relative_path}"
94
+ else
95
+ "#{host}#{uri.path}/#{relative_path}"
96
+ end
97
+ end
85
98
  end
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.1.0
4
+ version: 0.1.1
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: 2012-11-12 00:00:00.000000000 Z
13
+ date: 2012-11-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
17
- requirement: &70116370351140 !ruby/object:Gem::Requirement
17
+ requirement: &70223353182580 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *70116370351140
25
+ version_requirements: *70223353182580
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rdoc
28
- requirement: &70116370350460 !ruby/object:Gem::Requirement
28
+ requirement: &70223353181860 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *70116370350460
36
+ version_requirements: *70223353181860
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: bundler
39
- requirement: &70116370349400 !ruby/object:Gem::Requirement
39
+ requirement: &70223353203980 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *70116370349400
47
+ version_requirements: *70223353203980
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: jeweler
50
- requirement: &70116370365040 !ruby/object:Gem::Requirement
50
+ requirement: &70223353203500 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '0'
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *70116370365040
58
+ version_requirements: *70223353203500
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: nokogiri
61
- requirement: &70116370364240 !ruby/object:Gem::Requirement
61
+ requirement: &70223353203000 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,7 +66,18 @@ dependencies:
66
66
  version: '0'
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *70116370364240
69
+ version_requirements: *70223353203000
70
+ - !ruby/object:Gem::Dependency
71
+ name: addressable
72
+ requirement: &70223353202480 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: *70223353202480
70
81
  description: A simple Ruby library for parsing Open Graph Protocol information from
71
82
  a website. It also includes a fallback solution when the website has no Open Graph
72
83
  information.
@@ -97,7 +108,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
97
108
  version: '0'
98
109
  segments:
99
110
  - 0
100
- hash: -2116295098415564887
111
+ hash: 3401434948042854406
101
112
  required_rubygems_version: !ruby/object:Gem::Requirement
102
113
  none: false
103
114
  requirements: