vinegar 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,29 @@
1
+ # Similar
2
+ module Vinegar
3
+ class Client
4
+ # Similar
5
+ #
6
+ # @see http://developer.rottentomatoes.com/docs/json/v10/Movie_Similar
7
+ module Similar
8
+ # Shows similar movies for a movie.
9
+ #
10
+ # @see http://developer.rottentomatoes.com/docs/json/v10/Movie_Similar
11
+ #
12
+ # @param [Integer] movie_id The id of the movie from Rotten Tomatoes
13
+ # @param [Integer] limit Limit the number of similar movies to show
14
+ #
15
+ # @return [Hashie::Mash] Similar movies response
16
+ #
17
+ # @example Get the similar movies for a movie
18
+ # @client.similar_movies(12345)
19
+ #
20
+ # @author Jason Truluck
21
+ def similar_movies(movie_id, limit = 5, options = {})
22
+ options.merge!(
23
+ :limit => limit
24
+ )
25
+ get("movies/#{movie_id}/similar.json", options)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,23 @@
1
+ # Root
2
+ module Vinegar
3
+ class Client
4
+ # Root level tasks for Rotten Tomatoes API
5
+ #
6
+ # @see http://developer.rottentomatoes.com/docs/json/v10/
7
+ module Root
8
+ # Returns the root of the api
9
+ #
10
+ # @see http://developer.rottentomatoes.com/docs/json/v10/
11
+ #
12
+ # @return api root
13
+ #
14
+ # @example Return the root of the api
15
+ # @client.root
16
+ #
17
+ # @author Jason Truluck
18
+ def root(options = {})
19
+ get("", options)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,29 @@
1
+ #Configuration
2
+ module Vinegar
3
+ module Configuration
4
+ VALID_OPTIONS_KEYS = [
5
+ :api_key,
6
+ :api_version,
7
+ :api_endpoint
8
+ ]
9
+
10
+ DEFAULT_API_VERSION = 1.0
11
+ DEFAULT_API_ENDPOINT = "http://api.rottentomatoes.com/api/public/v#{DEFAULT_API_VERSION}"
12
+
13
+ attr_accessor(*VALID_OPTIONS_KEYS)
14
+
15
+ def configure
16
+ yield self
17
+ end
18
+
19
+ def options
20
+ VALID_OPTIONS_KEYS.inject({}){|o,k| o.merge!(k => send(k)) }
21
+ end
22
+
23
+ def reset!
24
+ self.api_key = nil
25
+ self.api_version = DEFAULT_API_VERSION
26
+ self.api_endpoint = DEFAULT_API_ENDPOINT
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,16 @@
1
+ # Connection
2
+ require "faraday_middleware"
3
+
4
+ module Vinegar
5
+ module Connection
6
+ def connection(options = {})
7
+ connection = Faraday.new(options) do |build|
8
+ build.use FaradayMiddleware::Mashify
9
+ build.use FaradayMiddleware::ParseJson
10
+ build.adapter Faraday.default_adapter
11
+ end
12
+
13
+ connection
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,29 @@
1
+ module Vinegar
2
+ module Request
3
+ def get(path, options = {})
4
+ response = request(:get, path, options)
5
+ response.body
6
+ end
7
+
8
+ private
9
+ def request(method, path, options = {})
10
+ url = options.delete(:api_endpoint) || api_endpoint
11
+ key = options.delete(:api_key) || api_key
12
+
13
+ connection_options = {
14
+ :url => url
15
+ }
16
+
17
+ response = connection(connection_options).send(method) do |request|
18
+ options.merge!(:apikey => key)
19
+
20
+ case method
21
+ when :get
22
+ request.url(path, options)
23
+ end
24
+ end
25
+
26
+ response
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module Vinegar
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,3 @@
1
+ api_key: 1234567890 # Your API key
2
+ movies_search: "Star Wars" # Movie title you would like to use for tests
3
+ movie_id: 9 # ID of a movie you would like to use for tests
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+
3
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
4
+ ENV["RAILS_ENV"] ||= 'test'
5
+
6
+ if ENV['RAILS_ENV'] == 'test'
7
+ require 'simplecov'
8
+ SimpleCov.start 'rails'
9
+ class SimpleCov::Formatter::QualityFormatter
10
+ def format(result)
11
+ SimpleCov::Formatter::HTMLFormatter.new.format(result)
12
+ File.open("coverage/covered_percent", "w") do |f|
13
+ f.puts result.source_files.covered_percent.to_f
14
+ end
15
+ end
16
+ end
17
+ SimpleCov.formatter = SimpleCov::Formatter::QualityFormatter
18
+ end
19
+
20
+ require 'vinegar'
21
+ require 'vcr'
22
+ require "webmock/rspec"
23
+ require "mocha/api"
24
+
25
+ # Load Authentications
26
+ auth = YAML::load(File.open(File.expand_path("../fixtures/authentications.yml", __FILE__)))
27
+
28
+ VCR.configure do |c|
29
+ c.cassette_library_dir = 'spec/cassettes'
30
+ c.hook_into :faraday
31
+ c.ignore_localhost = true
32
+ # Uncomment if you need to log VCR
33
+ # c.debug_logger = File.open(Rails.root.join("log","vcr_debugger.log"), 'w')
34
+ c.configure_rspec_metadata!
35
+ c.allow_http_connections_when_no_cassette = true
36
+ end
37
+
38
+ WebMock.allow_net_connect!
39
+
40
+ Dir[File.expand_path("spec/support/**/*.rb", __FILE__)].each {|f| require f}
41
+
42
+ RSpec.configure do |config|
43
+ config.treat_symbols_as_metadata_keys_with_true_values = true
44
+ config.order = "random"
45
+ end
@@ -0,0 +1,53 @@
1
+ require "spec_helper"
2
+
3
+ auth = YAML::load(File.open(File.expand_path("../../../../fixtures/authentications.yml", __FILE__)))
4
+
5
+ # Movie Search Spec
6
+ describe Vinegar::Client do
7
+ before do
8
+ Vinegar.reset!
9
+ Vinegar.configure do |c|
10
+ c.api_key = auth["api_key"]
11
+ end
12
+ end
13
+
14
+ let(:vinegar) { Vinegar::Client.new(:api_key => auth["api_key"]) }
15
+
16
+ describe "#full_movie_cast", :vcr do
17
+ let(:current_response) { vinegar.full_movie_cast(auth["movie_id"]) }
18
+
19
+ it "returns the full_movie_cast response" do
20
+ current_response.should_not be_nil
21
+ end
22
+
23
+ describe "methods" do
24
+ it "responds to .cast" do
25
+ current_response.should respond_to(:cast)
26
+ end
27
+
28
+ it "responds to .links" do
29
+ current_response.should respond_to(:links)
30
+ end
31
+
32
+ describe "within .links" do
33
+ it "responds to .rel" do
34
+ current_response.links.should respond_to(:rel)
35
+ end
36
+ end
37
+
38
+ describe "within .cast" do
39
+ it "responds to .id" do
40
+ current_response.cast.first.should respond_to(:id)
41
+ end
42
+
43
+ it "responds to .name" do
44
+ current_response.cast.first.should respond_to(:name)
45
+ end
46
+
47
+ it "responds to .characters" do
48
+ current_response.cast.first.should respond_to(:characters)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,65 @@
1
+ require "spec_helper"
2
+
3
+ auth = YAML::load(File.open(File.expand_path("../../../../fixtures/authentications.yml", __FILE__)))
4
+
5
+ # Movie Search Spec
6
+ describe Vinegar::Client do
7
+ before do
8
+ Vinegar.reset!
9
+ Vinegar.configure do |c|
10
+ c.api_key = auth["api_key"]
11
+ end
12
+ end
13
+
14
+ let(:vinegar) { Vinegar::Client.new(:api_key => auth["api_key"]) }
15
+
16
+ describe "#clips_for_movie", :vcr do
17
+ let(:current_response) { vinegar.clips_for_movie(auth["movie_id"]) }
18
+
19
+ it "should return the clips_for_movie response" do
20
+ current_response.should_not be_nil
21
+ end
22
+
23
+ describe "methods" do
24
+ it "responds to .clips" do
25
+ current_response.should respond_to(:clips)
26
+ end
27
+
28
+ it "responds to .links" do
29
+ current_response.should respond_to(:links)
30
+ end
31
+
32
+ describe "within each .clips item" do
33
+ it "responds to .title" do
34
+ current_response.clips.first.should respond_to(:title)
35
+ end
36
+
37
+ it "responds to .duration" do
38
+ current_response.clips.first.should respond_to(:duration)
39
+ end
40
+
41
+ it "responds to .thumbnail" do
42
+ current_response.clips.first.should respond_to(:thumbnail)
43
+ end
44
+
45
+ it "responds to .links" do
46
+ current_response.clips.first.should respond_to(:links)
47
+ end
48
+ end
49
+
50
+ describe "within .links" do
51
+ it "responds to .self" do
52
+ current_response.links.should respond_to(:self)
53
+ end
54
+
55
+ it "responds to .alternate" do
56
+ current_response.links.should respond_to(:alternate)
57
+ end
58
+
59
+ it "responds to .rel" do
60
+ current_response.links.should respond_to(:rel)
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,109 @@
1
+ require "spec_helper"
2
+
3
+ auth = YAML::load(File.open(File.expand_path("../../../../fixtures/authentications.yml", __FILE__)))
4
+
5
+ # Movie Search Spec
6
+ describe Vinegar::Client do
7
+ before do
8
+ Vinegar.reset!
9
+ Vinegar.configure do |c|
10
+ c.api_key = auth["api_key"]
11
+ end
12
+ end
13
+
14
+ let(:vinegar) { Vinegar::Client.new(:api_key => auth["api_key"]) }
15
+
16
+ describe "#reviews", :vcr do
17
+ let(:current_response) { vinegar.all_movie_reviews(auth["movie_id"]) }
18
+
19
+ it "returns the all_movie_review response" do
20
+ current_response.should_not be_nil
21
+ end
22
+
23
+ describe "methods" do
24
+ it "responds to .total" do
25
+ current_response.should respond_to(:total)
26
+ end
27
+
28
+ it "responds to .reviews" do
29
+ current_response.should respond_to(:reviews)
30
+ end
31
+
32
+ it "responds to .links" do
33
+ current_response.should respond_to(:links)
34
+ end
35
+
36
+ it "responds to .link_template" do
37
+ current_response.should respond_to(:link_template)
38
+ end
39
+
40
+ describe "within .reviews" do
41
+ it "responds to .critic" do
42
+ current_response.reviews.first.should respond_to(:critic)
43
+ end
44
+
45
+ it "responds to .date" do
46
+ current_response.reviews.first.should respond_to(:date)
47
+ end
48
+
49
+ it "responds to .freshness" do
50
+ current_response.reviews.first.should respond_to(:freshness)
51
+ end
52
+
53
+ it "responds to .publication" do
54
+ current_response.reviews.first.should respond_to(:publication)
55
+ end
56
+
57
+ it "responds to .quote" do
58
+ current_response.reviews.first.should respond_to(:quote)
59
+ end
60
+
61
+ it "responds to .links" do
62
+ current_response.reviews.first.should respond_to(:links)
63
+ end
64
+ end
65
+
66
+ describe "within .links" do
67
+ it "responds to .self" do
68
+ current_response.links.should respond_to(:self)
69
+ end
70
+
71
+ it "responds to .next" do
72
+ current_response.links.should respond_to(:next)
73
+ end
74
+
75
+ it "responds to .alternate" do
76
+ current_response.links.should respond_to(:alternate)
77
+ end
78
+
79
+ it "responds to .rel" do
80
+ current_response.links.should respond_to(:rel)
81
+ end
82
+ end
83
+ end
84
+
85
+ context "#all_movie_reviews" do
86
+ let(:current_response) { vinegar.all_movie_reviews(auth["movie_id"]) }
87
+
88
+ it "returns the all_movie_review response" do
89
+ current_response.should_not be_nil
90
+ end
91
+ end
92
+
93
+ context "#top_critic_movie_reviews" do
94
+ let(:current_response) { vinegar.top_critic_movie_reviews(auth["movie_id"]) }
95
+
96
+ it "returns the top_critic_movie_review response" do
97
+ current_response.should_not be_nil
98
+ end
99
+ end
100
+
101
+ context "#dvd_movie_reviews" do
102
+ let(:current_response) { vinegar.dvd_movie_reviews(auth["movie_id"]) }
103
+
104
+ it "returns the dvd_movie_review response" do
105
+ current_response.should_not be_nil
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,183 @@
1
+ require "spec_helper"
2
+
3
+ auth = YAML::load(File.open(File.expand_path("../../../../fixtures/authentications.yml", __FILE__)))
4
+
5
+ # Movie Search Spec
6
+ describe Vinegar::Client do
7
+ before do
8
+ Vinegar.reset!
9
+ Vinegar.configure do |c|
10
+ c.api_key = auth["api_key"]
11
+ end
12
+ end
13
+
14
+ let(:vinegar) { Vinegar::Client.new(:api_key => auth["api_key"]) }
15
+
16
+ describe "#similar_movies", :vcr do
17
+ let(:current_response) { vinegar.similar_movies(auth["movie_id"]) }
18
+
19
+ it "returns the similar_movies response" do
20
+ current_response.should_not be_nil
21
+ end
22
+
23
+ describe "methods" do
24
+ it "responds to .movies" do
25
+ current_response.should respond_to(:movies)
26
+ end
27
+
28
+ it "responds to .links" do
29
+ current_response.should respond_to(:links)
30
+ end
31
+
32
+ it "responds to .link_template" do
33
+ current_response.should respond_to(:link_template)
34
+ end
35
+
36
+ describe "within each .movies item" do
37
+ it "responds to .id" do
38
+ current_response.movies.first.should respond_to(:id)
39
+ end
40
+
41
+ it "responds to .title" do
42
+ current_response.movies.first.should respond_to(:title)
43
+ end
44
+
45
+ it "responds to .year" do
46
+ current_response.movies.first.should respond_to(:year)
47
+ end
48
+
49
+ it "responds to .mpaa_rating" do
50
+ current_response.movies.first.should respond_to(:mpaa_rating)
51
+ end
52
+
53
+ it "responds to .runtime" do
54
+ current_response.movies.first.should respond_to(:runtime)
55
+ end
56
+
57
+ it "responds to .critics_consensus" do
58
+ current_response.movies.first.should respond_to(:critics_consensus)
59
+ end
60
+
61
+ it "responds to .release_dates" do
62
+ current_response.movies.first.should respond_to(:release_dates)
63
+ end
64
+
65
+ it "responds to .ratings" do
66
+ current_response.movies.first.should respond_to(:ratings)
67
+ end
68
+
69
+ it "responds to .synopsis" do
70
+ current_response.movies.first.should respond_to(:synopsis)
71
+ end
72
+
73
+ it "responds to .posters" do
74
+ current_response.movies.first.should respond_to(:posters)
75
+ end
76
+
77
+ it "responds to .abridged_cast" do
78
+ current_response.movies.first.should respond_to(:abridged_cast)
79
+ end
80
+
81
+ it "responds to .alternate_ids" do
82
+ current_response.movies.first.should respond_to(:alternate_ids)
83
+ end
84
+
85
+ it "responds to .links" do
86
+ current_response.should respond_to(:links)
87
+ end
88
+
89
+ describe "within .release_dates" do
90
+ it "responds to .theater" do
91
+ current_response.movies.first.release_dates.should respond_to(:theater)
92
+ end
93
+
94
+ it "responds to .dvd" do
95
+ current_response.movies.first.release_dates.should respond_to(:dvd)
96
+ end
97
+ end
98
+
99
+ describe "within .ratings" do
100
+ it "responds to .critics_rating" do
101
+ current_response.movies.first.ratings.should respond_to(:critics_rating)
102
+ end
103
+
104
+ it "responds to .critics_score" do
105
+ current_response.movies.first.ratings.should respond_to(:critics_score)
106
+ end
107
+
108
+ it "responds to .audience_rating" do
109
+ current_response.movies.first.ratings.should respond_to(:audience_rating)
110
+ end
111
+
112
+ it "responds to .audience_score" do
113
+ current_response.movies.first.ratings.should respond_to(:audience_score)
114
+ end
115
+ end
116
+
117
+ describe "within .posters" do
118
+ it "responds to .thumbnail" do
119
+ current_response.movies.first.posters.should respond_to(:thumbnail)
120
+ end
121
+
122
+ it "responds to .profile" do
123
+ current_response.movies.first.posters.should respond_to(:profile)
124
+ end
125
+
126
+ it "responds to .detailed" do
127
+ current_response.movies.first.posters.should respond_to(:detailed)
128
+ end
129
+
130
+ it "responds to .original" do
131
+ current_response.movies.first.posters.should respond_to(:original)
132
+ end
133
+ end
134
+
135
+ describe "within each .abridged_cast item" do
136
+ it "responds to .name" do
137
+ current_response.movies.first.abridged_cast.first.should respond_to(:name)
138
+ end
139
+
140
+ it "responds to .characters" do
141
+ current_response.movies.first.abridged_cast.first.should respond_to(:characters)
142
+ end
143
+ end
144
+
145
+ describe "within .links" do
146
+ it "responds to .self" do
147
+ current_response.movies.first.links.should respond_to(:self)
148
+ end
149
+
150
+ it "responds to .alternate" do
151
+ current_response.movies.first.links.should respond_to(:alternate)
152
+ end
153
+
154
+ it "responds to .cast" do
155
+ current_response.movies.first.links.should respond_to(:cast)
156
+ end
157
+
158
+ it "responds to .clips" do
159
+ current_response.movies.first.links.should respond_to(:clips)
160
+ end
161
+
162
+ it "responds to .reviews" do
163
+ current_response.movies.first.links.should respond_to(:reviews)
164
+ end
165
+
166
+ it "responds to .similar" do
167
+ current_response.movies.first.links.should respond_to(:similar)
168
+ end
169
+ end
170
+ end
171
+
172
+ describe "within .links" do
173
+ it "responds to .rel" do
174
+ current_response.links.should respond_to(:rel)
175
+ end
176
+
177
+ it "responds to .self" do
178
+ current_response.links.should respond_to(:self)
179
+ end
180
+ end
181
+ end
182
+ end
183
+ end