Sha256: c68a163e38df0b9a551eb5f9f7805369b294c1916b6f176c609287ac931032b1
Contents?: true
Size: 684 Bytes
Versions: 26
Compression:
Stored size: 684 Bytes
Contents
require 'httparty' require 'json' module Peerflixrb module Imdb def self.find(title) params = { 'json' => '1', 'nr' => 1, 'tt' => 'on', 'q' => title } query = HTTParty.get('http://www.imdb.com/xml/find', query: params) results = JSON.load(query)['title_popular'] # Return the most popular for that search Movie.new(results.first) if results end class Movie attr_accessor :imdb_id, :title, :year def initialize(params) @imdb_id = params['id'] @title = params['title'] @year = params['description'].match(/\A\d+/).to_s end def to_s "#{title} (#{year})" end end end end
Version data entries
26 entries across 26 versions & 1 rubygems