Class: Lita::Handlers::WhatsBradEating

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

Constant Summary collapse

BLOG_URL =

START:blog_url

'https://whatsbradeating.tumblr.com'.freeze

Instance Method Summary collapse

Instance Method Details

#brad_eats(response) ⇒ Object

START:brad_eats



36
37
38
39
40
41
42
43
44
# File 'lib/lita/handlers/whats_brad_eating.rb', line 36

def brad_eats(response)
  # caption text had some stray newlines we don't need
  caption_text = caption.text.strip
  img_url = image.get_attribute('src')

  msg = "#{caption_text} >> #{img_url}"

  response.reply msg
end

#captionObject



31
32
33
# File 'lib/lita/handlers/whats_brad_eating.rb', line 31

def caption
  image.attributes.fetch('alt')
end

#first_postObject



23
24
25
# File 'lib/lita/handlers/whats_brad_eating.rb', line 23

def first_post
  parsed_response.css('section.post').first
end

#imageObject



27
28
29
# File 'lib/lita/handlers/whats_brad_eating.rb', line 27

def image
  first_post.css('.photo-wrapper img').first
end

#parsed_responseObject

END:blog_url



19
20
21
# File 'lib/lita/handlers/whats_brad_eating.rb', line 19

def parsed_response
  Nokogiri.parse(response.body)
end

#responseObject



14
15
16
# File 'lib/lita/handlers/whats_brad_eating.rb', line 14

def response
  @_response ||= http.get(BLOG_URL)
end