Sha256: cf3165a5e2f84af3d2c72771e5df8768fa255c61cbe540e6374f06d4260c819b

Contents?: true

Size: 1.26 KB

Versions: 5

Compression:

Stored size: 1.26 KB

Contents

#!/usr/bin/env ruby
#
# imagebin.ca class
#

require 'rubygems'
require 'httpclient'
require 'hpricot'

class Imagebin
    # This method takes a hash containing the variables in the POST
    # request.
    #
    #   ibin = Imagebin.new( { "t" => "file",
    #                          "name" => "",
    #                          "tags" => "",
    #                          "description" => "",
    #                          "adult" => "f",
    #                          "f" => "file_path",
    #                        }) 
    #
    def initialize(options)
        File.open(options["f"]) do |file|
            options["f"] = file
            clnt = HTTPClient.new
            res = clnt.post('http://imagebin.ca/upload.php', options).content
            @doc = Hpricot(res)
        end
    end

    # Returns the link to the HTML site of the post.
    #
    #   ibin.site_link    #=> "http://imagebin.ca/view/xxxxxxx.html"
    #
    def site_link
        @doc.at("a").innerHTML
    end

    # Returns the direct link to the file posted.
    #
    #   ibin.pic_link    #=> "http://imagebin.ca/img/xxxxxxx.jpg"
    #
    def pic_link
        clnt = HTTPClient.new
        res = clnt.get(@doc.at("a").innerHTML).content
        doc = Hpricot(res)
        doc.at("#theimg")["src"]
    end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
dougsko-imagebin-0.3.2 lib/imagebin.rb
imagebin-0.3.5 lib/imagebin.rb
imagebin-0.3.4 lib/imagebin.rb
imagebin-0.3.3 lib/imagebin.rb
imagebin-0.3.2 lib/imagebin.rb