synowebapi 0.0.2 → 0.0.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7ec3b360d441100cae0596ff45f524c9f48156e0
4
- data.tar.gz: a685d90e737519bce903bbfd62594a197a56b931
2
+ SHA256:
3
+ metadata.gz: cd7b2c36dcab9883e6f5f5487f7d25393a3a230d4e0d5fd1d75e7c6ffd2709e3
4
+ data.tar.gz: 52b1b96765944fde24b2aa6c3ebcbbb2fd6528297879f8b57f6339b02e1d52af
5
5
  SHA512:
6
- metadata.gz: 978be7989b2a57cdc5de5119dba59f8c7374980fa9b6f947da6ca966a54bdb8c3abc00177963c05751ce6ddad1026a40edfea716ebc8318fc550d857ff3dbf16
7
- data.tar.gz: c4e4250cef5f09be9f4fe01393eea63e31ee194c610207146dac02a00cbc23c678a0c5020d427742e6b038b09dca816626d72fdca814fbb2c179b2270ddf09f4
6
+ metadata.gz: 139fde7fc431783e0f3aa22864811f5039eeac85db8e08ef0dbd5cab123f4755e66694885bb3f7af81e2ce05ed8019e92e9c5f94214d32c32dd6439366f9f370
7
+ data.tar.gz: 94a8472a89085e32e507c463c7af3523fc0954581e95024e824f01e513f63cf99108c68db8cf9f01b6c398f8cd8384a2b50ab1a915708c4adf35ece06d8feacb
data/Gemfile.lock ADDED
@@ -0,0 +1,26 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ synowebapi (0.0.3)
5
+ faraday (~> 0)
6
+ faraday_middleware (~> 0)
7
+ httpclient
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ faraday (0.17.6)
13
+ multipart-post (>= 1.2, < 3)
14
+ faraday_middleware (0.14.0)
15
+ faraday (>= 0.7.4, < 1.0)
16
+ httpclient (2.8.3)
17
+ multipart-post (2.4.0)
18
+
19
+ PLATFORMS
20
+ x86_64-linux
21
+
22
+ DEPENDENCIES
23
+ synowebapi!
24
+
25
+ BUNDLED WITH
26
+ 2.3.5
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+
2
+ http://cccheng.mit-license.org/
3
+
4
+ Copyright © 2015 Chung-Chiang Cheng <shepjeng@gmail.com>
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ THE SOFTWARE.
23
+
data/README.md CHANGED
@@ -4,7 +4,7 @@ Ruby gem for [Synology](http://www.synology.com//) Web API
4
4
 
5
5
  ## Installation
6
6
 
7
- ```
7
+ ```sh
8
8
  $ gem install synowebapi
9
9
  ```
10
10
 
@@ -16,38 +16,29 @@ require 'synowebapi'
16
16
  client = SYNOWebAPI::Client.new('http://192.168.10.10:5000')
17
17
  client.connect(username: 'admin', password: 'password')
18
18
 
19
+ # Enable telnet service
20
+ # Check `cat /usr/syno/synoman/webapi/SYNO.Core.Terminal.lib | jq` for partial API info
19
21
  client['SYNO.Core.Terminal'].request(method: 'set', enable_telnet: true)
22
+ # Yet another way to send the identical request above
20
23
  client['SYNO.Core.Terminal'].set(enable_ssh: true)
21
24
 
25
+ # Show disks information.
26
+ # Check `cat /usr/syno/synoman/webapi/SYNO.Storage.CGI.lib | jq` for partial API info
27
+ resp = client['SYNO.Storage.CGI.Storage'].load_info
28
+ resp['disks'].each do |disk|
29
+ puts "%-8s %-10s %-25s %-20s" % [disk['name'], disk['vendor'], disk['model'], disk['serial']]
30
+ end
31
+
32
+ # Download file from shared folder 'public'
33
+ # https://global.download.synology.com/download/Document/DeveloperGuide/Synology_File_Station_API_Guide.pdf
34
+ client['SYNO.FileStation.Download'].download('/any/test.jpg', {method: 'download', version: 2, path: '/public/file', mode: 'open'})
35
+
22
36
  client.disconnect
23
37
  ```
24
38
 
25
39
  ## Requirements
26
40
 
41
+ * httpclient
27
42
  * faraday
28
43
  * faraday-middleware
29
44
 
30
- ## License
31
-
32
- http://cccheng.mit-license.org/
33
-
34
- Copyright © 2015 Chung-Chiang Cheng <shepjeng@gmail.com>
35
-
36
- Permission is hereby granted, free of charge, to any person obtaining a copy
37
- of this software and associated documentation files (the "Software"), to deal
38
- in the Software without restriction, including without limitation the rights
39
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
40
- copies of the Software, and to permit persons to whom the Software is
41
- furnished to do so, subject to the following conditions:
42
-
43
- The above copyright notice and this permission notice shall be included in
44
- all copies or substantial portions of the Software.
45
-
46
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
47
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
48
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
49
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
50
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
51
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
52
- THE SOFTWARE.
53
-
@@ -15,6 +15,20 @@ module SYNOWebAPI
15
15
  @request_format = params['requestFormat']
16
16
  end
17
17
 
18
+ def download(output_path, params, options = {})
19
+ @client.download(self, output_path, params, options)
20
+ end
21
+
22
+ def post(params)
23
+ resp = @client.post(self, params)
24
+
25
+ if resp['success']
26
+ resp['data']
27
+ else
28
+ error_handling(resp['error'])
29
+ end
30
+ end
31
+
18
32
  def request(params)
19
33
  resp = @client.send(self, params)
20
34
 
@@ -7,15 +7,14 @@ module SYNOWebAPI
7
7
  class Client
8
8
  attr_reader :url, :api, :session_id, :session_name
9
9
 
10
- def initialize(url, **params)
10
+ def initialize(url)
11
11
  @url = url
12
12
  @session_id = @session_name = ''
13
13
  @conn = Faraday.new(:url => @url) do |f|
14
14
  f.request(:url_encoded)
15
+ f.response(:json)
15
16
  f.adapter(Faraday.default_adapter)
16
- f.use(FaradayMiddleware::ParseJson)
17
17
  end
18
- connect(params) if params
19
18
  end
20
19
 
21
20
  def connect(params)
@@ -33,6 +32,37 @@ module SYNOWebAPI
33
32
  self['SYNO.API.Auth'].logout(:session => @session_id)
34
33
  end
35
34
 
35
+ def download(api, output_path, params = {}, options = {})
36
+ require 'httpclient'
37
+ http_client = HTTPClient.new
38
+ if options[:receive_timeout]
39
+ http_client.receive_timeout = options[:receive_timeout]
40
+ end
41
+ open(output_path, 'wb') do |file|
42
+ http_client.get_content(
43
+ URI.parse(URI.encode("#{@url}/webapi/#{api.path}")),
44
+ {
45
+ :api => api.api_name,
46
+ :version => api.max_version,
47
+ :_sid => @session_id,
48
+ }.merge(params)
49
+ ) do |chunk|
50
+ file.write chunk
51
+ end
52
+ end
53
+ end
54
+
55
+ def post(api, params = {})
56
+ @conn.post("/webapi/#{api.path}", {
57
+ :api => api.api_name,
58
+ :version => api.max_version,
59
+ :_sid => @session_id,
60
+ }.merge(params)).body
61
+
62
+ rescue Faraday::ParsingError
63
+ raise StandardError.new("Failed to parse response")
64
+ end
65
+
36
66
  def send(api, params = {})
37
67
  @conn.get("/webapi/#{api.path}", {
38
68
  :api => api.api_name,
@@ -62,8 +92,10 @@ module SYNOWebAPI
62
92
  api[api_name] = API.new(api_name, self, params)
63
93
  end
64
94
  end
95
+
96
+ rescue Faraday::ParsingError
97
+ raise StandardError.new("Failed to parse query response")
65
98
  end
66
99
 
67
100
  end
68
101
  end
69
-
@@ -1,5 +1,5 @@
1
1
 
2
2
  module SYNOWebAPI
3
- VERSION = '0.0.2'
3
+ VERSION = '0.0.4'
4
4
  end
5
5
 
data/lib/synowebapi.rb CHANGED
@@ -9,5 +9,4 @@ module SYNOWebAPI
9
9
  require 'synowebapi/version'
10
10
  require 'synowebapi/client'
11
11
  require 'synowebapi/api'
12
-
13
12
  end
data/synowebapi.gemspec CHANGED
@@ -9,12 +9,13 @@ Gem::Specification.new do |s|
9
9
  s.email = ['shepjeng@gmail.com', 'cccheng@synology.com']
10
10
  s.summary = 'Ruby gem for Synology Web API'
11
11
  s.description = s.summary
12
- s.homepage = 'http://github.com/shepjeng/ruby-synowebapi'
12
+ s.homepage = 'https://github.com/Synology/ruby-synowebapi'
13
13
  s.license = 'MIT'
14
14
 
15
15
  s.files = %x[git ls-files].split($/).sort
16
16
  s.require_paths = ['lib']
17
17
 
18
- s.add_dependency 'faraday', '~> 0'
19
- s.add_dependency 'faraday_middleware', '~> 0'
18
+ s.add_dependency 'httpclient'
19
+ s.add_dependency 'faraday'
20
+ s.add_dependency 'faraday_middleware'
20
21
  end
metadata CHANGED
@@ -1,41 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synowebapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chung-Chiang Cheng
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-07 00:00:00.000000000 Z
11
+ date: 2024-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httpclient
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: faraday
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
- - - "~>"
31
+ - - ">="
18
32
  - !ruby/object:Gem::Version
19
33
  version: '0'
20
34
  type: :runtime
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
- - - "~>"
38
+ - - ">="
25
39
  - !ruby/object:Gem::Version
26
40
  version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: faraday_middleware
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - "~>"
45
+ - - ">="
32
46
  - !ruby/object:Gem::Version
33
47
  version: '0'
34
48
  type: :runtime
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - "~>"
52
+ - - ">="
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
41
55
  description: Ruby gem for Synology Web API
@@ -47,6 +61,8 @@ extensions: []
47
61
  extra_rdoc_files: []
48
62
  files:
49
63
  - Gemfile
64
+ - Gemfile.lock
65
+ - LICENSE
50
66
  - README.md
51
67
  - lib/synowebapi.rb
52
68
  - lib/synowebapi/api.rb
@@ -54,7 +70,7 @@ files:
54
70
  - lib/synowebapi/error.rb
55
71
  - lib/synowebapi/version.rb
56
72
  - synowebapi.gemspec
57
- homepage: http://github.com/shepjeng/ruby-synowebapi
73
+ homepage: https://github.com/Synology/ruby-synowebapi
58
74
  licenses:
59
75
  - MIT
60
76
  metadata: {}
@@ -73,8 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
89
  - !ruby/object:Gem::Version
74
90
  version: '0'
75
91
  requirements: []
76
- rubyforge_project:
77
- rubygems_version: 2.4.5
92
+ rubygems_version: 3.3.5
78
93
  signing_key:
79
94
  specification_version: 4
80
95
  summary: Ruby gem for Synology Web API