oh-my-embed 1.0.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.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +9 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +164 -0
  8. data/Rakefile +6 -0
  9. data/bin/console +17 -0
  10. data/bin/setup +8 -0
  11. data/lib/oh_my_embed.rb +52 -0
  12. data/lib/oh_my_embed/crawler.rb +77 -0
  13. data/lib/oh_my_embed/provider.rb +116 -0
  14. data/lib/oh_my_embed/providers/facebook_post.rb +20 -0
  15. data/lib/oh_my_embed/providers/facebook_video.rb +15 -0
  16. data/lib/oh_my_embed/providers/flickr.rb +15 -0
  17. data/lib/oh_my_embed/providers/instagram.rb +15 -0
  18. data/lib/oh_my_embed/providers/kickstarter.rb +15 -0
  19. data/lib/oh_my_embed/providers/slideshare.rb +19 -0
  20. data/lib/oh_my_embed/providers/soundcloud.rb +14 -0
  21. data/lib/oh_my_embed/providers/spotify.rb +17 -0
  22. data/lib/oh_my_embed/providers/twitter.rb +14 -0
  23. data/lib/oh_my_embed/providers/youtube.rb +18 -0
  24. data/lib/oh_my_embed/response.rb +110 -0
  25. data/lib/oh_my_embed/version.rb +3 -0
  26. data/oh-my-embed.gemspec +33 -0
  27. data/spec/fixtures/vcr_cassettes/facebook_posts.yml +65 -0
  28. data/spec/fixtures/vcr_cassettes/facebook_videos.yml +65 -0
  29. data/spec/fixtures/vcr_cassettes/flickr.yml +90 -0
  30. data/spec/fixtures/vcr_cassettes/instagram.yml +75 -0
  31. data/spec/fixtures/vcr_cassettes/kickstarter.yml +65 -0
  32. data/spec/fixtures/vcr_cassettes/slideshare.yml +87 -0
  33. data/spec/fixtures/vcr_cassettes/soundcloud.yml +57 -0
  34. data/spec/fixtures/vcr_cassettes/spotify.yml +44 -0
  35. data/spec/fixtures/vcr_cassettes/twitter.yml +66 -0
  36. data/spec/fixtures/vcr_cassettes/youtube.yml +57 -0
  37. data/spec/oh_my_embed/crawler_spec.rb +99 -0
  38. data/spec/oh_my_embed/provider_spec.rb +103 -0
  39. data/spec/oh_my_embed/providers/facebook_post_spec.rb +40 -0
  40. data/spec/oh_my_embed/providers/facebook_video_spec.rb +40 -0
  41. data/spec/oh_my_embed/providers/flickr_spec.rb +44 -0
  42. data/spec/oh_my_embed/providers/instagram_spec.rb +44 -0
  43. data/spec/oh_my_embed/providers/kickstarter_spec.rb +44 -0
  44. data/spec/oh_my_embed/providers/slideshare_spec.rb +44 -0
  45. data/spec/oh_my_embed/providers/soundcloud_spec.rb +44 -0
  46. data/spec/oh_my_embed/providers/spotify_spec.rb +41 -0
  47. data/spec/oh_my_embed/providers/twitter_spec.rb +40 -0
  48. data/spec/oh_my_embed/providers/youtube_spec.rb +44 -0
  49. data/spec/oh_my_embed/response_spec.rb +174 -0
  50. data/spec/oh_my_embed_spec.rb +7 -0
  51. data/spec/spec_helper.rb +17 -0
  52. metadata +234 -0
@@ -0,0 +1,20 @@
1
+ module OhMyEmbed
2
+ module Providers
3
+ class FacebookPost < OhMyEmbed::Provider
4
+ # Facebook oembed documentation:
5
+ # https://developers.facebook.com/docs/plugins/oembed-endpoints
6
+
7
+ self.endpoint = 'https://www.facebook.com/plugins/post/oembed.json/'
8
+ self.schemes = [
9
+ '//www.facebook.com/*/posts/*',
10
+ '//www.facebook.com/*/activity/*',
11
+ '//www.facebook.com/photo.php?fbid=*',
12
+ '//www.facebook.com/photos/*',
13
+ '//www.facebook.com/permalink.php?story_fbid=*',
14
+ '//www.facebook.com/media/set?set=*',
15
+ '//www.facebook.com/questions/*',
16
+ '//www.facebook.com/notes/*/*/*',
17
+ ]
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,15 @@
1
+ module OhMyEmbed
2
+ module Providers
3
+ class FacebookVideo < OhMyEmbed::Provider
4
+ # Facebook oembed documentation:
5
+ # https://developers.facebook.com/docs/plugins/oembed-endpoints
6
+
7
+ self.endpoint = 'https://www.facebook.com/plugins/video/oembed.json/'
8
+ self.schemes = [
9
+ '//www.facebook.com/*/videos/*',
10
+ '//www.facebook.com/video.php?id=*',
11
+ '//www.facebook.com/video.php?v=*',
12
+ ]
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module OhMyEmbed
2
+ module Providers
3
+ class Flickr < OhMyEmbed::Provider
4
+ # Flickr oembed documentation:
5
+ # Flickr has no own documentation in the interwebz :(
6
+ # http://oembed.com/providers.json
7
+
8
+ self.endpoint = 'https://www.flickr.com/services/oembed/'
9
+ self.schemes = [
10
+ '//*.flickr.com/*',
11
+ '//flic.kr/*',
12
+ ]
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module OhMyEmbed
2
+ module Providers
3
+ class Instagram < OhMyEmbed::Provider
4
+ # Instagram oembed documentation:
5
+ # https://www.instagram.com/developer/embedding/?hl=de#oembed
6
+
7
+ self.endpoint = 'https://api.instagram.com/oembed/'
8
+ self.schemes = [
9
+ '//instagr.am/p/*',
10
+ '//instagram.com/p/*',
11
+ '//*.instagram.com/p/*',
12
+ ]
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module OhMyEmbed
2
+ module Providers
3
+ class Kickstarter < OhMyEmbed::Provider
4
+ # Kickstarter oembed documentation:
5
+ # Kickstarter has no own documentation in the interwebz :(
6
+ # http://oembed.com/providers.json
7
+
8
+ self.endpoint = 'https://www.kickstarter.com/services/oembed'
9
+ self.schemes = [
10
+ '//kickstarter.com/projects/*',
11
+ '//*.kickstarter.com/projects/*',
12
+ ]
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ module OhMyEmbed
2
+ module Providers
3
+ class Slideshare < OhMyEmbed::Provider
4
+ # Slideshare oembed documentation:
5
+ # http://de.slideshare.net/developers/oembed
6
+
7
+ self.endpoint = 'http://www.slideshare.net/api/oembed/2'
8
+ self.schemes = [
9
+ '//slideshare.net/*/*',
10
+ '//*.slideshare.net/*/*',
11
+ '//*.slideshare.net/mobile/*/*',
12
+ ]
13
+
14
+ self.custom_mapping = {
15
+ 'thumbnail.url' => 'thumbnail'
16
+ }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ module OhMyEmbed
2
+ module Providers
3
+ class Soundcloud < OhMyEmbed::Provider
4
+ # Soundcloud oembed documentation:
5
+ # https://developers.soundcloud.com/docs/oembed
6
+
7
+ self.endpoint = 'http://soundcloud.com/oembed'
8
+ self.schemes = [
9
+ '//soundcloud.com/*',
10
+ '//*.soundcloud.com/*',
11
+ ]
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ module OhMyEmbed
2
+ module Providers
3
+ class Spotify < OhMyEmbed::Provider
4
+ # Spotify oembed documentation:
5
+ # Spotify has no own documentation in the interwebz :(
6
+ # http://blog.embed.ly/post/45149936446/oembed-for-spotify
7
+ # https://twitter.com/nicklas2k/status/330094611202723840
8
+
9
+ self.endpoint = 'https://embed.spotify.com/oembed/'
10
+ self.schemes = [
11
+ '//spotify.com/*',
12
+ '//*.spotify.com/*',
13
+ 'spotify:*',
14
+ ]
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,14 @@
1
+ module OhMyEmbed
2
+ module Providers
3
+ class Twitter < OhMyEmbed::Provider
4
+ # Twitter oembed documentation:
5
+ # https://dev.twitter.com/rest/reference/get/statuses/oembed
6
+
7
+ self.endpoint = 'https://publish.twitter.com/oembed'
8
+ self.schemes = [
9
+ '//twitter.com/*/status/*',
10
+ '//*.twitter.com/*/status/*',
11
+ ]
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ module OhMyEmbed
2
+ module Providers
3
+ class Youtube < OhMyEmbed::Provider
4
+ # Youtube oembed documentation:
5
+ # Youtube has no own documentation in the interwebz :(
6
+ # http://uber-rob.co.uk/2014/05/youtube-oembed-documentation/
7
+ # http://oembed.com/providers.json
8
+
9
+ self.endpoint = 'https://www.youtube.com/oembed'
10
+ self.schemes = [
11
+ '//youtube.com/*',
12
+ '//*.youtube.com/*',
13
+ '//youtu.be/*',
14
+ '//*.youtu.be/*',
15
+ ]
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,110 @@
1
+ module OhMyEmbed
2
+ class Response
3
+ attr_reader :attributes
4
+ attr_reader :provider
5
+
6
+ delegate :mapping, to: :provider
7
+
8
+ # Initialize the OhMyEmbed::Response
9
+ #
10
+ # @param [OhMyEmbed::Provider] provider
11
+ # @param [String] url
12
+ # @param [Hash] data
13
+ def initialize(provider, url, data = {})
14
+ @provider = provider
15
+ @url = url
16
+ @attributes = data
17
+ end
18
+
19
+ # Get a single attribute from the raw response
20
+ #
21
+ # @param [String|Symbol] field_name
22
+ # @return [mixed]
23
+ def attribute(field_name)
24
+ @attributes.fetch(field_name.to_s, nil)
25
+ end
26
+
27
+ # Get the oembed type of the response
28
+ #
29
+ # @return [String] one of :photo, :video, :rich, :link
30
+ def type
31
+ attribute(mapping['type']).to_sym
32
+ end
33
+
34
+ # Get the oembed provider name
35
+ #
36
+ # @return [String]
37
+ def provider_name
38
+ attribute(mapping['provider_name']) || @provider.provider_name
39
+ end
40
+
41
+ # Get the provider url
42
+ #
43
+ # @return [String]
44
+ def provider_url
45
+ attribute(mapping['provider_url']) || @provider.endpoint
46
+ end
47
+
48
+ # Get the content url
49
+ #
50
+ # @return [String]
51
+ def url
52
+ attribute(mapping['url']) || @url
53
+ end
54
+
55
+ # Get the title
56
+ #
57
+ # @return [String]
58
+ def title
59
+ attribute(mapping['title'])
60
+ end
61
+
62
+ # Get the author informations
63
+ #
64
+ # @return [Hash] :name, :url
65
+ def author
66
+ author_name = attribute(mapping['author.name'])
67
+ author_url = attribute(mapping['author.url'])
68
+
69
+ if author_name || author_url
70
+ {
71
+ name: author_name,
72
+ url: author_url,
73
+ }.compact
74
+ else
75
+ nil
76
+ end
77
+ end
78
+
79
+ # Get the thumbnail informations
80
+ #
81
+ # @return [Hash] :url, :width, :height
82
+ def thumbnail
83
+ thumbnail_url = attribute(mapping['thumbnail.url'])
84
+
85
+ if thumbnail_url
86
+ {
87
+ url: thumbnail_url,
88
+ width: attribute(mapping['thumbnail.width']),
89
+ height: attribute(mapping['thumbnail.height']),
90
+ }
91
+ else
92
+ nil
93
+ end
94
+ end
95
+
96
+ # Get the embed informations
97
+ #
98
+ # @return [Hash] :html, :width, :height
99
+ def embed
100
+ html = attribute(mapping['embed.html'])
101
+
102
+ {
103
+ html: html,
104
+ url: html ? nil : url,
105
+ width: attribute(mapping['embed.width']),
106
+ height: attribute(mapping['embed.height']),
107
+ }.compact
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,3 @@
1
+ module OhMyEmbed
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'oh_my_embed/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'oh-my-embed'
8
+ spec.version = OhMyEmbed::VERSION
9
+ spec.authors = ['Axel Wahlen']
10
+ spec.email = ['axelwahlen@gmail.com']
11
+
12
+ spec.summary = 'Simple gem to interact with oauth providers'
13
+ spec.description = 'Simple gem to interact with oauth providers, for more informations see spec at http://www.oembed.com'
14
+ spec.homepage = 'https://www.mixxt.de'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.required_ruby_version = '>= 1.9.2'
23
+
24
+ spec.add_runtime_dependency 'activesupport', '>= 3.2.21'
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.12'
27
+ spec.add_development_dependency 'rake', '~> 11.1.2'
28
+ spec.add_development_dependency 'rspec', '~> 3.4.0'
29
+ spec.add_development_dependency 'webmock', '~> 2.0.1'
30
+ spec.add_development_dependency 'vcr', '~> 3.0.1'
31
+ spec.add_development_dependency 'simplecov', '~> 0.11.2'
32
+ spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.5.0'
33
+ end
@@ -0,0 +1,65 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://www.facebook.com/plugins/post/oembed.json/?format=json&url=https://www.facebook.com/FacebookDeutschland/posts/10153796066380932
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Strict-Transport-Security:
22
+ - max-age=15552000; preload
23
+ Cache-Control:
24
+ - private, no-cache, no-store, must-revalidate
25
+ Expires:
26
+ - Sat, 01 Jan 2000 00:00:00 GMT
27
+ Pragma:
28
+ - no-cache
29
+ Public-Key-Pins-Report-Only:
30
+ - max-age=500; pin-sha256="WoiWRyIOVNa9ihaBciRSC7XHjliYS9VwUGOIud4PB18="; pin-sha256="r/mIkG3eEpVdm+u/ko/cwxzOMo1bk4TyHIlByibiA5E=";
31
+ pin-sha256="q4PO2G2cbkZhZ82+JgmRUyGMoAeozA+BSXVXQWB8XWQ="; report-uri="http://reports.fb.com/hpkp/"
32
+ Content-Type:
33
+ - text/javascript; charset=UTF-8
34
+ X-Content-Type-Options:
35
+ - nosniff
36
+ X-Xss-Protection:
37
+ - '0'
38
+ X-Frame-Options:
39
+ - DENY
40
+ Vary:
41
+ - Accept-Encoding
42
+ X-Fb-Debug:
43
+ - G6RjLdrqPe8/KAKzPR9FA3Ayv4EfoebAqPUlmmAmM/JTFIvgxfqLk8oSwSQefQRM6yq0XpTkFREf1Qlb87cuWQ==
44
+ Date:
45
+ - Sun, 08 May 2016 11:18:20 GMT
46
+ Transfer-Encoding:
47
+ - chunked
48
+ Connection:
49
+ - keep-alive
50
+ body:
51
+ encoding: ASCII-8BIT
52
+ string: '{"author_name":"Facebook","author_url":"https://www.facebook.com/FacebookDeutschland/","provider_url":"https://www.facebook.com","provider_name":"Facebook","success":true,"height":null,"html":"\u003Cdiv
53
+ id=\"fb-root\">\u003C/div>\n\u003Cscript>(function(d, s, id) {\n var js,
54
+ fjs = d.getElementsByTagName(s)[0];\n if (d.getElementById(id)) return;\n js
55
+ = d.createElement(s); js.id = id;\n js.src = \"//connect.facebook.net/de_DE/sdk.js#xfbml=1&version=v2.3\";\n fjs.parentNode.insertBefore(js,
56
+ fjs);\n}(document, ''script'', ''facebook-jssdk''));\u003C/script>\u003Cdiv
57
+ class=\"fb-post\" data-href=\"https://www.facebook.com/FacebookDeutschland/posts/10153796066380932\"
58
+ data-width=\"552\">\u003Cdiv class=\"fb-xfbml-parse-ignore\">\u003Cblockquote
59
+ cite=\"https://www.facebook.com/FacebookDeutschland/posts/10153796066380932\">\u003Cp>Mark
60
+ Zuckerberg besucht Berlin.\u003C/p>Posted by \u003Ca href=\"https://www.facebook.com/FacebookDeutschland/\">Facebook\u003C/a>
61
+ on&nbsp;\u003Ca href=\"https://www.facebook.com/FacebookDeutschland/posts/10153796066380932\">Donnerstag,
62
+ 25. Februar 2016\u003C/a>\u003C/blockquote>\u003C/div>\u003C/div>","type":"rich","version":"1.0","url":"https://www.facebook.com/FacebookDeutschland/posts/10153796066380932","width":552}'
63
+ http_version:
64
+ recorded_at: Sun, 08 May 2016 11:18:20 GMT
65
+ recorded_with: VCR 3.0.1
@@ -0,0 +1,65 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://www.facebook.com/plugins/video/oembed.json/?format=json&url=https://www.facebook.com/facebook/videos/10153231379946729/
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Strict-Transport-Security:
22
+ - max-age=15552000; preload
23
+ Cache-Control:
24
+ - private, no-cache, no-store, must-revalidate
25
+ Expires:
26
+ - Sat, 01 Jan 2000 00:00:00 GMT
27
+ Pragma:
28
+ - no-cache
29
+ Public-Key-Pins-Report-Only:
30
+ - max-age=500; pin-sha256="WoiWRyIOVNa9ihaBciRSC7XHjliYS9VwUGOIud4PB18="; pin-sha256="r/mIkG3eEpVdm+u/ko/cwxzOMo1bk4TyHIlByibiA5E=";
31
+ pin-sha256="q4PO2G2cbkZhZ82+JgmRUyGMoAeozA+BSXVXQWB8XWQ="; report-uri="http://reports.fb.com/hpkp/"
32
+ Content-Type:
33
+ - text/javascript; charset=UTF-8
34
+ X-Content-Type-Options:
35
+ - nosniff
36
+ X-Xss-Protection:
37
+ - '0'
38
+ X-Frame-Options:
39
+ - DENY
40
+ Vary:
41
+ - Accept-Encoding
42
+ X-Fb-Debug:
43
+ - sqneNfNoRj99NDzfQJs+vX1mX2QPA0jjhfQAguxmp9odFp5V7BWDchtpb09ZLBBZyUkIQm3t7VPbCLSYeUS0aw==
44
+ Date:
45
+ - Sun, 08 May 2016 11:18:20 GMT
46
+ Transfer-Encoding:
47
+ - chunked
48
+ Connection:
49
+ - keep-alive
50
+ body:
51
+ encoding: ASCII-8BIT
52
+ string: '{"author_name":"Facebook","author_url":"https://www.facebook.com/facebook/","provider_url":"https://www.facebook.com","provider_name":"Facebook","success":true,"height":281,"html":"\u003Cdiv
53
+ id=\"fb-root\">\u003C/div>\n\u003Cscript>(function(d, s, id) {\n var js,
54
+ fjs = d.getElementsByTagName(s)[0];\n if (d.getElementById(id)) return;\n js
55
+ = d.createElement(s); js.id = id;\n js.src = \"//connect.facebook.net/de_DE/sdk.js#xfbml=1&version=v2.3\";\n fjs.parentNode.insertBefore(js,
56
+ fjs);\n}(document, ''script'', ''facebook-jssdk''));\u003C/script>\u003Cdiv
57
+ class=\"fb-video\" data-href=\"https://www.facebook.com/facebook/videos/10153231379946729/\">\u003Cdiv
58
+ class=\"fb-xfbml-parse-ignore\">\u003Cblockquote cite=\"https://www.facebook.com/facebook/videos/10153231379946729/\">\u003Ca
59
+ href=\"https://www.facebook.com/facebook/videos/10153231379946729/\">How to
60
+ Share With Just Friends\u003C/a>\u003Cp>How to share with just friends.\u003C/p>Posted
61
+ by \u003Ca href=\"https://www.facebook.com/facebook/\">Facebook\u003C/a> on
62
+ Freitag, 5. Dezember 2014\u003C/blockquote>\u003C/div>\u003C/div>","type":"video","version":"1.0","url":"https://www.facebook.com/facebook/videos/10153231379946729/","width":500}'
63
+ http_version:
64
+ recorded_at: Sun, 08 May 2016 11:18:20 GMT
65
+ recorded_with: VCR 3.0.1