tmdb_rexx 0.1.0

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,271 @@
1
+ module TmdbRexx
2
+ class Client
3
+ module Movie
4
+ RESOURCE = "movie".freeze
5
+
6
+ # Get the basic movie information for a specific movie id.
7
+ #
8
+ # @see http://docs.themoviedb.apiary.io/#reference/movies/movieid
9
+ #
10
+ # @param [String] id the movie id
11
+ #
12
+ # @return [Hashie::Mash] build response
13
+ #
14
+ # @example Get the movie api response
15
+ # TmdbRexx::Client.movie("movie-id")
16
+ def movie(movie_id, options = {})
17
+ get([RESOURCE, movie_id].join("/"), options)
18
+ end
19
+
20
+ # Get the alternative titles for a specific movie id.
21
+ #
22
+ # @see http://docs.themoviedb.apiary.io/#reference/movies/movieidalternativetitles
23
+ #
24
+ # @param [String] id the movie id
25
+ #
26
+ # @return [Hashie::Mash] build response
27
+ #
28
+ # @example Get the movie alternative titles api response
29
+ # TmdbRexx::Client.movie_alternative_titles("movie-id")
30
+ def movie_alternative_titles(movie_id, options = {})
31
+ get([RESOURCE, movie_id, "alternative_titles"].join("/"), options)
32
+ end
33
+
34
+ # Get the cast and crew information for a specific movie id.
35
+ #
36
+ # @see http://docs.themoviedb.apiary.io/#reference/movies/moviecredits
37
+ #
38
+ # @param [String] id the movie id
39
+ #
40
+ # @return [Hashie::Mash] build response
41
+ #
42
+ # @example Get the movie credits api response
43
+ # TmdbRexx::Client.movie_credits("movie-id")
44
+ def movie_credits(movie_id, options = {})
45
+ get([RESOURCE, movie_id, "credits"].join("/"), options)
46
+ end
47
+
48
+ # Get the images (posters and backdrops) for a specific movie id.
49
+ #
50
+ # @see http://docs.themoviedb.apiary.io/#reference/movies/movieimages
51
+ #
52
+ # @param [String] id the movie id
53
+ #
54
+ # @return [Hashie::Mash] build response
55
+ #
56
+ # @example Get the movie images api response
57
+ # TmdbRexx::Client.movie_images("movie-id")
58
+ def movie_images(movie_id, options = {})
59
+ get([RESOURCE, movie_id, "images"].join("/"), options)
60
+ end
61
+
62
+ # Get the backdrops for a specific movie id.
63
+ # This is a convenience method base on .movie_images
64
+ #
65
+ # @param [String] id the movie id
66
+ #
67
+ # @return [Hashie::Mash] build response
68
+ #
69
+ # @example Get the movie backdrops
70
+ # TmdbRexx::Client.movie_backdrops("movie-id")
71
+ def movie_backdrops(movie_id, options = {})
72
+ get([RESOURCE, movie_id, "images"].join("/"), options).backdrops
73
+ end
74
+
75
+ # Get the posters for a specific movie id.
76
+ # This is a convenience method base on .movie_images
77
+ #
78
+ # @param [String] id the movie id
79
+ #
80
+ # @return [Hashie::Mash] build response
81
+ #
82
+ # @example Get the movie posters
83
+ # TmdbRexx::Client.movie_posters("movie-id")
84
+ def movie_posters(movie_id, options = {})
85
+ get([RESOURCE, movie_id, "images"].join("/"), options).posters
86
+ end
87
+
88
+ # Get the plot keywords for a specific movie id.
89
+ #
90
+ # @see http://docs.themoviedb.apiary.io/#reference/movies/movieidkeywords
91
+ #
92
+ # @param [String] id the movie id
93
+ #
94
+ # @return [Hashie::Mash] build response
95
+ #
96
+ # @example Get the movie keywords
97
+ # TmdbRexx::Client.movie_keywords("movie-id")
98
+ def movie_keywords(movie_id, options = {})
99
+ get([RESOURCE, movie_id, "keywords"].join("/"), options)
100
+ end
101
+
102
+ # Get the release date and certification information by country for a specific movie id.
103
+ #
104
+ # @see http://docs.themoviedb.apiary.io/#reference/movies/movieidreleases
105
+ #
106
+ # @param [String] id the movie id
107
+ #
108
+ # @return [Hashie::Mash] build response
109
+ #
110
+ # @example Get the movie releases
111
+ # TmdbRexx::Client.movie_releases("movie-id")
112
+ def movie_releases(movie_id, options = {})
113
+ get([RESOURCE, movie_id, "releases"].join("/"), options)
114
+ end
115
+
116
+ # Get the videos (trailers, teasers, clips, etc...) for a specific movie id.
117
+ #
118
+ # @see http://docs.themoviedb.apiary.io/#reference/movies/movieidvideos
119
+ #
120
+ # @param [String] id the movie id
121
+ #
122
+ # @return [Hashie::Mash] build response
123
+ #
124
+ # @example Get the movie videos
125
+ # TmdbRexx::Client.movie_videos("movie-id")
126
+ def movie_videos(movie_id, options = {})
127
+ get([RESOURCE, movie_id, "videos"].join("/"), options)
128
+ end
129
+
130
+ # Get the translations for a specific movie id.
131
+ #
132
+ # @see http://docs.themoviedb.apiary.io/#reference/movies/movieidtranslations
133
+ #
134
+ # @param [String] id the movie id
135
+ #
136
+ # @return [Hashie::Mash] build response
137
+ #
138
+ # @example Get the movie translations
139
+ # TmdbRexx::Client.movie_translations("movie-id")
140
+ def movie_translations(movie_id, options = {})
141
+ get([RESOURCE, movie_id, "translations"].join("/"), options)
142
+ end
143
+
144
+ # Get the similar movies for a specific movie id.
145
+ #
146
+ # @see http://docs.themoviedb.apiary.io/#reference/movies/movieidsimilar
147
+ #
148
+ # @param [String] id the movie id
149
+ #
150
+ # @return [Hashie::Mash] build response
151
+ #
152
+ # @example Get the similar movies
153
+ # TmdbRexx::Client.similar_movies("movie-id")
154
+ def similar_movies(movie_id, options = {})
155
+ get([RESOURCE, movie_id, "similar"].join("/"), options)
156
+ end
157
+
158
+ # Get the reviews for a particular movie id.
159
+ #
160
+ # @see http://docs.themoviedb.apiary.io/#reference/movies/movieidreviews
161
+ #
162
+ # @param [String] id the movie id
163
+ #
164
+ # @return [Hashie::Mash] build response
165
+ #
166
+ # @example Get the movie reviews
167
+ # TmdbRexx::Client.movie_reviews("movie-id")
168
+ def movie_reviews(movie_id, options = {})
169
+ get([RESOURCE, movie_id, "reviews"].join("/"), options)
170
+ end
171
+
172
+ # Get the lists that the movie belongs to.
173
+ #
174
+ # @see http://docs.themoviedb.apiary.io/#reference/movies/movieidlists
175
+ #
176
+ # @param [String] id the movie id
177
+ #
178
+ # @return [Hashie::Mash] build response
179
+ #
180
+ # @example Get the movie lists
181
+ # TmdbRexx::Client.movie_lists("movie-id")
182
+ def movie_lists(movie_id, options = {})
183
+ get([RESOURCE, movie_id, "lists"].join("/"), options)
184
+ end
185
+
186
+ # Get the changes made to the movie.
187
+ #
188
+ # @see http://docs.themoviedb.apiary.io/#reference/movies/movieidchanges
189
+ #
190
+ # @param [String] id the movie id
191
+ #
192
+ # @return [Hashie::Mash] build response
193
+ #
194
+ # @example Get the movie changes
195
+ # TmdbRexx::Client.movie_changes("movie-id")
196
+ def movie_changes(movie_id, options = {})
197
+ get([RESOURCE, movie_id, "changes"].join("/"), options)
198
+ end
199
+
200
+ # Get the latest movie id.
201
+ #
202
+ # @see http://docs.themoviedb.apiary.io/#reference/movies/movieidlatest
203
+ #
204
+ # @param [String] id the movie id
205
+ #
206
+ # @return [Hashie::Mash] build response
207
+ #
208
+ # @example Get the movie latest
209
+ # TmdbRexx::Client.latest_movie("movie-id")
210
+ def latest_movie(movie_id, options = {})
211
+ get([RESOURCE, "latest"].join("/"), options)
212
+ end
213
+
214
+ # Get the list of movies playing that have been, or are being released this week. This list refreshes every day.
215
+ #
216
+ # @see http://docs.themoviedb.apiary.io/#reference/movies/movieidnow_playing
217
+ #
218
+ # @param [String] id the movie id
219
+ #
220
+ # @return [Hashie::Mash] build response
221
+ #
222
+ # @example Get the movies now_playing
223
+ # TmdbRexx::Client.now_playing("movie-id")
224
+ def now_playing(movie_id, options = {})
225
+ get([RESOURCE, "now_playing"].join("/"), options)
226
+ end
227
+
228
+ # Get the list of popular movies on The Movie Database. This list refreshes every day.
229
+ #
230
+ # @see http://docs.themoviedb.apiary.io/#reference/movies/movieidpopular
231
+ #
232
+ # @param [String] id the movie id
233
+ #
234
+ # @return [Hashie::Mash] build response
235
+ #
236
+ # @example Get the movies popular_movies
237
+ # TmdbRexx::Client.popular_movies("movie-id")
238
+ def popular_movies(movie_id, options = {})
239
+ get([RESOURCE, "popular"].join("/"), options)
240
+ end
241
+
242
+ # Get the list of top_rated movies on The Movie Database. This list refreshes every day.
243
+ #
244
+ # @see http://docs.themoviedb.apiary.io/#reference/movies/movieidtoprated
245
+ #
246
+ # @param [String] id the movie id
247
+ #
248
+ # @return [Hashie::Mash] build response
249
+ #
250
+ # @example Get the movies top rated
251
+ # TmdbRexx::Client.top_rated_movies("movie-id")
252
+ def top_rated_movies(movie_id, options = {})
253
+ get([RESOURCE, "top_rated"].join("/"), options)
254
+ end
255
+
256
+ # Get the list of movies playing that have been, or are being released this week. This list refreshes every day.
257
+ #
258
+ # @see http://docs.themoviedb.apiary.io/#reference/movies/movieidupcoming
259
+ #
260
+ # @param [String] id the movie id
261
+ #
262
+ # @return [Hashie::Mash] build response
263
+ #
264
+ # @example Get the movies upcoming
265
+ # TmdbRexx::Client.upcoming("movie-id")
266
+ def upcoming(movie_id, options = {})
267
+ get([RESOURCE, "upcoming"].join("/"), options)
268
+ end
269
+ end
270
+ end
271
+ end
@@ -0,0 +1,23 @@
1
+ module TmdbRexx
2
+ class Client
3
+ module Network
4
+ RESOURCE = "network".freeze
5
+
6
+ # This method is used to retrieve the basic information about a TV
7
+ # network. You can use this ID to search for TV shows with the discover.
8
+ # At this time we don't have much but this will be fleshed out over time.
9
+ #
10
+ # @see http://docs.themoviedb.apiary.io/#reference/networks
11
+ #
12
+ # @param [String] id the network id
13
+ #
14
+ # @return [Hashie::Mash] build response
15
+ #
16
+ # @example Get the network api response
17
+ # TmdbRexx::Client.network("network-id")
18
+ def network(network_id, options = {})
19
+ get([RESOURCE, network_id].join("/"), options)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,21 @@
1
+ module TmdbRexx
2
+ class Client
3
+ module Review
4
+ RESOURCE = "review".freeze
5
+
6
+ # Get the full details of a review by ID.
7
+ #
8
+ # @see http://docs.themoviedb.apiary.io/#reference/reviewid
9
+ #
10
+ # @param [String] id the review id
11
+ #
12
+ # @return [Hashie::Mash] build response
13
+ #
14
+ # @example Get the review api response
15
+ # TmdbRexx::Client.review("review-id")
16
+ def review(review_id, options = {})
17
+ get([RESOURCE, review_id].join("/"), options)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module TmdbRexx
2
+ class Client
3
+ module Timezone
4
+ RESOURCE = "timezones".freeze
5
+
6
+ # Get the list of supported timezones for the API
7
+ # methods that support them.
8
+ #
9
+ # @see
10
+ # http://docs.themoviedb.apiary.io/#reference/movies/timezones
11
+ #
12
+ # @return [Hashie::Mash] response
13
+ #
14
+ # @example Get the timezones api response
15
+ # client.timezones
16
+ def timezones(options = {})
17
+ get([RESOURCE, "list"].join("/"), options)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,55 @@
1
+ # Core
2
+ require 'tmdb_rexx/error'
3
+ require 'tmdb_rexx/connection'
4
+ require 'tmdb_rexx/default'
5
+ require 'tmdb_rexx/request'
6
+ # Client
7
+ require 'tmdb_rexx/client/movie'
8
+ require 'tmdb_rexx/client/certification'
9
+ require 'tmdb_rexx/client/changes'
10
+ require 'tmdb_rexx/client/collection'
11
+ require 'tmdb_rexx/client/company'
12
+ require 'tmdb_rexx/client/credit'
13
+ require 'tmdb_rexx/client/discover'
14
+ require 'tmdb_rexx/client/find'
15
+ require 'tmdb_rexx/client/genre'
16
+ require 'tmdb_rexx/client/job'
17
+ require 'tmdb_rexx/client/keyword'
18
+ require 'tmdb_rexx/client/network'
19
+ require 'tmdb_rexx/client/review'
20
+ require 'tmdb_rexx/client/timezone'
21
+
22
+ module TmdbRexx
23
+ class Client
24
+ # Core
25
+ include TmdbRexx::Connection
26
+ include TmdbRexx::Default
27
+ include TmdbRexx::Request
28
+ # Client
29
+ include TmdbRexx::Client::Movie
30
+ include TmdbRexx::Client::Certification
31
+ include TmdbRexx::Client::Changes
32
+ include TmdbRexx::Client::Collection
33
+ include TmdbRexx::Client::Company
34
+ include TmdbRexx::Client::Credit
35
+ include TmdbRexx::Client::Discover
36
+ include TmdbRexx::Client::Find
37
+ include TmdbRexx::Client::Genre
38
+ include TmdbRexx::Client::Job
39
+ include TmdbRexx::Client::Keyword
40
+ include TmdbRexx::Client::Network
41
+ include TmdbRexx::Client::Review
42
+ include TmdbRexx::Client::Timezone
43
+
44
+ def initialize(options = {})
45
+ TmdbRexx::Configuration.keys.each do |key|
46
+ instance_variable_set(
47
+ :"@#{key}", options[key] ||
48
+ TmdbRexx.instance_variable_get(:"@#{key}")
49
+ )
50
+ end
51
+
52
+ raise TmdbRexx::MissingAPIKeyError if @api_key.nil? || @api_key.empty?
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,38 @@
1
+ module TmdbRexx
2
+ module Configuration
3
+ VALID_OPTION_KEYS = %i(api_key base_url version include_adult language).freeze
4
+
5
+ #attr_accessor(*VALID_OPTION_KEYS)
6
+ attr_accessor :api_key, :base_url, :version, :include_adult, :language
7
+
8
+ class << self
9
+ def keys
10
+ @keys ||= VALID_OPTION_KEYS
11
+ end
12
+ end
13
+
14
+ def configure
15
+ yield self
16
+ end
17
+
18
+ # Reset configuration options to default values
19
+ def reset!
20
+ TmdbRexx::Configuration.keys.each do |key|
21
+ instance_variable_set(:"@#{key}", TmdbRexx::Default.options[key])
22
+ end
23
+ self
24
+ end
25
+
26
+ def respond_to?(method, include_private=false)
27
+ new.respond_to?(method, include_private) || super(method, include_private)
28
+ end
29
+
30
+ private
31
+
32
+ def options
33
+ Hash[TmdbRexx::Configuration.keys.map{|key|
34
+ [key, instance_variable_get(:"@#{key}")]
35
+ }]
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,15 @@
1
+ require "json"
2
+ require "faraday_middleware"
3
+
4
+ module TmdbRexx
5
+ module Connection
6
+ def connection(options = {})
7
+ Faraday.new(options) do |build|
8
+ build.request :url_encoded
9
+ build.response :mashify
10
+ build.response :json, :content_type => /\bjson$/
11
+ build.adapter Faraday.default_adapter
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,53 @@
1
+ module TmdbRexx
2
+ # Default configuration for {Client}
3
+ module Default
4
+ BASE_URL = "https://api.themoviedb.org".freeze
5
+ VERSION = 3
6
+ INCLUDE_ADULT = false
7
+ LANGUAGE = "en".freeze
8
+
9
+ # Default API endpoint built from the base url and version
10
+ # @return [String]
11
+ def api_endpoint
12
+ "#{@base_url}/#{@version}"
13
+ end
14
+
15
+ class << self
16
+ # Configuration options
17
+ # @return [Hash]
18
+ def options
19
+ Hash[TmdbRexx::Configuration.keys.map{|key| [key, send(key)]}]
20
+ end
21
+
22
+ # Default api_key key from ENV
23
+ # @return [String]
24
+ def api_key
25
+ ENV['MOVIEREXX_API_KEY'] || @api_key
26
+ end
27
+
28
+ # Default API base_url from ENV or {API_BASE_URL}
29
+ # @return [String]
30
+ def base_url
31
+ ENV['MOVIEREXX_BASE_URL'] || @base_url || BASE_URL
32
+ end
33
+
34
+ # Default API version from ENV or {API_VERSION}
35
+ # @return [String]
36
+ def version
37
+ ENV['MOVIEREXX_VERSION'] || @version || VERSION
38
+ end
39
+
40
+ # Default include_adult from ENV or {INCLUDE_ADULT}
41
+ # @return [String]
42
+ def include_adult
43
+ ENV['MOVIEREXX_INCLUDE_ADULT'] || @include_adult || INCLUDE_ADULT
44
+ end
45
+
46
+ # Default language from ENV or {LANGUAGE}
47
+ # @return [String]
48
+ def language
49
+ ENV['MOVIEREXX_LANGUAGE'] || @language || LANGUAGE
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,6 @@
1
+ module TmdbRexx
2
+ class InvalidAPIKeyError < StandardError; end
3
+ class MissingAPIKeyError < StandardError; end
4
+ class InvalidTypeError < StandardError; end
5
+ class InvalidExternalSourceError < StandardError; end
6
+ end
@@ -0,0 +1,39 @@
1
+ module TmdbRexx
2
+ module Request
3
+ def get(path, options = {})
4
+ request(:get, path, options)
5
+ end
6
+
7
+ def post(path, options = {})
8
+ request(:post, path, options)
9
+ end
10
+
11
+ def put(path, options = {})
12
+ request(:put, path, options)
13
+ end
14
+
15
+ def delete(path, options = {})
16
+ request(:delete, path, options)
17
+ end
18
+
19
+ def last_response
20
+ @last_response if defined? @last_response
21
+ end
22
+
23
+ private
24
+ def request(method, path, options = {})
25
+ url = options.delete(:api_endpoint) || api_endpoint
26
+
27
+ connection_options = {
28
+ :url => url
29
+ }
30
+
31
+ @last_response = response = connection(connection_options).send(method) do |request|
32
+ request.url(path, options)
33
+ request.params['api_key'] = @api_key
34
+ end
35
+
36
+ response.body
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module TmdbRexx
2
+ VERSION = "0.1.0"
3
+ end
data/lib/tmdb_rexx.rb ADDED
@@ -0,0 +1,15 @@
1
+ require "tmdb_rexx/version"
2
+ require "tmdb_rexx/configuration"
3
+ require "tmdb_rexx/client"
4
+
5
+ module TmdbRexx
6
+ class << self
7
+ include TmdbRexx::Configuration
8
+
9
+ # Alias for TmdbRexx::Client.new
10
+ # @return [TmdbRexx::Client]
11
+ def new(options = {})
12
+ TmdbRexx::Client.new(options)
13
+ end
14
+ end
15
+ end
data/tmdb_rexx.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tmdb_rexx/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tmdb_rexx"
8
+ spec.version = TmdbRexx::VERSION
9
+ spec.authors = ["Jason Truluck"]
10
+ spec.email = ["jason.truluck@gmail.com"]
11
+
12
+ spec.summary = %q{Ruby wrapper for TMDB API}
13
+ spec.description = %q{Ruby wrapper for TMDB API}
14
+ spec.homepage = "https://github.com/FilmRexx/tmdb_rexx"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.9"
23
+ spec.add_dependency "faraday", "~> 0.9"
24
+ spec.add_dependency "faraday_middleware", "~> 0.10"
25
+ spec.add_dependency "hashie", "~> 3.4"
26
+ spec.add_dependency 'multi_json', "~> 1.11"
27
+ spec.add_development_dependency "rspec", "~> 3.3"
28
+ spec.add_development_dependency "json_spec", "~> 1.1"
29
+ spec.add_development_dependency "rake", "~> 10"
30
+ spec.add_development_dependency "vcr", "~> 2.9"
31
+ spec.add_development_dependency "webmock", "~> 1.21"
32
+ spec.add_development_dependency "pry", "~> 0.10"
33
+ spec.add_development_dependency "codeclimate-test-reporter", "~> 0.4"
34
+ end