onebox 1.2.8 → 1.2.9

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: 2641fac6a4a3b4f3d745577e2b5bc649e07728cf
4
- data.tar.gz: 2367a864281c2a163d1b045842e4b51dc966ea54
3
+ metadata.gz: 08517acd13666e45ae3bb18e3f253ad67078e0e6
4
+ data.tar.gz: 3c8e281f915669cd668ce27e19818d3852f57b17
5
5
  SHA512:
6
- metadata.gz: a5f15317d816de8d5f7bbecc7cbf718636b15144f60863e0af59b0bc017aa217f670bfba1c8b803e749cbbe1da98faa6548dac96535d60cfc804e1d31dc0d184
7
- data.tar.gz: a1934a489750795ee66c17be45d8429efe88359d8e0a195bb22818747f8faeccb933273fde7dbdacb448c1d62c68ee3299b8d80b466e215af39172c54a4e56c7
6
+ metadata.gz: 163a4db5056c61763653d7993175e6cafe36a5b032abc98cf19ce43feedfd5f448841861cd16dcd05cc3fce0bb1f4334acc6bccdb3a585890bcc3ca30467c7cf
7
+ data.tar.gz: 021b17d816562c9a07022c9235b532c51f5d399301fd4230cb8a4b79380211af55c047a00c8f0551a5df767a6e7d886c948ac58bac8e5f16071840295f431c3c
data/lib/onebox.rb CHANGED
@@ -2,12 +2,13 @@ require "open-uri"
2
2
  require "multi_json"
3
3
  require "nokogiri"
4
4
  require "mustache"
5
- require "opengraph_parser"
6
5
  require "hexpress"
7
6
  require "hexpress/web"
8
7
  require "ostruct"
9
8
  require "moneta"
10
9
  require "cgi"
10
+ require "net/http"
11
+ require "digest"
11
12
 
12
13
  module Onebox
13
14
  DEFAULTS = {
@@ -19,7 +19,7 @@ module Onebox
19
19
  end
20
20
  end
21
21
 
22
- open_graph = OpenGraph.new(response.body, false)
22
+ open_graph = parse_open_graph(html_doc, url)
23
23
  if @raw
24
24
  @raw[:image] = open_graph.images.first if @raw[:image].nil? && open_graph && open_graph.images
25
25
 
@@ -31,6 +31,34 @@ module Onebox
31
31
 
32
32
  private
33
33
 
34
+ def parse_open_graph(html, url)
35
+ og = Struct.new(:url, :type, :title, :description, :images, :metadata).new
36
+ og.url = url
37
+ og.images = []
38
+ og.metadata = {}
39
+
40
+ attrs_list = %w(title url type description)
41
+ html.css('meta').each do |m|
42
+ if m.attribute('property') && m.attribute('property').to_s.match(/^og:/i)
43
+ m_content = m.attribute('content').to_s.strip
44
+ m_name = m.attribute('property').to_s.gsub('og:', '')
45
+ og.metadata[m_name.to_sym] ||= []
46
+ og.metadata[m_name.to_sym].push m_content
47
+ if m_name == "image"
48
+ image_uri = URI.parse(m_content)
49
+ if image_uri.host.nil?
50
+ image_uri.host = URI.parse(url).host
51
+ end
52
+ og.images.push image_uri.to_s
53
+ elsif attrs_list.include? m_name
54
+ og.send("#{m_name}=", m_content) unless m_content.empty?
55
+ end
56
+ end
57
+ end
58
+
59
+ og
60
+ end
61
+
34
62
  def fetch_response(location, limit = 3)
35
63
  raise Net::HTTPError.new('HTTP redirect too deep', location) if limit == 0
36
64
 
@@ -38,6 +66,10 @@ module Onebox
38
66
  http = Net::HTTP.new(uri.host, uri.port)
39
67
  http.open_timeout = Onebox.options.connect_timeout
40
68
  http.read_timeout = Onebox.options.timeout
69
+ if uri.is_a?(URI::HTTPS)
70
+ http.use_ssl = true
71
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
72
+ end
41
73
  response = http.request_get(uri.request_uri)
42
74
 
43
75
  case response
@@ -1,3 +1,3 @@
1
1
  module Onebox
2
- VERSION = "1.2.8"
2
+ VERSION = "1.2.9"
3
3
  end
data/onebox.gemspec CHANGED
@@ -21,7 +21,6 @@ Gem::Specification.new do |spec|
21
21
  spec.add_runtime_dependency "multi_json", "~> 1.7"
22
22
  spec.add_runtime_dependency "mustache", "~> 0.99"
23
23
  spec.add_runtime_dependency "nokogiri", "~> 1.6.1"
24
- spec.add_runtime_dependency "opengraph_parser", "~> 0.2.3"
25
24
  spec.add_runtime_dependency "hexpress", "~> 1.2"
26
25
  spec.add_runtime_dependency "moneta", "~> 0.7"
27
26
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onebox
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.8
4
+ version: 1.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joanna Zeta
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-03-26 00:00:00.000000000 Z
13
+ date: 2014-03-31 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: multi_json
@@ -54,20 +54,6 @@ dependencies:
54
54
  - - "~>"
55
55
  - !ruby/object:Gem::Version
56
56
  version: 1.6.1
57
- - !ruby/object:Gem::Dependency
58
- name: opengraph_parser
59
- requirement: !ruby/object:Gem::Requirement
60
- requirements:
61
- - - "~>"
62
- - !ruby/object:Gem::Version
63
- version: 0.2.3
64
- type: :runtime
65
- prerelease: false
66
- version_requirements: !ruby/object:Gem::Requirement
67
- requirements:
68
- - - "~>"
69
- - !ruby/object:Gem::Version
70
- version: 0.2.3
71
57
  - !ruby/object:Gem::Dependency
72
58
  name: hexpress
73
59
  requirement: !ruby/object:Gem::Requirement