tomato_power 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -0
- data/lib/tomato_power/api/api.rb +6 -21
- data/lib/tomato_power/client.rb +0 -2
- data/lib/tomato_power/movie/movie.rb +12 -17
- data/lib/tomato_power/version.rb +1 -1
- data/spec/unit_specs/movie/movie_spec.rb +1 -1
- data/tomato_power.gemspec +1 -1
- metadata +4 -4
data/README.md
CHANGED
data/lib/tomato_power/api/api.rb
CHANGED
@@ -3,38 +3,23 @@ require 'open-uri'
|
|
3
3
|
|
4
4
|
module TomatoPower
|
5
5
|
# API class to interface with Client
|
6
|
-
#
|
7
6
|
class API
|
8
7
|
|
9
8
|
def initialize api_key
|
10
9
|
@api_key = api_key
|
10
|
+
API.define_tomato_methods(*TOMATO_METHODS.keys)
|
11
11
|
end
|
12
12
|
|
13
13
|
#Defines methods that are in TOMATO_METHODS
|
14
14
|
#
|
15
|
-
#@param
|
15
|
+
#@param methods [Array] methods to be created.
|
16
16
|
#@param options [Hash] options for function call.
|
17
17
|
#@note TOMATO_METHODS is a hash containing all of the Rotten Tomatoes API calls.
|
18
|
-
def
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
def self.define_tomato_methods(*methods)
|
19
|
+
methods.each do |method|
|
20
|
+
define_method(method) do |options={}|
|
21
|
+
fetch(TOMATO_METHODS[method][:url], @api_key, options) if options_valid? method, options
|
22
22
|
end
|
23
|
-
else
|
24
|
-
super
|
25
|
-
end
|
26
|
-
self.send method, options
|
27
|
-
end
|
28
|
-
|
29
|
-
# Whether or not this class responds to a function.
|
30
|
-
#
|
31
|
-
# @param method method in question.
|
32
|
-
# @return [true, false]
|
33
|
-
def respond_to? method
|
34
|
-
if TOMATO_METHODS.key? method
|
35
|
-
true
|
36
|
-
else
|
37
|
-
super
|
38
23
|
end
|
39
24
|
end
|
40
25
|
|
data/lib/tomato_power/client.rb
CHANGED
@@ -6,8 +6,6 @@ module TomatoPower
|
|
6
6
|
# Main entry point for end users.
|
7
7
|
# Client handles interactions from the user and delegates API calls to the
|
8
8
|
# API class.
|
9
|
-
#
|
10
|
-
# Certain functions are not delegated due to usability design deicisons.
|
11
9
|
extend Forwardable
|
12
10
|
|
13
11
|
def initialize
|
@@ -7,8 +7,6 @@ module TomatoPower
|
|
7
7
|
:studio, :directors
|
8
8
|
|
9
9
|
def initialize movie={}
|
10
|
-
@api = TomatoPower::api
|
11
|
-
|
12
10
|
@info = movie
|
13
11
|
@id = movie["id"]
|
14
12
|
@title = movie["title"]
|
@@ -23,6 +21,9 @@ module TomatoPower
|
|
23
21
|
@links = movie["links"]
|
24
22
|
@directors = movie["abridged_directors"]
|
25
23
|
@studio = movie["studio"]
|
24
|
+
|
25
|
+
@api = TomatoPower::api
|
26
|
+
Movie.define_movie_methods(*MOVIE_METHOD_ALIAS.keys)
|
26
27
|
end
|
27
28
|
|
28
29
|
# Aliased API methods for a better interface.
|
@@ -31,7 +32,6 @@ module TomatoPower
|
|
31
32
|
:clips => :movie_clips,
|
32
33
|
:reviews => :movie_reviews,
|
33
34
|
:similar => :movie_similar,
|
34
|
-
:alias => :movie_alias
|
35
35
|
}
|
36
36
|
|
37
37
|
# Poster for a movie
|
@@ -47,23 +47,18 @@ module TomatoPower
|
|
47
47
|
@actors ||= TomatoPower::Parser::parse_cast @abridged_cast
|
48
48
|
end
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
|
50
|
+
#Defines methods that are in MOVIE_METHOD_ALIAS. Straight up delegation is not used
|
51
|
+
#because @id needs to be inserted into options before calling the method.
|
52
|
+
#
|
53
|
+
#@param methods [Array] methods to be created.
|
54
|
+
#@param options [Hash] options for function call.
|
55
|
+
#@note TOMATO_METHODS is a hash containing all of the Rotten Tomatoes API calls.
|
56
|
+
def self.define_movie_methods(*methods)
|
57
|
+
methods.each do |method|
|
58
|
+
define_method(method) do |options={}|
|
53
59
|
options[:movie_id] = @id
|
54
60
|
@api.send(MOVIE_METHOD_ALIAS[method], options)
|
55
61
|
end
|
56
|
-
else
|
57
|
-
super
|
58
|
-
end
|
59
|
-
self.send method, options
|
60
|
-
end
|
61
|
-
|
62
|
-
def respond_to? method
|
63
|
-
if MOVIE_METHOD_ALIAS.key? method
|
64
|
-
true
|
65
|
-
else
|
66
|
-
super
|
67
62
|
end
|
68
63
|
end
|
69
64
|
end
|
data/lib/tomato_power/version.rb
CHANGED
@@ -20,7 +20,7 @@ module TomatoPower
|
|
20
20
|
it { should respond_to(:synopsis)}
|
21
21
|
it { should respond_to(:alternate_ids)}
|
22
22
|
it { should respond_to(:links)}
|
23
|
-
it { should respond_to(:
|
23
|
+
it { should respond_to(:directors)}
|
24
24
|
it { should respond_to(:studio)}
|
25
25
|
end
|
26
26
|
|
data/tomato_power.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
|
|
12
12
|
gem.summary = %q{Easily access Rotten Tomatoes API methods}
|
13
13
|
gem.homepage = "https://github.com/seankay/tomato_power"
|
14
14
|
|
15
|
-
gem.add_dependency
|
15
|
+
gem.add_dependency 'active_support','>= 3.2.12'
|
16
16
|
|
17
17
|
gem.add_development_dependency "rspec"
|
18
18
|
gem.add_development_dependency "pry"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tomato_power
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: active_support
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: 3.2.12
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: 3.2.12
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: rspec
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|