rotten 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rotten (0.1.0)
4
+ rotten (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/README.md CHANGED
@@ -4,12 +4,23 @@
4
4
  ### Usage
5
5
  require "rotten"
6
6
  Rotten.api_key = 'your_key'
7
- movies = Rotten::Movies.search "There will be blood"
7
+
8
+ # Info about a specific film
9
+ movies = Rotten::Movies.search("There will be blood").pop
10
+ movie.reviews
11
+ movie.cast
12
+
13
+ # list upcoming movies
14
+ Rotten::Movie.upcoming
15
+
16
+ # list movies opening this week
17
+ Rotten::Movie.opening
8
18
 
9
19
  ### Features
10
20
  - Movie search
11
21
  - Movies opening this week
12
22
  - Movies upcoming
23
+ - Movie reviews
13
24
 
14
25
  #### TODO
15
26
  - Implement all APIs
@@ -2,10 +2,12 @@ lib = File.expand_path('../', __FILE__)
2
2
  $:.unshift lib unless $:.include?(lib)
3
3
 
4
4
  module Rotten
5
- autoload :Api, "rotten/api"
6
- autoload :Actor, "rotten/actor"
7
- autoload :Cast, "rotten/cast"
8
- autoload :Movie, "rotten/movie"
5
+ autoload :Entity, "rotten/entity"
6
+ autoload :Api, "rotten/api"
7
+ autoload :Actor, "rotten/actor"
8
+ autoload :Cast, "rotten/cast"
9
+ autoload :Review, "rotten/review"
10
+ autoload :Movie, "rotten/movie"
9
11
 
10
12
  def api_key=(val)
11
13
  @api_key = val
@@ -1,8 +1,4 @@
1
1
  module Rotten
2
- class Actor
3
- attr_reader :name
4
- def initialize name
5
- @name = name
6
- end
2
+ class Actor < Entity
7
3
  end
8
4
  end
@@ -25,7 +25,7 @@ module Rotten
25
25
 
26
26
  def get path, options={}
27
27
  if Rotten.api_key.nil?
28
- raise UndefinedApiKeyError, "Please define your API key with #{self}.api_key=(your_key)"
28
+ raise UndefinedApiKeyError, "Please define your API key with Rotten.api_key=(your_key)"
29
29
  end
30
30
 
31
31
  url = url_for(path, options)
@@ -6,7 +6,7 @@ module Rotten
6
6
  def initialize array=[]
7
7
  @actors = Set.new
8
8
  @characters = []
9
- process array
9
+ process (array || [])
10
10
  end
11
11
 
12
12
  def inspect
@@ -17,11 +17,11 @@ module Rotten
17
17
  @characters[index]
18
18
  end
19
19
 
20
- def first; [0]; end
20
+ def first; at[0]; end
21
21
 
22
22
  def process array
23
23
  array.each do |hash|
24
- actor = @actors.detect{|a| a.name == hash["name"] } || Actor.new(hash["name"])
24
+ actor = @actors.detect{|a| a.name == hash["name"] } || a=Actor.new; a.attributes=hash
25
25
  @actors << actor
26
26
  @characters << [ actor, hash["characters"] ]
27
27
  end
@@ -44,6 +44,5 @@ module Rotten
44
44
  @characters.include?(other)
45
45
  end
46
46
  end
47
-
48
47
  end
49
48
  end
@@ -1,5 +1,5 @@
1
1
  module Rotten
2
- class Movie
2
+ class Movie < Entity
3
3
  class InvalidSearchQueryError < StandardError; end
4
4
  include Api
5
5
 
@@ -37,25 +37,34 @@ module Rotten
37
37
 
38
38
  attr_reader :actors, :cast
39
39
  def initialize movie_hash={}
40
+ super
40
41
  @actors = []
41
42
  process movie_hash
42
43
  end
43
44
 
44
45
  def inspect
45
- "<Rotten::Movie title='#{@title}' id='#{@id}'>"
46
+ "<Rotten::Movie title='#{title}' id='#{id}'>"
46
47
  end
47
48
 
48
49
  def to_s
49
50
  title
50
51
  end
51
52
 
53
+ # Moview reviews
54
+ # @return [Array]
55
+ def reviews options={}
56
+ Movie.get "movies/#{id}/reviews", options do |json|
57
+ json["reviews"].map{|review| Review.from_json(review) }
58
+ end
59
+ end
60
+
52
61
  # Show cast
53
62
  #
54
63
  # @param [Symbol #kind] Defaults to :abridged, but can accept :full to retrieve full cast info.
55
64
  # @return [Rotten::Cast]
56
65
  def cast( kind = :abridged )
57
66
  if kind == :full
58
- Movie.get "movies/#{@id}/cast" do |json|
67
+ Movie.get "movies/#{id}/cast" do |json|
59
68
  @cast = Cast.new json["cast"]
60
69
  end
61
70
  self.cast
@@ -65,16 +74,16 @@ module Rotten
65
74
  end
66
75
 
67
76
  def process hash
68
- hash.each_pair{|k,v| instance_variable_set("@#{k}", v); self.class.send(:attr_reader, k.to_sym) }
69
- @cast = Cast.new( @abridged_cast )
70
- @actors = @cast.actors
77
+ attributes= hash
78
+ @cast = Cast.new( abridged_cast )
79
+ @actors = @cast.actors
71
80
  end
72
81
 
73
82
  # Fetch updated, potentially additional movie information
74
83
  # @return [Rotten::Movie]
75
84
  def reload
76
- return false unless @id
77
- Movie.get "movies/#{@id}" do |json|
85
+ return false unless id
86
+ Movie.get "movies/#{id}" do |json|
78
87
  process json
79
88
  end
80
89
  self
@@ -1,3 +1,3 @@
1
1
  module Rotten
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -15,6 +15,19 @@ describe Rotten::Movie do
15
15
  end
16
16
  end
17
17
  end
18
+
19
+ context "#reviews" do
20
+ before :each do
21
+ simulate_movie_search
22
+ @movie = Rotten::Movie.search("There Will Be Blood").pop
23
+ simulate_movie_reviews(@movie)
24
+ end
25
+
26
+ it "should return an array of Review" do
27
+ @movie.reviews.should be_an_instance_of(Array)
28
+ @movie.reviews.shift.should be_an_instance_of(Rotten::Review)
29
+ end
30
+ end
18
31
 
19
32
  context ".opening" do
20
33
  before :each do
@@ -19,6 +19,11 @@ RSpec.configure do |config|
19
19
  :body => File.read( File.join(fixture_path, "search.json") ))
20
20
  end
21
21
 
22
+ def simulate_movie_reviews(movie)
23
+ FakeWeb.register_uri(:get, Rotten::Movie.url_for("movies/#{movie.id}/reviews"),
24
+ :body => File.read( File.join(fixture_path, "reviews.json") ))
25
+ end
26
+
22
27
  def simulate_full_cast(movie)
23
28
  FakeWeb.register_uri(:get, Rotten::Movie.url_for("movies/#{movie.id}/cast"),
24
29
  :body => File.read( File.join(fixture_path, "cast.json") ))
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
7
+ - 3
8
8
  - 0
9
- version: 0.2.0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - James Cook
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-04-15 00:00:00 -05:00
17
+ date: 2011-04-16 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency