tmdb-api 0.0.3 → 0.0.4

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,11 @@
1
+ language: ruby
2
+ script: bundle exec rspec spec
3
+ rvm:
4
+ - 2.0.0
5
+ - 1.9.3
6
+ notifications:
7
+ email: false
8
+ campfire:
9
+ rooms:
10
+ - secure: VkO6I3V//FGfYngmANVEdTGRMeRDPwivLopNZJyeSRHE25XMhDrB0HWZfQF0OI6qtziVjyYOXGF+sPAHfYJcUvCNyw4I+7JA5/veZ/lEgv/6NZq1t8DdPfhoDs+cYhg0DYa1czsVbRDzCtub+nQ8LxewSZGO3zd2W+uVBJ0VPzs=
11
+
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # The Movie Database API
2
2
 
3
+ [![Build Status](https://travis-ci.org/andrielfn/tmdb-api.png)](https://travis-ci.org/andrielfn/tmdb-api)
4
+ [![Code Climate](https://codeclimate.com/github/andrielfn/tmdb-api.png)](https://codeclimate.com/github/andrielfn/tmdb-api)
5
+
3
6
  A simple Ruby wrapper for the The Movie Database API v3.
4
7
 
5
8
  About the TMDb API documentation and everything else you can se here: [http://docs.themoviedb.apiary.io/](http://docs.themoviedb.apiary.io).
@@ -39,6 +42,12 @@ TMDB::Movie.find(603, language: 'pt')
39
42
  # => #<TMDb::Movie:0x007f99 @id=603, @title="The Matrix", @imdb_id="tt0133093" ... >
40
43
  ```
41
44
 
45
+ Available attributes: `id`, `adult`, `backdrop_path`, `belongs_to_collection`,
46
+ `budget`, `genres`, `homepage`, `imdb_id`, `original_title`, `overview`,
47
+ `popularity`, `poster_path`, `production_companies`, `runtime`,
48
+ `production_countries`, `release_date`, `revenue`, `spoken_languages`, `status`,
49
+ `tagline`, `title`, `vote_average`, `vote_count`.
50
+
42
51
  ### Search movies
43
52
  Search for movies by title.
44
53
 
@@ -162,36 +171,6 @@ TMDb::Movie.upcoming
162
171
  # ]
163
172
  ```
164
173
 
165
- ### Movie object
166
-
167
- ```ruby
168
- movie = TMDb::Movie.find(27205)
169
-
170
- movie.id # => 27205
171
- movie.adult # => false
172
- movie.backdrop_path # => /s2bT29y0ngXxxu2IA8AOzzXTRhd.jpg
173
- movie.belongs_to_collection # => {"id"=>179836, "name"=>"Inception Collection", "poster_path"=>"/7OtEJQjBhxNug5TyY0ny4ttuKdg.jpg", "backdrop_path"=>"/73WuAqGGCv3F8Rwy5FTnYlji6IS.jpg"}
174
- movie.budget # => 160000000
175
- movie.genres # => [{"id"=>28, "name"=>"Action"}, {"id"=>12, "name"=>"Adventure"}, {"id"=>9648, "name"=>"Mystery"}, {"id"=>878, "name"=>"Science Fiction"}, {"id"=>53, "name"=>"Thriller"}]
176
- movie.homepage # => http://inceptionmovie.warnerbros.com/
177
- movie.imdb_id # => tt1375666
178
- movie.original_title # => Inception
179
- 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.
180
- movie.popularity # => 8.908730111185815
181
- movie.poster_path # => /tAXARVreJnWfoANIHASmgYk4SB0.jpg
182
- movie.production_companies # => [{"name"=>"Warner Bros. Pictures", "id"=>174}, {"name"=>"Syncopy", "id"=>9996}]
183
- movie.runtime # => 148
184
- movie.production_countries # => [{"iso_3166_1"=>"US", "name"=>"United States of America"}]
185
- movie.release_date # => 2010-07-16
186
- movie.revenue # => 825532764
187
- movie.spoken_languages # => [{"iso_639_1"=>"en", "name"=>"English"}, {"iso_639_1"=>"ja", "name"=>"日本語"}, {"iso_639_1"=>"fr", "name"=>"Français"}]
188
- movie.status # => Released
189
- movie.tagline # => Your mind is the scene of the crime.
190
- movie.title # => Inception
191
- movie.vote_average # => 8.2
192
- movie.vote_count # => 497
193
- ```
194
-
195
174
  ## Contributing
196
175
 
197
176
  1. Fork it
@@ -1,12 +1,19 @@
1
- require "httparty"
2
- require "json"
1
+ require 'httparty'
2
+ require 'json'
3
3
 
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"
4
+ require 'tmdb-api/httparty'
5
+
6
+ require 'tmdb-api/base'
7
+ require 'tmdb-api/searchable'
8
+
9
+ require 'tmdb-api/movie'
10
+ require 'tmdb-api/genre'
11
+ require 'tmdb-api/production_company'
12
+ require 'tmdb-api/production_country'
13
+ require 'tmdb-api/spoken_language'
14
+ require 'tmdb-api/changes'
15
+
16
+ require 'tmdb-api/version'
10
17
 
11
18
  module TMDb
12
19
  class << self
@@ -1,3 +1,5 @@
1
+ require 'active_support/core_ext/string'
2
+
1
3
  module TMDb
2
4
  class Base
3
5
  include HTTParty
@@ -36,8 +38,22 @@ module TMDb
36
38
  # Returns nothing
37
39
  def load(attributes)
38
40
  attributes.each do |key, value|
41
+ value = build_objects(key, value) if value.is_a?(Array)
39
42
  self.instance_variable_set("@#{key}", value)
40
43
  end
41
44
  end
45
+
46
+ # Internal: Builds objects for the nested resources from API.
47
+ #
48
+ # key - attribute related to the object (ex: genres, spoken_languages).
49
+ # values - values of the attribute.
50
+ #
51
+ # Returns an array of objects
52
+ def build_objects(key, values)
53
+ klass = TMDb.const_get(key.classify)
54
+ values.map do |attr|
55
+ klass.new(attr)
56
+ end
57
+ end
42
58
  end
43
59
  end
@@ -0,0 +1,9 @@
1
+ module TMDb
2
+ class Genre < Base
3
+
4
+ # Genre attributes
5
+ ATTRIBUTES = :id, :name
6
+
7
+ attr_reader *ATTRIBUTES
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module TMDb
2
+ class ProductionCompany < Base
3
+
4
+ # Genre attributes
5
+ ATTRIBUTES = :id, :name
6
+
7
+ attr_reader *ATTRIBUTES
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ module TMDb
2
+ class ProductionCountry < Base
3
+
4
+ # Genre attributes
5
+ ATTRIBUTES = :iso_3166_1, :name
6
+
7
+ attr_reader *ATTRIBUTES
8
+
9
+ # Public: alias for the iso_3166_1 attribute.
10
+ def code
11
+ @iso_3166_1
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module TMDb
2
+ class SpokenLanguage < Base
3
+
4
+ # Spoken language attributes
5
+ ATTRIBUTES = :iso_639_1, :name
6
+
7
+ attr_reader *ATTRIBUTES
8
+
9
+ # Public: alias for the iso_639_1 attribute.
10
+ def code
11
+ @iso_639_1
12
+ end
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module TMDb
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -25,7 +25,7 @@
25
25
  "id": 598,
26
26
  "imdb_id": "tt0317248",
27
27
  "original_title": "Cidade de Deus",
28
- "overview": "City of God depicts the raw violence in the ghettos of Rio de Janeiro. In the 1970’s that kids are carrying guns and joining gangs when they should be playing hide-and-seek.",
28
+ "overview": "City of God depicts the raw violence in the ghettos of Rio de Janeiro.",
29
29
  "popularity": 1.3497251049225558,
30
30
  "poster_path": "/mwDnSQR1CkxuDjSKfgiNT0sIOjM.jpg",
31
31
  "production_companies": [
@@ -1,94 +1,123 @@
1
+ # coding: utf-8
1
2
  require 'spec_helper'
2
3
 
3
4
  describe TMDb::Movie do
4
5
  describe '.find' do
5
- it 'find a movie given your ID' do
6
+ before do
6
7
  stub_get('/movie/24').to_return(json_response('movie/find.json'))
8
+ end
7
9
 
8
- movie = TMDb::Movie.find(24)
10
+ let(:movie) { TMDb::Movie.find(24) }
9
11
 
12
+ it 'returns the "adult" attribute' do
10
13
  expect(movie.adult).to eq(false)
14
+ end
15
+
16
+ it 'returns the "backdrop_path" attribute' do
11
17
  expect(movie.backdrop_path).to eq('/hSaH9tt67bozo9K50sbH0s4YjEc.jpg')
18
+ end
19
+
20
+ it 'returns the "belongs_to_collection" attribute' do
12
21
  expect(movie.belongs_to_collection).to eq(nil)
22
+ end
23
+
24
+ it 'returns the "budget" attribute' do
13
25
  expect(movie.budget).to eq(3300000)
14
- expect(movie.genres).to eq([
15
- {
16
- 'id' => 28,
17
- 'name' => 'Action'
18
- },
19
- {
20
- 'id' => 80,
21
- 'name' => 'Crime'
22
- },
23
- {
24
- 'id' => 18,
25
- 'name' => 'Drama'
26
- },
27
- {
28
- 'id' => 10769,
29
- 'name' => 'Foreign'
30
- }
31
- ])
26
+ end
27
+
28
+ it 'returns movie genres as objects' do
29
+ expect(movie.genres).to have(4).genres
30
+
31
+ first_genre = movie.genres.first
32
+ expect(first_genre.id).to eql(28)
33
+ expect(first_genre.name).to eql('Action')
34
+ end
35
+
36
+ it 'returns the "homepage" attribute' do
32
37
  expect(movie.homepage).to eq('http://cidadededeus.globo.com/')
38
+ end
39
+
40
+ it 'returns the "id" attribute' do
33
41
  expect(movie.id).to eq(598)
42
+ end
43
+
44
+ it 'returns the "imdb_id" attribute' do
34
45
  expect(movie.imdb_id).to eq('tt0317248')
46
+ end
47
+
48
+ it 'returns the "original_title" attribute' do
35
49
  expect(movie.original_title).to eq('Cidade de Deus')
36
- expect(movie.overview).to eq('City of God depicts the raw violence in the ghettos of Rio de Janeiro. In the 1970’s that kids are carrying guns and joining gangs when they should be playing hide-and-seek.')
50
+ end
51
+
52
+ it 'returns the "overview" attribute' do
53
+ expect(movie.overview).to eq(
54
+ 'City of God depicts the raw violence in the ghettos of Rio de Janeiro.'
55
+ )
56
+ end
57
+
58
+ it 'returns the "popularity" attribute' do
37
59
  expect(movie.popularity).to eq(1.3497251049225558)
60
+ end
61
+
62
+ it 'returns the "poster_path" attribute' do
38
63
  expect(movie.poster_path).to eq('/mwDnSQR1CkxuDjSKfgiNT0sIOjM.jpg')
39
- expect(movie.production_companies).to eq([
40
- {
41
- 'name' => 'O2 Filmes',
42
- 'id' => 345
43
- },
44
- {
45
- 'name' => 'VideoFilmes',
46
- 'id' => 346
47
- },
48
- {
49
- 'name' => 'Globo filmes',
50
- 'id' => 10954
51
- },
52
- {
53
- 'name' => 'Lumiere',
54
- 'id' => 11444
55
- },
56
- {
57
- 'name' => 'Wild Bunch',
58
- 'id' => 856
59
- },
60
- {
61
- 'name' => 'Hank Levine Film',
62
- 'id' => 11445
63
- },
64
- {
65
- 'name' => 'Lereby Productions',
66
- 'id' => 11446
67
- }
68
- ])
69
- expect(movie.production_countries).to eq([
70
- {
71
- 'iso_3166_1' => 'BR',
72
- 'name' => 'Brazil'
73
- },
74
- {
75
- 'iso_3166_1' => 'FR',
76
- 'name' => 'France'
77
- }
78
- ])
64
+ end
65
+
66
+ it 'returns movie production companies as objects' do
67
+ expect(movie.production_companies).to have(7).production_companies
68
+
69
+ first_company = movie.production_companies.first
70
+ expect(first_company.id).to eql(345)
71
+ expect(first_company.name).to eql('O2 Filmes')
72
+ end
73
+
74
+ it 'returns movie production countries as objects' do
75
+ expect(movie.production_countries).to have(2).production_countries
76
+
77
+ first_country = movie.production_countries.first
78
+ expect(first_country.iso_3166_1).to eql('BR')
79
+ expect(first_country.code).to eql('BR')
80
+ expect(first_country.name).to eql('Brazil')
81
+ end
82
+
83
+ it 'returns the "release_date" attribute' do
79
84
  expect(movie.release_date).to eq('2002-08-31')
85
+ end
86
+
87
+ it 'returns the "revenue" attribute' do
80
88
  expect(movie.revenue).to eq(27387381)
89
+ end
90
+
91
+ it 'returns the "runtime" attribute' do
81
92
  expect(movie.runtime).to eq(130)
82
- expect(movie.spoken_languages).to eq([
83
- {
84
- 'iso_639_1' => 'pt',
85
- 'name' => 'Português'
86
- }
87
- ])
93
+ end
94
+
95
+ it 'returns movie spoken languages as objects' do
96
+ expect(movie.spoken_languages).to have(1).spoken_languages
97
+
98
+ first_country = movie.spoken_languages.first
99
+ expect(first_country.iso_639_1).to eql('pt')
100
+ expect(first_country.code).to eql('pt')
101
+ expect(first_country.name).to eql('Português')
102
+ end
103
+
104
+ it 'returns the "status" attribute' do
88
105
  expect(movie.status).to eq('Released')
106
+ end
107
+
108
+ it 'returns the "tagline" attribute' do
89
109
  expect(movie.tagline).to eq('If you run you\'re dead...if you stay, you\'re dead again. Period.')
110
+ end
111
+
112
+ it 'returns the "title" attribute' do
90
113
  expect(movie.title).to eq('City of God')
114
+ end
115
+
116
+ it 'returns the "vote_average" attribute' do
91
117
  expect(movie.vote_average).to eq(8.2)
118
+ end
119
+
120
+ it 'returns the "vote_count" attribute' do
92
121
  expect(movie.vote_count).to eq(52)
93
122
  end
94
123
 
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "httparty"
22
+ spec.add_dependency "activesupport"
22
23
 
23
24
  spec.add_development_dependency "bundler", "~> 1.3"
24
25
  spec.add_development_dependency "rake"
metadata CHANGED
@@ -1,32 +1,52 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tmdb-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Andriel Nuernberg
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-08-06 00:00:00.000000000 Z
12
+ date: 2013-08-10 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: httparty
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - '>='
19
+ - - ! '>='
18
20
  - !ruby/object:Gem::Version
19
21
  version: '0'
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - '>='
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: activesupport
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
25
44
  - !ruby/object:Gem::Version
26
45
  version: '0'
27
46
  - !ruby/object:Gem::Dependency
28
47
  name: bundler
29
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
30
50
  requirements:
31
51
  - - ~>
32
52
  - !ruby/object:Gem::Version
@@ -34,6 +54,7 @@ dependencies:
34
54
  type: :development
35
55
  prerelease: false
36
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
37
58
  requirements:
38
59
  - - ~>
39
60
  - !ruby/object:Gem::Version
@@ -41,57 +62,65 @@ dependencies:
41
62
  - !ruby/object:Gem::Dependency
42
63
  name: rake
43
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
44
66
  requirements:
45
- - - '>='
67
+ - - ! '>='
46
68
  - !ruby/object:Gem::Version
47
69
  version: '0'
48
70
  type: :development
49
71
  prerelease: false
50
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
51
74
  requirements:
52
- - - '>='
75
+ - - ! '>='
53
76
  - !ruby/object:Gem::Version
54
77
  version: '0'
55
78
  - !ruby/object:Gem::Dependency
56
79
  name: rspec
57
80
  requirement: !ruby/object:Gem::Requirement
81
+ none: false
58
82
  requirements:
59
- - - '>='
83
+ - - ! '>='
60
84
  - !ruby/object:Gem::Version
61
85
  version: '0'
62
86
  type: :development
63
87
  prerelease: false
64
88
  version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
65
90
  requirements:
66
- - - '>='
91
+ - - ! '>='
67
92
  - !ruby/object:Gem::Version
68
93
  version: '0'
69
94
  - !ruby/object:Gem::Dependency
70
95
  name: webmock
71
96
  requirement: !ruby/object:Gem::Requirement
97
+ none: false
72
98
  requirements:
73
- - - '>='
99
+ - - ! '>='
74
100
  - !ruby/object:Gem::Version
75
101
  version: '0'
76
102
  type: :development
77
103
  prerelease: false
78
104
  version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
79
106
  requirements:
80
- - - '>='
107
+ - - ! '>='
81
108
  - !ruby/object:Gem::Version
82
109
  version: '0'
83
110
  - !ruby/object:Gem::Dependency
84
111
  name: pry
85
112
  requirement: !ruby/object:Gem::Requirement
113
+ none: false
86
114
  requirements:
87
- - - '>='
115
+ - - ! '>='
88
116
  - !ruby/object:Gem::Version
89
117
  version: '0'
90
118
  type: :development
91
119
  prerelease: false
92
120
  version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
93
122
  requirements:
94
- - - '>='
123
+ - - ! '>='
95
124
  - !ruby/object:Gem::Version
96
125
  version: '0'
97
126
  description: The Movie Database API v3
@@ -103,6 +132,7 @@ extra_rdoc_files: []
103
132
  files:
104
133
  - .gitignore
105
134
  - .rspec
135
+ - .travis.yml
106
136
  - Gemfile
107
137
  - LICENSE.txt
108
138
  - README.md
@@ -110,9 +140,13 @@ files:
110
140
  - lib/tmdb-api.rb
111
141
  - lib/tmdb-api/base.rb
112
142
  - lib/tmdb-api/changes.rb
143
+ - lib/tmdb-api/genre.rb
113
144
  - lib/tmdb-api/httparty.rb
114
145
  - lib/tmdb-api/movie.rb
146
+ - lib/tmdb-api/production_company.rb
147
+ - lib/tmdb-api/production_country.rb
115
148
  - lib/tmdb-api/searchable.rb
149
+ - lib/tmdb-api/spoken_language.rb
116
150
  - lib/tmdb-api/version.rb
117
151
  - spec/fixtures/changes/movies.json
118
152
  - spec/fixtures/movie/alternative_titles.json
@@ -132,26 +166,27 @@ files:
132
166
  homepage: https://github.com/andrielfn/tmdb-api
133
167
  licenses:
134
168
  - MIT
135
- metadata: {}
136
169
  post_install_message:
137
170
  rdoc_options: []
138
171
  require_paths:
139
172
  - lib
140
173
  required_ruby_version: !ruby/object:Gem::Requirement
174
+ none: false
141
175
  requirements:
142
- - - '>='
176
+ - - ! '>='
143
177
  - !ruby/object:Gem::Version
144
178
  version: '0'
145
179
  required_rubygems_version: !ruby/object:Gem::Requirement
180
+ none: false
146
181
  requirements:
147
- - - '>='
182
+ - - ! '>='
148
183
  - !ruby/object:Gem::Version
149
184
  version: '0'
150
185
  requirements: []
151
186
  rubyforge_project:
152
- rubygems_version: 2.0.2
187
+ rubygems_version: 1.8.23
153
188
  signing_key:
154
- specification_version: 4
189
+ specification_version: 3
155
190
  summary: The Mobie Database API v3
156
191
  test_files:
157
192
  - spec/fixtures/changes/movies.json
@@ -168,4 +203,3 @@ test_files:
168
203
  - spec/tmdb-api/movie_spec.rb
169
204
  - spec/tmdb-api/searchable_spec.rb
170
205
  - spec/tmdb-api/tmdb_spec.rb
171
- has_rdoc:
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: c76aa958ad9a98caf296205a2502e1e1c2ad5fad
4
- data.tar.gz: 89d617732b3e977403147bc352e085c9ca312e4d
5
- SHA512:
6
- metadata.gz: cc125c9dcbf62d451fdf3299a5596da0d263ccd4e862cc81a4aefb1c66c2ee526544141ed07be182de0a1139ae5389c751f9b7a53ac24a9a73fb5d84a9f8af9d
7
- data.tar.gz: ae14ee8e385273f5ac9a90854e23870867eeb060251ae8b07d2bd1caea927ee46666a8d6aa379235c2c07e5dff0955d73570f1b7208d39f0e473a3b324f53c5d