ruby-oembed 0.13.1 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.rdoc +6 -1
- data/README.md +20 -0
- data/lib/oembed/providers.rb +24 -39
- data/lib/oembed/providers/{embedly_urls.yml → aggregators/embedly_urls.yml} +0 -0
- data/lib/oembed/providers/{noembed_urls.yml → aggregators/noembed_urls.yml} +0 -0
- data/lib/oembed/providers/{oohembed_urls.yml → aggregators/oohembed_urls.yml} +0 -0
- data/lib/oembed/providers/facebook_post.rb +25 -0
- data/lib/oembed/providers/facebook_video.rb +18 -0
- data/lib/oembed/providers/instagram.rb +28 -0
- data/lib/oembed/version.rb +2 -2
- data/lib/tasks/oembed.rake +2 -2
- data/spec/providers/facebook_spec.rb +50 -0
- data/spec/providers_spec.rb +48 -0
- metadata +12 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ce690eea65c79e7df55ec323c59bf8c2ec43c9b94c1f084ad558b70c392cef9
|
4
|
+
data.tar.gz: b964d57ad3902a1dc99911aecc7f7f566a89ce2b6fdaa22ab34763c01a4e8aba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e694d02b886ff90fa2d14afcbaefeda99ab258e632d8126e0e2d61c308edb0eb3001cd517ce1342e3eea033d31eeca1a8016068392e406689ffb08c95242c02
|
7
|
+
data.tar.gz: 3aba0c2994ae8fa2b87a172e03dfb4a529eec7ccfabd393b2182a91822bb4856ae2409983d0cb3755a092a191729d0af84c755f14e384a3cd5a2ce9c80b814f6
|
data/CHANGELOG.rdoc
CHANGED
data/README.md
CHANGED
@@ -34,6 +34,26 @@ resource.html #=> <<-HTML
|
|
34
34
|
HTML
|
35
35
|
```
|
36
36
|
|
37
|
+
### Providers requiring an access token
|
38
|
+
|
39
|
+
Some built-in providers require authorization in order to work. These providers won't be registered unless an access token is provided. You can either pass access tokens to the `register_app` method.
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
OEmbed::Providers.register_all(access_tokens: { facebook: @my_facebook_token })
|
43
|
+
```
|
44
|
+
|
45
|
+
Or you can provide access tokens via environment variable
|
46
|
+
```ruby
|
47
|
+
ENV['OEMBED_FACEBOOK_TOKEN'] #=> 'my-access-token'
|
48
|
+
OEmbed::Providers.register_all
|
49
|
+
```
|
50
|
+
|
51
|
+
#### Currently supported access tokens
|
52
|
+
|
53
|
+
| access_token | environment variable | Associaed Providers |
|
54
|
+
|--------------|-------------------------|---------------------|
|
55
|
+
| `:facebook` | `OEMBED_FACEBOOK_TOKEN` | `FacebookPost`, `FacebookVideo`, `Instagram` |
|
56
|
+
|
37
57
|
## Custom Providers
|
38
58
|
|
39
59
|
If you'd like to use a provider that isn't included in the library, it's easy to create one. Just provide the oEmbed API endpoint and URL scheme(s).
|
data/lib/oembed/providers.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'yaml'
|
3
3
|
|
4
|
+
require 'oembed/providers/facebook_post'
|
5
|
+
require 'oembed/providers/facebook_video'
|
6
|
+
require 'oembed/providers/instagram'
|
7
|
+
|
4
8
|
module OEmbed
|
5
9
|
# Allows OEmbed to perform tasks across several, registered, Providers
|
6
10
|
# at once.
|
@@ -44,8 +48,11 @@ module OEmbed
|
|
44
48
|
# Register all Providers built into this gem.
|
45
49
|
# The including_sub_type parameter should be one of the following values:
|
46
50
|
# * :aggregators: also register provider aggregator endpoints, like Embedly
|
47
|
-
|
51
|
+
# The access_token keys can be one of the following:
|
52
|
+
# * :facebook: See https://developers.facebook.com/docs/instagram/oembed#access-tokens
|
53
|
+
def register_all(*including_sub_type, access_tokens: {})
|
48
54
|
register(*@@to_register[""])
|
55
|
+
register_access_token_providers(access_tokens)
|
49
56
|
including_sub_type.each do |sub_type|
|
50
57
|
register(*@@to_register[sub_type.to_s])
|
51
58
|
end
|
@@ -122,6 +129,20 @@ module OEmbed
|
|
122
129
|
@@to_register[sub_type.to_s] ||= []
|
123
130
|
@@to_register[sub_type.to_s] << provider_class
|
124
131
|
end
|
132
|
+
|
133
|
+
# Takes a Hash of tokens, and registers providers that use the given tokens.
|
134
|
+
# Also supports "OEMBED_*_TOKEN" environment variables.
|
135
|
+
# Currently supported tokens:
|
136
|
+
# * facebook: See https://developers.facebook.com/docs/instagram/oembed#access-tokens
|
137
|
+
def register_access_token_providers(access_tokens)
|
138
|
+
tokens = { facebook: ENV['OEMBED_FACEBOOK_TOKEN'] }.merge(access_tokens)
|
139
|
+
|
140
|
+
if tokens[:facebook]
|
141
|
+
register OEmbed::Providers::FacebookPost.new(access_token: tokens[:facebook])
|
142
|
+
register OEmbed::Providers::FacebookVideo.new(access_token: tokens[:facebook])
|
143
|
+
register OEmbed::Providers::Instagram.new(access_token: tokens[:facebook])
|
144
|
+
end
|
145
|
+
end
|
125
146
|
end
|
126
147
|
|
127
148
|
# Custom providers:
|
@@ -201,42 +222,6 @@ module OEmbed
|
|
201
222
|
Vine << "https://*.vine.co/v/*"
|
202
223
|
add_official_provider(Vine)
|
203
224
|
|
204
|
-
# Provider for instagram.com
|
205
|
-
# https://instagr.am/developer/embedding/
|
206
|
-
Instagram = OEmbed::Provider.new("https://api.instagram.com/oembed", :json)
|
207
|
-
Instagram << "http://instagr.am/p/*"
|
208
|
-
Instagram << "http://instagram.com/p/*"
|
209
|
-
Instagram << "http://www.instagram.com/p/*"
|
210
|
-
Instagram << "https://instagr.am/p/*"
|
211
|
-
Instagram << "https://instagram.com/p/*"
|
212
|
-
Instagram << "https://www.instagram.com/p/*"
|
213
|
-
Instagram << "http://instagr.am/tv/*"
|
214
|
-
Instagram << "http://instagram.com/tv/*"
|
215
|
-
Instagram << "http://www.instagram.com/tv/*"
|
216
|
-
Instagram << "https://instagr.am/tv/*"
|
217
|
-
Instagram << "https://instagram.com/tv/*"
|
218
|
-
Instagram << "https://www.instagram.com/tv/*"
|
219
|
-
add_official_provider(Instagram)
|
220
|
-
|
221
|
-
# Providers for Facebook Posts & Videos
|
222
|
-
# https://developers.facebook.com/docs/plugins/oembed-endpoints
|
223
|
-
FacebookPost = OEmbed::Provider.new('https://www.facebook.com/plugins/post/oembed.json/', :json)
|
224
|
-
FacebookPost << 'https://www.facebook.com/*/posts/*'
|
225
|
-
FacebookPost << 'https://www.facebook.com/*/activity/*'
|
226
|
-
FacebookPost << 'https://www.facebook.com/photo*'
|
227
|
-
FacebookPost << 'https://www.facebook.com/photos*'
|
228
|
-
FacebookPost << 'https://www.facebook.com/*/photos*'
|
229
|
-
FacebookPost << 'https://www.facebook.com/permalink*'
|
230
|
-
FacebookPost << 'https://www.facebook.com/media*'
|
231
|
-
FacebookPost << 'https://www.facebook.com/questions*'
|
232
|
-
FacebookPost << 'https://www.facebook.com/notes*'
|
233
|
-
add_official_provider(FacebookPost)
|
234
|
-
|
235
|
-
FacebookVideo = OEmbed::Provider.new('https://www.facebook.com/plugins/video/oembed.json/', :json)
|
236
|
-
FacebookVideo << 'https://www.facebook.com/*/videos/*'
|
237
|
-
FacebookVideo << 'https://www.facebook.com/video*'
|
238
|
-
add_official_provider(FacebookVideo)
|
239
|
-
|
240
225
|
# Provider for slideshare.net
|
241
226
|
# http://www.slideshare.net/developers/oembed
|
242
227
|
Slideshare = OEmbed::Provider.new("https://www.slideshare.net/api/oembed/2")
|
@@ -422,7 +407,7 @@ module OEmbed
|
|
422
407
|
Noembed = OEmbed::Provider.new("https://noembed.com/embed")
|
423
408
|
# Add all known URL regexps for Noembed.
|
424
409
|
# To update this list run `rake oembed:update_noembed`
|
425
|
-
YAML.load_file(File.join(File.dirname(__FILE__), "/providers/noembed_urls.yml")).each do |url|
|
410
|
+
YAML.load_file(File.join(File.dirname(__FILE__), "/providers/aggregators/noembed_urls.yml")).each do |url|
|
426
411
|
Noembed << Regexp.new(url)
|
427
412
|
end
|
428
413
|
add_official_provider(Noembed, :aggregators)
|
@@ -437,7 +422,7 @@ module OEmbed
|
|
437
422
|
# If you don't yet have an API key you'll need to sign up here: http://embed.ly/pricing
|
438
423
|
Embedly = OEmbed::Provider.new("http://api.embed.ly/1/oembed")
|
439
424
|
# Add all known URL regexps for Embedly. To update this list run `rake oembed:update_embedly`
|
440
|
-
YAML.load_file(File.join(File.dirname(__FILE__), "/providers/embedly_urls.yml")).each do |url|
|
425
|
+
YAML.load_file(File.join(File.dirname(__FILE__), "/providers/aggregators/embedly_urls.yml")).each do |url|
|
441
426
|
Embedly << url
|
442
427
|
end
|
443
428
|
add_official_provider(Embedly, :aggregators)
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module OEmbed
|
2
|
+
class Providers
|
3
|
+
# Provider for Facebook posts
|
4
|
+
class FacebookPost < OEmbed::Provider
|
5
|
+
def initialize(access_token:)
|
6
|
+
super("https://graph.facebook.com/v8.0/oembed_post?access_token=#{access_token}", :json)
|
7
|
+
register_urls!
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def register_urls!
|
13
|
+
['https://www.facebook.com/*/posts/*',
|
14
|
+
'https://www.facebook.com/*/activity/*',
|
15
|
+
'https://www.facebook.com/photo*',
|
16
|
+
'https://www.facebook.com/photos*',
|
17
|
+
'https://www.facebook.com/*/photos*',
|
18
|
+
'https://www.facebook.com/permalink*',
|
19
|
+
'https://www.facebook.com/media*',
|
20
|
+
'https://www.facebook.com/questions*',
|
21
|
+
'https://www.facebook.com/notes*'].each { |u| self << u }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module OEmbed
|
2
|
+
class Providers
|
3
|
+
# Provider for Facebook videos
|
4
|
+
class FacebookVideo < OEmbed::Provider
|
5
|
+
def initialize(access_token:)
|
6
|
+
super("https://graph.facebook.com/v8.0/oembed_video?access_token=#{access_token}", :json)
|
7
|
+
register_urls!
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def register_urls!
|
13
|
+
['https://www.facebook.com/*/videos/*',
|
14
|
+
'https://www.facebook.com/video*'].each { |u| self << u }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module OEmbed
|
2
|
+
class Providers
|
3
|
+
# Provider for instagram.com
|
4
|
+
class Instagram < OEmbed::Provider
|
5
|
+
def initialize(access_token:)
|
6
|
+
super("https://graph.facebook.com/v8.0/instagram_oembed?access_token=#{access_token}", :json)
|
7
|
+
register_urls!
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def register_urls!
|
13
|
+
["http://instagr.am/p/*",
|
14
|
+
"http://instagram.com/p/*",
|
15
|
+
"http://www.instagram.com/p/*",
|
16
|
+
"https://instagr.am/p/*",
|
17
|
+
"https://instagram.com/p/*",
|
18
|
+
"https://www.instagram.com/p/*",
|
19
|
+
"http://instagr.am/tv/*",
|
20
|
+
"http://instagram.com/tv/*",
|
21
|
+
"http://www.instagram.com/tv/*",
|
22
|
+
"https://instagr.am/tv/*",
|
23
|
+
"https://instagram.com/tv/*",
|
24
|
+
"https://www.instagram.com/tv/*"].each { |u| self << u }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/oembed/version.rb
CHANGED
data/lib/tasks/oembed.rake
CHANGED
@@ -8,7 +8,7 @@ begin
|
|
8
8
|
task :update_noembed do
|
9
9
|
# Details at http://api.embed.ly/docs/service
|
10
10
|
json_uri = URI.parse("https://noembed.com/providers")
|
11
|
-
yaml_path = File.join(File.dirname(__FILE__), "../oembed/providers/noembed_urls.yml")
|
11
|
+
yaml_path = File.join(File.dirname(__FILE__), "../oembed/providers/aggregators/noembed_urls.yml")
|
12
12
|
|
13
13
|
services = JSON.parse(json_uri.read)
|
14
14
|
|
@@ -25,7 +25,7 @@ begin
|
|
25
25
|
task :update_embedly do
|
26
26
|
# Details at http://api.embed.ly/docs/service
|
27
27
|
json_uri = URI.parse("http://api.embed.ly/1/services")
|
28
|
-
yaml_path = File.join(File.dirname(__FILE__), "../oembed/providers/embedly_urls.yml")
|
28
|
+
yaml_path = File.join(File.dirname(__FILE__), "../oembed/providers/aggregators/embedly_urls.yml")
|
29
29
|
|
30
30
|
services = JSON.parse(json_uri.read)
|
31
31
|
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../spec_helper')
|
2
|
+
|
3
|
+
describe 'Facebook providers' do
|
4
|
+
let(:access_token) { 'my-fake-access-token' }
|
5
|
+
|
6
|
+
describe 'FacebookPost provider' do
|
7
|
+
let(:provider) { OEmbed::Providers::FacebookPost.new(access_token: access_token) }
|
8
|
+
let(:embed_url) { 'https://www.facebook.com/exampleuser/posts/1234567890' }
|
9
|
+
|
10
|
+
it 'sets the endpoint URL' do
|
11
|
+
expect(provider.endpoint).to(
|
12
|
+
eq("https://graph.facebook.com/v8.0/oembed_post?access_token=#{access_token}")
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'recognizes embed URLs' do
|
17
|
+
expect(provider).to include(embed_url)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'FacebookVideo provider' do
|
22
|
+
let(:provider) { OEmbed::Providers::FacebookVideo.new(access_token: access_token) }
|
23
|
+
let(:embed_url) { 'https://www.facebook.com/exampleuser/videos/1234567890' }
|
24
|
+
|
25
|
+
it 'sets the endpoint URL' do
|
26
|
+
expect(provider.endpoint).to(
|
27
|
+
eq("https://graph.facebook.com/v8.0/oembed_video?access_token=#{access_token}")
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'recognizes embed URLs' do
|
32
|
+
expect(provider).to include(embed_url)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'Instagram provider' do
|
37
|
+
let(:provider) { OEmbed::Providers::Instagram.new(access_token: access_token) }
|
38
|
+
let(:embed_url) { 'https://www.instagram.com/p/r4nd0m1mg/' }
|
39
|
+
|
40
|
+
it 'sets the endpoint URL' do
|
41
|
+
expect(provider.endpoint).to(
|
42
|
+
eq("https://graph.facebook.com/v8.0/instagram_oembed?access_token=#{access_token}")
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'recognizes embed URLs' do
|
47
|
+
expect(provider).to include(embed_url)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/spec/providers_spec.rb
CHANGED
@@ -210,6 +210,54 @@ describe OEmbed::Providers do
|
|
210
210
|
end
|
211
211
|
end
|
212
212
|
|
213
|
+
describe 'register_access_token_providers' do
|
214
|
+
describe 'tokens[:facebook]' do
|
215
|
+
let(:access_token) { 'my-fake-access-token' }
|
216
|
+
let(:embed_url) { 'https://www.facebook.com/exampleuser/posts/1234567890' }
|
217
|
+
|
218
|
+
around(:each) do |each|
|
219
|
+
previous_value = ENV['OEMBED_FACEBOOK_TOKEN']
|
220
|
+
ENV['OEMBED_FACEBOOK_TOKEN'] = nil
|
221
|
+
each.run
|
222
|
+
ENV['OEMBED_FACEBOOK_TOKEN'] = previous_value
|
223
|
+
OEmbed::Providers.unregister_all
|
224
|
+
end
|
225
|
+
|
226
|
+
subject { OEmbed::Providers.find(embed_url) }
|
227
|
+
|
228
|
+
context 'when NO access token is provided' do
|
229
|
+
before do
|
230
|
+
OEmbed::Providers.register_all
|
231
|
+
end
|
232
|
+
|
233
|
+
it { is_expected.to_not be_a(OEmbed::Providers::FacebookPost) }
|
234
|
+
end
|
235
|
+
|
236
|
+
context 'when access token is provided to register_all' do
|
237
|
+
before do
|
238
|
+
OEmbed::Providers.register_all(access_tokens: { facebook: access_token })
|
239
|
+
end
|
240
|
+
|
241
|
+
it { is_expected.to be_a(OEmbed::Providers::FacebookPost) }
|
242
|
+
end
|
243
|
+
|
244
|
+
context 'when access token is set as an environment variable' do
|
245
|
+
before do
|
246
|
+
ENV['OEMBED_FACEBOOK_TOKEN'] = access_token
|
247
|
+
OEmbed::Providers.register_all
|
248
|
+
end
|
249
|
+
|
250
|
+
it { is_expected.to be_a(OEmbed::Providers::FacebookPost) }
|
251
|
+
end
|
252
|
+
|
253
|
+
context 'without access token' do
|
254
|
+
before { OEmbed::Providers.register_all }
|
255
|
+
|
256
|
+
it { is_expected.to eq(nil) }
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
213
261
|
describe 'add_official_provider' do
|
214
262
|
it "should register a new official provider" do
|
215
263
|
expect(defined?(OEmbed::Providers::Fake)).to_not be
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-oembed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Magnus Holm
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2020-05
|
14
|
+
date: 2020-11-05 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: xml-simple
|
@@ -79,9 +79,12 @@ files:
|
|
79
79
|
- lib/oembed/provider.rb
|
80
80
|
- lib/oembed/provider_discovery.rb
|
81
81
|
- lib/oembed/providers.rb
|
82
|
-
- lib/oembed/providers/embedly_urls.yml
|
83
|
-
- lib/oembed/providers/noembed_urls.yml
|
84
|
-
- lib/oembed/providers/oohembed_urls.yml
|
82
|
+
- lib/oembed/providers/aggregators/embedly_urls.yml
|
83
|
+
- lib/oembed/providers/aggregators/noembed_urls.yml
|
84
|
+
- lib/oembed/providers/aggregators/oohembed_urls.yml
|
85
|
+
- lib/oembed/providers/facebook_post.rb
|
86
|
+
- lib/oembed/providers/facebook_video.rb
|
87
|
+
- lib/oembed/providers/instagram.rb
|
85
88
|
- lib/oembed/response.rb
|
86
89
|
- lib/oembed/response/link.rb
|
87
90
|
- lib/oembed/response/photo.rb
|
@@ -105,6 +108,7 @@ files:
|
|
105
108
|
- spec/formatter_spec.rb
|
106
109
|
- spec/provider_discovery_spec.rb
|
107
110
|
- spec/provider_spec.rb
|
111
|
+
- spec/providers/facebook_spec.rb
|
108
112
|
- spec/providers/slideshare_spec.rb
|
109
113
|
- spec/providers/twitter_spec.rb
|
110
114
|
- spec/providers_spec.rb
|
@@ -121,7 +125,7 @@ rdoc_options:
|
|
121
125
|
- "--main"
|
122
126
|
- README.rdoc
|
123
127
|
- "--title"
|
124
|
-
- ruby-oembed-0.
|
128
|
+
- ruby-oembed-0.14.0
|
125
129
|
- "--inline-source"
|
126
130
|
- "--exclude"
|
127
131
|
- tasks
|
@@ -139,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
143
|
- !ruby/object:Gem::Version
|
140
144
|
version: '0'
|
141
145
|
requirements: []
|
142
|
-
rubygems_version: 3.
|
146
|
+
rubygems_version: 3.1.4
|
143
147
|
signing_key:
|
144
148
|
specification_version: 4
|
145
149
|
summary: oEmbed for Ruby
|
@@ -158,6 +162,7 @@ test_files:
|
|
158
162
|
- spec/formatter_spec.rb
|
159
163
|
- spec/provider_discovery_spec.rb
|
160
164
|
- spec/provider_spec.rb
|
165
|
+
- spec/providers/facebook_spec.rb
|
161
166
|
- spec/providers/slideshare_spec.rb
|
162
167
|
- spec/providers/twitter_spec.rb
|
163
168
|
- spec/providers_spec.rb
|