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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 67438e97e5e5268e64fb7ab3d9ad7ca6fc2b38a6
4
- data.tar.gz: 5decea42a488c490de612f711ebf3d170cf41751
3
+ metadata.gz: a8928be83c7ac5d9f86cff1b129b95ba970bc0c6
4
+ data.tar.gz: 21c97b32025427979226899acdc5d48827c3a97f
5
5
  SHA512:
6
- metadata.gz: 2a9d28a59be90ed7f7e0f43f77b30ab99c0b47a140aa0852f461070b35b5f3cbb911601302f5c00d5ccda04ab21d1dd6795602acfe2a9226bf5f785fb9d76880
7
- data.tar.gz: 2911e10132b2aea33f595403ca3776acace9d641677453dd56d42cf4dbdce856dfe3b563c0093853e46ab939cd4fe90ffabb7fed02135a108d9353450060792f
6
+ metadata.gz: 0192210b4779c8f3b241f155b33a5df83782688646efaa849d68f4a86b414c2c1fe2d7817dd002c1470f665e96f180ab20b659529d2c3251561a6f55d57011b5
7
+ data.tar.gz: c648e6c07bc7f0393788353bcd5f5b61124d4da29aa81c4feefd4fbfa5f077a393230440ee57aa30f5aa8eed50643cc403ea28e4ead00335d2f6283544a2c3e8
@@ -1,2 +1,3 @@
1
+ require 'blinkbox_films/search_results_page_not_recognised'
1
2
  require 'blinkbox_films/search'
2
3
 
@@ -6,20 +6,26 @@ module BlinkboxFilms
6
6
  class Search
7
7
  def search(query)
8
8
  r = response(query)
9
- if r.ok?
10
- rental_fragments(r.body).map { |f|
11
- {
12
- :title => rental_title(f),
13
- :url => rental_url(f),
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
@@ -0,0 +1,4 @@
1
+ module BlinkboxFilms
2
+ class SearchResultsPageNotRecognised < StandardError
3
+ end
4
+ end
@@ -1,12 +1,12 @@
1
1
  require 'spec_helper'
2
2
  require 'blinkbox_films'
3
3
 
4
- describe 'A search', :vcr do
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
@@ -1,4 +1,5 @@
1
1
  require 'vcr'
2
+ require 'webmock/rspec'
2
3
 
3
4
  VCR.configure do |c|
4
5
  c.cassette_library_dir = 'spec/cassettes'
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.1
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