Class: Filebin
Instance Method Summary collapse
-
#initialize(options) ⇒ Filebin
constructor
This method takes a hash containing the variables in the POST request.
-
#link ⇒ Object
Returns the link to the uploaded file.
-
#short_link ⇒ Object
Returns a shortened link to the uploaded file.
Constructor Details
#initialize(options) ⇒ Filebin
This method takes a hash containing the variables in the POST request.
fbin = Filebin.new({ "path" => "file_path"})
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/filebin.rb', line 19 def initialize() ["MAX_FILE_SIZE"] = "82428800" # Get UPLOAD_IDENTIFIER clnt = HTTPClient.new res = clnt.get('http://filebin.ca').content doc = Hpricot(res) ["UPLOAD_IDENTIFIER"] = doc.at("//div[@id='form']/fieldset/form/input[2]")['value'] # Upload file File.open(["path"]) do |file| ["file"] = file .delete("path") clnt = HTTPClient.new res = clnt.post('http://filebin.ca/upload.php', ).content doc = Hpricot(res) end doc.inner_html.match(/file is available at (.*)\n/) @link = $1 end |
Instance Method Details
#link ⇒ Object
Returns the link to the uploaded file.
42 43 44 |
# File 'lib/filebin.rb', line 42 def link @link end |
#short_link ⇒ Object
Returns a shortened link to the uploaded file.
47 48 49 |
# File 'lib/filebin.rb', line 47 def short_link UrlShort::IsGd.shorten @link end |