omdb 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/Guardfile +24 -0
- data/LICENSE.txt +22 -0
- data/README.md +45 -0
- data/Rakefile +4 -0
- data/lib/omdb.rb +6 -0
- data/lib/omdb/api.rb +50 -0
- data/lib/omdb/movie.rb +21 -0
- data/lib/omdb/network.rb +14 -0
- data/lib/omdb/version.rb +3 -0
- data/omdb.gemspec +33 -0
- data/spec/fixtures/movies_search.json +1 -0
- data/spec/fixtures/no_results.json +1 -0
- data/spec/fixtures/star_wars.json +12 -0
- data/spec/lib/omdb/api_spec.rb +89 -0
- data/spec/lib/omdb/movie_spec.rb +100 -0
- data/spec/lib/omdb/network_spec.rb +47 -0
- data/spec/spec_helper.rb +19 -0
- metadata +198 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 52eb3f1def7c54d8f2fa1ddc162459758e3c6f9b
|
4
|
+
data.tar.gz: dc179e03a99536bad4d2831b09c330179a8d9dfa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 404fb809e1063a94edee5d1eb492579207108c54ca4aff837b9da9b7c457da0331533974b4859b747b8214306a212f17ed75b9fe483605eb7f8b3bd0c913acbf
|
7
|
+
data.tar.gz: d8fd2743700ef40d03e58d38de3d05d3983827481c0f7b7169c91489e7d582ce6a64086eab19bdb3f6f1e55a9d119364661c11bee810e1238e8e86d5ec88a460
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard :rspec do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
|
9
|
+
# Rails example
|
10
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
11
|
+
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
12
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
13
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
14
|
+
watch('config/routes.rb') { "spec/routing" }
|
15
|
+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
16
|
+
|
17
|
+
# Capybara features specs
|
18
|
+
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
|
19
|
+
|
20
|
+
# Turnip features and steps
|
21
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
22
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
|
23
|
+
end
|
24
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 TODO: Write your name
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# Omdb
|
2
|
+
[![Code Climate](https://codeclimate.com/repos/51dc6afbc7f3a37a72002061/badges/c245beb7b5f063dc7e94/gpa.png)](https://codeclimate.com/repos/51dc6afbc7f3a37a72002061/feed)
|
3
|
+
[![Build Status](https://travis-ci.org/jvanbaarsen/omdb.png?branch=master)](https://travis-ci.org/jvanbaarsen/omdb)
|
4
|
+
|
5
|
+
This gem is an easy way to access the OMDB Api (http://www.omdbapi.com)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'omdb'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install omdb
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Finding movies
|
24
|
+
|
25
|
+
Omdb::Api.new.search('MOVIE NAME')
|
26
|
+
|
27
|
+
This will return an hash with movies
|
28
|
+
|
29
|
+
### Fetching movie
|
30
|
+
To fetch a single movie (when you know the full name):
|
31
|
+
|
32
|
+
Omdb::Api.new.fetch('MOVIE NAME')
|
33
|
+
|
34
|
+
This will return a Omdb::Movie object with the following properties:
|
35
|
+
|
36
|
+
:loaded, :title, :year, :rated, :released, :runtime, :genre, :director, :writer, :actors, :plot,
|
37
|
+
:poster, :imdb_rating, :imdb_votes, :imdb_id, :type
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
1. Fork it
|
42
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
43
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
44
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
45
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/omdb.rb
ADDED
data/lib/omdb/api.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'omdb/network'
|
2
|
+
require 'omdb/movie'
|
3
|
+
module Omdb
|
4
|
+
class Api
|
5
|
+
def search(search_term)
|
6
|
+
res = network.call({s: search_term})
|
7
|
+
if res[:data]["Response"] == "False"
|
8
|
+
response = {
|
9
|
+
:movies => {},
|
10
|
+
:status => 404
|
11
|
+
}
|
12
|
+
else
|
13
|
+
response = {
|
14
|
+
:movies => parse_movies(res[:data]),
|
15
|
+
:status => res[:code]
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def fetch(title, year = nil)
|
21
|
+
res = network.call({t: title, year: nil})
|
22
|
+
if res[:data]["Response"] == "False"
|
23
|
+
response = {:status => 404}
|
24
|
+
else
|
25
|
+
response = {
|
26
|
+
status: res[:code],
|
27
|
+
movie: parse_movie(res[:data])
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
def parse_movies(json_string)
|
34
|
+
data = json_string["Search"]
|
35
|
+
movies = Array.new
|
36
|
+
data.each do |movie|
|
37
|
+
movies.push(parse_movie(movie))
|
38
|
+
end
|
39
|
+
return movies
|
40
|
+
end
|
41
|
+
|
42
|
+
def parse_movie(data)
|
43
|
+
Movie.new(data)
|
44
|
+
end
|
45
|
+
|
46
|
+
def network
|
47
|
+
@network ||= Omdb::Network.new
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/omdb/movie.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Omdb
|
2
|
+
class Movie
|
3
|
+
attr_reader :loaded, :title, :year, :rated, :released, :runtime, :genre, :director, :writer, :actors, :plot,
|
4
|
+
:poster, :imdb_rating, :imdb_votes, :imdb_id, :type
|
5
|
+
|
6
|
+
def initialize(movie)
|
7
|
+
@title = movie["Title"]
|
8
|
+
@year = movie["Year"].to_i
|
9
|
+
@imdb_id = movie["imdbID"]
|
10
|
+
@type = movie["Type"]
|
11
|
+
@rated = movie["Rated"]
|
12
|
+
@released = movie["Released"]
|
13
|
+
@runtime = movie["Runtime"]
|
14
|
+
@genre = movie["Genre"]
|
15
|
+
@director = movie["Director"]
|
16
|
+
@writer = movie["Writer"]
|
17
|
+
@actors = movie["Actors"]
|
18
|
+
@plot = movie["Plot"]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/omdb/network.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
require 'json'
|
3
|
+
module Omdb
|
4
|
+
class Network
|
5
|
+
OMDB_API_URL = 'http://www.omdbapi.com'
|
6
|
+
def call(params)
|
7
|
+
response = RestClient.get OMDB_API_URL, {params: params}
|
8
|
+
{
|
9
|
+
code: response.code,
|
10
|
+
data: JSON.parse(response.body)
|
11
|
+
}
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/omdb/version.rb
ADDED
data/omdb.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'omdb/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "omdb"
|
8
|
+
spec.version = Omdb::VERSION
|
9
|
+
spec.authors = ["Jeroen van Baarsen"]
|
10
|
+
spec.email = ["jeroen@logiconline.nl"]
|
11
|
+
spec.description = %q{Easy gateway to the OMDB Api}
|
12
|
+
spec.summary = %q{Easy gateway to the OMDB Api}
|
13
|
+
spec.homepage = "http://github.com/jvanbaarsen/omdb"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# Productions gems
|
22
|
+
spec.add_dependency "json"
|
23
|
+
spec.add_dependency "rest-client"
|
24
|
+
|
25
|
+
# Development gems
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
27
|
+
spec.add_development_dependency "rake"
|
28
|
+
spec.add_development_dependency "rspec"
|
29
|
+
spec.add_development_dependency "guard"
|
30
|
+
spec.add_development_dependency "guard-rspec"
|
31
|
+
spec.add_development_dependency "terminal-notifier-guard"
|
32
|
+
spec.add_development_dependency "webmock"
|
33
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
{"Search":[{"Title":"Star Wars","Year":"1977","imdbID":"tt0076759","Type":"movie"},{"Title":"Star Wars: Episode V - The Empire Strikes Back","Year":"1980","imdbID":"tt0080684","Type":"movie"},{"Title":"Star Wars: Episode VI - Return of the Jedi","Year":"1983","imdbID":"tt0086190","Type":"movie"},{"Title":"Star Wars: Episode I - The Phantom Menace","Year":"1999","imdbID":"tt0120915","Type":"movie"},{"Title":"Star Wars: Episode III - Revenge of the Sith","Year":"2005","imdbID":"tt0121766","Type":"movie"},{"Title":"Star Wars: Episode II - Attack of the Clones","Year":"2002","imdbID":"tt0121765","Type":"movie"},{"Title":"Star Wars: The Clone Wars","Year":"2008","imdbID":"tt1185834","Type":"movie"},{"Title":"Star Wars: Clone Wars","Year":"2003","imdbID":"tt0361243","Type":"series"},{"Title":"Star Wars: The Clone Wars","Year":"2008","imdbID":"tt0458290","Type":"series"},{"Title":"The Star Wars Holiday Special","Year":"1978","imdbID":"tt0193524","Type":"movie"}]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"Response":"False","Error":"Movie not found!"}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
{
|
2
|
+
"Title":"Star Wars",
|
3
|
+
"Year":"1977",
|
4
|
+
"Rated":"PG",
|
5
|
+
"Released":"25 May 1977",
|
6
|
+
"Runtime":"2 h 1 min",
|
7
|
+
"Genre":"Action, Adventure, Fantasy, Sci-Fi",
|
8
|
+
"Director":"George Lucas",
|
9
|
+
"Writer":"George Lucas",
|
10
|
+
"Actors":"Mark Hamill, Harrison Ford, Carrie Fisher, Alec Guinness",
|
11
|
+
"Plot":"Luke Skywalker joins forces with a Jedi Knight, a cocky pilot, a wookiee and two droids to save the universe from the Empire's world-destroying battle-station, while also attempting to rescue Princess Leia from the evil Darth Vader.","Poster":"http://ia.media-imdb.com/images/M/MV5BMTU4NTczODkwM15BMl5BanBnXkFtZTcwMzEyMTIyMw@@._V1_SX300.jpg","imdbRating":"8.8","imdbVotes":"542,574","imdbID":"tt0076759","Type":"movie","Response":"True"
|
12
|
+
}
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'omdb/api'
|
3
|
+
|
4
|
+
describe 'Omdb::Api' do
|
5
|
+
it "Should return a instance of OMDB::API" do
|
6
|
+
expect(Omdb::Api.new).to be_a(Omdb::Api)
|
7
|
+
end
|
8
|
+
|
9
|
+
context "When searching for 'Star Wars'" do
|
10
|
+
it "responds to a search call" do
|
11
|
+
expect(Omdb::Api.new).to respond_to(:search).with(1).argument
|
12
|
+
end
|
13
|
+
|
14
|
+
it "return status code 200" do
|
15
|
+
expect(do_movie_search[:status]).to eq(200)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns a total of 10 items" do
|
19
|
+
expect(do_movie_search[:movies].size).to eq(10)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returned list movies should be of the type Omdb::Movie" do
|
23
|
+
expect(do_movie_search[:movies][0]).to be_a(Omdb::Movie)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "Searching for a single movie" do
|
28
|
+
context "When searching for an existing movie" do
|
29
|
+
it "responds to a fetch call" do
|
30
|
+
expect(Omdb::Api.new).to respond_to(:fetch).with(1).argument
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "the return object" do
|
34
|
+
it "has status code 200" do
|
35
|
+
expect(movie_fetch[:status]).to eq(200)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "has a movie object" do
|
39
|
+
expect(movie_fetch[:movie]).to be_a(Omdb::Movie)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "has a director called 'George Lucas'" do
|
43
|
+
expect(movie_fetch[:movie].director).to eq("George Lucas")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe 'Searching for a movie, with no results' do
|
50
|
+
it 'returns status code 404' do
|
51
|
+
expect(no_result_search[:status]).to eq(404)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'returns an empty movie hash' do
|
55
|
+
expect(no_result_search[:movies].size).to eq(0)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'Fetching an unknown movie' do
|
60
|
+
it 'returns status code 404' do
|
61
|
+
expect(no_result_fetch[:status]).to eq(404)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def do_movie_search
|
66
|
+
omdb_return_data = File.read(File.join("spec", "fixtures", "movies_search.json"))
|
67
|
+
stub_request(:any, /.*www.omdbapi.com.*/).to_return(:body => omdb_return_data, :code => 200 )
|
68
|
+
Omdb::Api.new.search("Star Wars")
|
69
|
+
end
|
70
|
+
|
71
|
+
def no_result_search
|
72
|
+
omdb_return_data = File.read(File.join("spec", "fixtures", "no_results.json"))
|
73
|
+
stub_request(:any, /.*www.omdbapi.com.*/).to_return(:body => omdb_return_data, :code => 200)
|
74
|
+
Omdb::Api.new.search("Search term")
|
75
|
+
end
|
76
|
+
|
77
|
+
def movie_fetch
|
78
|
+
omdb_return_data = File.read(File.join("spec", "fixtures", "star_wars.json"))
|
79
|
+
stub_request(:any, /.*www.omdbapi.com.*/).to_return(body: omdb_return_data, code: 200)
|
80
|
+
Omdb::Api.new.fetch("Star Wars")
|
81
|
+
end
|
82
|
+
|
83
|
+
def no_result_fetch
|
84
|
+
omdb_return_data = File.read(File.join("spec", "fixtures", "no_results.json"))
|
85
|
+
stub_request(:any, /.*www.omdbapi.com.*/).to_return(:body => omdb_return_data, :code => 200)
|
86
|
+
Omdb::Api.new.fetch("Search term")
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'omdb/movie'
|
3
|
+
|
4
|
+
describe 'Omdb::Movie' do
|
5
|
+
it "should return an instance of Omdb::Movie when parsed with the correct values" do
|
6
|
+
movie = create_movie_object("{}")
|
7
|
+
expect(movie).to be_instance_of(Omdb::Movie)
|
8
|
+
end
|
9
|
+
|
10
|
+
context "With the basic information loaded" do
|
11
|
+
describe '#title' do
|
12
|
+
it 'returns the title' do
|
13
|
+
movie = create_movie_object('{"Title":"Star Wars"}')
|
14
|
+
expect(movie.title).to eq('Star Wars')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#year' do
|
19
|
+
it 'returns the year' do
|
20
|
+
movie = create_movie_object('{"Year":"1977"}')
|
21
|
+
expect(movie.year).to eq(1977)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#rated' do
|
26
|
+
it 'returns the rating' do
|
27
|
+
movie = create_movie_object('{"Rated": "PG"}')
|
28
|
+
expect(movie.rated).to eq("PG")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#released' do
|
33
|
+
it 'returns the release date' do
|
34
|
+
movie = create_movie_object('{"Released": "25 May 1977"}')
|
35
|
+
expect(movie.released).to eq("25 May 1977")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#runtime' do
|
40
|
+
it 'returns the runtime' do
|
41
|
+
movie = create_movie_object('{"Runtime":"2 h 1 min"}')
|
42
|
+
expect(movie.runtime).to eq('2 h 1 min')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#genre' do
|
47
|
+
it 'returns the genre' do
|
48
|
+
movie = create_movie_object('{"Genre":"Action, Adventure"}')
|
49
|
+
expect(movie.genre).to eq("Action, Adventure")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#director' do
|
54
|
+
it 'returns the director' do
|
55
|
+
movie = create_movie_object('{"Director": "George Lucas"}')
|
56
|
+
expect(movie.director).to eq('George Lucas')
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '#writer' do
|
61
|
+
it 'returns the writer' do
|
62
|
+
movie = create_movie_object('{"Writer": "George Lucas"}')
|
63
|
+
expect(movie.writer).to eq('George Lucas')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '#actors' do
|
68
|
+
it 'returns the actors' do
|
69
|
+
movie = create_movie_object('{"Actors":"Mark Hamill, Harrison Ford"}')
|
70
|
+
expect(movie.actors).to eq('Mark Hamill, Harrison Ford')
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#plot' do
|
75
|
+
it 'returns the plot' do
|
76
|
+
movie = create_movie_object('{"Plot":"This is the plot story"}')
|
77
|
+
expect(movie.plot).to eq("This is the plot story")
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe '#imdb_id' do
|
82
|
+
it 'returns the IMDB ID' do
|
83
|
+
movie = create_movie_object('{"imdbID":"tt0076759"}')
|
84
|
+
expect(movie.imdb_id).to eq("tt0076759")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe '#type' do
|
89
|
+
it 'returns the type' do
|
90
|
+
movie = create_movie_object('{"Type":"movie"}')
|
91
|
+
expect(movie.type).to eq('movie')
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def create_movie_object(json_data)
|
97
|
+
Omdb::Movie.new(JSON.parse(json_data))
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'omdb/network'
|
3
|
+
|
4
|
+
describe Omdb::Network do
|
5
|
+
it "returns a instance of Omdb::Network" do
|
6
|
+
network = Omdb::Network.new
|
7
|
+
expect(network).to be_a(Omdb::Network)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#call" do
|
11
|
+
it "returns a hash when called" do
|
12
|
+
expect(search_movie).to be_a(Hash)
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'When called with {t: "Star Wars"} as params' do
|
16
|
+
it 'returns value contains "Star Wars"' do
|
17
|
+
expect(fetch_movie[:data]).to include(
|
18
|
+
{"Title"=> "Star Wars"}
|
19
|
+
)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'When called with {s: "Star Wars"{ as params' do
|
24
|
+
it 'returns value contains "Star Wars: The Clone Wars"' do
|
25
|
+
expect(search_movie[:data]["Search"].last).to include (
|
26
|
+
{"Title" => "The Star Wars Holiday Special"}
|
27
|
+
)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def search_movie
|
32
|
+
omdb_return_data = File.read(File.join("spec", "fixtures", "movies_search.json"))
|
33
|
+
stub_request(:any, "http://www.omdbapi.com").
|
34
|
+
with({query: {"s" => "Star Wars"}}).
|
35
|
+
to_return(:body => omdb_return_data, :code => 200 )
|
36
|
+
Omdb::Network.new.call({s: "Star Wars"})
|
37
|
+
end
|
38
|
+
|
39
|
+
def fetch_movie
|
40
|
+
omdb_return_data = File.read(File.join("spec", "fixtures", "star_wars.json"))
|
41
|
+
stub_request(:any, "http://www.omdbapi.com").
|
42
|
+
with({query: {"t" => "Star Wars"}}).
|
43
|
+
to_return(:body => omdb_return_data, :code => 200 )
|
44
|
+
Omdb::Network.new.call({t: "Star Wars"})
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
require 'webmock/rspec'
|
8
|
+
require 'json'
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
11
|
+
config.run_all_when_everything_filtered = true
|
12
|
+
config.filter_run :focus
|
13
|
+
|
14
|
+
# Run specs in random order to surface order dependencies. If you find an
|
15
|
+
# order dependency and want to debug it, you can fix the order by providing
|
16
|
+
# the seed, which is printed after each run.
|
17
|
+
# --seed 1234
|
18
|
+
config.order = 'random'
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,198 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omdb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeroen van Baarsen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
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'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rest-client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: guard-rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: terminal-notifier-guard
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: webmock
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: Easy gateway to the OMDB Api
|
140
|
+
email:
|
141
|
+
- jeroen@logiconline.nl
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- .gitignore
|
147
|
+
- .rspec
|
148
|
+
- .travis.yml
|
149
|
+
- Gemfile
|
150
|
+
- Guardfile
|
151
|
+
- LICENSE.txt
|
152
|
+
- README.md
|
153
|
+
- Rakefile
|
154
|
+
- lib/omdb.rb
|
155
|
+
- lib/omdb/api.rb
|
156
|
+
- lib/omdb/movie.rb
|
157
|
+
- lib/omdb/network.rb
|
158
|
+
- lib/omdb/version.rb
|
159
|
+
- omdb.gemspec
|
160
|
+
- spec/fixtures/movies_search.json
|
161
|
+
- spec/fixtures/no_results.json
|
162
|
+
- spec/fixtures/star_wars.json
|
163
|
+
- spec/lib/omdb/api_spec.rb
|
164
|
+
- spec/lib/omdb/movie_spec.rb
|
165
|
+
- spec/lib/omdb/network_spec.rb
|
166
|
+
- spec/spec_helper.rb
|
167
|
+
homepage: http://github.com/jvanbaarsen/omdb
|
168
|
+
licenses:
|
169
|
+
- MIT
|
170
|
+
metadata: {}
|
171
|
+
post_install_message:
|
172
|
+
rdoc_options: []
|
173
|
+
require_paths:
|
174
|
+
- lib
|
175
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
176
|
+
requirements:
|
177
|
+
- - '>='
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: '0'
|
180
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
181
|
+
requirements:
|
182
|
+
- - '>='
|
183
|
+
- !ruby/object:Gem::Version
|
184
|
+
version: '0'
|
185
|
+
requirements: []
|
186
|
+
rubyforge_project:
|
187
|
+
rubygems_version: 2.0.6
|
188
|
+
signing_key:
|
189
|
+
specification_version: 4
|
190
|
+
summary: Easy gateway to the OMDB Api
|
191
|
+
test_files:
|
192
|
+
- spec/fixtures/movies_search.json
|
193
|
+
- spec/fixtures/no_results.json
|
194
|
+
- spec/fixtures/star_wars.json
|
195
|
+
- spec/lib/omdb/api_spec.rb
|
196
|
+
- spec/lib/omdb/movie_spec.rb
|
197
|
+
- spec/lib/omdb/network_spec.rb
|
198
|
+
- spec/spec_helper.rb
|