Class: Lita::Handlers::OnewheelTwitterPhoto

Inherits:
Handler
  • Object
show all
Defined in:
lib/lita/handlers/onewheel_twitter_photo.rb

Instance Method Summary collapse

Instance Method Details

#get_twitter_photo(response) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 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) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# 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\./, ''
    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)
  end
end