ogo 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ogo.rb +11 -4
- data/lib/ogo/image_info.rb +3 -1
- data/lib/ogo/utils/redirect_follower.rb +10 -2
- data/lib/ogo/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4fba6b9bc8792f074086c685f99e20bcf96a58c6
|
4
|
+
data.tar.gz: 4c74bbb20a1fab2e467218c4aee4294de8e6e4ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29193a3849f04852df9b584dd220d6a16af1d7ef46e2725f211715236efe6ef1a09f16c8df0fea236e6d489e3a8f4415b8fcbcaf56222677eca23871bbf346a6
|
7
|
+
data.tar.gz: 3687e02783b0807ae49ea2f5ca8a688b3e6581f9b5749db6ec76058c0874c5d0e304bcce2dcf73809e87747685db6df541f7a046318dd0093b6f638fd2c679c3
|
data/lib/ogo.rb
CHANGED
@@ -9,11 +9,18 @@ require_relative 'ogo/utils/redirect_follower'
|
|
9
9
|
require_relative 'ogo/version'
|
10
10
|
|
11
11
|
module Ogo
|
12
|
+
@config = {
|
13
|
+
redirect_limit: 5,
|
14
|
+
http_timeout: 3
|
15
|
+
}
|
12
16
|
|
13
|
-
def self.
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
+
def self.config
|
18
|
+
@config
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.parse_opengraph(url, fallback=true)
|
22
|
+
og = Ogo::Parsers::Opengraph.new(url)
|
23
|
+
og.metadata(fallback)
|
17
24
|
end
|
18
25
|
|
19
26
|
end
|
data/lib/ogo/image_info.rb
CHANGED
@@ -4,15 +4,22 @@ module Ogo
|
|
4
4
|
module Utils
|
5
5
|
class RedirectFollower
|
6
6
|
REDIRECT_DEFAULT_LIMIT = 5
|
7
|
+
HTTP_DEFAULT_TIMEOUT = 3 # seconds
|
7
8
|
|
8
9
|
class TooManyRedirects < StandardError; end
|
9
10
|
class EmptyURLError < ArgumentError; end
|
10
11
|
|
11
|
-
attr_accessor :url, :body, :charset, :redirect_limit, :
|
12
|
+
attr_accessor :url, :body, :charset, :redirect_limit, :http_timeout,
|
13
|
+
:response, :headers
|
12
14
|
|
13
15
|
def initialize(url, options = {})
|
14
16
|
raise EmptyURLError if url.to_s.empty?
|
15
|
-
@redirect_limit = options[:
|
17
|
+
@redirect_limit = options[:redirect_limit] ||
|
18
|
+
Ogo.config[:redirect_limit] ||
|
19
|
+
REDIRECT_DEFAULT_LIMIT
|
20
|
+
@http_timeout = options[:http_timeout] ||
|
21
|
+
Ogo.config[:http_timeout] ||
|
22
|
+
HTTP_DEFAULT_TIMEOUT
|
16
23
|
@headers = options[:headers] || {}
|
17
24
|
@url = url.start_with?('http') ? url : "http://#{url}"
|
18
25
|
end
|
@@ -23,6 +30,7 @@ module Ogo
|
|
23
30
|
uri = Addressable::URI.parse(url).normalize
|
24
31
|
|
25
32
|
http = Net::HTTP.new(uri.host, uri.inferred_port)
|
33
|
+
http.read_timeout = http_timeout
|
26
34
|
if uri.scheme == 'https'
|
27
35
|
http.use_ssl = true
|
28
36
|
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
data/lib/ogo/version.rb
CHANGED