lib/meme.rb
def generate *args
      url = URI.parse 'http://memegenerator.net/create/instance'
      res = nil
      location = nil

      # Prepend the default line if this meme has one and we only had 1 text input
      args.unshift @default_line if @default_line and args.size <= 1

      raise Error, "two lines are required for #{@generator_name}" unless
        args.size > 1

      post_data = { 'imageID'    => @template_id,
                    'generatorID' => @generator_id,
                    'watermark1' => 1,
                    'uploadtoImgur' => 'false' }

      # go through each argument and add it back into the post data as textN
      (0..args.size).map {|num| post_data.merge! "text#{num}" => args[num] }

      Net::HTTP.start url.host do |http|
        post = Net::HTTP::Post.new url.path
        post['User-Agent'] = USER_AGENT
        post.set_form_data post_data

        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

      if Net::HTTPSuccess === res then
        doc = Nokogiri.HTML res.body
        doc.css("meta")[7]['content']
      else
        raise Error, "memegenerator.net appears to be down, got #{res.code}"
      end
    end
##
# 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 *args
      url = URI.parse 'http://memegenerator.net/create/instance'
      res = nil
      location = nil
      args.unshift @default_line if @default_line and args.size <= 1
      raise Error, "two lines are required for #{@generator_name}" unless
        args.size > 1
      post_data = { 'imageID'    => @template_id,
                    'generatorID' => @generator_id,
                    'watermark1' => 1,
                    'uploadtoImgur' => 'false' }
      (0..args.size).map {|num| post_data.merge! "text#{num}" => args[num] }
      Net::HTTP.start url.host do |http|
        post = Net::HTTP::Post.new url.path
        post['User-Agent'] = USER_AGENT
        post.set_form_data post_data
        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
      if Net::HTTPSuccess === res then
        doc = Nokogiri.HTML res.body
        doc.css("meta")[7]['content']
      else
        raise Error, "memegenerator.net appears to be down, got #{res.code}"
      end
    end
def generate * args url = URI . parse 'http://memegenerator.net/create/instance' res = nil location = nil args . unshift @default_line if @default_line and args . size <= 1 raise Error , "two lines are required for #{@generator_name}" unless args . size > 1 post_data = { 'imageID' => @template_id , 'generatorID' => @generator_id , 'watermark1' => 1 , 'uploadtoImgur' => 'false' } ( 0 .. args . size ) . map { | num | post_data . merge! "text#{num}" => args [ num ] } Net :: HTTP . start url . host do | http | post = Net :: HTTP :: Post . new url . path post [ 'User-Agent' ] = USER_AGENT post . set_form_data post_data 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 if Net :: HTTPSuccess === res then doc = Nokogiri . HTML res . body doc . css ( "meta" ) [ 7 ] [ 'content' ] else raise Error , "memegenerator.net appears to be down, got #{res.code}" end end
Generates a meme with +line1+ and +line2+.
Generates a meme with + line1 + and + line2 + .
# Prepend the default line if this meme has one and we only had 1 text input # go through each argument and add it back into the post data as textN
args