neo-tmdb 0.2.0 → 0.3.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.
- data/Changelog.markdown +6 -0
- data/README.markdown +39 -0
- data/lib/neo-tmdb.rb +1 -0
- data/lib/tmdb.rb +10 -8
- data/lib/tmdb/configuration.rb +5 -1
- data/lib/tmdb/null_cache.rb +17 -0
- data/lib/tmdb/version.rb +1 -1
- metadata +19 -2
data/Changelog.markdown
CHANGED
data/README.markdown
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Neo TMDb
|
2
2
|
|
3
3
|
Neo TMDb is a Ruby wrapper for the v3 [TMDb API][api] from www.themoviedb.org.
|
4
|
+
It provides read-only access with caching.
|
4
5
|
|
5
6
|
[api]: http://help.themoviedb.org/kb/api/about-3
|
6
7
|
|
@@ -32,6 +33,44 @@ people.each do |person|
|
|
32
33
|
end
|
33
34
|
```
|
34
35
|
|
36
|
+
### Configure caching
|
37
|
+
|
38
|
+
You can configure caching so that duplicate requests for the same person are
|
39
|
+
read from the cache rather than directly from the TMDb servers. This helps
|
40
|
+
improve the performance of you application but also prevents it from exceeding
|
41
|
+
the [API request limits][limits] on the TMDb servers.
|
42
|
+
|
43
|
+
[limits]: http://help.themoviedb.org/kb/general/api-request-limits
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
require 'active_support'
|
47
|
+
require 'benchmark'
|
48
|
+
require 'neo-tmdb'
|
49
|
+
|
50
|
+
TMDb.configure do |config|
|
51
|
+
config.api_key = 'my-tmdb-api-key-here'
|
52
|
+
# You should configure your cache to expire entries after an appropriate
|
53
|
+
# period. Note that MemoryStore may not be the best choice for your
|
54
|
+
# application.
|
55
|
+
config.cache = ActiveSupport::Cache::MemoryStore.new
|
56
|
+
end
|
57
|
+
|
58
|
+
# Note in the following how the first request takes considerable longer than
|
59
|
+
# the subsequent cached requests.
|
60
|
+
100.times do |n|
|
61
|
+
Benchmark.benchmark('find ') do |b|
|
62
|
+
b.report(n.to_s) do
|
63
|
+
person = TMDb::Person.find(6384)
|
64
|
+
puts " #{person.name} load #{n}"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
```
|
69
|
+
|
70
|
+
You can use any cache that implements ActiveSupport's `Cache` interface.
|
71
|
+
|
72
|
+
### Documentation
|
73
|
+
|
35
74
|
Further [documentation can be found on rdoc.info][docs].
|
36
75
|
|
37
76
|
[docs]: http://rdoc.info/github/andrewdsmith/neo-tmdb/master/frames
|
data/lib/neo-tmdb.rb
CHANGED
data/lib/tmdb.rb
CHANGED
@@ -17,14 +17,16 @@ module TMDb
|
|
17
17
|
# called directly by client code, instead you should call methods such as
|
18
18
|
# +Person.find+ that return TMDb wrapper objects.
|
19
19
|
def get_api_response(path, params = {})
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
configuration.cache.fetch([path, params]) do
|
21
|
+
connection = Faraday.new(:url => 'http://api.themoviedb.org/3/') do |builder|
|
22
|
+
builder.request :url_encoded
|
23
|
+
builder.adapter :net_http
|
24
|
+
end
|
25
|
+
response = connection.get(
|
26
|
+
path,
|
27
|
+
params.merge({ :api_key => TMDb.configuration.api_key })
|
28
|
+
)
|
29
|
+
JSON.parse(response.body)
|
23
30
|
end
|
24
|
-
response = connection.get(
|
25
|
-
path,
|
26
|
-
params.merge({ :api_key => TMDb.configuration.api_key })
|
27
|
-
)
|
28
|
-
JSON.parse(response.body)
|
29
31
|
end
|
30
32
|
end
|
data/lib/tmdb/configuration.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
module TMDb
|
2
|
+
|
3
|
+
# Looks like a cache but doesn't perform any caching. This helps us avoid
|
4
|
+
# checking for whether a cache is configured or not, as per the Null Object
|
5
|
+
# pattern: http://en.wikipedia.org/wiki/Null_Object_pattern.
|
6
|
+
#
|
7
|
+
class NullCache
|
8
|
+
|
9
|
+
# Returns the value of the yielded block. Assumes that a block is passed;
|
10
|
+
# ActiveSupport::Cache::Store#fetch allows for no block but we don't use
|
11
|
+
# this internally. Ignores +cache_key+ because no caching is performed.
|
12
|
+
#
|
13
|
+
def fetch(cache_key)
|
14
|
+
yield
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/tmdb/version.rb
CHANGED
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.3.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-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 0.8.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: '3.2'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '3.2'
|
30
46
|
- !ruby/object:Gem::Dependency
|
31
47
|
name: rspec
|
32
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -83,6 +99,7 @@ extra_rdoc_files: []
|
|
83
99
|
files:
|
84
100
|
- lib/tmdb.rb
|
85
101
|
- lib/tmdb/configuration.rb
|
102
|
+
- lib/tmdb/null_cache.rb
|
86
103
|
- lib/tmdb/person.rb
|
87
104
|
- lib/tmdb/attributes.rb
|
88
105
|
- lib/tmdb/version.rb
|