onebox 2.1.5 → 2.1.6

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
  SHA256:
3
- metadata.gz: 372344282cacdb38dfceab5dfb6c156d7c9fa5ec04cca9cc21eb8502987ce077
4
- data.tar.gz: 02a26147e10f54261596572328cf85a758178cda845a20c9999cc1b5f96ffe18
3
+ metadata.gz: b6fd88926ec341ed84409e7c77dbfcce244dbf2a0c74e0a19736e81b2b693e84
4
+ data.tar.gz: 18f53e5fb7b1fa4eab35ea27f87e97600e82af0eaf4fd5eed0809744bf7e53c7
5
5
  SHA512:
6
- metadata.gz: 187c7a40761cea4d784175373600c00c2045d29ba911c8838614bf51b76454ecd7080ee93ca787d6745e69fc9d823b6de0e592746a2ccc30e9a9d55847e86cd4
7
- data.tar.gz: f73f392c9451e85e5678dd0eff146092bfc0f3ae6a261eb4dfae02fb6a614976571837f3ec52e512334a4e815c3e3c8f49694179a7a41ec387d7195153cb7810
6
+ metadata.gz: 5a5c344336f529d53b51ac47b5b0efee1b6fb29b0b2541948d650fa1d81e11f97edfa3d1a2f8abb7915b8cf9c86e41c74b64cb40b26924e380f68d52e0015c33
7
+ data.tar.gz: 9cefe31755197bbfb71ba3e741329c7bdba10fd9bb19892b237cb78b22769e0e19824119b94cb3cdd24f7bec10f4aeb91cbad3a7d40eefd84c2cbe64866908b0
@@ -30,6 +30,7 @@ module Onebox
30
30
 
31
31
  attr_reader :url, :uri
32
32
  attr_reader :timeout
33
+ attr :errors
33
34
 
34
35
  DEFAULT = {}
35
36
  def options
@@ -44,6 +45,7 @@ module Onebox
44
45
  end
45
46
 
46
47
  def initialize(link, timeout = nil)
48
+ @errors = {}
47
49
  @options = DEFAULT
48
50
  class_name = self.class.name.split("::").last.to_s
49
51
 
@@ -256,6 +256,15 @@ module Onebox
256
256
  d[:data_1] = Onebox::Helpers.truncate("#{d[:price_currency].strip} #{d[:price_amount].strip}")
257
257
  end
258
258
 
259
+ skip_missing_tags = [:video]
260
+ d.each do |k, v|
261
+ next if skip_missing_tags.include?(k)
262
+ if v == nil || v == ''
263
+ errors[k] ||= []
264
+ errors[k] << 'is blank'
265
+ end
266
+ end
267
+
259
268
  d
260
269
  end
261
270
  end
@@ -15,35 +15,30 @@ module Onebox
15
15
  end
16
16
 
17
17
  def data
18
- og = get_opengraph
19
-
20
- # There are at least two different versions of the description. e.g.
21
- # - "3,227 Likes, 88 Comments - An Account (@user.name) on Instagram: “Look at my picture!”"
22
- # - "@user.name posted on their Instagram profile: “Look at my picture!”"
23
-
24
- m = og.description.match(/\(@([\w\.]+)\) on Instagram/)
25
- author_name = m[1] if m
26
-
27
- author_name ||= begin
28
- m = og.description.match(/^\@([\w\.]+)\ posted/)
29
- m[1] if m
30
- end
31
-
32
- raise "Author username not found for post #{clean_url}" unless author_name
33
-
34
- permalink = clean_url.gsub("/#{author_name}/", "/")
18
+ oembed = get_oembed
19
+ permalink = clean_url.gsub("/#{oembed.author_name}/", "/")
35
20
 
36
21
  { link: permalink,
37
- title: "@#{author_name}",
38
- image: og.image,
39
- description: Onebox::Helpers.truncate(og.title, 250)
22
+ title: "@#{oembed.author_name}",
23
+ image: oembed.thumbnail_url,
24
+ description: Onebox::Helpers.truncate(oembed.title, 250),
40
25
  }
26
+
41
27
  end
42
28
 
43
29
  protected
44
30
 
31
+ def access_token
32
+ (options[:facebook_app_access_token] || Onebox.options.facebook_app_access_token).to_s
33
+ end
34
+
45
35
  def get_oembed_url
46
- oembed_url = "https://api.instagram.com/oembed/?url=#{clean_url}"
36
+ if access_token != ''
37
+ oembed_url = "https://graph.facebook.com/v9.0/instagram_oembed?url=#{clean_url}&access_token=#{access_token}"
38
+ else
39
+ # The following is officially deprecated by Instagram, but works in some limited circumstances.
40
+ oembed_url = "https://api.instagram.com/oembed/?url=#{clean_url}"
41
+ end
47
42
  end
48
43
  end
49
44
  end
@@ -91,7 +91,7 @@ module Onebox
91
91
  html_doc.css('meta').each do |m|
92
92
  if (m["property"] && m["property"][/^twitter:(.+)$/i]) || (m["name"] && m["name"][/^twitter:(.+)$/i])
93
93
  value = (m["content"] || m["value"]).to_s
94
- twitter[$1.tr('-:' , '_').to_sym] ||= value unless Onebox::Helpers::blank?(value)
94
+ twitter[$1.tr('-:' , '_').to_sym] ||= value unless (Onebox::Helpers::blank?(value) || value == "0 minutes")
95
95
  end
96
96
  end
97
97
 
@@ -156,6 +156,7 @@ module Onebox
156
156
  end
157
157
 
158
158
  def self.truncate(string, length = 50)
159
+ return string if string.nil?
159
160
  string.size > length ? string[0...(string.rindex(" ", length) || length)] + "..." : string
160
161
  end
161
162
 
@@ -31,6 +31,16 @@ module Onebox
31
31
  ""
32
32
  end
33
33
 
34
+ def errors
35
+ return {} unless engine
36
+ engine.errors
37
+ end
38
+
39
+ def data
40
+ return {} unless engine
41
+ engine.data
42
+ end
43
+
34
44
  def options
35
45
  OpenStruct.new(@options)
36
46
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Onebox
4
- VERSION = "2.1.5"
4
+ VERSION = "2.1.6"
5
5
  end
@@ -8,4 +8,6 @@
8
8
  </div>
9
9
  {{/image}}
10
10
 
11
- <div class="instagram-description">{{description}}</div>
11
+ {{#description}}
12
+ <div class="instagram-description">{{description}}</div>
13
+ {{/description}}
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: 2.1.5
4
+ version: 2.1.6
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: 2020-11-06 00:00:00.000000000 Z
13
+ date: 2020-11-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: addressable