Class: Stashboxr
- Inherits:
-
Object
- Object
- Stashboxr
- Defined in:
- lib/stashboxr.rb
Overview
A library for dealing with files on stashbox.org
Defined Under Namespace
Classes: File
Constant Summary collapse
- Agent =
Settings for the browser emulation
Mechanize.new { |agent| agent.user_agent = 'Stashboxr' }
Class Method Summary collapse
- .autosave=(pref) ⇒ Object
- .autosave? ⇒ Boolean
-
.loggedin? ⇒ Boolean
Is someone logged in?.
-
.login(username, password) ⇒ Object
Log into stashbox.
-
.logout ⇒ Object
Log out of stashbox.
-
.search(q) ⇒ Object
Search stashbox.org - the site has this advice for formatting searches:.
-
.username ⇒ Object
Username of current logged in user (nil if not logged in).
Class Method Details
.autosave=(pref) ⇒ Object
47 48 49 |
# File 'lib/stashboxr.rb', line 47 def self.autosave=(pref) @@autosave = (pref == true) end |
.autosave? ⇒ Boolean
51 52 53 |
# File 'lib/stashboxr.rb', line 51 def self.autosave? @@autosave rescue true end |
.loggedin? ⇒ Boolean
Is someone logged in?
38 39 40 |
# File 'lib/stashboxr.rb', line 38 def self.loggedin? !@@username.nil? rescue false end |
.login(username, password) ⇒ Object
Log into stashbox
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/stashboxr.rb', line 19 def self.login(username,password) res = Agent.post('http://stashbox.org/',{ :dologin => 1, :user => username, :password => password }) raise RuntimeError, "Log in failed" if res.code != "200" @@username = username end |
.logout ⇒ Object
Log out of stashbox
31 32 33 34 35 |
# File 'lib/stashboxr.rb', line 31 def self.logout Agent.get('http://stashbox.org/logout.php') @@username = nil true end |
.search(q) ⇒ Object
Search stashbox.org - the site has this advice for formatting searches:
You can use any number of terms in your search, all of which will be required in the results. You can also use the following search types (using “type:the_type” format): archives, audio, code, documents, images, movies
Search types can be combined with normal search keywords to refine your results.
In addition, remember you can search for both full and partial mimetypes, ie application/pdf.
62 63 64 65 66 67 68 |
# File 'lib/stashboxr.rb', line 62 def self.search(q) res = Nokogiri::XML(Agent.get("http://stashbox.org/browse.php?wants_rss=1&q=#{URI.encode(q)}").body) res.search('//item').collect do |item| File.new(item.search('link').inner_text) end end |
.username ⇒ Object
Username of current logged in user (nil if not logged in)
43 44 45 |
# File 'lib/stashboxr.rb', line 43 def self.username @@username end |