lib/meme.rb
##
# Generates a meme with +line1+ and +line2+.  For some generators you only
# have to supply one line because the first line is defaulted for you.
# Isn't that great?
Generates a meme with +line1+ and +line2+.  For some generators you only
have to supply one line because the first line is defaulted for you.
Generates a meme with + line1 + and + line2 + . For some generators you only have to supply one line because the first line is defaulted for you .
def generate line1, line2 = nil
    url = URI.parse 'http://memegenerator.net/Instance/CreateOrEdit'
    res = nil
    location = nil
    unless line2 then
      line2 = line1
      line1 = @default_line
    end
    raise Error, "two lines are required for #{@generator_name}" unless line1
    Net::HTTP.start url.host do |http|
      post = Net::HTTP::Post.new url.path
      post['User-Agent'] = USER_AGENT
      post.set_form_data('templateType'  => 'AdviceDogSpinoff',
                         'text0'         => line1,
                         'text1'         => line2,
                         'templateID'    => @template_id,
                         'generatorName' => @generator_name)
      res = http.request post
      location = res['Location']
      redirect = url + location
      get = Net::HTTP::Get.new redirect.request_uri
      get['User-Agent'] = USER_AGENT
      res = http.request get
    end
    doc = Nokogiri.HTML res.body
    doc.css("a[href=\"#{location}\"] img").first['src']
  end
def generate line1 , line2 = nil url = URI . parse 'http://memegenerator.net/Instance/CreateOrEdit' res = nil location = nil unless line2 then line2 = line1 line1 = @default_line end raise Error , "two lines are required for #{@generator_name}" unless line1 Net :: HTTP . start url . host do | http | post = Net :: HTTP :: Post . new url . path post [ 'User-Agent' ] = USER_AGENT post . set_form_data ( 'templateType' => 'AdviceDogSpinoff' , 'text0' => line1 , 'text1' => line2 , 'templateID' => @template_id , 'generatorName' => @generator_name ) res = http . request post location = res [ 'Location' ] redirect = url + location get = Net :: HTTP :: Get . new redirect . request_uri get [ 'User-Agent' ] = USER_AGENT res = http . request get end doc = Nokogiri . HTML res . body doc . css ( "a[href=\"#{location}\"] img" ) . first [ 'src' ] end
Generates a meme with +line1+ and +line2+.
Generates a meme with + line1 + and + line2 + .
line1
line2