Sha256: 308985a6ba7651487e09e7acd2ce308ea6dfc9dd67d8eb667fe08d8a58e1471d

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

module FilmBuff
  class IMDb
    attr_reader :locale

    include HTTParty
    include HTTParty::Icebox
    cache :store => 'file', :timeout => 120, :location => Dir.tmpdir

    base_uri 'app.imdb.com'
    default_params = {
      "api" => "v1",
      "app_id" => "iphone1_1",
      "locale" => @locale,
      "timestamp" => Time.now.utc.to_i,
      "sig" => "app1_1"
    }

    def initialize
      @locale = "en_US"
    end

    public
    def locale=(locale)
      locales = %w[ de_DE en_US es_ES fr_FR it_IT pt_PT ]

      if locales.include? locale
        @locale = locale
      else
        raise "Unknown locale. Only the following are allowed:\n" <<
        locales.join(", ")
      end
    end

    def find_by_id(imdb_id)
      result = self.class.get('/title/maindetails', :query => {
        tconst: imdb_id
      }).parsed_response
      Title.new(result["data"])
    end

    def find_by_title(title)
      results = self.class.get('/find', :query => { q: title }).parsed_response
      find_by_id(results["data"]["results"][0]["list"][0]["tconst"])
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
filmbuff-0.1.1 lib/filmbuff/imdb.rb
filmbuff-0.1.0 lib/filmbuff/imdb.rb