Class: Filebin
- Inherits:
-
Object
- Object
- Filebin
- Defined in:
- lib/filebin.rb
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"})
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() ["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.
40 41 42 |
# File 'lib/filebin.rb', line 40 def link @link end |
#short_link ⇒ Object
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 |