Sha256: d3bdd94df7936ffb4c9a707eedb0f2e9d84498abe6ab7c2124f2f0152c59f58d
Contents?: true
Size: 1.81 KB
Versions: 1
Compression:
Stored size: 1.81 KB
Contents
require 'active_support/core_ext/object/blank' require 'crawler/movie/providers/tmdb/configuration' require 'crawler/movie' require 'date' require 'faraday' require 'json' module Crawler module Movie module Providers module Tmdb def self.search(query) movies = [] current_page = 1 loop do response = Faraday.get('https://api.themoviedb.org/3/search/movie', api_key: config.api_key, language: config.language, query: query, page: current_page, include_adult: config.include_adult, region: config.region ) break if !response.success? || !response.body json = JSON.parse(response.body) results = json['results'].map do |movie| { id: movie['id'], source: 'the-movie-database', title: movie['title'], poster_url: movie['poster_path'].presence && "https://image.tmdb.org/t/p/original#{movie['poster_path']}", backdrop_url: movie['backdrop_path'].presence && "https://image.tmdb.org/t/p/original#{movie['backdrop_path']}", original_languages: movie['original_language'].present? ? [movie['original_language']] : [], original_title: movie['original_title'].presence, genres: movie['genre_ids'], overview: movie['overview'].presence, release_date: movie['release_date'].present? && Date.parse(movie['release_date']) } end movies.concat(results) break if current_page >= json['total_pages'] current_page += 1 end movies end end end end end Crawler::Movie.add_provider :tmdb, score: 0.95
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
crawler-movie-tmdb-1.0.2 | lib/crawler/movie/providers/tmdb.rb |