badfruit 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +10 -0
- data/README.md +15 -0
- data/Rakefile +13 -0
- data/badfruit.gemspec +35 -0
- data/lib/badfruit/Actors/actor.rb +8 -0
- data/lib/badfruit/Lists/lists.rb +23 -0
- data/lib/badfruit/Movies/movie.rb +39 -0
- data/lib/badfruit/Movies/movies.rb +16 -0
- data/lib/badfruit/Reviews/review.rb +11 -0
- data/lib/badfruit/base.rb +76 -0
- data/lib/badfruit.rb +16 -0
- metadata +97 -0
data/Manifest
ADDED
data/README.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
BadFruit Client For Rotten Tomatoes
|
2
|
+
===================================
|
3
|
+
|
4
|
+
This is a rough gem to interface with the Rotten Tomatoes API.
|
5
|
+
|
6
|
+
Usage
|
7
|
+
-----
|
8
|
+
|
9
|
+
>require 'badfruit'
|
10
|
+
bf = BadFruit.new("YOUR_API_KEY_HERE")
|
11
|
+
movies = bf.movies.search_by_name("Hackers")
|
12
|
+
cast = movies[0].fullCast
|
13
|
+
reviews = movies[0].reviews
|
14
|
+
|
15
|
+
This should get you started, I should also mention that the Lists part of the API has not yet been implemented in this gem. I'll take a look at it soon though.
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('badfruit', '0.0.3') do |p|
|
6
|
+
p.description = "Interface with the Rotten Tomatoes API"
|
7
|
+
p.url = "http://www.github.com/brianmichel/badfruit"
|
8
|
+
p.author = "Brian Michel"
|
9
|
+
p.email = "brian.michel@gmail.com"
|
10
|
+
p.runtime_dependencies = ["json", "httparty"]
|
11
|
+
end
|
12
|
+
|
13
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
data/badfruit.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{badfruit}
|
5
|
+
s.version = "0.0.3"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Brian Michel"]
|
9
|
+
s.date = %q{2011-04-17}
|
10
|
+
s.description = %q{Interface with the Rotten Tomatoes API}
|
11
|
+
s.email = %q{brian.michel@gmail.com}
|
12
|
+
s.extra_rdoc_files = ["README.md", "lib/badfruit.rb", "lib/badfruit/Actors/actor.rb", "lib/badfruit/Lists/lists.rb", "lib/badfruit/Movies/movie.rb", "lib/badfruit/Movies/movies.rb", "lib/badfruit/Reviews/review.rb", "lib/badfruit/base.rb"]
|
13
|
+
s.files = ["Manifest", "README.md", "Rakefile", "lib/badfruit.rb", "lib/badfruit/Actors/actor.rb", "lib/badfruit/Lists/lists.rb", "lib/badfruit/Movies/movie.rb", "lib/badfruit/Movies/movies.rb", "lib/badfruit/Reviews/review.rb", "lib/badfruit/base.rb", "badfruit.gemspec"]
|
14
|
+
s.homepage = %q{http://www.github.com/brianmichel/badfruit}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Badfruit", "--main", "README.md"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{badfruit}
|
18
|
+
s.rubygems_version = %q{1.7.2}
|
19
|
+
s.summary = %q{Interface with the Rotten Tomatoes API}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
s.specification_version = 3
|
23
|
+
|
24
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
25
|
+
s.add_runtime_dependency(%q<json>, [">= 0"])
|
26
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0"])
|
27
|
+
else
|
28
|
+
s.add_dependency(%q<json>, [">= 0"])
|
29
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
30
|
+
end
|
31
|
+
else
|
32
|
+
s.add_dependency(%q<json>, [">= 0"])
|
33
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module BadFruit
|
2
|
+
class Lists
|
3
|
+
def initialize(badfruit)
|
4
|
+
@badfruit = badfruit
|
5
|
+
end
|
6
|
+
|
7
|
+
def openingMovies
|
8
|
+
return @badfruit.parseMoviesArray(JSON.parse(@badfruit.get_lists_action("opening")))
|
9
|
+
end
|
10
|
+
|
11
|
+
def upcomingMovies
|
12
|
+
return @badfruit.parseMoviesArray(JSON.parse(@badfruit.get_lists_action("upcoming")))
|
13
|
+
end
|
14
|
+
|
15
|
+
def inTheaters
|
16
|
+
return @badfruit.parseMoviesArray(JSON.parse(@badfruit.get_lists_action("in_theaters")))
|
17
|
+
end
|
18
|
+
|
19
|
+
def newDVDReleases
|
20
|
+
return @badfruit.parseMoviesArray(JSON.parse(@badfruit.get_lists_action("new_releases")))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class Movie
|
2
|
+
attr_accessor :id, :name, :cast, :scores
|
3
|
+
|
4
|
+
def initialize(movieHash, badfruit)
|
5
|
+
@id = movieHash["id"]
|
6
|
+
@name = movieHash["title"]
|
7
|
+
@cast = movieHash["abridged_cast"]
|
8
|
+
@scores = movieHash["ratings"]
|
9
|
+
@badfruit = badfruit
|
10
|
+
end
|
11
|
+
|
12
|
+
def averageScores
|
13
|
+
puts "average!"
|
14
|
+
end
|
15
|
+
|
16
|
+
# for the three following methods, pass in your BadFruit client instance to retreive the info
|
17
|
+
# this will be fixed when all results are parsed into movie assets for the user
|
18
|
+
def fullCast
|
19
|
+
data = JSON.parse(@badfruit.get_movie_info(@id, "cast"))
|
20
|
+
actors = Array.new
|
21
|
+
data["cast"].each do |actor|
|
22
|
+
actors.push(Actor.new(actor))
|
23
|
+
end
|
24
|
+
return actors
|
25
|
+
end
|
26
|
+
|
27
|
+
def reviews
|
28
|
+
data = JSON.parse(@badfruit.get_movie_info(@id, "reviews"))
|
29
|
+
reviews = Array.new
|
30
|
+
data["reviews"].each do |review|
|
31
|
+
reviews.push(Review.new(review))
|
32
|
+
end
|
33
|
+
return reviews
|
34
|
+
end
|
35
|
+
|
36
|
+
def info
|
37
|
+
return JSON.parse(@badfruit.get_movie_info(@id, "details"))
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module BadFruit
|
2
|
+
class Movies
|
3
|
+
MAX_PAGE_LIMIT = 50
|
4
|
+
|
5
|
+
def initialize(badfruit)
|
6
|
+
@badfruit = badfruit
|
7
|
+
end
|
8
|
+
|
9
|
+
def search_by_name(name, page_limit=1, page=1)
|
10
|
+
if page_limit > 50
|
11
|
+
page_limit = MAX_PAGE_LIMIT #current limitation of the rotten tomatos API
|
12
|
+
end
|
13
|
+
return @badfruit.parseMoviesArray(JSON.parse(@badfruit.search_movies(name, page_limit, page)))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class Review
|
2
|
+
attr_accessor :critic, :date, :publication, :quote, :links
|
3
|
+
|
4
|
+
def initialize(reviewHash)
|
5
|
+
@critic = reviewHash["critic"]
|
6
|
+
@date = reviewHash["date"]
|
7
|
+
@publication = reviewHash["publication"]
|
8
|
+
@quote = reviewHash["quote"]
|
9
|
+
@links = reviewHash["links"]
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module BadFruit
|
2
|
+
class Base
|
3
|
+
attr_accessor :api_key
|
4
|
+
API_VERSION = "v1.0"
|
5
|
+
MOVIE_DETAIL_BASE_URL = "http://api.rottentomatoes.com/api/public/#{API_VERSION}/movies"
|
6
|
+
LISTS_DETAIL_BASE_URL = "http://api.rottentomatoes.com/api/public/#{API_VERSION}/lists"
|
7
|
+
|
8
|
+
def movies(); @movie || BadFruit::Movies.new(self); end
|
9
|
+
def lists(); @list || BadFruit::Lists.new(self); end
|
10
|
+
|
11
|
+
def initialize(key)
|
12
|
+
@api_key = key
|
13
|
+
@@base_api_url = "http://api.rottentomatoes.com/api/public/#{API_VERSION}"
|
14
|
+
@@movies_query_url = "#{@@base_api_url}/movies.json?apikey=#{@api_key}"
|
15
|
+
@@lists_query_url = "#{@@base_api_url}/lists.json?apikey=#{@api_key}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def search_movies(name, page_limit, page)
|
19
|
+
url = "#{@@movies_query_url}&q=#{CGI::escape(name)}&page_limit=#{page_limit}&page=#{page}"
|
20
|
+
return get(url)
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_movie_info(movie_id, action)
|
24
|
+
url = nil
|
25
|
+
case action
|
26
|
+
when "details"
|
27
|
+
url = "#{MOVIE_DETAIL_BASE_URL}/#{movie_id}.json?apikey=#{@api_key}"
|
28
|
+
when "reviews"
|
29
|
+
url = "#{MOVIE_DETAIL_BASE_URL}/#{movie_id}/reviews.json?apikey=#{@api_key}"
|
30
|
+
when "cast"
|
31
|
+
url = "#{MOVIE_DETAIL_BASE_URL}/#{movie_id}/cast.json?apikey=#{@api_key}"
|
32
|
+
else
|
33
|
+
puts "Not a valid action"
|
34
|
+
return
|
35
|
+
end
|
36
|
+
return get(url)
|
37
|
+
end
|
38
|
+
|
39
|
+
def get_lists_action(action)
|
40
|
+
url = nil
|
41
|
+
case action
|
42
|
+
when "new_releases"
|
43
|
+
url = "#{LISTS_DETAIL_BASE_URL}/dvds/new_releases.json?apikey=#{@api_key}"
|
44
|
+
when "opening"
|
45
|
+
url = "#{LISTS_DETAIL_BASE_URL}/movies/opening.json?apikey=#{@api_key}"
|
46
|
+
when "upcoming"
|
47
|
+
url = "#{LISTS_DETAIL_BASE_URL}/movies/upcoming.json?apikey=#{@api_key}"
|
48
|
+
when "in_theaters"
|
49
|
+
url = "#{LISTS_DETAIL_BASE_URL}/movies/in_theaters.json?apikey=#{@api_key}"
|
50
|
+
else
|
51
|
+
puts "Not a valid action"
|
52
|
+
return
|
53
|
+
end
|
54
|
+
return get(url)
|
55
|
+
end
|
56
|
+
|
57
|
+
def get(url)
|
58
|
+
data = nil
|
59
|
+
puts "Getting #{url}"
|
60
|
+
resp = HTTParty.get(url)
|
61
|
+
|
62
|
+
if resp.code == 200
|
63
|
+
puts "Response: OK"
|
64
|
+
return resp.body
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def parseMoviesArray(hash)
|
69
|
+
moviesArray = Array.new
|
70
|
+
hash["movies"].each do |movie|
|
71
|
+
moviesArray.push(Movie.new(movie, self))
|
72
|
+
end
|
73
|
+
return moviesArray
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/lib/badfruit.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'JSON'
|
3
|
+
require 'cgi'
|
4
|
+
|
5
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'badfruit', 'base')
|
6
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'badfruit', 'Lists', 'lists')
|
7
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'badfruit', 'Movies', 'movies')
|
8
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'badfruit', 'Movies', 'movie')
|
9
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'badfruit', 'Reviews', 'review')
|
10
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'badfruit', 'Actors', 'actor')
|
11
|
+
|
12
|
+
module BadFruit
|
13
|
+
def self.new(apikey)
|
14
|
+
BadFruit::Base.new(apikey)
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: badfruit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.3
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brian Michel
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-04-17 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: json
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: httparty
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0"
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id002
|
37
|
+
description: Interface with the Rotten Tomatoes API
|
38
|
+
email: brian.michel@gmail.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files:
|
44
|
+
- README.md
|
45
|
+
- lib/badfruit.rb
|
46
|
+
- lib/badfruit/Actors/actor.rb
|
47
|
+
- lib/badfruit/Lists/lists.rb
|
48
|
+
- lib/badfruit/Movies/movie.rb
|
49
|
+
- lib/badfruit/Movies/movies.rb
|
50
|
+
- lib/badfruit/Reviews/review.rb
|
51
|
+
- lib/badfruit/base.rb
|
52
|
+
files:
|
53
|
+
- Manifest
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- lib/badfruit.rb
|
57
|
+
- lib/badfruit/Actors/actor.rb
|
58
|
+
- lib/badfruit/Lists/lists.rb
|
59
|
+
- lib/badfruit/Movies/movie.rb
|
60
|
+
- lib/badfruit/Movies/movies.rb
|
61
|
+
- lib/badfruit/Reviews/review.rb
|
62
|
+
- lib/badfruit/base.rb
|
63
|
+
- badfruit.gemspec
|
64
|
+
homepage: http://www.github.com/brianmichel/badfruit
|
65
|
+
licenses: []
|
66
|
+
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options:
|
69
|
+
- --line-numbers
|
70
|
+
- --inline-source
|
71
|
+
- --title
|
72
|
+
- Badfruit
|
73
|
+
- --main
|
74
|
+
- README.md
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: "0"
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: "1.2"
|
89
|
+
requirements: []
|
90
|
+
|
91
|
+
rubyforge_project: badfruit
|
92
|
+
rubygems_version: 1.7.2
|
93
|
+
signing_key:
|
94
|
+
specification_version: 3
|
95
|
+
summary: Interface with the Rotten Tomatoes API
|
96
|
+
test_files: []
|
97
|
+
|