Class: Qnap::FileStation

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

Constant Summary collapse

DEBUG =
false
DISCARD_EXTRANEOUS =
true
PROTOCOL =
'https'
API_METHODS =
{
	cancel_compress: [:pid],
	cancel_extract: [:pid],
	cancel_transcode: [:pid],
	cancel_trash_recovery: [:pid],
	compress: [:compress_file, :compress_name, :encryipt, :level, :pwd, :total, :type],
	copy: [:dest_path, :dup, :mode, :source_file, :source_path, :source_total],
	createdir: [:dest_folder, :dest_path],
	delete: [:file_name, :file_total, :path],
	delete_share: [:download_link, :file_total, :filename],
	delete_share_all: [],
	delete_transcode: [:file_name, :file_total, :keep_trans, :mode, :path],
	download: [:compress, :isfolder, :source_file, :source_path, :source_total],
	extract: [:code_page, :dest_path, :extract_file, :mode, :overwrite, :path_mode, :pwd],
	get_compress_status: [:pid],
	get_domain_ip_list: [],
	get_extract_list: [:code_page, :dir, :extract_file, :limit, :path, :sort, :start],
	get_file_size: [:name, :name, :path, :total],
	get_list: [:dir, :filename, :flv_720, :hidden_file, :is_iso, :limit, :list_mode, :mp4_360, :mp4_720, :path, :sort, :start, :type],
	get_share_link: [:access_code, :access_enabled, :addressee, :content, :day, :download_type, :file_name, :file_total, :hostname, :hour, :include_access_code, :network_type, :path, :ssl, :subject, :valid_duration],
	get_share_list: [:dir, :limit, :sort, :start],
	get_thumb: [:name, :path, :size],
	get_tree: [:is_iso, :node],
	get_video_qstatus: [:pid],
	move: [:mode, :source_file, :source_path, :source_total],
	qrpac: [:op],
	rename: [:dest_name, :path, :source_name],
	search: [:dir, :keyword, :limit, :sort, :source_path, :start],
	share_file: [:access_code, :access_enabled, :addressee, :content, :day, :dowdownload_type, :expire_time, :file_name, :file_total, :hostname, :hour, :include_access_code, :link_url, :mail_content_date, :mail_content_pwd, :network_type, :path, :ssl, :subject, :valid_duration],
	stat: [:file_name, :file_total, :mtime, :path, :settime],
	trash_recovery: [:mode, :source_file, :source_path, :source_total],
	update_share_link: [:access_code, :access_enabled, :datetime, :dowdownload_type, :file_total, :hostname, :ssids, :ssl, :valid_duration],
	upload: [:dest_path, :overwrite, :progress, :type],
	video_list: [:source_path, :source_total],
	video_ml_queue: [:filename, :op, :path, :subop, :total],
	video_ml_status: [:filename, :path, :total],
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, username, password) ⇒ FileStation

Returns a new instance of FileStation.



106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/qnap/file_station.rb', line 106

def initialize(host, username, password)
	@host     = host
	@username = username
	@password = password
	@sid      = nil
	@base_uri = URI "#{PROTOCOL}://#{@host}"
	@path     = "/cgi-bin/filemanager/utilRequest.cgi"
	@agent    = Net::HTTP.new @base_uri.host, @base_uri.port
	
	@agent.use_ssl = PROTOCOL == 'https',
	@agent.verify_mode = OpenSSL::SSL::VERIFY_NONE
	@agent.keep_alive_timeout = 10
	@agent.set_debug_output $stdout if DEBUG
end

Class Method Details

.session(*args) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/qnap/file_station.rb', line 51

def self.session(*args)
	ds = self.new *args
	begin
		yield ds
	ensure
		ds.logout
	end
end

Instance Method Details

#get_sidObject



102
103
104
# File 'lib/qnap/file_station.rb', line 102

def get_sid
	@sid ||= (user: @username, pwd: Base64.encode64(@password).strip)[:sid]
end

#login(params = {}) ⇒ Object



81
82
83
84
85
86
# File 'lib/qnap/file_station.rb', line 81

def (params={})
	despatch_query(
		"/cgi-bin/filemanager/wfm2Login.cgi",
		params
	)
end

#logout(params = {}) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/qnap/file_station.rb', line 88

def logout(params={})
	return unless @sid
	despatch_query(
		"/cgi-bin/filemanager/wfm2Logout.cgi",
		params.merge(sid: @sid)
	)
	@sid = nil

	if @agent.started?
		@agent.finish
		puts "\e[1;32mClosing connection\e[0m" if DEBUG
	end
end