qnap-download_station 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 95c97768502e19e7b96d3d507bf82287141dfede
4
+ data.tar.gz: 78f15e2110972d614542ecf16b22c49e8f170e53
5
+ SHA512:
6
+ metadata.gz: 4c110e4dc4cd730ccf8970961c10b77af96e6bc14847af6c2246db0f5644901cd7cc99c599ecd9609bbc255e86ace8159413da1afc8600f5654ea67604753034
7
+ data.tar.gz: ba26c14d726db3a5e30f80a44a0fa3cfd71e1e141d54be7e48f399be5b35eb22462d7ddf78efe0d3496c4cb5024a574828429103e78d05b5b55bfddf66f012cc
@@ -0,0 +1,85 @@
1
+ Qnap::DownloadStation
2
+ =======
3
+
4
+ This gem provides an interface to the Download Station app that comes installed by default on many QNAP NAS
5
+
6
+ It proves access to all endpoints, but only a few have been documented.
7
+
8
+ Installation
9
+ -------
10
+
11
+ `gem install qnap-download_station`
12
+
13
+ Usage
14
+ -------
15
+
16
+ ```ruby
17
+ require 'qnap/download_station'
18
+
19
+ magnet_link = "magnet:?xt=urn:btih:c12fe1c06bba254a9dc9f519b335aa7c1367a88a&dn"
20
+
21
+ ds = Qnap::DownloadStation.new '192.168.1.100', 'username', 'password'
22
+ ds.task_add_url temp: 'Download', move: 'Multimedia/New', url: magnet_link
23
+ active_downloads = ds.task_query
24
+ ds.logout
25
+ ```
26
+
27
+ Available methods
28
+ -------
29
+
30
+ **Account methods**
31
+ * account_add
32
+ * account_query
33
+ * account_remove
34
+ * account_update
35
+
36
+ **Addon methods**
37
+ * addon_enable
38
+ * addon_install
39
+ * addon_query
40
+ * addon_search
41
+ * addon_uninstall
42
+ * addon_verify
43
+
44
+ **Config methods**
45
+ * config_get
46
+ * config_set
47
+
48
+ **Misc methods**
49
+ * misc_dir
50
+ * misc_env
51
+ * misc_login
52
+ * misc_logout
53
+ * misc_socks_5
54
+
55
+ **Rss methods**
56
+ * rss_add
57
+ * rss_add_job
58
+ * rss_query
59
+ * rss_query_feed
60
+ * rss_query_job
61
+ * rss_remove
62
+ * rss_remove_job
63
+ * rss_update
64
+ * rss_update_feed
65
+ * rss_update_job
66
+
67
+ **Tasks**
68
+ * task_add_torrent
69
+ * task_add_url
70
+ * task_detail
71
+ * task_get_file
72
+ * task_pause
73
+ * task_priority
74
+ * task_query
75
+ * task_remove
76
+ * task_set_file
77
+ * task_start
78
+ * task_status
79
+ * task_stop
80
+
81
+ Notes and known issues
82
+ -------
83
+
84
+ * Needs inputs validation
85
+ * Need to allow users to specify a SSL cert instead of just ignoring certificate errors
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ end
6
+
7
+ desc "Run tests"
8
+ task :default => :test
@@ -0,0 +1,91 @@
1
+ require 'json'
2
+ require 'net/http'
3
+ require 'openssl'
4
+ require 'base64'
5
+
6
+ module Qnap
7
+ class DownloadStation
8
+ PROTOCOL = 'https'
9
+ APP_NAME = 'downloadstation'
10
+ API_VERSION = 'V4'
11
+ API_METHODS = {
12
+ misc: [:dir, :env, :login, :logout, :socks_5],
13
+ task: [:status, :query, :detail, :add_url, :add_torrent, :start, :stop, :pause, :remove, :priority, :get_file, :set_file],
14
+ rss: [:add, :query, :update, :remove, :query_feed, :update_feed, :add_job, :query_job, :update_job, :remove_job],
15
+ config: [:get, :set],
16
+ account: [:add, :query, :update, :remove],
17
+ addon: [:query, :enable, :verify, :install, :uninstall, :search],
18
+ }
19
+
20
+ def logout
21
+ return unless @sid
22
+
23
+ data = misc_logout
24
+
25
+ @sid = nil
26
+ data
27
+ end
28
+
29
+ def misc_login(params={})
30
+ # override the auto-gen method
31
+ # otherwise `get_sid` is called
32
+ despatch_query(uri_for_path(:misc, :login), params)
33
+ end
34
+
35
+ API_METHODS.each do |app, endpoints|
36
+ endpoints.each do |endpoint|
37
+
38
+ method_name = "#{app}_#{endpoint}".to_sym
39
+ next if method_defined? method_name
40
+
41
+ define_method method_name, Proc.new { |params={}|
42
+ despatch_query(
43
+ uri_for_path(app, endpoint),
44
+ params.merge(sid: get_sid)
45
+ )
46
+ }
47
+ end
48
+ end
49
+
50
+ def get_sid
51
+ @sid ||= misc_login(user: @username, pass: Base64.encode64(@password))[:sid]
52
+ end
53
+
54
+ def initialize(host, username, password)
55
+ @host = host
56
+ @username = username
57
+ @password = password
58
+ @sid = nil
59
+ end
60
+
61
+ private
62
+
63
+ def uri_for_path(app, endpoint)
64
+ path = [app, endpoint].map { |s| s.to_s.gsub(/(^|_)(.)/){ $2.upcase } }.join "/"
65
+ URI("#{PROTOCOL}://#{@host}/#{APP_NAME}/#{API_VERSION}/#{path}")
66
+ end
67
+
68
+ def despatch_query(uri, params)
69
+ req = Net::HTTP::Post.new uri
70
+ req.form_data = params
71
+
72
+ response = Net::HTTP.start(
73
+ uri.host,
74
+ uri.port,
75
+ use_ssl: PROTOCOL == 'https',
76
+ verify_mode: OpenSSL::SSL::VERIFY_NONE
77
+ ) do |https|
78
+ https.request req
79
+ end
80
+
81
+ data = JSON.parse response.read_body, symbolize_names: true
82
+
83
+ if (data.key?(:error) and data[:error] > 0)
84
+ pp data
85
+ raise RuntimeError.new data[:reason]
86
+ end
87
+
88
+ data
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,13 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "qnap-download_station"
3
+ s.version = "0.0.1"
4
+ s.date = "2016-09-21"
5
+ s.summary = "Interface to the Download Station API"
6
+ s.description = "Manage your downloads in Download Station"
7
+ s.authors = "cyclotron3k"
8
+ s.files = ["lib/qnap/download_station.rb", "Rakefile", "qnap-download_station.gemspec", "README.md"]
9
+ s.test_files = ["test/test_download_station.rb"]
10
+ s.homepage = "https://github.com/cyclotron3k/qnap-download_station"
11
+ s.license = "MIT"
12
+ s.required_ruby_version = ">= 1.9.0"
13
+ end
@@ -0,0 +1,10 @@
1
+ require 'minitest/autorun'
2
+ require 'qnap/download_station'
3
+
4
+ class TestDownloadStation < Minitest::Test
5
+ def test_argument
6
+ assert_raises ArgumentError do
7
+ Qnap::DownloadStation.new
8
+ end
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qnap-download_station
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - cyclotron3k
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-21 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Manage your downloads in Download Station
14
+ email:
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - README.md
20
+ - Rakefile
21
+ - lib/qnap/download_station.rb
22
+ - qnap-download_station.gemspec
23
+ - test/test_download_station.rb
24
+ homepage: https://github.com/cyclotron3k/qnap-download_station
25
+ licenses:
26
+ - MIT
27
+ metadata: {}
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 1.9.0
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 2.5.1
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: Interface to the Download Station API
48
+ test_files:
49
+ - test/test_download_station.rb