vinegar 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,32 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ spec/cassettes
20
+ spec/.DS_Store
21
+
22
+ spec/fixtures/authentications.yml
23
+
24
+ spec/vinegar/.DS_Store
25
+
26
+ lib/vinegar/.DS_Store
27
+
28
+ lib/vinegar/client/movies/.DS_Store
29
+
30
+ lib/vinegar/client/movie/.DS_Store
31
+
32
+ spec/vinegar/client/movies/.DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vinegar.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jason Truluck
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.
@@ -0,0 +1,88 @@
1
+ # Vinegar
2
+
3
+ Rotten Tomatoes API Wrapper in Ruby. Currently the wrapper supports the movies api and lists api is comming shortly.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'vinegar'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install vinegar
18
+
19
+ ## Documentation
20
+
21
+ http://rdoc.info/github/jasontruluck/vinegar
22
+
23
+ ## Usage
24
+
25
+ ### Setup a new client
26
+
27
+ ```ruby
28
+ client = Vinegar::Client.new(:api_key => 1234567890)
29
+ ```
30
+
31
+ ### [Search for movies](http://rdoc.info/github/jasontruluck/vinegar/Vinegar/Client/Movie#movies_search-instance_method)
32
+
33
+ ```ruby
34
+ client.movies_search("Star Wars")
35
+ ```
36
+
37
+ ### [View a single movie](http://rdoc.info/github/jasontruluck/vinegar/Vinegar/Client/Movie#movie-instance_method)
38
+
39
+ ```ruby
40
+ client.movie(12345) #12345 is the movies Rotten Tomatoes ID
41
+ ```
42
+
43
+ ### [Get the cast for a movie](http://rdoc.info/github/jasontruluck/vinegar/Vinegar/Client/Cast)
44
+
45
+ ```ruby
46
+ client.full_movie_cast(12345) #12345 is the movies Rotten Tomatoes ID
47
+ ```
48
+
49
+ ### [Get reviews for a movie](http://rdoc.info/github/jasontruluck/vinegar/Vinegar/Client/Review)
50
+
51
+ ```ruby
52
+ client.all_movie_reviews(12345) #12345 is the movies Rotten Tomatoes ID
53
+ ```
54
+
55
+ ### [Get similar movies for a movie](http://rdoc.info/github/jasontruluck/vinegar/Vinegar/Client/Similar)
56
+
57
+ ```ruby
58
+ client.similar_movies(12345) #12345 is the movies Rotten Tomatoes ID
59
+ ```
60
+
61
+ ### [Get clips for a movie](http://rdoc.info/github/jasontruluck/vinegar/Vinegar/Client/Clip)
62
+
63
+ ```ruby
64
+ client.clips_for_movie(12345) #12345 is the movies Rotten Tomatoes ID
65
+ ```
66
+
67
+ ## Testing
68
+
69
+ This gem uses VCR to record requests to the api so you must test using a valid API key from Rotten Tomatoes.
70
+
71
+ Add a sample authentications file to your `spec/fixtures` directory:
72
+
73
+ ```ruby
74
+ #spec/fixtures/authentications.yml
75
+ api_key: 1234567890 # Your API key
76
+ movies_search: "Star Wars" # Movie title you would like to use for search tests
77
+ movie_id: 9 # ID of a movie you would like to use for movie tests
78
+ ```
79
+
80
+ A sample is included in the [directory](https://github.com/jasontruluck/vinegar/blob/master/spec/fixtures/authentication.yml.sample).
81
+
82
+ ## Contributing
83
+
84
+ 1. Fork it
85
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
86
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
87
+ 4. Push to the branch (`git push origin my-new-feature`)
88
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ require "vinegar/version"
2
+ require "vinegar/configuration"
3
+ require "vinegar/client"
4
+
5
+ module Vinegar
6
+ extend Configuration
7
+
8
+ class << self
9
+ # Alias for Vinegar::Client.new
10
+ # @return [Vinegar::Client]
11
+ def new(options = {})
12
+ Vinegar::Client.new(options)
13
+ end
14
+
15
+ def respond_to?(method, include_private=false)
16
+ new.respond_to?(method, include_private) || super(method, include_private)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ # Authentication Module
2
+ module Vinegar
3
+ module Authentication
4
+ def authentication
5
+ if api_key
6
+ { :api_key => api_key}
7
+ else
8
+ {}
9
+ end
10
+ end
11
+
12
+ def authenticated?
13
+ !authentication.empty?
14
+ end
15
+
16
+ def login_token(api_key = "")
17
+ return if api_key.nil?
18
+ self.api_key = api_key
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,40 @@
1
+ # Client Module
2
+ require "vinegar/authentication"
3
+ require "vinegar/connection"
4
+ require "vinegar/request"
5
+
6
+ require "vinegar/client/root"
7
+ require "vinegar/client/movie"
8
+ require "vinegar/client/movie/review"
9
+ require "vinegar/client/movie/cast"
10
+ require "vinegar/client/movie/similar"
11
+ require "vinegar/client/movie/clip"
12
+
13
+ module Vinegar
14
+ class Client
15
+ attr_accessor(*Configuration::VALID_OPTIONS_KEYS)
16
+
17
+ def initialize(options = {})
18
+ Vinegar.reset!
19
+ options = Vinegar.options.merge(options)
20
+
21
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
22
+ send("#{key}=", options[key])
23
+ end
24
+
25
+ login_token(options[:api_key])
26
+ end
27
+
28
+
29
+ include Vinegar::Authentication
30
+ include Vinegar::Connection
31
+ include Vinegar::Request
32
+
33
+ include Vinegar::Client::Root
34
+ include Vinegar::Client::Movie
35
+ include Vinegar::Client::Review
36
+ include Vinegar::Client::Cast
37
+ include Vinegar::Client::Similar
38
+ include Vinegar::Client::Clip
39
+ end
40
+ end
@@ -0,0 +1,55 @@
1
+ # Movies
2
+ module Vinegar
3
+ class Client
4
+ # Movies Search
5
+ #
6
+ # @see http://developer.rottentomatoes.com/docs/json/v10/Movies_Search
7
+ module Movie
8
+ # Returns the response from querying the movies search endpoint
9
+ #
10
+ # @see http://developer.rottentomatoes.com/docs/json/v10/Movies_Search
11
+ #
12
+ # @param [String] query The query you want to search on
13
+ # @param [Integer] page_limit The amount of movie search results to show per page
14
+ # @param [Integer] page The selected page of movie search results
15
+ #
16
+ # @return [Hashie::Mash] Movies serach Response
17
+ #
18
+ # @example Get the search results for a query
19
+ # @client.movies_search("Movie Title")
20
+ #
21
+ # @example Get the search results for a query with a page limit
22
+ # @client.movies_search("Movie Title", 10)
23
+ #
24
+ # @example Get the search results for a query with a page limit and a page
25
+ # @client.movies_search("Movie Title", 10, 1)
26
+ #
27
+ # @author Jason Truluck
28
+ def movies_search(query, per_page = "", page = "", options = {})
29
+ options.merge!(
30
+ :q => query,
31
+ :page_limit => per_page,
32
+ :page => page
33
+ )
34
+ get("movies.json", options)
35
+ end
36
+
37
+ # Detailed information on a specific movie specified by Id. You can use the movies search endpoint
38
+ # or peruse the lists of movies/dvds to get the urls to movies.
39
+ #
40
+ # @see http://developer.rottentomatoes.com/docs/json/v10/Movie_Info
41
+ #
42
+ # @param [Integer] Movie ID from Rotten Tomatoes
43
+ #
44
+ # @return [Hashie::Mash] Movie Response
45
+ #
46
+ # @example Get the results for a specific movie id
47
+ # @client.movie(12345)
48
+ #
49
+ # @author Jason Truluck
50
+ def movie(movie_id, options = {})
51
+ get("movies/#{movie_id}.json", options)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,25 @@
1
+ # Cast
2
+ module Vinegar
3
+ class Client
4
+ # Cast
5
+ #
6
+ # @see http://developer.rottentomatoes.com/docs/json/v10/Movie_Cast
7
+ module Cast
8
+ # Pulls the complete movie cast for a movie
9
+ #
10
+ # @see http://developer.rottentomatoes.com/docs/json/v10/Movie_Cast
11
+ #
12
+ # @param [Integer] movie_id The id of the movie from Rotten Tomatoes
13
+ #
14
+ # @return [Hashie::Mash] Movie cast response
15
+ #
16
+ # @example Get the cast results for a movie
17
+ # @client.full_movie_cast(12345)
18
+ #
19
+ # @author Jason Truluck
20
+ def full_movie_cast(movie_id, options = {})
21
+ get("movies/#{movie_id}/cast.json", options)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ # Clip
2
+ module Vinegar
3
+ class Client
4
+ # Clip
5
+ #
6
+ # @see http://developer.rottentomatoes.com/docs/json/v10/Movie_Clips
7
+ module Clip
8
+ # Related movie clips and trailers for a movie
9
+ #
10
+ # @see http://developer.rottentomatoes.com/docs/json/v10/Movie_Clips
11
+ #
12
+ # @param [Integer] movie_id The id of the movie from Rotten Tomatoes
13
+ #
14
+ # @return [Hashie::Mash] Clips movies response
15
+ #
16
+ # @example Get the similar movies for a movie
17
+ # @client.clips_for_movie(12345)
18
+ #
19
+ # @author Jason Truluck
20
+ def clips_for_movie(movie_id, options = {})
21
+ get("movies/#{movie_id}/clips.json", options)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,98 @@
1
+ # Reviews
2
+ module Vinegar
3
+ class Client
4
+ # Reviews
5
+ #
6
+ # @see http://developer.rottentomatoes.com/docs/json/v10/Movie_Reviews
7
+ module Review
8
+ # Retrieves all reviews for a movie. Results are paginated if they go past the specified page limit
9
+ #
10
+ # @see http://developer.rottentomatoes.com/docs/json/v10/Movie_Reviews
11
+ #
12
+ # @param [Integer] movie_id The id of the movie from Rotten Tomatoes
13
+ # @param [String] country Provides localized data for the selected country if available. Otherwise, returns US data.
14
+ # @param [Integer] page_limit The amount of movie search results to show per page
15
+ # @param [Integer] page The selected page of movie search results
16
+ #
17
+ # @return [Hashie::Mash] Movies reviews Response
18
+ #
19
+ # @example Get the search results for a query
20
+ # @client.all_movie_reviews("12345")
21
+ #
22
+ # @author Jason Truluck
23
+ def all_movie_reviews(movie_id, country = "us", per_page = "", page = "", options = {})
24
+ options.merge!(
25
+ :review_type => :all,
26
+ :country => country,
27
+ :page_limit => per_page,
28
+ :page => page
29
+ )
30
+ reviews(movie_id, options)
31
+ end
32
+
33
+ # Retrieves top_critic reviews for a movie. Results are paginated if they go past the specified page limit
34
+ #
35
+ # @see http://developer.rottentomatoes.com/docs/json/v10/Movie_Reviews
36
+ #
37
+ # @param [Integer] movie_id The id of the movie from Rotten Tomatoes
38
+ # @param [String] country Provides localized data for the selected country if available. Otherwise, returns US data.
39
+ # @param [Integer] page_limit The amount of movie search results to show per page
40
+ # @param [Integer] page The selected page of movie search results
41
+ #
42
+ # @return [Hashie::Mash] Movies reviews Response
43
+ #
44
+ # @example Get the search results for a query
45
+ # @client.top_critic_movie_reviews("12345")
46
+ #
47
+ # @author Jason Truluck
48
+ def top_critic_movie_reviews(movie_id, country = "us", per_page = "", page = "", options = {})
49
+ options.merge!(
50
+ :review_type => :top_critic,
51
+ :country => country,
52
+ :page_limit => per_page,
53
+ :page => page
54
+ )
55
+ reviews(movie_id, options)
56
+ end
57
+
58
+ # Retrieves dvd reviews for a movie. Results are paginated if they go past the specified page limit
59
+ #
60
+ # @see http://developer.rottentomatoes.com/docs/json/v10/Movie_Reviews
61
+ #
62
+ # @param [Integer] movie_id The id of the movie from Rotten Tomatoes
63
+ # @param [String] country Provides localized data for the selected country if available. Otherwise, returns US data.
64
+ # @param [Integer] page_limit The amount of movie search results to show per page
65
+ # @param [Integer] page The selected page of movie search results
66
+ #
67
+ # @return [Hashie::Mash] Movies reviews Response
68
+ #
69
+ # @example Get the search results for a query
70
+ # @client.dvd_movie_reviews("12345")
71
+ #
72
+ # @author Jason Truluck
73
+ def dvd_movie_reviews(movie_id, country = "us", per_page = "", page = "", options = {})
74
+ options.merge!(
75
+ :review_type => :dvd,
76
+ :country => country,
77
+ :page_limit => per_page,
78
+ :page => page
79
+ )
80
+ reviews(movie_id, options)
81
+ end
82
+
83
+ private
84
+ # @private
85
+ #
86
+ # General method to handle endpoints for grabing reviews
87
+ #
88
+ # @param [Integer] movie_id The id of the movie from Rotten Tomatoes
89
+ #
90
+ # @return [Hashie::Mash] Movies reviews Response
91
+ #
92
+ # @author Jason Truluck
93
+ def reviews(movie_id, options)
94
+ get("movies/#{movie_id}/reviews.json", options)
95
+ end
96
+ end
97
+ end
98
+ end