oembed_proxy 0.1.0
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 +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.rubocop.yml +15 -0
- data/.travis.yml +10 -0
- data/Gemfile +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +106 -0
- data/Rakefile +8 -0
- data/bin/console +14 -0
- data/bin/rspec +21 -0
- data/bin/rubocop +21 -0
- data/bin/setup +8 -0
- data/lib/oembed_proxy/associated_press.rb +30 -0
- data/lib/oembed_proxy/embedly.rb +29 -0
- data/lib/oembed_proxy/first_party.rb +96 -0
- data/lib/oembed_proxy/fusiontable_map.rb +30 -0
- data/lib/oembed_proxy/google_document.rb +30 -0
- data/lib/oembed_proxy/google_mapsengine.rb +39 -0
- data/lib/oembed_proxy/google_spreadsheet.rb +30 -0
- data/lib/oembed_proxy/handler.rb +30 -0
- data/lib/oembed_proxy/inactive_support.rb +23 -0
- data/lib/oembed_proxy/oembed_exception.rb +5 -0
- data/lib/oembed_proxy/tableau.rb +50 -0
- data/lib/oembed_proxy/utility.rb +16 -0
- data/lib/oembed_proxy/version.rb +5 -0
- data/lib/oembed_proxy.rb +17 -0
- data/lib/providers/embedly_patterns.def +647 -0
- data/lib/providers/first_party.yml +91 -0
- data/oembed_proxy.gemspec +29 -0
- metadata +115 -0
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'oembed_proxy/inactive_support'
|
4
|
+
|
5
|
+
module OembedProxy
|
6
|
+
# Tableau Fauxembed
|
7
|
+
class Tableau
|
8
|
+
using InactiveSupport
|
9
|
+
|
10
|
+
TABLEAU_REGEX = %r{\Ahttps://public\.tableau\.com/(?:profile/[^/]+/vizhome|views)/([^?]+)}
|
11
|
+
|
12
|
+
def handles_url?(url)
|
13
|
+
!TABLEAU_REGEX.match(url).nil?
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_data(url, _other_params = {}) # rubocop:disable Metrics/MethodLength
|
17
|
+
return nil unless handles_url? url
|
18
|
+
|
19
|
+
chart_id = url.match(TABLEAU_REGEX)[1]
|
20
|
+
div_id = self.class.build_div_id(chart_id)
|
21
|
+
|
22
|
+
{
|
23
|
+
'type' => 'rich',
|
24
|
+
'version' => '1.0',
|
25
|
+
'provider_name' => 'Tableau',
|
26
|
+
'provider_url' => 'https://tableau.com/',
|
27
|
+
'width' => 500,
|
28
|
+
'height' => 500,
|
29
|
+
'html' => <<~HTML
|
30
|
+
<div id="#{div_id}"></div>
|
31
|
+
<script type="text/javascript" src="https://public.tableau.com/javascripts/api/tableau-2.min.js"></script>
|
32
|
+
<script type="text/javascript">
|
33
|
+
(function() {
|
34
|
+
var container = document.getElementById('#{div_id}');
|
35
|
+
var url = 'https://public.tableau.com/views/#{chart_id}?:embed=y&:display_count=yes';
|
36
|
+
var options = {};
|
37
|
+
var viz = new tableau.Viz(container, url, options);
|
38
|
+
})();
|
39
|
+
</script>
|
40
|
+
HTML
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
# Make a unique div_id by slapping a random 10-digit number on the end
|
45
|
+
def self.build_div_id(chart_id)
|
46
|
+
chart_slug = chart_id.parameterize
|
47
|
+
format('%<slug>s-%<rand>010d', slug: chart_slug, rand: rand(1_000_000_000))
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OembedProxy
|
4
|
+
# Utility methods
|
5
|
+
module Utility
|
6
|
+
def self.clean_pattern(pattern_raw)
|
7
|
+
pattern = pattern_raw.strip.freeze
|
8
|
+
|
9
|
+
if pattern =~ /^#.*#i$/
|
10
|
+
pattern.slice(1..-3)
|
11
|
+
else
|
12
|
+
pattern
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/oembed_proxy.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'oembed_proxy/version'
|
4
|
+
require 'oembed_proxy/handler'
|
5
|
+
require 'oembed_proxy/associated_press'
|
6
|
+
require 'oembed_proxy/embedly'
|
7
|
+
require 'oembed_proxy/first_party'
|
8
|
+
require 'oembed_proxy/fusiontable_map'
|
9
|
+
require 'oembed_proxy/google_document'
|
10
|
+
require 'oembed_proxy/google_mapsengine'
|
11
|
+
require 'oembed_proxy/google_spreadsheet'
|
12
|
+
require 'oembed_proxy/tableau'
|
13
|
+
|
14
|
+
# Gem namespace
|
15
|
+
module OembedProxy
|
16
|
+
# Your code goes here...
|
17
|
+
end
|