opengraph_parser 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/open_graph.rb +8 -4
  2. data/lib/redirect_follower.rb +10 -4
  3. metadata +46 -16
data/lib/open_graph.rb CHANGED
@@ -5,19 +5,23 @@ require "addressable/uri"
5
5
  class OpenGraph
6
6
  attr_accessor :src, :url, :type, :title, :description, :images, :metadata, :response, :original_images
7
7
 
8
- def initialize(src, fallback = true)
8
+ def initialize(src, fallback = true, options = {})
9
+ if fallback.is_a? Hash
10
+ options = fallback
11
+ fallback = true
12
+ end
9
13
  @src = src
10
14
  @images = []
11
15
  @metadata = {}
12
- parse_opengraph
16
+ parse_opengraph(options)
13
17
  load_fallback if fallback
14
18
  check_images_path
15
19
  end
16
20
 
17
21
  private
18
- def parse_opengraph
22
+ def parse_opengraph(options = {})
19
23
  begin
20
- @response = RedirectFollower.new(@src).resolve
24
+ @response = RedirectFollower.new(@src, options).resolve
21
25
  rescue
22
26
  @title = @url = @src
23
27
  return
@@ -1,12 +1,18 @@
1
1
  require 'net/https'
2
2
 
3
3
  class RedirectFollower
4
+ REDIRECT_DEFAULT_LIMIT = 5
4
5
  class TooManyRedirects < StandardError; end
5
6
 
6
- attr_accessor :url, :body, :redirect_limit, :response
7
+ attr_accessor :url, :body, :redirect_limit, :response, :headers
7
8
 
8
- def initialize(url, limit = 5)
9
+ def initialize(url, limit = REDIRECT_DEFAULT_LIMIT, options = {})
10
+ if limit.is_a? Hash
11
+ options = limit
12
+ limit = REDIRECT_DEFAULT_LIMIT
13
+ end
9
14
  @url, @redirect_limit = url, limit
15
+ @headers = options[:headers] || {}
10
16
  end
11
17
 
12
18
  def resolve
@@ -17,9 +23,9 @@ class RedirectFollower
17
23
  https = Net::HTTP.new(uri.host, 443)
18
24
  https.use_ssl = true
19
25
  https.verify_mode = OpenSSL::SSL::VERIFY_PEER
20
- self.response = https.request_get(uri.request_uri)
26
+ self.response = https.request_get(uri.request_uri, @headers)
21
27
  else
22
- self.response = Net::HTTP.get_response(uri)
28
+ self.response = Net::HTTP.get_response(uri, @headers)
23
29
  end
24
30
 
25
31
  if response.kind_of?(Net::HTTPRedirection)
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.0
4
+ version: 0.2.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: 2013-01-16 00:00:00.000000000 Z
13
+ date: 2013-02-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: nokogiri
17
- requirement: &70256296829180 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,15 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70256296829180
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
26
31
  - !ruby/object:Gem::Dependency
27
32
  name: addressable
28
- requirement: &70256296828540 !ruby/object:Gem::Requirement
33
+ requirement: !ruby/object:Gem::Requirement
29
34
  none: false
30
35
  requirements:
31
36
  - - ! '>='
@@ -33,10 +38,15 @@ dependencies:
33
38
  version: '0'
34
39
  type: :runtime
35
40
  prerelease: false
36
- version_requirements: *70256296828540
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
37
47
  - !ruby/object:Gem::Dependency
38
48
  name: rspec
39
- requirement: &70256296827720 !ruby/object:Gem::Requirement
49
+ requirement: !ruby/object:Gem::Requirement
40
50
  none: false
41
51
  requirements:
42
52
  - - ! '>='
@@ -44,10 +54,15 @@ dependencies:
44
54
  version: '0'
45
55
  type: :development
46
56
  prerelease: false
47
- version_requirements: *70256296827720
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
48
63
  - !ruby/object:Gem::Dependency
49
64
  name: rdoc
50
- requirement: &70256296826860 !ruby/object:Gem::Requirement
65
+ requirement: !ruby/object:Gem::Requirement
51
66
  none: false
52
67
  requirements:
53
68
  - - ! '>='
@@ -55,10 +70,15 @@ dependencies:
55
70
  version: '0'
56
71
  type: :development
57
72
  prerelease: false
58
- version_requirements: *70256296826860
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
59
79
  - !ruby/object:Gem::Dependency
60
80
  name: bundler
61
- requirement: &70256296825620 !ruby/object:Gem::Requirement
81
+ requirement: !ruby/object:Gem::Requirement
62
82
  none: false
63
83
  requirements:
64
84
  - - ! '>='
@@ -66,10 +86,15 @@ dependencies:
66
86
  version: '0'
67
87
  type: :development
68
88
  prerelease: false
69
- version_requirements: *70256296825620
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
70
95
  - !ruby/object:Gem::Dependency
71
96
  name: jeweler
72
- requirement: &70256296818460 !ruby/object:Gem::Requirement
97
+ requirement: !ruby/object:Gem::Requirement
73
98
  none: false
74
99
  requirements:
75
100
  - - ! '>='
@@ -77,7 +102,12 @@ dependencies:
77
102
  version: '0'
78
103
  type: :development
79
104
  prerelease: false
80
- version_requirements: *70256296818460
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
81
111
  description: A simple Ruby library for parsing Open Graph Protocol information from
82
112
  a website. It also includes a fallback solution when the website has no Open Graph
83
113
  information.
@@ -108,7 +138,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
138
  version: '0'
109
139
  segments:
110
140
  - 0
111
- hash: -777082750492777387
141
+ hash: -485403588792843274
112
142
  required_rubygems_version: !ruby/object:Gem::Requirement
113
143
  none: false
114
144
  requirements:
@@ -117,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
147
  version: '0'
118
148
  requirements: []
119
149
  rubyforge_project:
120
- rubygems_version: 1.8.10
150
+ rubygems_version: 1.8.24
121
151
  signing_key:
122
152
  specification_version: 3
123
153
  summary: A simple Ruby library for parsing Open Graph Protocol information from a