tmdb-api 0.0.2

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.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +1 -0
  4. data/Gemfile +3 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +148 -0
  7. data/Rakefile +1 -0
  8. data/lib/tmdb.rb +18 -0
  9. data/lib/tmdb/changes.rb +22 -0
  10. data/lib/tmdb/fetcher.rb +30 -0
  11. data/lib/tmdb/movie.rb +105 -0
  12. data/lib/tmdb/searchable.rb +33 -0
  13. data/lib/tmdb/version.rb +3 -0
  14. data/spec/fixtures/alternative_titles.json +41 -0
  15. data/spec/fixtures/alternative_titles_by_country.json +9 -0
  16. data/spec/fixtures/changes/movie_changes.json +407 -0
  17. data/spec/fixtures/changes/movie_changes_page_2.json +407 -0
  18. data/spec/fixtures/changes/movie_changes_start_date.json +407 -0
  19. data/spec/fixtures/find_movie.json +19 -0
  20. data/spec/fixtures/find_movie_by_id.json +85 -0
  21. data/spec/fixtures/find_movie_by_id_and_language.json +66 -0
  22. data/spec/fixtures/invalid_id.json +4 -0
  23. data/spec/fixtures/movie/upcoming.json +251 -0
  24. data/spec/fixtures/movie/upcoming_page_2.json +251 -0
  25. data/spec/fixtures/movie_images.json +214 -0
  26. data/spec/fixtures/movie_images_by_language.json +42 -0
  27. data/spec/fixtures/movie_keywords.json +33 -0
  28. data/spec/fixtures/movie_releases.json +35 -0
  29. data/spec/fixtures/no_results.json +6 -0
  30. data/spec/fixtures/search_movie_by_name.json +91 -0
  31. data/spec/fixtures/search_movie_by_name_and_adult_filter.json +55 -0
  32. data/spec/fixtures/search_movie_by_name_and_page.json +247 -0
  33. data/spec/fixtures/search_movie_by_name_and_year.json +19 -0
  34. data/spec/spec_helper.rb +19 -0
  35. data/spec/support/stubber.rb +33 -0
  36. data/spec/tmdb/changes_spec.rb +52 -0
  37. data/spec/tmdb/movie/upcoming_spec.rb +28 -0
  38. data/spec/tmdb/movie_spec.rb +473 -0
  39. data/spec/tmdb/searchable_spec.rb +9 -0
  40. data/spec/tmdb/tmdb_spec.rb +13 -0
  41. data/tmdb.gemspec +28 -0
  42. metadata +195 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 822a6f146cbfddcbe6007e076c8cdd4be137514d
4
+ data.tar.gz: 1b6c94c5562335ba4d604306c61d2c0ec205ff55
5
+ SHA512:
6
+ metadata.gz: 950acc07d687cf84826b5cf4f71156ecef0431912645e4e660c0daea875762070e00981b034bde80d7d7d855805888003090b878fc0027ec54619c04b3e65180
7
+ data.tar.gz: c597a1d67a25cfc1cf9c252a06a536cf82973a0cd95cc48ed6af6aca7b2fbe457a40ea2941c44c8a5b6f849588e493baa8b3e815d039c4c6d793ed442848d4f4
@@ -0,0 +1,17 @@
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
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour --format doc
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Andriel Nuernberg
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,148 @@
1
+ # The Movie Database API v3
2
+
3
+ Ruby wrapper for the The Movie Database API.
4
+
5
+ This wrapper uses the last version of TMDb API.
6
+
7
+ More info about the API you can see here: [http://docs.themoviedb.apiary.io/](http://docs.themoviedb.apiary.io).
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'tmdb-api'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install tmdb
22
+
23
+ ## Usage
24
+
25
+ ### API Key
26
+ First of all, you need set your API Key provided by TMDb.
27
+
28
+ ```ruby
29
+ TMDb.api_key = '56565958363476674e5e63643c787867'
30
+ ```
31
+
32
+ ### Find a movie
33
+ Get the basic movie information for a specific movie ID.
34
+
35
+ ```ruby
36
+ TMDB::Movie.find(24)
37
+ # => #<TMDb::Movie:0x007f99 @id=24, @title="Kill Bill: Vol. 1", @imdb_id="tt0266697" ... >
38
+
39
+ TMDB::Movie.find(603, language: 'pt')
40
+ # => #<TMDb::Movie:0x007f99 @id=603, @title="The Matrix", @imdb_id="tt0133093" ... >
41
+ ```
42
+
43
+ ### Search movie
44
+ Search for movies by title.
45
+
46
+ ```ruby
47
+ TMDb::Movie.search('Forrest')
48
+ # => [#<TMDb::Movie:0x007f92 @id=13, @title="Forrest Gump", ...>,
49
+ # #<TMDb::Movie:0x007f93 @id=711, @title="Finding Forrester", ...>,
50
+ # #<TMDb::Movie:0x007f94 ... >, ...]
51
+
52
+ TMDb::Movie.search('wall e', year: 2003)
53
+ # => [#<TMDb::Movie:0x007f92 @id=10681, @original_title="WALL·E", ...>]
54
+ ```
55
+ You can filter the serch with the following options: _page_, _language_,
56
+ _include_adult_, and _year_.
57
+
58
+ ### Alternative titles
59
+ Get the alternative titles for a specific movie ID.
60
+
61
+ ```ruby
62
+ movie = TMDB::Movie.find(598)
63
+
64
+ movie.alternative_titles
65
+ # => [{"iso_3166_1"=>"RU", "title"=>"Город бога"},
66
+ # {"iso_3166_1"=>"IT", "title"=>"City of God - La città di Dio"},
67
+ # {"iso_3166_1"=>"BR", "title"=>"Cidade de Deus"},
68
+ # {"iso_3166_1"=>"FR", "title"=>"La cité de Dieu"},
69
+ # {"iso_3166_1"=>"DE", "title"=>"City of God"},
70
+ # {"iso_3166_1"=>"CN", "title"=>"上帝之城"},
71
+ # {"iso_3166_1"=>"HK", "title"=>"无主之城"},
72
+ # {"iso_3166_1"=>"US", "title"=>"City of God"},
73
+ # {"iso_3166_1"=>"TW", "title"=>"無法無天"}]
74
+
75
+ movie.alternative_titles(country: 'br')
76
+ # => [{"iso_3166_1"=>"BR", "title"=>"Cidade de Deus"}]
77
+ ```
78
+
79
+ ### Images
80
+ Get the images (posters and backdrops) for a specific movie ID.
81
+
82
+ ```ruby
83
+ TMDb::Movie.find(598).images
84
+ # => {"id"=>598,
85
+ # "backdrops"=> [
86
+ # {
87
+ # "file_path"=>"/hSaH9tt67bozo9K50sbH0s4YjEc.jpg",
88
+ # "width"=>1532,
89
+ # "height"=>862,
90
+ # "iso_639_1"=>nil,
91
+ # "aspect_ratio"=>1.78,
92
+ # "vote_average"=>5.4421768707483,
93
+ # "vote_count"=>7
94
+ # },
95
+ # {
96
+ # "file_path"=>"/k4BAPrE5WkNLvpsPsiMfu8W4Zyi.jpg",
97
+ # "width"=>1920,
98
+ # "height"=>1080,
99
+ # "iso_639_1"=>nil,
100
+ # "aspect_ratio"=>1.78,
101
+ # "vote_average"=>5.399159663865546,
102
+ # "vote_count"=>5
103
+ # },
104
+ # {
105
+ # ...
106
+ # }
107
+ # ]}
108
+
109
+ TMDb::Movie.find(598).images(language: 'pt')
110
+ ```
111
+
112
+ ### Movie object
113
+
114
+ ```ruby
115
+ movie = TMDb::Movie.find(27205)
116
+
117
+ movie.id # => 27205
118
+ movie.adult # => false
119
+ movie.backdrop_path # => /s2bT29y0ngXxxu2IA8AOzzXTRhd.jpg
120
+ movie.belongs_to_collection # => {"id"=>179836, "name"=>"Inception Collection", "poster_path"=>"/7OtEJQjBhxNug5TyY0ny4ttuKdg.jpg", "backdrop_path"=>"/73WuAqGGCv3F8Rwy5FTnYlji6IS.jpg"}
121
+ movie.budget # => 160000000
122
+ movie.genres # => [{"id"=>28, "name"=>"Action"}, {"id"=>12, "name"=>"Adventure"}, {"id"=>9648, "name"=>"Mystery"}, {"id"=>878, "name"=>"Science Fiction"}, {"id"=>53, "name"=>"Thriller"}]
123
+ movie.homepage # => http://inceptionmovie.warnerbros.com/
124
+ movie.imdb_id # => tt1375666
125
+ movie.original_title # => Inception
126
+ movie.overview # => Dom Cobb, a skilled thief who commits corporate espionage by infiltrating the subconscious of his targets is offered a chance to regain his old life as payment for a task considered to be impossible: "inception", the implantation of another person's idea into a target's subconscious.
127
+ movie.popularity # => 8.908730111185815
128
+ movie.poster_path # => /tAXARVreJnWfoANIHASmgYk4SB0.jpg
129
+ movie.production_companies # => [{"name"=>"Warner Bros. Pictures", "id"=>174}, {"name"=>"Syncopy", "id"=>9996}]
130
+ movie.runtime # => 148
131
+ movie.production_countries # => [{"iso_3166_1"=>"US", "name"=>"United States of America"}]
132
+ movie.release_date # => 2010-07-16
133
+ movie.revenue # => 825532764
134
+ movie.spoken_languages # => [{"iso_639_1"=>"en", "name"=>"English"}, {"iso_639_1"=>"ja", "name"=>"日本語"}, {"iso_639_1"=>"fr", "name"=>"Français"}]
135
+ movie.status # => Released
136
+ movie.tagline # => Your mind is the scene of the crime.
137
+ movie.title # => Inception
138
+ movie.vote_average # => 8.2
139
+ movie.vote_count # => 497
140
+ ```
141
+
142
+ ## Contributing
143
+
144
+ 1. Fork it
145
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
146
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
147
+ 4. Push to the branch (`git push origin my-new-feature`)
148
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,18 @@
1
+ require "httparty"
2
+ require "json"
3
+
4
+ require "tmdb/fetcher"
5
+ require "tmdb/searchable"
6
+ require "tmdb/movie"
7
+ require "tmdb/changes"
8
+ require "tmdb/version"
9
+
10
+ module TMDb
11
+ class << self
12
+ # Set the API Key that will be use to fetch the data.
13
+ attr_accessor :api_key
14
+
15
+ # Set the default language of the fetched data.
16
+ attr_accessor :default_language
17
+ end
18
+ end
@@ -0,0 +1,22 @@
1
+ module TMDb
2
+ class Changes
3
+ # Get a list of movie ids that have been edited. By default we show the
4
+ # last 24 hours and only 100 items per page. The maximum number of days
5
+ # that can be returned in a single request is 14.
6
+ #
7
+ # options - The hash options used to filter the search (default: {}):
8
+ # :page - Page.
9
+ # :start_date - Start date (YYYY-MM-DD).
10
+ # :end_date - End date (YYYY-MM-DD).
11
+ #
12
+ # Examples
13
+ #
14
+ # TMDb::Movie.find(24)
15
+ #
16
+ # TMDb::Movie.find(32123, language: 'pt')
17
+ #
18
+ def self.movies(options = {})
19
+ Fetcher::get('/movie/changes', options)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,30 @@
1
+ class APIKeyNotSet < StandardError; end
2
+
3
+ module TMDb
4
+ module Fetcher
5
+ include HTTParty
6
+ base_uri 'http://api.themoviedb.org/3/'
7
+ headers 'Accept' => 'application/json'
8
+ format :json
9
+
10
+ def self.get(url, options = {})
11
+ verify_api!
12
+
13
+ options.merge!(api_key: TMDb.api_key)
14
+
15
+ result = super(url, query: options)
16
+
17
+ if result.success?
18
+ result
19
+ else
20
+ raise ArgumentError, JSON.parse(result.response.body)['status_message']
21
+ end
22
+ end
23
+
24
+ def self.verify_api!
25
+ if TMDb.api_key.nil? || TMDb.api_key.empty?
26
+ raise ArgumentError, 'TMDb.api_key must be set before using the API'
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,105 @@
1
+ module TMDb
2
+ class Movie
3
+ extend Searchable
4
+
5
+ # Movie attributes
6
+ ATTRIBUTES = :id, :adult, :backdrop_path, :belongs_to_collection, :budget,
7
+ :genres, :homepage, :imdb_id, :original_title, :overview,
8
+ :popularity, :poster_path, :production_companies, :runtime,
9
+ :production_countries, :release_date, :revenue, :spoken_languages,
10
+ :status, :tagline, :title, :vote_average, :vote_count
11
+
12
+ attr_accessor *ATTRIBUTES
13
+
14
+ def initialize(attrs)
15
+ ATTRIBUTES.each { |attr| instance_variable_set("@#{attr}", attrs[attr.to_s]) }
16
+ end
17
+
18
+ # Get the basic movie information for a specific movie ID.
19
+ #
20
+ # id - Movie ID.
21
+ # options - The hash options used to filter the search (default: {}):
22
+ # :language - Language of the result data (ISO 639-1 codes) (default: en).
23
+ #
24
+ # Examples
25
+ #
26
+ # TMDb::Movie.find(24)
27
+ #
28
+ # TMDb::Movie.find(32123, language: 'pt')
29
+ #
30
+ def self.find(id, options = {})
31
+ new Fetcher::get("/movie/#{id}", options)
32
+ end
33
+
34
+ # Get the alternative titles for a specific movie ID.
35
+ #
36
+ # options - The hash options used to filter the search (default: {}):
37
+ # :country - Titles for a specific country (ISO 3166-1 code).
38
+ #
39
+ # Examples
40
+ #
41
+ # TMDb::Movie.alternative_titles(598, country: 'br')
42
+ #
43
+ def self.alternative_titles(id, options = {})
44
+ result = Fetcher::get("/movie/#{id}/alternative_titles", options)
45
+ result['titles']
46
+ end
47
+
48
+ # Get the images (posters and backdrops) for a specific movie id.
49
+ #
50
+ # options - The hash options used to filter the search (default: {}):
51
+ # :language - Images of a specific language (ISO 639-1 code).
52
+ #
53
+ # Examples
54
+ #
55
+ # TMDb::Movie.find(598).images
56
+ #
57
+ # movie = TMDb::Movie.images(598, language: 'pt')
58
+ #
59
+ def self.images(id, options = {})
60
+ Fetcher::get("/movie/#{id}/images", options)
61
+ end
62
+
63
+ # Get the plot keywords for a specific movie id.
64
+ #
65
+ # options - The hash options used to filter the search (default: {}):
66
+ # :language - Images of a specific language (ISO 639-1 code).
67
+ #
68
+ # Examples
69
+ #
70
+ # TMDb::Movie.keywords(331, language: pt)
71
+ #
72
+ def self.keywords(id, options = {})
73
+ result = Fetcher::get("/movie/#{id}/keywords", options)
74
+ result['keywords']
75
+ end
76
+
77
+ # Get the release date by country for a specific movie id.
78
+ #
79
+ # Examples
80
+ #
81
+ # TMDb::Movie.releases(8711)
82
+ #
83
+ def self.releases(id)
84
+ result = Fetcher::get("/movie/#{id}/releases")
85
+ result['countries']
86
+ end
87
+
88
+ # Get the list of upcoming movies. This list refreshes every day.
89
+ # The maximum number of items this list will include is 100.
90
+ #
91
+ # options - The hash options used to filter the search (default: {}):
92
+ # :page - Page.
93
+ # :language - Images of a specific language (ISO 639-1 code).
94
+ #
95
+ # Examples
96
+ #
97
+ # TMDb::Movie.upcoming
98
+ # TMDb::Movie.upcoming(page: 3, language: 'pt')
99
+ #
100
+ def self.upcoming(options = {})
101
+ response = Fetcher::get('/movie/upcoming', options)
102
+ response['results'].map { |movie| new(movie) }
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,33 @@
1
+ require "cgi"
2
+
3
+ module TMDb
4
+ module Searchable
5
+ # Search movies.
6
+ #
7
+ # query - Query string that will be matched with the movie name.
8
+ # options - The hash options used to filter the search (default: {}):
9
+ # :page - The current page of results.
10
+ # :language - Language of the result data (ISO 639-1 codes) (default: en).
11
+ # :include_adult - Toggle the inclusion of adult titles. Expected value is: true or false.
12
+ # :year - Filter results to only include this value.
13
+ #
14
+ # Examples
15
+ #
16
+ # TMDb::Movie.search('Iron Man')
17
+ #
18
+ # TMDb::Movie.search('The Matrix', year: 1999)
19
+ #
20
+ # TMDb::Movie.search('Forret Gump', language: 'pt', year: 1994)
21
+ def search(query, options = {})
22
+ # require "pry"; binding.pry
23
+ options.merge!(query: query)
24
+ result = Fetcher::get("/search/#{resource}", options)
25
+ result['results'].map { |attributes| new(attributes) }
26
+ end
27
+
28
+ # Removes the module part from the expression in the string.
29
+ def resource
30
+ name.split('::').last.downcase || ''
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module TMDb
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,41 @@
1
+ {
2
+ "id": 598,
3
+ "titles": [
4
+ {
5
+ "iso_3166_1": "RU",
6
+ "title": "Город бога"
7
+ },
8
+ {
9
+ "iso_3166_1": "IT",
10
+ "title": "City of God - La città di Dio"
11
+ },
12
+ {
13
+ "iso_3166_1": "BR",
14
+ "title": "Cidade de Deus"
15
+ },
16
+ {
17
+ "iso_3166_1": "FR",
18
+ "title": "La cité de Dieu"
19
+ },
20
+ {
21
+ "iso_3166_1": "DE",
22
+ "title": "City of God"
23
+ },
24
+ {
25
+ "iso_3166_1": "CN",
26
+ "title": "上帝之城"
27
+ },
28
+ {
29
+ "iso_3166_1": "HK",
30
+ "title": "无主之城"
31
+ },
32
+ {
33
+ "iso_3166_1": "US",
34
+ "title": "City of God"
35
+ },
36
+ {
37
+ "iso_3166_1": "TW",
38
+ "title": "無法無天"
39
+ }
40
+ ]
41
+ }