Class: Qnap::DownloadStation
- Inherits:
-
Object
- Object
- Qnap::DownloadStation
- Defined in:
- lib/qnap/download_station.rb
Constant Summary collapse
- PROTOCOL =
'https'- APP_NAME =
'downloadstation'- API_VERSION =
'V4'- API_METHODS =
{ misc: [:dir, :env, :login, :logout, :socks_5], task: [:status, :query, :detail, :add_url, :add_torrent, :start, :stop, :pause, :remove, :priority, :get_file, :set_file, :get_torrent_file], rss: [:add, :query, :update, :remove, :query_feed, :update_feed, :add_job, :query_job, :update_job, :remove_job], config: [:get, :set], account: [:add, :query, :update, :remove], addon: [:query, :enable, :verify, :install, :uninstall, :search], }
Class Method Summary collapse
Instance Method Summary collapse
- #get_sid ⇒ Object
-
#initialize(host, username = , password = ) ⇒ DownloadStation
constructor
A new instance of DownloadStation.
- #logout ⇒ Object
- #misc_login(params = {}) ⇒ Object
Constructor Details
#initialize(host, username = , password = ) ⇒ DownloadStation
Returns a new instance of DownloadStation.
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/qnap/download_station.rb', line 63 def initialize(host, username = ENV['QNAP_USERNAME'], password = ENV['QNAP_PASSWORD']) raise ArgumentError.new("No username defined") if username.nil? raise ArgumentError.new("No password defined") if password.nil? @host = host @username = username @password = password @sid = nil end |
Class Method Details
.session(*args) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/qnap/download_station.rb', line 20 def self.session(*args) ds = self.new *args begin yield ds ensure ds.logout end end |
Instance Method Details
#get_sid ⇒ Object
59 60 61 |
# File 'lib/qnap/download_station.rb', line 59 def get_sid @sid ||= misc_login(user: @username, pass: Base64.encode64(@password))[:sid] end |
#logout ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/qnap/download_station.rb', line 29 def logout return unless @sid data = misc_logout @sid = nil data end |
#misc_login(params = {}) ⇒ Object
38 39 40 41 42 |
# File 'lib/qnap/download_station.rb', line 38 def misc_login(params={}) # override the auto-gen method # otherwise `get_sid` is called despatch_query(uri_for_path(:misc, :login), params) end |