open_graph_reader 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 54533bcbded9b149032a31977d775c2f898d77d4
4
- data.tar.gz: 39a32a31b7bdff1a1bbcd5577222a3ccbc80770e
3
+ metadata.gz: a0a3bc88e9a52edb75e3e43fb979c7e80e08c28f
4
+ data.tar.gz: 6f4c978e5ecd6dce4abf675fe928e6ef785d3538
5
5
  SHA512:
6
- metadata.gz: 8b50816f5d78ec562bda2c3120250050b9ba381409d5659595a824c16922c8d1ce9b4ff5a09d0178978ff630d8d89a96c05304e9be2e4152d886d923873f271e
7
- data.tar.gz: cc958a19ba7db998332c666ed42e40a646b28dc26e1ee533636c3a5d5178d4c924a03f3f2fc69d34f79cc1b7374f09d1429c6b574a64de39280251620d495c91
6
+ metadata.gz: d7fc1741f800e9bd13368916914e101c3da9345eb85cdd3bbf6933ed2235265ec190b58cb035273060148c9721196dbf8573371a7c8218299dab3d893c5eca4c
7
+ data.tar.gz: 1f1013ee595b4fcfc0434034cb66f3662e2bc884c7932ebc82536909ac1ccadc753587c3131a53864ba78d7b0456c2f432546d32db2e5254ce201ebaffb3926a
@@ -26,8 +26,11 @@ module OpenGraphReader
26
26
  def initialize uri
27
27
  raise ArgumentError, "url needs to be an instance of URI" unless uri.is_a? URI
28
28
  @uri = uri
29
+ @fetch_failed = false
29
30
  @connection = Faraday.default_connection.dup
30
31
  @connection.headers.replace(HEADERS)
32
+ @head_response = nil
33
+ @get_response = nil
31
34
 
32
35
  prepend_middleware Faraday::CookieJar if defined? Faraday::CookieJar
33
36
  prepend_middleware FaradayMiddleware::FollowRedirects if defined? FaradayMiddleware
@@ -46,6 +49,7 @@ module OpenGraphReader
46
49
  def fetch
47
50
  @get_response = @connection.get(@uri)
48
51
  rescue Faraday::Error
52
+ @fetch_failed = true
49
53
  end
50
54
  alias_method :fetch_body, :fetch
51
55
 
@@ -55,6 +59,7 @@ module OpenGraphReader
55
59
  def fetch_headers
56
60
  @head_response = @connection.head(@uri)
57
61
  rescue Faraday::Error
62
+ @fetch_failed = true
58
63
  end
59
64
 
60
65
  # Retrieve the body
@@ -64,7 +69,8 @@ module OpenGraphReader
64
69
  # @return [String]
65
70
  def body
66
71
  fetch_body unless fetched?
67
- raise ArgumentError, "Did not receive a HTML site at #{@uri}" unless html?
72
+ raise NoOpenGraphDataError, "No response body received for #{@uri}" if fetch_failed?
73
+ raise NoOpenGraphDataError, "Did not receive a HTML site at #{@uri}" unless html?
68
74
  @get_response.body
69
75
  end
70
76
 
@@ -74,6 +80,7 @@ module OpenGraphReader
74
80
  def html?
75
81
  fetch_headers unless fetched_headers?
76
82
  response = @get_response || @head_response
83
+ return false if fetch_failed?
77
84
  return false unless response
78
85
  return false unless response.success?
79
86
  return false unless response["content-type"]
@@ -84,7 +91,7 @@ module OpenGraphReader
84
91
  #
85
92
  # @return [Bool]
86
93
  def fetched?
87
- !@get_response.nil?
94
+ fetch_failed? || !@get_response.nil?
88
95
  end
89
96
  alias_method :fetched_body?, :fetched?
90
97
 
@@ -92,11 +99,15 @@ module OpenGraphReader
92
99
  #
93
100
  # @return [Bool]
94
101
  def fetched_headers?
95
- !@get_response.nil? || !@head_response.nil?
102
+ fetch_failed? || !@get_response.nil? || !@head_response.nil?
96
103
  end
97
104
 
98
105
  private
99
106
 
107
+ def fetch_failed?
108
+ @fetch_failed
109
+ end
110
+
100
111
  def prepend_middleware middleware
101
112
  return if @connection.builder.handlers.include? middleware
102
113
 
@@ -1,4 +1,4 @@
1
1
  module OpenGraphReader
2
2
  # Tbe library version
3
- VERSION = "0.6.1"
3
+ VERSION = "0.6.2"
4
4
  end
@@ -0,0 +1,20 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe OpenGraphReader::Fetcher do
4
+ let(:uri) { URI("http://example.org") }
5
+ let(:fetcher) { described_class.new uri }
6
+ let(:good_response) { {status: 200, body: "", headers: {"Content-Type" => "text/html"}} }
7
+
8
+ context "error during body fetch" do
9
+ before do
10
+ stub_request(:head, uri).to_return(good_response)
11
+ stub_request(:get, uri).to_raise(Faraday::ConnectionFailed.new("execution expired"))
12
+ end
13
+
14
+ describe "#body" do
15
+ it "raises" do
16
+ expect { fetcher.body }.to raise_error OpenGraphReader::NoOpenGraphDataError, /response body/
17
+ end
18
+ end
19
+ end
20
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: open_graph_reader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonne Haß
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-12 00:00:00.000000000 Z
11
+ date: 2017-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -28,14 +28,14 @@ dependencies:
28
28
  name: faraday
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.9.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.9.0
41
41
  - !ruby/object:Gem::Dependency
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '10.0'
61
+ version: '12.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '10.0'
68
+ version: '12.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '1.20'
89
+ version: '2.3'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '1.20'
96
+ version: '2.3'
97
97
  description: A library to fetch and parse OpenGraph properties from an URL or a given
98
98
  string.
99
99
  email:
@@ -186,6 +186,7 @@ files:
186
186
  - spec/integration/invalid_examples_spec.rb
187
187
  - spec/integration/real_world_spec.rb
188
188
  - spec/integration/valid_examples_spec.rb
189
+ - spec/open_graph_reader/fetcher_spec.rb
189
190
  - spec/open_graph_reader_spec.rb
190
191
  - spec/spec_helper.rb
191
192
  homepage: https://github.com/jhass/open_graph_reader
@@ -208,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
208
209
  version: '0'
209
210
  requirements: []
210
211
  rubyforge_project:
211
- rubygems_version: 2.4.5
212
+ rubygems_version: 2.6.8
212
213
  signing_key:
213
214
  specification_version: 4
214
215
  summary: OpenGraph protocol parser
@@ -279,6 +280,6 @@ test_files:
279
280
  - spec/integration/invalid_examples_spec.rb
280
281
  - spec/integration/real_world_spec.rb
281
282
  - spec/integration/valid_examples_spec.rb
283
+ - spec/open_graph_reader/fetcher_spec.rb
282
284
  - spec/open_graph_reader_spec.rb
283
285
  - spec/spec_helper.rb
284
- has_rdoc: