Sha256: 39e0cd4d48aea92a553bf35bd76ba7b4c671c6d07f39dd3356f04b43732ee8cc

Contents?: true

Size: 943 Bytes

Versions: 2

Compression:

Stored size: 943 Bytes

Contents

require 'rest-client'
require 'nokogiri'

module Lita
  module Handlers
    class OnewheelFilmplot < Handler
      config :api_key
      config :distance
      config :mode, default: :irc

      route /^filmplot\s+(.*)$/i,
            :get_plot,
            command: true,
            help: { '!filmplot <title>' => 'Gives you rotten tomatoes\' film summary.' }
      route /^plotline\s+(.*)$/i,
            :get_plot,
            command: true

      def get_plot(response)
        movie_slug = response.matches[0][0].gsub ' ', '_'
        begin
          r = RestClient.get("https://www.rottentomatoes.com/m/#{movie_slug}")
          noko_doc = Nokogiri::HTML(r)
          node = noko_doc.css('div#movieSynopsis')
          response.reply node.text.strip
        rescue RestClient::ResourceNotFound => e
          response.reply "#{movie_slug} not found."
        end
      end
    end

    Lita.register_handler(OnewheelFilmplot)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lita-onewheel-filmplot-0.0.2 lib/lita/handlers/onewheel_filmplot.rb
lita-onewheel-filmplot-0.0.1 lib/lita/handlers/onewheel_filmplot.rb