ogo 0.1.1 → 0.1.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: 3916d06ba08cf0c304c487d5754590b0bfdb64aa
4
- data.tar.gz: 06cc4a8c9e9c38f84c86fe56acab9756901ea058
3
+ metadata.gz: 4fba6b9bc8792f074086c685f99e20bcf96a58c6
4
+ data.tar.gz: 4c74bbb20a1fab2e467218c4aee4294de8e6e4ba
5
5
  SHA512:
6
- metadata.gz: c13484e58cf8a94f6cf675f346116277e315bc42ba21b9e031d7abf2be99d48bfffa7a3ab5134bb71e87b134a17c855b62bb7a2cd1af048f29a09fa66eb61d5b
7
- data.tar.gz: 866bf793b4475f784ca534119063e6ebe18452993ff1fdef32f08f48231c90d9c4bf4f622561512a37b3a83c5024226b92ca6015a184a9d0c1e7a0bb599976af
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.parse_opengraph(url)
14
- og = Ogo::Opengraph.new(url)
15
- og.parse
16
- og
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
@@ -46,7 +46,9 @@ module Ogo
46
46
  fi_check(:type, url).to_s
47
47
  else
48
48
  uri = Addressable::URI.parse(url).normalize
49
- uri.path.split('.').last.to_s
49
+ if uri.path.include?('.')
50
+ uri.path.split('.').last.to_s
51
+ end
50
52
  end
51
53
  end
52
54
 
@@ -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, :response, :headers
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[:limit] || REDIRECT_DEFAULT_LIMIT
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
@@ -1,3 +1,3 @@
1
1
  module Ogo
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ogo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - gazay