film_snob 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e5cf5187ccef0d72407e749995d632fbe0968aa5
4
- data.tar.gz: 331e57a39f3440897aabe54fcf907f67d6f2b9ce
3
+ metadata.gz: 1fc68c945f24304a496d99c3221e53a4a527d7d7
4
+ data.tar.gz: dfb6ae2311def8d250d8c398a4b3c663c5dbaa95
5
5
  SHA512:
6
- metadata.gz: f91e99db74870dca7681ccc136bee472d117488c27784c1636fc9bf191daa2c93ff393b962a85e0612975e260785861a657360b88f8ae8e1f02027eef5a9447b
7
- data.tar.gz: bb3d04364b7fe58da0c62082c894a83075770ec1bffdcb4ea8b0e5651e98d9249de70332191c319754e3512cb49ac839be1b997d716f0d109ad50c52786e17de
6
+ metadata.gz: 00f47df3ef20e36f75bea37d10c8e517028a2f441109c684fc33ed68dd775df065f731bbd766f6d2c1584f366f82355af5c96c1ad62d6fe39270c6801d3d151e
7
+ data.tar.gz: a13630cb2358218339801196cf2eb35c7994fdb9299299b9768ac3cb2ad6556a8b4cc68bd8f7079ac930d098a32f4ca4fea4482b45f05a046f8248a05382d664
data/film_snob.gemspec CHANGED
@@ -20,6 +20,9 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.6"
22
22
  spec.add_development_dependency "rake"
23
- spec.add_development_dependency "rspec", "~> 3.0.0.beta2"
23
+ spec.add_development_dependency "rspec", "~> 3.0.0.beta2"
24
+ spec.add_development_dependency "webmock", "~> 1.17"
25
+ spec.add_development_dependency "vcr", "~> 2.9"
24
26
  spec.add_development_dependency "debugger"
27
+ spec.add_runtime_dependency "httparty","~> 0.13"
25
28
  end
@@ -1,3 +1,4 @@
1
1
  class FilmSnob
2
2
  class NotSupportedURLError < StandardError; end
3
+ class NotEmbeddableError < StandardError; end
3
4
  end
@@ -7,6 +7,10 @@ class FilmSnob
7
7
  ]
8
8
  end
9
9
 
10
+ def self.oembed_endpoint
11
+ 'http://www.hulu.com/api/oembed.json'
12
+ end
13
+
10
14
  def clean_url
11
15
  @clean_url ||= "http://www.hulu.com/watch/#{id}"
12
16
  end
@@ -1,3 +1,3 @@
1
1
  class FilmSnob
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,3 +1,5 @@
1
+ require 'httparty'
2
+
1
3
  class FilmSnob
2
4
  class VideoSite
3
5
 
@@ -19,6 +21,22 @@ class FilmSnob
19
21
  []
20
22
  end
21
23
 
24
+ def self.oembed_endpoint
25
+ ''
26
+ end
27
+
28
+ def title
29
+ oembed['title']
30
+ end
31
+
32
+ def html
33
+ if oembed['html']
34
+ oembed['html']
35
+ else
36
+ raise NotEmbeddableError.new("#{clean_url} is not embeddable")
37
+ end
38
+ end
39
+
22
40
  private
23
41
 
24
42
  def matching_pattern
@@ -27,5 +45,12 @@ class FilmSnob
27
45
  end
28
46
  end
29
47
 
48
+ def oembed
49
+ @oembed ||= HTTParty.get(
50
+ self.class.oembed_endpoint,
51
+ query: { url: clean_url }
52
+ )
53
+ end
54
+
30
55
  end
31
56
  end
@@ -15,5 +15,9 @@ class FilmSnob
15
15
  @clean_url ||= "https://vimeo.com/#{id}"
16
16
  end
17
17
 
18
+ def self.oembed_endpoint
19
+ 'http://vimeo.com/api/oembed.json'
20
+ end
21
+
18
22
  end
19
23
  end
@@ -8,6 +8,10 @@ class FilmSnob
8
8
  ]
9
9
  end
10
10
 
11
+ def self.oembed_endpoint
12
+ 'https://www.youtube.com/oembed'
13
+ end
14
+
11
15
  def clean_url
12
16
  @clean_url ||= "https://www.youtube.com/watch?v=#{id}"
13
17
  end
data/lib/film_snob.rb CHANGED
@@ -10,25 +10,19 @@ class FilmSnob
10
10
  @video = FilmSnob::UrlToVideo.new(url).video
11
11
  end
12
12
 
13
- def site
14
- complain_about_bad_urls!(:site)
15
- video.site
16
- end
17
-
18
- def id
19
- complain_about_bad_urls!(:id)
20
- video.id
21
- end
22
-
23
- def clean_url
24
- complain_about_bad_urls!(:clean_url)
25
- video.clean_url
26
- end
27
-
28
13
  def watchable?
29
14
  !video.nil?
30
15
  end
31
16
 
17
+ def method_missing(m)
18
+ if [:site, :id, :clean_url, :title, :html].include?(m)
19
+ complain_about_bad_urls!(m)
20
+ video.send(m)
21
+ else
22
+ super
23
+ end
24
+ end
25
+
32
26
  private
33
27
 
34
28
  def complain_about_bad_urls!(method)
File without changes
@@ -0,0 +1,43 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=malformedid
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 404
13
+ message: Not Found
14
+ headers:
15
+ Date:
16
+ - Sun, 13 Apr 2014 22:47:31 GMT
17
+ Server:
18
+ - gwiseguy/2.0
19
+ Content-Type:
20
+ - text/html; charset=utf-8
21
+ X-Xss-Protection:
22
+ - 1; mode=block; report=https://www.google.com/appserve/security-bugs/log/youtube
23
+ X-Frame-Options:
24
+ - ALLOWALL
25
+ Cache-Control:
26
+ - no-cache
27
+ P3p:
28
+ - CP="This is not a P3P policy! See http://support.google.com/accounts/bin/answer.py?answer=151657&hl=en
29
+ for more info."
30
+ Expires:
31
+ - Tue, 27 Apr 1971 19:44:06 EST
32
+ X-Content-Type-Options:
33
+ - nosniff
34
+ Content-Length:
35
+ - '9'
36
+ Alternate-Protocol:
37
+ - 443:quic
38
+ body:
39
+ encoding: UTF-8
40
+ string: Not Found
41
+ http_version:
42
+ recorded_at: Sun, 13 Apr 2014 22:47:31 GMT
43
+ recorded_with: VCR 2.9.0
@@ -0,0 +1,50 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=7q5Ltr0qc8c
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Date:
16
+ - Sun, 13 Apr 2014 22:37:31 GMT
17
+ Server:
18
+ - gwiseguy/2.0
19
+ X-Content-Type-Options:
20
+ - nosniff
21
+ P3p:
22
+ - CP="This is not a P3P policy! See http://support.google.com/accounts/bin/answer.py?answer=151657&hl=en
23
+ for more info."
24
+ X-Xss-Protection:
25
+ - 1; mode=block; report=https://www.google.com/appserve/security-bugs/log/youtube
26
+ Content-Type:
27
+ - application/json
28
+ X-Frame-Options:
29
+ - ALLOWALL
30
+ Expires:
31
+ - Tue, 27 Apr 1971 19:44:06 EST
32
+ Cache-Control:
33
+ - no-cache
34
+ Alternate-Protocol:
35
+ - 443:quic
36
+ Transfer-Encoding:
37
+ - chunked
38
+ body:
39
+ encoding: UTF-8
40
+ string: '{"title": "Billy on the Street: Amateur Speed Sketching!", "author_name":
41
+ "billyonthestreettv", "height": 270, "width": 480, "thumbnail_width": 480,
42
+ "author_url": "http:\/\/www.youtube.com\/user\/billyonthestreettv", "thumbnail_height":
43
+ 360, "type": "video", "thumbnail_url": "http:\/\/i1.ytimg.com\/vi\/7q5Ltr0qc8c\/hqdefault.jpg",
44
+ "provider_url": "http:\/\/www.youtube.com\/", "html": "\u003ciframe width=\"480\"
45
+ height=\"270\" src=\"http:\/\/www.youtube.com\/embed\/7q5Ltr0qc8c?feature=oembed\"
46
+ frameborder=\"0\" allowfullscreen\u003e\u003c\/iframe\u003e", "version": "1.0",
47
+ "provider_name": "YouTube"}'
48
+ http_version:
49
+ recorded_at: Sun, 13 Apr 2014 22:37:31 GMT
50
+ recorded_with: VCR 2.9.0
@@ -0,0 +1,43 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://www.hulu.com/api/oembed.json?url=http://www.hulu.com/watch/285095
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Server:
16
+ - nginx
17
+ Content-Type:
18
+ - application/json; charset=utf-8
19
+ Content-Length:
20
+ - '821'
21
+ Status:
22
+ - 200 OK
23
+ X-Ua-Compatible:
24
+ - IE=EmulateIE9; IE=EmulateIE7
25
+ Accept-Ranges:
26
+ - bytes
27
+ Cache-Control:
28
+ - max-age=3568
29
+ Date:
30
+ - Sun, 13 Apr 2014 22:40:14 GMT
31
+ Connection:
32
+ - keep-alive
33
+ body:
34
+ encoding: UTF-8
35
+ string: '{"cache_age":3600,"type":"video","large_thumbnail_url":"http://ib.huluim.com/video/50172061?size=512x288&caller=h1o&img=i","height":296,"html":"<iframe
36
+ width=\"512\" height=\"296\" src=\"http://www.hulu.com/embed.html?eid=CbtnRM8PBJsCfZpUy2V3Yg\"
37
+ frameborder=\"0\" scrolling=\"no\" webkitAllowFullScreen mozallowfullscreen
38
+ allowfullscreen> </iframe>","large_thumbnail_width":512,"embed_url":"http://www.hulu.com/embed.html?eid=CbtnRM8PBJsCfZpUy2V3Yg","air_date":"Thu
39
+ Oct 13 00:00:00 UTC 2011","large_thumbnail_height":288,"thumbnail_url":"http://ib.huluim.com/video/50172061?size=145x80&caller=h1o&img=i","author_name":"NBC","provider_name":"Hulu","title":"Remedial
40
+ Chaos Theory (Community)","thumbnail_width":145,"provider_url":"http://www.hulu.com/","duration":1286.87,"version":"1.0","thumbnail_height":80,"width":512}'
41
+ http_version:
42
+ recorded_at: Sun, 13 Apr 2014 22:40:14 GMT
43
+ recorded_with: VCR 2.9.0
@@ -0,0 +1,63 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://vimeo.com/api/oembed.json?url=https://vimeo.com/16010689
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Server:
16
+ - Apache
17
+ Access-Control-Allow-Origin:
18
+ - '*'
19
+ Access-Control-Allow-Headers:
20
+ - X-Requested-With
21
+ Expires:
22
+ - Sun, 13 Apr 2014 22:40:15 GMT
23
+ Last-Modified:
24
+ - Sun, 13 Apr 2014 19:06:59 GMT
25
+ Etag:
26
+ - '"3ee9abac968dd90ff3d61a6c3ed1e6aac5a93a7d"'
27
+ X-Ua-Compatible:
28
+ - IE=edge
29
+ X-Dns-Prefetch-Control:
30
+ - 'on'
31
+ Vary:
32
+ - Accept-Encoding
33
+ Content-Type:
34
+ - application/json
35
+ Transfer-Encoding:
36
+ - chunked
37
+ Date:
38
+ - Sun, 13 Apr 2014 22:39:15 GMT
39
+ X-Varnish:
40
+ - '2109561577'
41
+ Age:
42
+ - '0'
43
+ Via:
44
+ - 1.1 varnish
45
+ X-Varnish-Cache:
46
+ - '0'
47
+ Nncoection:
48
+ - close
49
+ X-Vserver:
50
+ - 10.90.128.188
51
+ body:
52
+ encoding: UTF-8
53
+ string: '{"type":"video","version":"1.0","provider_name":"Vimeo","provider_url":"https:\/\/vimeo.com\/","title":"Days
54
+ Like Today","author_name":"Stephen_Scott_Day","author_url":"http:\/\/vimeo.com\/stephenscottday","is_plus":"1","html":"<iframe
55
+ src=\"\/\/player.vimeo.com\/video\/16010689\" width=\"1280\" height=\"720\"
56
+ frameborder=\"0\" title=\"Days Like Today\" webkitallowfullscreen mozallowfullscreen
57
+ allowfullscreen><\/iframe>","width":1280,"height":720,"duration":463,"description":"more
58
+ info @ www.followthroughfilms.com\n\nI don''t expect many people to watch
59
+ the whole thing, but if you do, lemme know. \n\nTuesday, October 19th, 2010.
60
+ Somewhere between 3:40pm and 3:50pm. Alhambra, CA.","thumbnail_url":"http:\/\/i.vimeocdn.com\/video\/97388869_1280.jpg","thumbnail_width":1280,"thumbnail_height":720,"video_id":16010689}'
61
+ http_version:
62
+ recorded_at: Sun, 13 Apr 2014 22:39:15 GMT
63
+ recorded_with: VCR 2.9.0
@@ -1,4 +1,4 @@
1
- require 'film_snob'
1
+ require_relative 'spec_helper'
2
2
 
3
3
  describe FilmSnob do
4
4
 
@@ -24,6 +24,9 @@ describe FilmSnob do
24
24
  expect(snob).to be_watchable
25
25
  expect(snob.id).to eq "7q5Ltr0qc8c"
26
26
  expect(snob.site).to eq :youtube
27
+ VCR.use_cassette('billy') do
28
+ expect(snob.title).to eq 'Billy on the Street: Amateur Speed Sketching!'
29
+ end
27
30
  end
28
31
 
29
32
  it 'should parse YouTube URLs with dashes' do
@@ -62,6 +65,9 @@ describe FilmSnob do
62
65
  snob = FilmSnob.new("https://vimeo.com/16010689")
63
66
  expect(snob.id).to eq "16010689"
64
67
  expect(snob.site).to eq :vimeo
68
+ VCR.use_cassette('stephen') do
69
+ expect(snob.title).to eq 'Days Like Today'
70
+ end
65
71
  end
66
72
 
67
73
  it 'should parse http vimeo URLs' do
@@ -97,6 +103,10 @@ describe FilmSnob do
97
103
  snob = FilmSnob.new("http://www.hulu.com/watch/285095")
98
104
  expect(snob.id).to eq '285095'
99
105
  expect(snob.site).to eq :hulu
106
+ VCR.use_cassette('harmon') do
107
+ expect(snob.title).to eq 'Remedial Chaos Theory (Community)'
108
+ expect{snob.html}.not_to raise_error
109
+ end
100
110
  end
101
111
  end
102
112
 
@@ -0,0 +1,9 @@
1
+ require 'film_snob'
2
+ require 'webmock/rspec'
3
+ require 'vcr'
4
+
5
+ VCR.configure do |c|
6
+ c.cassette_library_dir = 'spec/cassettes'
7
+ c.hook_into :webmock
8
+ end
9
+
@@ -0,0 +1,11 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe FilmSnob::YouTube do
4
+ it 'may not be embeddable' do
5
+ VCR.use_cassette('bad_youtube_url') do
6
+ snob = FilmSnob.new('http://youtube.com/watch?v=malformedid')
7
+ video = snob.video
8
+ expect{video.html}.to raise_error(FilmSnob::NotEmbeddableError)
9
+ end
10
+ end
11
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: film_snob
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Jacobson
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: 3.0.0.beta2
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.17'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.17'
69
+ - !ruby/object:Gem::Dependency
70
+ name: vcr
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '2.9'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '2.9'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: debugger
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +94,20 @@ dependencies:
66
94
  - - '>='
67
95
  - !ruby/object:Gem::Version
68
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: httparty
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: '0.13'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: '0.13'
69
111
  description: Help understand URLs for video sites
70
112
  email:
71
113
  - max@hardscrabble.net
@@ -88,7 +130,14 @@ files:
88
130
  - lib/film_snob/video_site.rb
89
131
  - lib/film_snob/vimeo.rb
90
132
  - lib/film_snob/youtube.rb
133
+ - spec/cassettes/.keep
134
+ - spec/cassettes/bad_youtube_url.yml
135
+ - spec/cassettes/billy.yml
136
+ - spec/cassettes/harmon.yml
137
+ - spec/cassettes/stephen.yml
91
138
  - spec/film_snob_spec.rb
139
+ - spec/spec_helper.rb
140
+ - spec/youtube_spec.rb
92
141
  homepage: https://github.com/maxjacobson/film_snob
93
142
  licenses:
94
143
  - MIT
@@ -114,4 +163,11 @@ signing_key:
114
163
  specification_version: 4
115
164
  summary: Help understand URLs for video sites
116
165
  test_files:
166
+ - spec/cassettes/.keep
167
+ - spec/cassettes/bad_youtube_url.yml
168
+ - spec/cassettes/billy.yml
169
+ - spec/cassettes/harmon.yml
170
+ - spec/cassettes/stephen.yml
117
171
  - spec/film_snob_spec.rb
172
+ - spec/spec_helper.rb
173
+ - spec/youtube_spec.rb