simple_themoviedb 0.1.1 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf12e1f85c9a12ccf3ee97f8975890ac44b309fc495a423522768202f8f4e8df
4
- data.tar.gz: 868c4ec54420f6023552b982ca0380644b5d498009b35250160e78ac5fc9633d
3
+ metadata.gz: 2366ccb8f61c3ea9b48bff67e2783b14370e0051254de0ea08453927b76c7777
4
+ data.tar.gz: f1198a2e823502c80d57b23515bc3988df1e9401731580d0f59e967d205cf1ef
5
5
  SHA512:
6
- metadata.gz: 5603ee05feb92153dd39272f1a17f72b6475ceb0f3723075f6148c1eaf38ac45298e3b57bcc14956d7acde64a916b92795fb2ac3471a98687775637b2f7520df
7
- data.tar.gz: aa773e43b2973646049b8f6abc52ab6860c5b5614d447d450412f403770d77662f865a1ad63161244eb20efee56c7ad3798b660ae5109a19c90bece3078a5ddf
6
+ metadata.gz: 9dc6eb2fa0aeae0cea1c3759782cb9103c0cf49116d4f2def86869d567832148d1b1da03f4a225350ba683b0bc62143e40de3c5ec15a6a2ae921fb400d030c87
7
+ data.tar.gz: a8123125c5bca0d5f30a93aed63f3306086196e3e9d8eeb5c03de6179fc53e40312e60b0aa9ac1f3e05f49902f30f8b2d5b1a0d0643eb80a8cdbac43c57501cf
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
- source "https://rubygems.org"
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simple_themoviedb (0.1.1)
4
+ simple_themoviedb (0.2.0)
5
5
  httparty
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -18,7 +18,56 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
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
@@ -1,6 +1,6 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "simple_themoviedb"
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 "irb"
13
+ require 'irb'
14
14
  IRB.start(__FILE__)
@@ -1,3 +1,3 @@
1
1
  module SimpleTheMovieDB
2
- VERSION = "0.1.1"
2
+ VERSION = '0.2.0'.freeze
3
3
  end
@@ -1,46 +1,42 @@
1
- require "simple_themoviedb/version"
2
- require "httparty"
1
+ require 'simple_themoviedb/version'
2
+ require 'httparty'
3
3
 
4
4
  module SimpleTheMovieDB
5
5
  class Client
6
- attr_reader :base, :api_key
6
+ attr_reader :api_key
7
7
 
8
- include HTTParty
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 = "/search/movie?"
19
- options = { :query => title, :api_key => @api_key }
20
- options = options.merge( :include_adult => adult ) if adult
21
-
22
- response = self.class.get(url + options.to_query)
23
- parsed_response = response.parsed_response
24
- total_pages = parsed_response["total_pages"]
25
-
26
- if total_pages && total_pages.is_a?(Integer)
27
- (2..total_pages).inject(parsed_response["results"]) do |res, page|
28
- options[:page] = page
29
- page_results = self.class.get(url + options.to_query).parsed_response["results"] || []
30
- res + page_results
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 = "/configuration?"
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 = { :api_key => @api_key }
43
- options = options.merge(:language => lang) if lang
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
- self.class.get(url + to_query(options)).parsed_response
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
@@ -1,38 +1,38 @@
1
1
 
2
- lib = File.expand_path("../lib", __FILE__)
2
+ lib = File.expand_path('lib', __dir__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "simple_themoviedb/version"
4
+ require 'simple_themoviedb/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "simple_themoviedb"
7
+ spec.name = 'simple_themoviedb'
8
8
  spec.version = SimpleTheMovieDB::VERSION
9
- spec.authors = ["Gawyn"]
10
- spec.email = ["me@cristianplanas.com"]
9
+ spec.authors = ['Gawyn']
10
+ spec.email = ['me@cristianplanas.com']
11
11
 
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"
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["allowed_push_host"] = "https://rubygems.org"
20
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
21
21
  else
22
- raise "RubyGems 2.0 or newer is required to protect against " \
23
- "public gem pushes."
22
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
23
+ 'public gem pushes.'
24
24
  end
25
25
 
26
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
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 = "exe"
29
+ spec.bindir = 'exe'
30
30
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
- spec.require_paths = ["lib"]
31
+ spec.require_paths = ['lib']
32
32
 
33
- spec.add_dependency "httparty"
33
+ spec.add_dependency 'httparty'
34
34
 
35
- spec.add_development_dependency "bundler", "~> 1.16"
36
- spec.add_development_dependency "rake", "~> 10.0"
37
- spec.add_development_dependency "rspec", "~> 3.0"
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_themoviedb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gawyn