tmdb-api 0.0.2 → 0.0.3

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 (41) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +73 -20
  3. data/lib/{tmdb.rb → tmdb-api.rb} +6 -5
  4. data/lib/tmdb-api/base.rb +43 -0
  5. data/lib/tmdb-api/changes.rb +21 -0
  6. data/lib/tmdb-api/httparty.rb +10 -0
  7. data/lib/{tmdb → tmdb-api}/movie.rb +35 -39
  8. data/lib/{tmdb → tmdb-api}/searchable.rb +12 -10
  9. data/lib/tmdb-api/version.rb +3 -0
  10. data/spec/fixtures/changes/{movie_changes.json → movies.json} +0 -0
  11. data/spec/fixtures/{alternative_titles.json → movie/alternative_titles.json} +0 -0
  12. data/spec/fixtures/{find_movie_by_id.json → movie/find.json} +0 -0
  13. data/spec/fixtures/{movie_images.json → movie/images.json} +0 -0
  14. data/spec/fixtures/{movie_keywords.json → movie/keywords.json} +0 -0
  15. data/spec/fixtures/{movie_releases.json → movie/releases.json} +0 -0
  16. data/spec/spec_helper.rb +1 -1
  17. data/spec/tmdb-api/change_spec.rb +26 -0
  18. data/spec/tmdb-api/movie_spec.rb +312 -0
  19. data/spec/tmdb-api/searchable_spec.rb +33 -0
  20. data/spec/{tmdb → tmdb-api}/tmdb_spec.rb +0 -0
  21. data/{tmdb.gemspec → tmdb-api.gemspec} +4 -4
  22. metadata +34 -58
  23. data/lib/tmdb/changes.rb +0 -22
  24. data/lib/tmdb/fetcher.rb +0 -30
  25. data/lib/tmdb/version.rb +0 -3
  26. data/spec/fixtures/alternative_titles_by_country.json +0 -9
  27. data/spec/fixtures/changes/movie_changes_page_2.json +0 -407
  28. data/spec/fixtures/changes/movie_changes_start_date.json +0 -407
  29. data/spec/fixtures/find_movie.json +0 -19
  30. data/spec/fixtures/find_movie_by_id_and_language.json +0 -66
  31. data/spec/fixtures/invalid_id.json +0 -4
  32. data/spec/fixtures/movie/upcoming_page_2.json +0 -251
  33. data/spec/fixtures/movie_images_by_language.json +0 -42
  34. data/spec/fixtures/no_results.json +0 -6
  35. data/spec/fixtures/search_movie_by_name_and_adult_filter.json +0 -55
  36. data/spec/fixtures/search_movie_by_name_and_page.json +0 -247
  37. data/spec/fixtures/search_movie_by_name_and_year.json +0 -19
  38. data/spec/tmdb/changes_spec.rb +0 -52
  39. data/spec/tmdb/movie/upcoming_spec.rb +0 -28
  40. data/spec/tmdb/movie_spec.rb +0 -473
  41. data/spec/tmdb/searchable_spec.rb +0 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 822a6f146cbfddcbe6007e076c8cdd4be137514d
4
- data.tar.gz: 1b6c94c5562335ba4d604306c61d2c0ec205ff55
3
+ metadata.gz: c76aa958ad9a98caf296205a2502e1e1c2ad5fad
4
+ data.tar.gz: 89d617732b3e977403147bc352e085c9ca312e4d
5
5
  SHA512:
6
- metadata.gz: 950acc07d687cf84826b5cf4f71156ecef0431912645e4e660c0daea875762070e00981b034bde80d7d7d855805888003090b878fc0027ec54619c04b3e65180
7
- data.tar.gz: c597a1d67a25cfc1cf9c252a06a536cf82973a0cd95cc48ed6af6aca7b2fbe457a40ea2941c44c8a5b6f849588e493baa8b3e815d039c4c6d793ed442848d4f4
6
+ metadata.gz: cc125c9dcbf62d451fdf3299a5596da0d263ccd4e862cc81a4aefb1c66c2ee526544141ed07be182de0a1139ae5389c751f9b7a53ac24a9a73fb5d84a9f8af9d
7
+ data.tar.gz: ae14ee8e385273f5ac9a90854e23870867eeb060251ae8b07d2bd1caea927ee46666a8d6aa379235c2c07e5dff0955d73570f1b7208d39f0e473a3b324f53c5d
data/README.md CHANGED
@@ -1,10 +1,8 @@
1
- # The Movie Database API v3
1
+ # The Movie Database API
2
2
 
3
- Ruby wrapper for the The Movie Database API.
3
+ A simple Ruby wrapper for the The Movie Database API v3.
4
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).
5
+ About the TMDb API documentation and everything else you can se here: [http://docs.themoviedb.apiary.io/](http://docs.themoviedb.apiary.io).
8
6
 
9
7
  ## Installation
10
8
 
@@ -14,23 +12,24 @@ Add this line to your application's Gemfile:
14
12
 
15
13
  And then execute:
16
14
 
17
- $ bundle
15
+ $ bundle install
18
16
 
19
17
  Or install it yourself as:
20
18
 
21
19
  $ gem install tmdb
22
20
 
23
- ## Usage
24
21
 
25
- ### API Key
22
+ ## API Key
26
23
  First of all, you need set your API Key provided by TMDb.
27
24
 
28
25
  ```ruby
29
26
  TMDb.api_key = '56565958363476674e5e63643c787867'
30
27
  ```
31
28
 
32
- ### Find a movie
33
- Get the basic movie information for a specific movie ID.
29
+ ## Usage
30
+
31
+ ### Find a movie by id
32
+ Get the basic movie information for a specific movie id.
34
33
 
35
34
  ```ruby
36
35
  TMDB::Movie.find(24)
@@ -40,7 +39,7 @@ TMDB::Movie.find(603, language: 'pt')
40
39
  # => #<TMDb::Movie:0x007f99 @id=603, @title="The Matrix", @imdb_id="tt0133093" ... >
41
40
  ```
42
41
 
43
- ### Search movie
42
+ ### Search movies
44
43
  Search for movies by title.
45
44
 
46
45
  ```ruby
@@ -52,16 +51,14 @@ TMDb::Movie.search('Forrest')
52
51
  TMDb::Movie.search('wall e', year: 2003)
53
52
  # => [#<TMDb::Movie:0x007f92 @id=10681, @original_title="WALL·E", ...>]
54
53
  ```
55
- You can filter the serch with the following options: _page_, _language_,
56
- _include_adult_, and _year_.
54
+ You also have another options that you can use to filter the search: `:page`,
55
+ `:language`, `:include_adult` and `:year`.
57
56
 
58
57
  ### Alternative titles
59
- Get the alternative titles for a specific movie ID.
58
+ Get the alternative titles for a specific movie id.
60
59
 
61
60
  ```ruby
62
- movie = TMDB::Movie.find(598)
63
-
64
- movie.alternative_titles
61
+ TMDB::Movie.alternative_titles(598)
65
62
  # => [{"iso_3166_1"=>"RU", "title"=>"Город бога"},
66
63
  # {"iso_3166_1"=>"IT", "title"=>"City of God - La città di Dio"},
67
64
  # {"iso_3166_1"=>"BR", "title"=>"Cidade de Deus"},
@@ -77,10 +74,10 @@ movie.alternative_titles(country: 'br')
77
74
  ```
78
75
 
79
76
  ### Images
80
- Get the images (posters and backdrops) for a specific movie ID.
77
+ Get the images (posters and backdrops) for a specific movie id.
81
78
 
82
79
  ```ruby
83
- TMDb::Movie.find(598).images
80
+ TMDb::Movie.images(598)
84
81
  # => {"id"=>598,
85
82
  # "backdrops"=> [
86
83
  # {
@@ -106,7 +103,63 @@ TMDb::Movie.find(598).images
106
103
  # }
107
104
  # ]}
108
105
 
109
- TMDb::Movie.find(598).images(language: 'pt')
106
+ TMDb::Movie.images(598, language: 'pt')
107
+ ```
108
+
109
+ ### Movie keywords
110
+
111
+ Get the plot keywords for a specific movie id.
112
+
113
+ ```ruby
114
+ TMDb::Movie.keywords(68721)
115
+ # => [
116
+ # {"id"=>2651, "name"=>"nanotechnology"},
117
+ # {"id"=>9715, "name"=>"superhero"},
118
+ # {"id"=>180547, "name"=>"marvel cinematic universe"},
119
+ # {"id"=>156792, "name"=>"3d"},
120
+ # {"id"=>156395, "name"=>"imax"},
121
+ # {"id"=>179430, "name"=>"aftercreditsstinger"},
122
+ # {"id"=>10836, "name"=>"third part"}
123
+ # ]
124
+ ```
125
+
126
+ ### Movie releases
127
+
128
+ Get the release date by country for a specific movie id.
129
+
130
+ ```ruby
131
+ TMDb::Movie.releases(68721)
132
+ # => [
133
+ # {"iso_3166_1"=>"US", "certification"=>"PG-13", "release_date"=>"2013-05-03"},
134
+ # {"iso_3166_1"=>"DE", "certification"=>"12", "release_date"=>"2013-04-30"},
135
+ # {"iso_3166_1"=>"FR", "certification"=>"", "release_date"=>"2013-04-24"},
136
+ # {"iso_3166_1"=>"BG", "certification"=>"C", "release_date"=>"2013-04-26"},
137
+ # {"iso_3166_1"=>"NL", "certification"=>"", "release_date"=>"2013-04-24"},
138
+ # {"iso_3166_1"=>"NO", "certification"=>"", "release_date"=>"2013-04-26"},
139
+ # ...,
140
+ # ]
141
+ ```
142
+
143
+ ### Upcoming movies
144
+
145
+ Get the list of upcoming movies. This list refreshes every day.
146
+ The maximum number of items this list will include is 100.
147
+
148
+ ```ruby
149
+ TMDb::Movie.upcoming
150
+ # => [
151
+ # #<TMDb::Movie:0x007fefa4202a10
152
+ # @adult=false,
153
+ # @backdrop_path="/rwibG3yurWQvpjut54nbeiSGhVt.jpg",
154
+ # @id=157375,
155
+ # @original_title="The Lifeguard",
156
+ # @popularity=8.708121262,
157
+ # @poster_path="/xoX6C3mLynwSNRij2tyDT5eVmoc.jpg",
158
+ # @release_date="2013-08-30",
159
+ # @title="The Lifeguard",
160
+ # @vote_average=5.5,
161
+ # @vote_count=3>
162
+ # ]
110
163
  ```
111
164
 
112
165
  ### Movie object
@@ -1,11 +1,12 @@
1
1
  require "httparty"
2
2
  require "json"
3
3
 
4
- require "tmdb/fetcher"
5
- require "tmdb/searchable"
6
- require "tmdb/movie"
7
- require "tmdb/changes"
8
- require "tmdb/version"
4
+ require "tmdb-api/httparty"
5
+ require "tmdb-api/base"
6
+ require "tmdb-api/searchable"
7
+ require "tmdb-api/movie"
8
+ require "tmdb-api/changes"
9
+ require "tmdb-api/version"
9
10
 
10
11
  module TMDb
11
12
  class << self
@@ -0,0 +1,43 @@
1
+ module TMDb
2
+ class Base
3
+ include HTTParty
4
+ base_uri 'http://api.themoviedb.org/3/'
5
+ headers 'Accept' => 'application/json'
6
+ headers 'Content-Type' => 'application/json'
7
+ format :json
8
+
9
+ # Internal: Raises an exception depending on the type of
10
+ # the response.
11
+ #
12
+ # response - Result of a request.
13
+ #
14
+ # Raises an exception.
15
+ def self.bad_response(response)
16
+ if response.class == HTTParty::Response
17
+ raise ArgumentError, response['status_message']
18
+ end
19
+ raise StandardError, 'Unkown error'
20
+ end
21
+
22
+ # Internal: creates a new TMDb::Base object.
23
+ #
24
+ # attributes - Attributes fetched from the API.
25
+ def initialize(attributes = {})
26
+ load(attributes)
27
+ end
28
+
29
+ private
30
+
31
+ # Internal: Sets the attributes to the object.
32
+ #
33
+ # attributes - A hash containing the keys and values to be
34
+ # set in the object.
35
+ #
36
+ # Returns nothing
37
+ def load(attributes)
38
+ attributes.each do |key, value|
39
+ self.instance_variable_set("@#{key}", value)
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,21 @@
1
+ module TMDb
2
+ class Changes < Base
3
+ # Public: Get a list of movie ids that have been edited. By default we
4
+ # show the last 24 hours and only 100 items per page. The maximum number
5
+ # of days 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(68721)
15
+ # TMDb::Movie.find(68721, language: 'pt')
16
+ def self.movies(options = {})
17
+ res = get('/movie/changes', query: options)
18
+ res.success? ? res : bad_response(res)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,10 @@
1
+ module HTTParty
2
+ class Request
3
+ alias_method :original_query_string, :query_string
4
+
5
+ def query_string(uri)
6
+ options[:default_params].merge!(api_key: TMDb.api_key)
7
+ original_query_string(uri)
8
+ end
9
+ end
10
+ end
@@ -1,5 +1,5 @@
1
1
  module TMDb
2
- class Movie
2
+ class Movie < Base
3
3
  extend Searchable
4
4
 
5
5
  # Movie attributes
@@ -9,83 +9,75 @@ module TMDb
9
9
  :production_countries, :release_date, :revenue, :spoken_languages,
10
10
  :status, :tagline, :title, :vote_average, :vote_count
11
11
 
12
- attr_accessor *ATTRIBUTES
12
+ attr_reader *ATTRIBUTES
13
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.
14
+ # Public: Get the basic movie information for a specific movie ID.
19
15
  #
20
- # id - Movie ID.
16
+ # id - The ID of the movie.
21
17
  # options - The hash options used to filter the search (default: {}):
22
- # :language - Language of the result data (ISO 639-1 codes) (default: en).
18
+ # :language - Language of the result data (ISO 639-1 codes)
19
+ # (default: en).
23
20
  #
24
21
  # Examples
25
22
  #
26
- # TMDb::Movie.find(24)
27
- #
28
- # TMDb::Movie.find(32123, language: 'pt')
29
- #
23
+ # TMDb::Movie.find(68721)
24
+ # TMDb::Movie.find(68721, language: 'pt')
30
25
  def self.find(id, options = {})
31
- new Fetcher::get("/movie/#{id}", options)
26
+ res = get("/movie/#{id}", query: options)
27
+ res.success? ? Movie.new(res) : bad_response(res)
32
28
  end
33
29
 
34
- # Get the alternative titles for a specific movie ID.
30
+ # Public: Get the alternative titles for a specific movie ID.
35
31
  #
36
32
  # options - The hash options used to filter the search (default: {}):
37
33
  # :country - Titles for a specific country (ISO 3166-1 code).
38
34
  #
39
35
  # Examples
40
36
  #
41
- # TMDb::Movie.alternative_titles(598, country: 'br')
42
- #
37
+ # TMDb::Movie.alternative_titles(68721, country: 'br')
43
38
  def self.alternative_titles(id, options = {})
44
- result = Fetcher::get("/movie/#{id}/alternative_titles", options)
45
- result['titles']
39
+ res = get("/movie/#{id}/alternative_titles", query: options)
40
+ res.success? ? res['titles'] : bad_response(res)
46
41
  end
47
42
 
48
- # Get the images (posters and backdrops) for a specific movie id.
43
+ # Public: Get the images (posters and backdrops) for a specific movie ID.
49
44
  #
50
45
  # options - The hash options used to filter the search (default: {}):
51
46
  # :language - Images of a specific language (ISO 639-1 code).
52
47
  #
53
48
  # Examples
54
49
  #
55
- # TMDb::Movie.find(598).images
56
- #
57
- # movie = TMDb::Movie.images(598, language: 'pt')
58
- #
50
+ # TMDb::Movie.find(68721).images
51
+ # TMDb::Movie.images(68721, language: 'pt')
59
52
  def self.images(id, options = {})
60
- Fetcher::get("/movie/#{id}/images", options)
53
+ res = get("/movie/#{id}/images", query: options)
54
+ res.success? ? res : bad_response(res)
61
55
  end
62
56
 
63
- # Get the plot keywords for a specific movie id.
57
+ # Public: Get the plot keywords for a specific movie ID.
64
58
  #
65
59
  # options - The hash options used to filter the search (default: {}):
66
60
  # :language - Images of a specific language (ISO 639-1 code).
67
61
  #
68
62
  # Examples
69
63
  #
70
- # TMDb::Movie.keywords(331, language: pt)
71
- #
64
+ # TMDb::Movie.keywords(68721, language: pt)
72
65
  def self.keywords(id, options = {})
73
- result = Fetcher::get("/movie/#{id}/keywords", options)
74
- result['keywords']
66
+ res = get("/movie/#{id}/keywords", query: options)
67
+ res.success? ? res['keywords'] : bad_response(res)
75
68
  end
76
69
 
77
- # Get the release date by country for a specific movie id.
70
+ # Public: Get the release date by country for a specific movie ID.
78
71
  #
79
72
  # Examples
80
73
  #
81
- # TMDb::Movie.releases(8711)
82
- #
74
+ # TMDb::Movie.releases(68721)
83
75
  def self.releases(id)
84
- result = Fetcher::get("/movie/#{id}/releases")
85
- result['countries']
76
+ res = get("/movie/#{id}/releases")
77
+ res.success? ? res['countries'] : bad_response(res)
86
78
  end
87
79
 
88
- # Get the list of upcoming movies. This list refreshes every day.
80
+ # Public: Get the list of upcoming movies. This list refreshes every day.
89
81
  # The maximum number of items this list will include is 100.
90
82
  #
91
83
  # options - The hash options used to filter the search (default: {}):
@@ -96,10 +88,14 @@ module TMDb
96
88
  #
97
89
  # TMDb::Movie.upcoming
98
90
  # TMDb::Movie.upcoming(page: 3, language: 'pt')
99
- #
100
91
  def self.upcoming(options = {})
101
- response = Fetcher::get('/movie/upcoming', options)
102
- response['results'].map { |movie| new(movie) }
92
+ res = get('/movie/upcoming', query: options)
93
+
94
+ if res.success?
95
+ res['results'].map { |movie| Movie.new(movie) }
96
+ else
97
+ bad_response(res)
98
+ end
103
99
  end
104
100
  end
105
101
  end
@@ -1,9 +1,8 @@
1
- require "cgi"
2
-
3
1
  module TMDb
4
2
  module Searchable
5
- # Search movies.
3
+ # Public: Search resources like a movie, a person, a collection and so on.
6
4
  #
5
+ ## For a movie
7
6
  # query - Query string that will be matched with the movie name.
8
7
  # options - The hash options used to filter the search (default: {}):
9
8
  # :page - The current page of results.
@@ -13,21 +12,24 @@ module TMDb
13
12
  #
14
13
  # Examples
15
14
  #
15
+ ## For a movie
16
16
  # TMDb::Movie.search('Iron Man')
17
- #
18
17
  # TMDb::Movie.search('The Matrix', year: 1999)
19
- #
20
18
  # TMDb::Movie.search('Forret Gump', language: 'pt', year: 1994)
21
19
  def search(query, options = {})
22
- # require "pry"; binding.pry
23
20
  options.merge!(query: query)
24
- result = Fetcher::get("/search/#{resource}", options)
25
- result['results'].map { |attributes| new(attributes) }
21
+ res = get("/search/#{resource}", query: options)
22
+ if res.success?
23
+ res['results'].map { |attributes| new(attributes) }
24
+ else
25
+ bad_response(res)
26
+ end
26
27
  end
27
28
 
28
- # Removes the module part from the expression in the string.
29
+ private
30
+
29
31
  def resource
30
- name.split('::').last.downcase || ''
32
+ name.split('::').last.downcase
31
33
  end
32
34
  end
33
35
  end
@@ -0,0 +1,3 @@
1
+ module TMDb
2
+ VERSION = "0.0.3"
3
+ end