neo-tmdb 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog.markdown +27 -0
- data/README.markdown +16 -3
- data/lib/tmdb/attributes.rb +10 -0
- data/lib/tmdb/configuration.rb +30 -0
- data/lib/tmdb/person.rb +32 -14
- data/lib/tmdb/version.rb +1 -1
- data/lib/tmdb.rb +17 -0
- metadata +20 -2
data/Changelog.markdown
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## In git master branch
|
4
|
+
|
5
|
+
Nothing yet.
|
6
|
+
|
7
|
+
## 0.2.0 (2012-06-15)
|
8
|
+
|
9
|
+
New features:
|
10
|
+
|
11
|
+
* The `Person#profile_image_url` method, which uses the base image URL fetched
|
12
|
+
from the TMDb configuration.
|
13
|
+
* Methods on `Configuration` for fetching and caching the [TMDb
|
14
|
+
configuration][], which can be used to build image URLs from a
|
15
|
+
`Person#profile_path`.
|
16
|
+
* An initial implementation of the `Person.find` method for getting a person by
|
17
|
+
their TMDb id.
|
18
|
+
|
19
|
+
[TMDb configuration]: http://help.themoviedb.org/kb/api/configuration
|
20
|
+
|
21
|
+
## 0.1.0 (2012-06-05)
|
22
|
+
|
23
|
+
New features:
|
24
|
+
|
25
|
+
* An initial implementation of the `Person.where` method that searches for
|
26
|
+
people on TMDb by name.
|
27
|
+
|
data/README.markdown
CHANGED
@@ -6,23 +6,36 @@ Neo TMDb is a Ruby wrapper for the v3 [TMDb API][api] from www.themoviedb.org.
|
|
6
6
|
|
7
7
|
## Use
|
8
8
|
|
9
|
-
Currently you can
|
10
|
-
the first 20 results for searches are returned.
|
9
|
+
Currently you can find people by their TMDb id or search for people.
|
11
10
|
|
11
|
+
```ruby
|
12
12
|
require 'neo-tmdb'
|
13
13
|
|
14
|
-
```ruby
|
15
14
|
TMDb.configure do |config|
|
16
15
|
# You must configure this library with a TMDb API key before you can use it.
|
17
16
|
config.api_key = 'my-tmdb-api-key-here'
|
18
17
|
end
|
19
18
|
|
19
|
+
person = TMDb::Person.find(6384)
|
20
|
+
puts "#{person.name}, born #{person.birthday} in #{person.place_of_birth}"
|
21
|
+
# => Keanu Reeves, born 1964-09-02 in Beirut, Lebanon
|
22
|
+
|
23
|
+
smallest = TMDb.configuration.image_profile_sizes.first
|
24
|
+
puts person.profile_image_url(smallest)
|
25
|
+
# => http://cf2.imgobject.com/t/p/w45/jmjeALlAVaPB8SonLR3qBN5myjc.jpg
|
26
|
+
|
27
|
+
# Note: Only the first 20 results are returned.
|
20
28
|
people = TMDb::Person.where(:name => "Reeves")
|
21
29
|
people.each do |person|
|
30
|
+
# Note: Only attributes available in the search API will be populated here.
|
22
31
|
puts "#{person.name} has TMDb id #{person.id}"
|
23
32
|
end
|
24
33
|
```
|
25
34
|
|
35
|
+
Further [documentation can be found on rdoc.info][docs].
|
36
|
+
|
37
|
+
[docs]: http://rdoc.info/github/andrewdsmith/neo-tmdb/master/frames
|
38
|
+
|
26
39
|
## Contribute
|
27
40
|
|
28
41
|
* Source hosted on [GitHub][].
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module TMDb
|
2
|
+
# A module for managing TMDb-derived attributes of a class.
|
3
|
+
module Attributes
|
4
|
+
# Adds an attribute reader with the given +name+ (symbol) that delegates to
|
5
|
+
# the instance's +@tmdb_attrs+ hash entry of the same name.
|
6
|
+
def tmdb_attr(name)
|
7
|
+
define_method(name) { @tmdb_attrs[name.to_s] }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
data/lib/tmdb/configuration.rb
CHANGED
@@ -1,5 +1,35 @@
|
|
1
1
|
module TMDb
|
2
2
|
class Configuration
|
3
3
|
attr_accessor :api_key
|
4
|
+
|
5
|
+
# Returns the base URL for use in constructing image URLs.
|
6
|
+
def image_base_url
|
7
|
+
tmdb_config_images['base_url']
|
8
|
+
end
|
9
|
+
|
10
|
+
# Returns the list of film backdrop image sizes for use in constructing
|
11
|
+
# image URLs.
|
12
|
+
def image_backdrop_sizes
|
13
|
+
tmdb_config_images['backdrop_sizes']
|
14
|
+
end
|
15
|
+
|
16
|
+
# Returns the list of film poster image sizes for use in constructing image
|
17
|
+
# URLs.
|
18
|
+
def image_poster_sizes
|
19
|
+
tmdb_config_images['poster_sizes']
|
20
|
+
end
|
21
|
+
|
22
|
+
# Returns the list of person profile image sizes for use in constructing
|
23
|
+
# image URLs.
|
24
|
+
def image_profile_sizes
|
25
|
+
tmdb_config_images['profile_sizes']
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
|
30
|
+
def tmdb_config_images
|
31
|
+
@tmdb_config ||= TMDb.get_api_response('configuration')
|
32
|
+
@tmdb_config['images']
|
33
|
+
end
|
4
34
|
end
|
5
35
|
end
|
data/lib/tmdb/person.rb
CHANGED
@@ -1,10 +1,29 @@
|
|
1
|
+
require 'tmdb/attributes'
|
2
|
+
|
1
3
|
module TMDb
|
2
4
|
class Person
|
3
|
-
|
5
|
+
extend Attributes
|
6
|
+
|
7
|
+
tmdb_attr :adult
|
8
|
+
tmdb_attr :also_known_as
|
9
|
+
tmdb_attr :biography
|
10
|
+
tmdb_attr :birthday
|
11
|
+
tmdb_attr :deathday
|
12
|
+
tmdb_attr :homepage
|
13
|
+
tmdb_attr :id
|
14
|
+
tmdb_attr :name
|
15
|
+
tmdb_attr :place_of_birth
|
16
|
+
tmdb_attr :profile_path
|
4
17
|
|
5
18
|
def initialize(args)
|
6
|
-
@
|
7
|
-
|
19
|
+
@tmdb_attrs = args
|
20
|
+
end
|
21
|
+
|
22
|
+
# Returns the person with TMDb id of +id+.
|
23
|
+
#
|
24
|
+
def self.find(id)
|
25
|
+
response = TMDb.get_api_response("person/#{id}")
|
26
|
+
new(response)
|
8
27
|
end
|
9
28
|
|
10
29
|
# Returns an enumerable containing all the people matching the
|
@@ -16,17 +35,16 @@ module TMDb
|
|
16
35
|
# Only the first page of results (20 people) are returned.
|
17
36
|
#
|
18
37
|
def self.where(args)
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
body["results"].map {|attrs| new(attrs) }
|
38
|
+
response = TMDb.get_api_response('search/person', :query => args[:name])
|
39
|
+
response["results"].map {|attrs| new(attrs) }
|
40
|
+
end
|
41
|
+
|
42
|
+
# Returns a URL for the person's profile image at the given +size+. Valid
|
43
|
+
# sizes should be discovered via the +Configuration.image_profile_sizes+
|
44
|
+
# method.
|
45
|
+
#
|
46
|
+
def profile_image_url(size)
|
47
|
+
[TMDb.configuration.image_base_url, size, profile_path].join
|
30
48
|
end
|
31
49
|
end
|
32
50
|
end
|
data/lib/tmdb/version.rb
CHANGED
data/lib/tmdb.rb
CHANGED
@@ -10,4 +10,21 @@ module TMDb
|
|
10
10
|
def configure
|
11
11
|
yield configuration
|
12
12
|
end
|
13
|
+
|
14
|
+
# Makes a TMDb API request given to the (relative) +path+ with the given
|
15
|
+
# query +params+ and using the configured API key. Returns the response as a
|
16
|
+
# hash (parsed from the original JSON). This method is not intended to be
|
17
|
+
# called directly by client code, instead you should call methods such as
|
18
|
+
# +Person.find+ that return TMDb wrapper objects.
|
19
|
+
def get_api_response(path, params = {})
|
20
|
+
connection = Faraday.new(:url => 'http://api.themoviedb.org/3/') do |builder|
|
21
|
+
builder.request :url_encoded
|
22
|
+
builder.adapter :net_http
|
23
|
+
end
|
24
|
+
response = connection.get(
|
25
|
+
path,
|
26
|
+
params.merge({ :api_key => TMDb.configuration.api_key })
|
27
|
+
)
|
28
|
+
JSON.parse(response.body)
|
29
|
+
end
|
13
30
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: neo-tmdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -43,6 +43,22 @@ dependencies:
|
|
43
43
|
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '2.10'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: webmock
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.8'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.8'
|
46
62
|
- !ruby/object:Gem::Dependency
|
47
63
|
name: vcr
|
48
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -68,9 +84,11 @@ files:
|
|
68
84
|
- lib/tmdb.rb
|
69
85
|
- lib/tmdb/configuration.rb
|
70
86
|
- lib/tmdb/person.rb
|
87
|
+
- lib/tmdb/attributes.rb
|
71
88
|
- lib/tmdb/version.rb
|
72
89
|
- lib/neo-tmdb.rb
|
73
90
|
- LICENSE
|
91
|
+
- Changelog.markdown
|
74
92
|
- README.markdown
|
75
93
|
homepage: https://github.com/andrewdsmith/neo-tmdb
|
76
94
|
licenses:
|