Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ahmetabdi/themoviedb
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: trakt/themoviedb
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 9 commits
  • 9 files changed
  • 2 contributors

Commits on Sep 2, 2014

  1. Copy the full SHA
    3e27e9b View commit details

Commits on Sep 3, 2014

  1. Copy the full SHA
    a296232 View commit details

Commits on Sep 5, 2014

  1. Copy the full SHA
    a894ab3 View commit details
  2. Copy the full SHA
    1d79e26 View commit details

Commits on Sep 16, 2014

  1. tv latest added

    rudf0rd committed Sep 16, 2014
    Copy the full SHA
    8296167 View commit details

Commits on Feb 29, 2016

  1. movie/similar, tv/similar

    rectifyer committed Feb 29, 2016
    Copy the full SHA
    72e5a8b View commit details

Commits on Mar 1, 2016

  1. allow debug mode

    rectifyer committed Mar 1, 2016
    Copy the full SHA
    dc9f94b View commit details
  2. Copy the full SHA
    39bdfc9 View commit details

Commits on Jul 10, 2017

  1. Copy the full SHA
    79b9fe6 View commit details
Showing with 126 additions and 15 deletions.
  1. +2 −1 lib/themoviedb/api.rb
  2. +27 −0 lib/themoviedb/episode.rb
  3. +18 −5 lib/themoviedb/movie.rb
  4. +13 −3 lib/themoviedb/person.rb
  5. +3 −2 lib/themoviedb/resource.rb
  6. +9 −2 lib/themoviedb/search.rb
  7. +24 −0 lib/themoviedb/season.rb
  8. +29 −1 lib/themoviedb/tv.rb
  9. +1 −1 lib/themoviedb/version.rb
3 changes: 2 additions & 1 deletion lib/themoviedb/api.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module Tmdb
class Api
include HTTParty
base_uri 'http://api.themoviedb.org/3/'
# debug_output $stdout
base_uri 'https://api.themoviedb.org/3/'
format :json
headers 'Accept' => 'application/json'
headers 'Content-Type' => 'application/json'
27 changes: 27 additions & 0 deletions lib/themoviedb/episode.rb
Original file line number Diff line number Diff line change
@@ -2,6 +2,33 @@ module Tmdb
class Episode < Resource
has_resource 'episode', :plural => 'episodes'

@@fields = [
:air_date,
:episode_number,
:name,
:overview,
:id,
:production_code,
:season_number,
:still_path,
:vote_average,
:vote_count,
:changes,
:credits,
:external_ids,
:images,
:videos,
:page,
:total_pages,
:total_results,
:start_date,
:end_date
]

@@fields.each do |field|
attr_accessor field
end

#Get the primary information about a TV episode by combination of a season and episode number.
def self.detail(id, season, episode, conditions={})
search = Tmdb::Search.new("/tv/#{self.endpoint_id + id.to_s}/season/#{self.endpoint_id + season.to_s}/#{self.endpoints[:singular]}/#{self.endpoint_id + episode.to_s}")
23 changes: 18 additions & 5 deletions lib/themoviedb/movie.rb
Original file line number Diff line number Diff line change
@@ -36,7 +36,12 @@ class Movie < Resource
:translations,
:reviews,
:lists,
:changes
:changes,
:page,
:total_pages,
:total_results,
:start_date,
:end_date
]

@@fields.each do |field|
@@ -129,8 +134,8 @@ def self.translations(id, conditions={})
end

#Get the similar movies for a specific movie id.
def self.similar_movies(id, conditions={})
search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/similar_movies")
def self.similar(id, conditions={})
search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/similar")
search.filter(conditions)
search.fetch
end
@@ -146,8 +151,16 @@ def self.lists(id, conditions={})
#By default, only the last 24 hours of changes are returned.
#The maximum number of days that can be returned in a single request is 14.
#The language is present on fields that are translatable.
def self.changes(id, conditions={})
search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/changes")
#
#If no id passed, will grab list of all movies udpated over the last 24 hours (default)
#Accepts conditions: page, start_date, end_date
def self.changes(id=nil, conditions={})
if id.present?
search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/changes")
else
search = Tmdb::Search.new("/movie/changes")
search.filter(conditions)
end
search.fetch_response
end

16 changes: 13 additions & 3 deletions lib/themoviedb/person.rb
Original file line number Diff line number Diff line change
@@ -18,7 +18,12 @@ class Person < Resource
:tv_credits,
:combined_credits,
:images,
:changes
:changes,
:page,
:total_pages,
:total_results,
:start_date,
:end_date
]

@@fields.each do |field|
@@ -77,8 +82,13 @@ def self.tagged_images(id, conditions={})
#Changes are grouped by key, and ordered by date in descending order.
#By default, only the last 24 hours of changes are returned.
#The maximum number of days that can be returned in a single request is 14. The language is present on fields that are translatable.
def self.changes(id, conditions={})
search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/changes")
def self.changes(id=nil, conditions={})
if id.present?
search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/changes")
else
search = Tmdb::Search.new("/person/changes")
search.filter(conditions)
end
search.fetch_response
end

5 changes: 3 additions & 2 deletions lib/themoviedb/resource.rb
Original file line number Diff line number Diff line change
@@ -34,8 +34,9 @@ def self.list(conditions={})
end
end

def self.search(query)
def self.search(query, conditions={})
search = Tmdb::Search.new
search.filter(conditions)
search.resource("#{self.endpoints[:singular]}")
search.query(query)
search.fetch.collect do |result|
@@ -55,4 +56,4 @@ def initialize(attributes={})
end
end
end
end
end
11 changes: 9 additions & 2 deletions lib/themoviedb/search.rb
Original file line number Diff line number Diff line change
@@ -65,14 +65,21 @@ def fetch_response(conditions={})
if conditions[:external_source]
options = @params.merge(Api.config.merge({external_source: conditions[:external_source]}))
else
options = @params.merge(Api.config)
options = Api.config.merge(@params)
end
response = Api.get(@resource, :query => options)

# rate limit reached
if response.code == 429
puts "TMDB rate limit reached: waiting 10 seconds"
sleep 11
response = Api.get(@resource, :query => options)
end

original_etag = response.headers.fetch('etag', '')
etag = original_etag.gsub(/"/, '')

Api.set_response({'code' => response.code, 'etag' => etag})
Api.set_response('code' => response.code, 'etag' => etag)
return response.to_hash.to_hashugar
end
end
24 changes: 24 additions & 0 deletions lib/themoviedb/season.rb
Original file line number Diff line number Diff line change
@@ -2,6 +2,30 @@ module Tmdb
class Season < Resource
has_resource 'season', :plural => 'seasons'

@@fields = [
:air_date,
:episodes,
:name,
:overview,
:id,
:poster_path,
:season_number,
:credits,
:external_ids,
:images,
:videos,
:changes,
:page,
:total_pages,
:total_results,
:start_date,
:end_date
]

@@fields.each do |field|
attr_accessor field
end

#Get the primary information about a TV season by its season number.
def self.detail(id, season, conditions={})
search = Tmdb::Search.new("/tv/#{self.endpoint_id + id.to_s}/#{self.endpoints[:singular]}/#{self.endpoint_id + season.to_s}")
30 changes: 29 additions & 1 deletion lib/themoviedb/tv.rb
Original file line number Diff line number Diff line change
@@ -28,13 +28,25 @@ class TV < Resource
:vote_average,
:vote_count,
:credits,
:external_ids
:external_ids,
:changes,
:page,
:total_pages,
:total_results,
:start_date,
:end_date
]

@@fields.each do |field|
attr_accessor field
end

#Get the latest movie id. singular
def self.latest
search = Tmdb::Search.new("/tv/latest")
search.fetch_response
end

#Get the list of popular TV shows. This list refreshes every day.
def self.popular
search = Tmdb::Search.new("/tv/popular")
@@ -78,5 +90,21 @@ def self.images(id, conditions={})
search.fetch_response
end

#Get the similar tv shows for a specific tv show id.
def self.similar(id, conditions={})
search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/similar")
search.filter(conditions)
search.fetch
end

def self.changes(id=nil, conditions={})
if id.present?
search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/changes")
else
search = Tmdb::Search.new("/tv/changes")
search.filter(conditions)
end
search.fetch_response
end
end
end
2 changes: 1 addition & 1 deletion lib/themoviedb/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Tmdb
VERSION = "0.0.24"
VERSION = "0.0.26"
end