video_info 1.3.2 → 1.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 64fbda9846def2092874a10b4eeca13e05b9f007
4
- data.tar.gz: ff9bd825e8c2430ba2b11f582653f1a651db653a
3
+ metadata.gz: d7056b4b9244e1aa2f8978a96b5887ef218f0383
4
+ data.tar.gz: ed2c2485d1f4ebb86384f174dc25fd939a672db2
5
5
  SHA512:
6
- metadata.gz: 4ced72da987c5be066ff9eb2c748ac03e84fcd2e19bb00ea8edb23c1aecb0563a27e05491cd29154fb5a8ac4aa49b8a379be9c2918edc9d99a7c4fd373600c3c
7
- data.tar.gz: b538194b9db7043ba9777ba03bebd5e38c07d0dc42a57e0c8f52812ca67b352aac5daf374c514f660535983ca1d0a9908cf59677adf87422c25e85c58f7d2132
6
+ metadata.gz: f08606831ea05ba23c64e01d82a6baf73c2bf214d7c684dd132a28bfdb31ff10848bfed8b76806a3a4aa36f86c99f84d58d6749bf09cc79e6b39fcce6388bfdf
7
+ data.tar.gz: 7ad2a13d1f48702155894e9ef1c9e21991ccbb730a74f3096ba4788c40f7cc37120d7a881ed0298b98c4b26518d56b4174477467e5634ee6c8e7718148dba56e
data/README.md CHANGED
@@ -66,13 +66,18 @@ User-Agent when empty defaults to "VideoInfo/VERSION" - where version is current
66
66
 
67
67
  It supports all openURI header fields (options), for more information see: [openURI DOCS](http://www.ruby-doc.org/stdlib-1.9.3/libdoc/open-uri/rdoc/OpenURI.html)
68
68
 
69
- You can also include an `iframe_attributes` hash to include arbitrary attributes in the iframe embed code:
69
+ You can also include an `iframe_attributes` or `url_attributes` hash to the `embed_code` method to include arbitrary attributes in the iframe embed code or as additional URL params:
70
70
 
71
71
  ``` ruby
72
- VideoInfo.get("http://www.youtube.com/watch?v=mZqGqE0D0n4", :iframe_attributes => { :width => 800, :height => 600, "data-key" => "value" } ).embed_code
73
- => '<iframe src="http://www.youtube.com/embed/mZqGqE0D0n4" frameborder="0" allowfullscreen="allowfullscreen" width="800" height="600" data-key="value"></iframe>'
72
+ VideoInfo.get("http://www.youtube.com/watch?v=mZqGqE0D0n4").embed_code(:iframe_attributes => { :width => 800, :height => 600, "data-key" => "value" })
73
+ => '<iframe src="http://www.youtube.com/embed/mZqGqE0D0n4" frameborder="0" allowfullscreen="allowfullscreen" width="800" height="600" data-key="value"></iframe>
74
+
75
+ 'VideoInfo.get("http://www.youtube.com/watch?v=mZqGqE0D0n4").embed_code(:url_attributes => { :autoplay => 1 })
76
+ => '<iframe src="http://www.youtube.com/embed/mZqGqE0D0n4?autoplay=1" frameborder="0" allowfullscreen="allowfullscreen"></iframe>'
74
77
  ```
75
78
 
79
+
80
+
76
81
  Author
77
82
  ------
78
83
 
@@ -1,14 +1,15 @@
1
+ require "addressable/uri"
2
+
1
3
  module VideoInfo
2
4
  class Provider
3
5
 
4
6
  attr_accessor :url, :options, :iframe_attributes, :video_id
5
- attr_accessor :embed_url, :embed_code, :provider, :title, :description, :keywords,
6
- :duration, :date, :width, :height,
7
- :thumbnail_small, :thumbnail_medium, :thumbnail_large,
8
- :view_count
7
+ attr_accessor :embed_url, :provider, :title, :description, :keywords,
8
+ :duration, :date, :width, :height,
9
+ :thumbnail_small, :thumbnail_medium, :thumbnail_large,
10
+ :view_count
9
11
 
10
- def initialize(url, options = {}, iframe_attributes = nil)
11
- @iframe_attributes = _hash_to_attributes(options.delete(:iframe_attributes))
12
+ def initialize(url, options = {})
12
13
  @options = _clean_options(options)
13
14
  @url = url
14
15
  _set_video_id_from_url
@@ -19,6 +20,21 @@ module VideoInfo
19
20
  raise NotImplementedError.new('Provider class must implement .usable? public method')
20
21
  end
21
22
 
23
+ def embed_code(options = {})
24
+ url_attributes = options.fetch(:url_attributes, {})
25
+ url_attrs = default_url_attributes.merge(url_attributes)
26
+
27
+ url = embed_url
28
+ url += "?#{_hash_to_params(url_attrs)}" unless url_attrs.empty?
29
+
30
+ iframe_attrs = ["src=\"#{url}\"", "frameborder=\"0\""]
31
+
32
+ iframe_attributes = options.fetch(:iframe_attributes, {})
33
+ iframe_attrs << _hash_to_attributes(default_iframe_attributes.merge(iframe_attributes))
34
+
35
+ "<iframe #{iframe_attrs.reject(&:empty?).join(" ")}></iframe>"
36
+ end
37
+
22
38
  private
23
39
 
24
40
  def _set_video_id_from_url
@@ -49,10 +65,14 @@ module VideoInfo
49
65
  end
50
66
 
51
67
  def _hash_to_attributes(hash)
52
- if hash.is_a?(Hash)
53
- s = hash.map{|k,v| "#{k}=\"#{v}\""}.join(' ')
54
- " #{s}"
55
- end
68
+ return unless hash.is_a?(Hash)
69
+ hash.map{|k,v| "#{k}=\"#{v}\""}.join(' ')
70
+ end
71
+
72
+ def _hash_to_params(hash)
73
+ uri = Addressable::URI.new
74
+ uri.query_values = hash
75
+ uri.query
56
76
  end
57
77
  end
58
78
  end
@@ -9,6 +9,17 @@ module VideoInfo
9
9
  url =~ /vimeo\.com/
10
10
  end
11
11
 
12
+ def default_iframe_attributes
13
+ {}
14
+ end
15
+
16
+ def default_url_attributes
17
+ { :title => 0,
18
+ :byline => 0,
19
+ :portrait => 0,
20
+ :autoplay => 0 }
21
+ end
22
+
12
23
  private
13
24
 
14
25
  def _url_regex
@@ -18,10 +29,10 @@ module VideoInfo
18
29
  def _set_info_from_api
19
30
  uri = open("http://vimeo.com/api/v2/video/#{video_id}.json", options)
20
31
  video = MultiJson.load(uri.read).first
32
+
21
33
  @provider = "Vimeo"
22
34
  @url = video['url']
23
35
  @embed_url = "http://player.vimeo.com/video/#{video_id}"
24
- @embed_code = "<iframe src=\"#{embed_url}?title=0&amp;byline=0&amp;portrait=0&amp;autoplay=0\" frameborder=\"0\"#{iframe_attributes}></iframe>"
25
36
  @title = video['title']
26
37
  @description = video['description']
27
38
  @keywords = video['tags']
@@ -9,6 +9,14 @@ module VideoInfo
9
9
  url =~ /(youtube\.com)|(youtu\.be)/
10
10
  end
11
11
 
12
+ def default_iframe_attributes
13
+ { :allowfullscreen => "allowfullscreen" }
14
+ end
15
+
16
+ def default_url_attributes
17
+ {}
18
+ end
19
+
12
20
  private
13
21
 
14
22
  def _url_regex
@@ -21,7 +29,6 @@ module VideoInfo
21
29
  @provider = "YouTube"
22
30
  @url = url
23
31
  @embed_url = "http://www.youtube.com/embed/#{video_id}"
24
- @embed_code = "<iframe src=\"#{embed_url}\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"#{iframe_attributes}></iframe>"
25
32
  video['entry'].tap do |entry|
26
33
  @title = entry['title']['$t']
27
34
  @description = entry['media$group']['media$description']['$t']
@@ -1,3 +1,3 @@
1
1
  module VideoInfo
2
- VERSION = "1.3.2"
2
+ VERSION = "1.4.0"
3
3
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: video_info
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thibaud Guillaume-Gentil
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-19 00:00:00.000000000 Z
11
+ date: 2013-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: addressable
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: multi_json
15
29
  requirement: !ruby/object:Gem::Requirement