simple_themoviedb 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/Gemfile.lock +1 -1
- data/README.md +50 -1
- data/Rakefile +3 -3
- data/bin/console +3 -3
- data/lib/simple_themoviedb/version.rb +1 -1
- data/lib/simple_themoviedb.rb +28 -26
- data/simple_themoviedb.gemspec +19 -19
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2366ccb8f61c3ea9b48bff67e2783b14370e0051254de0ea08453927b76c7777
|
4
|
+
data.tar.gz: f1198a2e823502c80d57b23515bc3988df1e9401731580d0f59e967d205cf1ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9dc6eb2fa0aeae0cea1c3759782cb9103c0cf49116d4f2def86869d567832148d1b1da03f4a225350ba683b0bc62143e40de3c5ec15a6a2ae921fb400d030c87
|
7
|
+
data.tar.gz: a8123125c5bca0d5f30a93aed63f3306086196e3e9d8eeb5c03de6179fc53e40312e60b0aa9ac1f3e05f49902f30f8b2d5b1a0d0643eb80a8cdbac43c57501cf
|
data/Gemfile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
3
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
4
|
|
5
5
|
# Specify your gem's dependencies in simple_themoviedb.gemspec
|
6
6
|
gemspec
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -18,7 +18,56 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
First of all, initialize a client:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
@client = SimpleTheMovieDB::Client.new('your-api-key')
|
25
|
+
```
|
26
|
+
|
27
|
+
The SimpleTheMovieDB::Client has a few methods at your disposal:
|
28
|
+
|
29
|
+
- #search
|
30
|
+
|
31
|
+
Accepts one string (the query) as parameter. Returns an Array of Hashes. Each Hash contains a summarized version of the movie data.
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
@client.search('The Wolf of Wall Street')
|
35
|
+
=> [{"vote_count"=>8895, "id"=>106646, "video"=>false, "vote_average"=>7.9, "title"=>"The Wolf of Wall Street", "popularity"=>36.903397, "poster_path"=>"/vK1o5rZGqxyovfIhZyMELhk03wO.jpg", "original_language"=>"en", "original_title"=>"The Wolf of Wall Street", "genre_ids"=>[80, 18, 35], "backdrop_path"=>"/rP36Rx5RQh0rmH2ynEIaG8DxbV2.jpg", "adult"=>false, "overview"=>"A New York stockbroker refuses to cooperate in a large securities fraud case involving corruption on Wall Street, corporate banking world and mob infiltration. Based on Jordan Belfort's autobiography.", "release_date"=>"2013-12-25"}, {"vote_count"=>0, "id"=>423766, "video"=>false, "vote_average"=>0, "title"=>"The Wolf of Wall Street", "popularity"=>1.00119, "poster_path"=>"/aNGsE1nVtQHu4pvPzNvqVaczztb.jpg", "original_language"=>"en", "original_title"=>"The Wolf of Wall Street", "genre_ids"=>[], "backdrop_path"=>nil, "adult"=>false, "overview"=>"A ruthless stockbroker sells short in the copper business and ruins the life of his friends by ruining their finances.", "release_date"=>"1929-02-09"}]
|
36
|
+
```
|
37
|
+
|
38
|
+
- #get_movie
|
39
|
+
|
40
|
+
Accepts one integer (the ID) as parameter. Returns the full data for the given movie.
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
@client.get_movie(106646)
|
44
|
+
=> {"adult"=>false, "backdrop_path"=>"/rP36Rx5RQh0rmH2ynEIaG8DxbV2.jpg", "belongs_to_collection"=>nil, "budget"=>100000000, "genres"=>[{"id"=>80, "name"=>"Crime"}, {"id"=>18, "name"=>"Drama"}, {"id"=>35, "name"=>"Comedy"}], "homepage"=>"http://www.thewolfofwallstreet.com/", "id"=>106646, "imdb_id"=>"tt0993846", "original_language"=>"en", "original_title"=>"The Wolf of Wall Street", "overview"=>"A New York stockbroker refuses to cooperate in a large securities fraud case involving corruption on Wall Street, corporate banking world and mob infiltration. Based on Jordan Belfort's autobiography.", "popularity"=>35.903397, "poster_path"=>"/vK1o5rZGqxyovfIhZyMELhk03wO.jpg", "production_companies"=>[{"id"=>14654, "logo_path"=>nil, "name"=>"EMJAG Productions", "origin_country"=>""}, {"id"=>4, "logo_path"=>"/fycMZt242LVjagMByZOLUGbCvv3.png", "name"=>"Paramount", "origin_country"=>"US"}, {"id"=>19177, "logo_path"=>nil, "name"=>"Red Granite Pictures", "origin_country"=>""}, {"id"=>562, "logo_path"=>"/k3NsSdV854UX4zEReX1dl1Psxbb.png", "name"=>"Appian Way", "origin_country"=>"US"}, {"id"=>23243, "logo_path"=>nil, "name"=>"Sikelia Productions", "origin_country"=>""}], "production_countries"=>[{"iso_3166_1"=>"US", "name"=>"United States of America"}], "release_date"=>"2013-12-25", "revenue"=>392000694, "runtime"=>180, "spoken_languages"=>[{"iso_639_1"=>"fr", "name"=>"Français"}, {"iso_639_1"=>"en", "name"=>"English"}], "status"=>"Released", "tagline"=>"EARN. SPEND. PARTY.", "title"=>"The Wolf of Wall Street", "video"=>false, "vote_average"=>7.9, "vote_count"=>8898}
|
45
|
+
2.5.1 :031
|
46
|
+
```
|
47
|
+
|
48
|
+
- #get_images
|
49
|
+
|
50
|
+
Accepts one integer (the movie ID) as parameter. Returns an Array of Hashes with information on the images The MovieDatabase has of that particular movie.
|
51
|
+
|
52
|
+
- #get_cast
|
53
|
+
|
54
|
+
Accepts one integer (the movie ID) as parameter. Returns a Hash with three keys: id, cast and crew. ID is self-explanatory. Cast and crew are array of hashes with information on each member of the cast and the crew of the movie
|
55
|
+
|
56
|
+
- #get_person
|
57
|
+
|
58
|
+
Accepts one integer (the person ID) as parameter. Returns the full data for the given person.
|
59
|
+
|
60
|
+
- #get_person_images
|
61
|
+
|
62
|
+
Accepts one integer (the person ID) as parameter. Returns an Array of Hashes with information on the images The MovieDatabase has of that particular person.
|
63
|
+
|
64
|
+
- #get_person_credits
|
65
|
+
|
66
|
+
Accepts one integer (the person ID) as parameter. Returns a Hash with three keys: id, cast and crew. ID is self-explanatory. Cast and crew are array of hashes with information on the roles taken by this particular person in all of his movies, as an actor or as a crew-member.
|
67
|
+
|
68
|
+
- #get_configuration
|
69
|
+
|
70
|
+
Accepts no parameters. Returns information about the parameters accepted by The Movie Database.
|
22
71
|
|
23
72
|
## Development
|
24
73
|
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'simple_themoviedb'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,5 @@ require "simple_themoviedb"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start(__FILE__)
|
data/lib/simple_themoviedb.rb
CHANGED
@@ -1,46 +1,42 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'simple_themoviedb/version'
|
2
|
+
require 'httparty'
|
3
3
|
|
4
4
|
module SimpleTheMovieDB
|
5
5
|
class Client
|
6
|
-
attr_reader :
|
6
|
+
attr_reader :api_key
|
7
7
|
|
8
|
-
|
9
|
-
base_uri "http://api.themoviedb.org/3"
|
10
|
-
headers 'accept' => 'application/json'
|
11
|
-
format :json
|
8
|
+
BASE_URL = 'http://api.themoviedb.org/3'.freeze
|
12
9
|
|
13
10
|
def initialize(api_key)
|
14
11
|
@api_key = api_key
|
15
12
|
end
|
16
13
|
|
17
14
|
def search(title, adult = nil)
|
18
|
-
url =
|
19
|
-
options = { :
|
20
|
-
options = options.merge(
|
21
|
-
|
22
|
-
response =
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
15
|
+
url = '/search/movie?'
|
16
|
+
options = { query: title, api_key: @api_key }
|
17
|
+
options = options.merge(include_adult: adult) if adult
|
18
|
+
|
19
|
+
response = get_and_parse(url, options)
|
20
|
+
total_pages = response['total_pages']
|
21
|
+
|
22
|
+
return unless total_pages && total_pages.is_a?(Integer)
|
23
|
+
|
24
|
+
(2..total_pages).inject(response['results']) do |res, page|
|
25
|
+
options[:page] = page
|
26
|
+
page_results = get_and_parse(url, options)['results'] || []
|
27
|
+
res + page_results
|
32
28
|
end
|
33
29
|
end
|
34
30
|
|
35
31
|
def get_configuration
|
36
|
-
url =
|
32
|
+
url = '/configuration?'
|
37
33
|
get_and_parse(url)
|
38
34
|
end
|
39
35
|
|
40
36
|
def get_movie(id, lang = nil)
|
41
37
|
url = "/movie/#{id}?"
|
42
|
-
options = { :
|
43
|
-
options = options.merge(:
|
38
|
+
options = { api_key: @api_key }
|
39
|
+
options = options.merge(language: lang) if lang
|
44
40
|
get_and_parse(url, options)
|
45
41
|
end
|
46
42
|
|
@@ -72,13 +68,19 @@ module SimpleTheMovieDB
|
|
72
68
|
private
|
73
69
|
|
74
70
|
def get_and_parse(url, options = { api_key: @api_key })
|
75
|
-
|
71
|
+
response = HTTParty.get(
|
72
|
+
BASE_URL + url + to_query(options),
|
73
|
+
headers: { 'accept' => 'applcation/json' },
|
74
|
+
format: :json
|
75
|
+
)
|
76
|
+
|
77
|
+
response.parsed_response
|
76
78
|
end
|
77
79
|
|
78
80
|
def to_query(options)
|
79
81
|
options.map do |key, value|
|
80
82
|
"#{key}=#{value}"
|
81
|
-
end.join(
|
83
|
+
end.join('&')
|
82
84
|
end
|
83
85
|
end
|
84
86
|
end
|
data/simple_themoviedb.gemspec
CHANGED
@@ -1,38 +1,38 @@
|
|
1
1
|
|
2
|
-
lib = File.expand_path(
|
2
|
+
lib = File.expand_path('lib', __dir__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
4
|
+
require 'simple_themoviedb/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'simple_themoviedb'
|
8
8
|
spec.version = SimpleTheMovieDB::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['Gawyn']
|
10
|
+
spec.email = ['me@cristianplanas.com']
|
11
11
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
12
|
+
spec.summary = 'A simple wrapper on the TheMovieDB API'
|
13
|
+
spec.description = 'A simple wrapper on the TheMovieDB API'
|
14
|
+
spec.homepage = 'https://github.com/Gawyn/simple_themoviedb'
|
15
|
+
spec.license = 'MIT'
|
16
16
|
|
17
17
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
18
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
19
|
if spec.respond_to?(:metadata)
|
20
|
-
spec.metadata[
|
20
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
21
21
|
else
|
22
|
-
raise
|
23
|
-
|
22
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
23
|
+
'public gem pushes.'
|
24
24
|
end
|
25
25
|
|
26
|
-
spec.files
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
27
|
f.match(%r{^(test|spec|features)/})
|
28
28
|
end
|
29
|
-
spec.bindir =
|
29
|
+
spec.bindir = 'exe'
|
30
30
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
-
spec.require_paths = [
|
31
|
+
spec.require_paths = ['lib']
|
32
32
|
|
33
|
-
spec.add_dependency
|
33
|
+
spec.add_dependency 'httparty'
|
34
34
|
|
35
|
-
spec.add_development_dependency
|
36
|
-
spec.add_development_dependency
|
37
|
-
spec.add_development_dependency
|
35
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
36
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
37
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
38
38
|
end
|