Class: Filebin

Inherits:
Object
  • Object
show all
Defined in:
lib/filebin.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Filebin

This method takes a hash containing the variables in the POST request.

fbin = Filebin.new({ "path" => "file_path"})


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/filebin.rb', line 17

def initialize(options)
    options["MAX_FILE_SIZE"] = "82428800"

    # Get UPLOAD_IDENTIFIER
    clnt = HTTPClient.new
    res = clnt.get('http://filebin.ca').content
    doc = Hpricot(res)
    options["UPLOAD_IDENTIFIER"] = doc.at("//div[@id='form']/fieldset/form/input[2]")['value']

    # Upload file
    File.open(options["path"]) do |file|
        options["file"] = file
        options.delete("path")
        clnt = HTTPClient.new
        res = clnt.post('http://filebin.ca/upload.php', options).content
        doc = Hpricot(res)
    end

    doc.inner_html.match(/file is available at (.*)\n/)
    @link = $1
end

Instance Method Details

Returns the link to the uploaded file.



40
41
42
# File 'lib/filebin.rb', line 40

def link
    @link
end

Returns a shortened link to the uploaded file.



45
46
47
48
49
50
# File 'lib/filebin.rb', line 45

def short_link
    clnt = HTTPClient.new
    res = clnt.get('http://is.gd/api.php', {:longurl => @link} ).content
    doc = Hpricot(res)
    doc.html
end