oembed_proxy 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OembedProxy
4
+ VERSION = '0.1.0'
5
+ end
@@ -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