blinkbox_films 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/blinkbox_films.rb +1 -0
- data/lib/blinkbox_films/search.rb +14 -8
- data/lib/blinkbox_films/search_results_page_not_recognised.rb +4 -0
- data/spec/feature/search_spec.rb +22 -3
- data/spec/spec_helper.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8928be83c7ac5d9f86cff1b129b95ba970bc0c6
|
4
|
+
data.tar.gz: 21c97b32025427979226899acdc5d48827c3a97f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0192210b4779c8f3b241f155b33a5df83782688646efaa849d68f4a86b414c2c1fe2d7817dd002c1470f665e96f180ab20b659529d2c3251561a6f55d57011b5
|
7
|
+
data.tar.gz: c648e6c07bc7f0393788353bcd5f5b61124d4da29aa81c4feefd4fbfa5f077a393230440ee57aa30f5aa8eed50643cc403ea28e4ead00335d2f6283544a2c3e8
|
data/lib/blinkbox_films.rb
CHANGED
@@ -6,20 +6,26 @@ module BlinkboxFilms
|
|
6
6
|
class Search
|
7
7
|
def search(query)
|
8
8
|
r = response(query)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
:image_url => rental_image_url(f)
|
15
|
-
}
|
9
|
+
rentals = rental_fragments(r.body).map { |f|
|
10
|
+
{
|
11
|
+
:title => rental_title(f),
|
12
|
+
:url => rental_url(f),
|
13
|
+
:image_url => rental_image_url(f)
|
16
14
|
}
|
15
|
+
}
|
16
|
+
|
17
|
+
if rentals.empty? & !no_results_page?(r.body)
|
18
|
+
raise BlinkboxFilms::SearchResultsPageNotRecognised
|
17
19
|
else
|
18
|
-
|
20
|
+
rentals
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
22
24
|
private
|
25
|
+
def no_results_page?(page)
|
26
|
+
page.include?('no results found for')
|
27
|
+
end
|
28
|
+
|
23
29
|
def response(query)
|
24
30
|
HTTPClient.new.get('http://www.blinkbox.com/search', { 'Search' => query })
|
25
31
|
end
|
data/spec/feature/search_spec.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'blinkbox_films'
|
3
3
|
|
4
|
-
describe 'A search'
|
5
|
-
context 'with zero results' do
|
4
|
+
describe 'A search' do
|
5
|
+
context 'with zero results', :vcr do
|
6
6
|
it { expect(BlinkboxFilms::Search.new.search('qwerty')).to be_empty }
|
7
7
|
end
|
8
8
|
|
9
|
-
context 'with some results' do
|
9
|
+
context 'with some results', :vcr do
|
10
10
|
subject { BlinkboxFilms::Search.new.search('dark knight') }
|
11
11
|
|
12
12
|
it { expect(subject).to_not be_empty }
|
@@ -14,4 +14,23 @@ describe 'A search', :vcr do
|
|
14
14
|
it { expect(subject.first[:url]).to eq('http://www.blinkbox.com/movies/the-dark-knight-(28710)') }
|
15
15
|
it { expect(subject.first[:image_url]).to eq('http://cdn2.blinkboxmedia.com/i/contentasset31/000/028/710/1gkiab4e/v=316/w=234;h=132;rm=Crop;q=85/image.jpg') }
|
16
16
|
end
|
17
|
+
|
18
|
+
context 'with unrecognised page format returned' do
|
19
|
+
before do
|
20
|
+
VCR.turn_off!
|
21
|
+
|
22
|
+
stub_request(:get, "http://www.blinkbox.com/search?Search=dark%20knight").
|
23
|
+
to_return(:body => '<html><body><h1>Not what you expected</h1></body></html>')
|
24
|
+
end
|
25
|
+
|
26
|
+
after do
|
27
|
+
VCR.turn_on!
|
28
|
+
end
|
29
|
+
|
30
|
+
it do
|
31
|
+
expect {
|
32
|
+
BlinkboxFilms::Search.new.search('dark knight')
|
33
|
+
}.to raise_error('BlinkboxFilms::SearchResultsPageNotRecognised')
|
34
|
+
end
|
35
|
+
end
|
17
36
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blinkbox_films
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joel Chippindale
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- Rakefile
|
105
105
|
- lib/blinkbox_films.rb
|
106
106
|
- lib/blinkbox_films/search.rb
|
107
|
+
- lib/blinkbox_films/search_results_page_not_recognised.rb
|
107
108
|
- spec/feature/search_spec.rb
|
108
109
|
- spec/spec_helper.rb
|
109
110
|
homepage: https://github.com/mocoso/blinkbox_films
|