class Lita::Handlers::OnewheelTwitterPhoto

Public Instance Methods

get_twitter_photo(response) click to toggle source
# File lib/lita/handlers/onewheel_twitter_photo.rb, line 11
def get_twitter_photo(response)
  uri = response.matches[0][0]
  doc = RestClient.get uri
  noko_doc = Nokogiri::HTML doc
  noko_doc.xpath('//meta').each do |meta|
    attrs = meta.attributes
    if attrs['property'].to_s == 'og:image'
      image = attrs['content'].to_s
      if /media/.match image
        Lita.logger.debug 'Twitter image response: ' + image.sub(/:large/, '')
        response.reply image.sub /:large/, ''
      end
    end
  end
end
get_twitter_title(response) click to toggle source
# File lib/lita/handlers/onewheel_twitter_photo.rb, line 27
def get_twitter_title(response)
  if response.message.source.room == config.room
    uri = response.matches[0][0]
    uri.sub! /mobile\./, ''
    Lita.logger.debug "Getting #{uri}"
    doc = RestClient.get uri
    noko_doc = Nokogiri::HTML doc
    title = noko_doc.xpath('//title').text.to_s
    Lita.logger.debug title
    response.reply title
    get_twitter_photo(response)
  else
    Lita.logger.debug "#{response.message.source.room} !== #{config.room}"
  end
end