transmission-rpc-ruby-ext 0.1.0

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.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +5 -0
  5. data/CHANGELOG.md +3 -0
  6. data/Gemfile +10 -0
  7. data/Gemfile.lock +62 -0
  8. data/LICENSE +19 -0
  9. data/README.md +173 -0
  10. data/Rakefile +5 -0
  11. data/lib/transmission.rb +11 -0
  12. data/lib/transmission/arguments.rb +50 -0
  13. data/lib/transmission/arguments/location_set.rb +11 -0
  14. data/lib/transmission/arguments/session_set.rb +56 -0
  15. data/lib/transmission/arguments/torrent_add.rb +24 -0
  16. data/lib/transmission/arguments/torrent_set.rb +32 -0
  17. data/lib/transmission/config.rb +18 -0
  18. data/lib/transmission/extensions.rb +4 -0
  19. data/lib/transmission/extensions/torrent_actions.rb +15 -0
  20. data/lib/transmission/extensions/torrent_attributes.rb +103 -0
  21. data/lib/transmission/extensions/torrent_status.rb +42 -0
  22. data/lib/transmission/extensions/transmission.rb +82 -0
  23. data/lib/transmission/fields.rb +41 -0
  24. data/lib/transmission/fields/session_get.rb +61 -0
  25. data/lib/transmission/fields/session_stats.rb +15 -0
  26. data/lib/transmission/fields/torrent_get.rb +76 -0
  27. data/lib/transmission/model.rb +8 -0
  28. data/lib/transmission/model/session.rb +48 -0
  29. data/lib/transmission/model/session_stats.rb +28 -0
  30. data/lib/transmission/model/torrent.rb +152 -0
  31. data/lib/transmission/rpc.rb +116 -0
  32. data/lib/transmission/rpc/connector.rb +67 -0
  33. data/lib/transmission/utils.rb +24 -0
  34. data/spec/helpers/stubs.rb +82 -0
  35. data/spec/spec_helper.rb +13 -0
  36. data/spec/transmission/arguments_spec.rb +78 -0
  37. data/spec/transmission/fields_spec.rb +60 -0
  38. data/spec/transmission/model/session_spec.rb +85 -0
  39. data/spec/transmission/model/torrent_spec.rb +345 -0
  40. data/spec/transmission/rpc/connector_spec.rb +82 -0
  41. data/spec/transmission/rpc_spec.rb +33 -0
  42. data/spec/transmission/utils_spec.rb +69 -0
  43. data/transmission-rpc-ruby-ext.gemspec +17 -0
  44. metadata +141 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 66baaca80a270473f4376d93b17afe57752e4141
4
+ data.tar.gz: 44d49c586066b362dfd039c4172786f21741877b
5
+ SHA512:
6
+ metadata.gz: 0bc47e4df2187ef7fc082b3339559792a86f123812a406d091ae1b79ce813e143440a5f2628ea4000fa906a70c22723533340af2cc2f2dd3a7617d090aac682e
7
+ data.tar.gz: c2b07193fd83431021f1990887549d620532f5de469042198924f6ae5e07502d6fbb5cb22524304847e95838b14f08865604e4948278af8ff9514c0663430173
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ ## Documentation cache and generated files:
14
+ /.yardoc/
15
+ /_yardoc/
16
+ /doc/
17
+ /rdoc/
18
+
19
+ ## Environment normalization:
20
+ /.bundle/
21
+ /vendor/bundle
22
+ /lib/bundler/man/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2
4
+ - 2.1
5
+ - 2.0
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## v0.1.0 (2016-12-28)
2
+
3
+ - Initial fork and basic additions.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'faraday', '~> 0.10'
4
+
5
+ group :development, :test do
6
+ gem 'rspec', '~> 3.5'
7
+ gem 'webmock', '~> 2.3'
8
+ gem 'rake', '~> 12.0'
9
+ gem 'coveralls', '~> 0.8', require: false
10
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,62 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ addressable (2.5.0)
5
+ public_suffix (~> 2.0, >= 2.0.2)
6
+ coveralls (0.8.17)
7
+ json (>= 1.8, < 3)
8
+ simplecov (~> 0.12.0)
9
+ term-ansicolor (~> 1.3)
10
+ thor (~> 0.19.1)
11
+ tins (~> 1.6)
12
+ crack (0.4.3)
13
+ safe_yaml (~> 1.0.0)
14
+ diff-lcs (1.2.5)
15
+ docile (1.1.5)
16
+ faraday (0.10.0)
17
+ multipart-post (>= 1.2, < 3)
18
+ hashdiff (0.3.2)
19
+ json (2.0.2)
20
+ multipart-post (2.0.0)
21
+ public_suffix (2.0.4)
22
+ rake (12.0.0)
23
+ rspec (3.5.0)
24
+ rspec-core (~> 3.5.0)
25
+ rspec-expectations (~> 3.5.0)
26
+ rspec-mocks (~> 3.5.0)
27
+ rspec-core (3.5.4)
28
+ rspec-support (~> 3.5.0)
29
+ rspec-expectations (3.5.0)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.5.0)
32
+ rspec-mocks (3.5.0)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.5.0)
35
+ rspec-support (3.5.0)
36
+ safe_yaml (1.0.4)
37
+ simplecov (0.12.0)
38
+ docile (~> 1.1.0)
39
+ json (>= 1.8, < 3)
40
+ simplecov-html (~> 0.10.0)
41
+ simplecov-html (0.10.0)
42
+ term-ansicolor (1.4.0)
43
+ tins (~> 1.0)
44
+ thor (0.19.4)
45
+ tins (1.13.0)
46
+ webmock (2.3.1)
47
+ addressable (>= 2.3.6)
48
+ crack (>= 0.3.2)
49
+ hashdiff
50
+
51
+ PLATFORMS
52
+ ruby
53
+
54
+ DEPENDENCIES
55
+ coveralls (~> 0.8)
56
+ faraday (~> 0.10)
57
+ rake (~> 12.0)
58
+ rspec (~> 3.5)
59
+ webmock (~> 2.3)
60
+
61
+ BUNDLED WITH
62
+ 1.13.6
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2015 Tommaso Barbato
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,173 @@
1
+ # Transmission RPC Ruby Extended
2
+
3
+ [![Build Status](https://travis-ci.org/epistrephein/transmission-rpc-ruby-ext.svg?branch=master)](https://travis-ci.org/epistrephein/transmission-rpc-ruby-ext) [![Code Climate](https://codeclimate.com/github/epistrephein/transmission-rpc-ruby-ext/badges/gpa.svg)](https://codeclimate.com/github/epistrephein/transmission-rpc-ruby-ext) [![Coverage Status](https://coveralls.io/repos/github/epistrephein/transmission-rpc-ruby-ext/badge.svg?branch=master)](https://coveralls.io/github/epistrephein/transmission-rpc-ruby-ext?branch=master) [![Dependency Status](https://gemnasium.com/badges/github.com/epistrephein/transmission-rpc-ruby-ext.svg)](https://gemnasium.com/github.com/epistrephein/transmission-rpc-ruby-ext) [![Inline docs](http://inch-ci.org/github/epistrephein/transmission-rpc-ruby-ext.svg?branch=master)](http://inch-ci.org/github/epistrephein/transmission-rpc-ruby-ext)
4
+
5
+ This is a fork of [transmission-rails/transmission-rpc-ruby](https://github.com/transmission-rails/transmission-rpc-ruby) with some shortcut methods added and revised codebase.
6
+
7
+ ## Installation
8
+
9
+ ```
10
+ gem install transmission-rpc-ruby-ext
11
+ ```
12
+
13
+ Then require it
14
+
15
+ ```ruby
16
+ require 'transmission'
17
+ ```
18
+
19
+ ## Additions
20
+
21
+ Get an array of all torrents
22
+
23
+ ```ruby
24
+ Transmission.all
25
+ ```
26
+
27
+ All finished torrents
28
+
29
+ ```ruby
30
+ Transmission.finished
31
+ ```
32
+
33
+ All completed or incomplete torrents
34
+
35
+ ```ruby
36
+ Transmission.completed
37
+ Transmission.incomplete
38
+ ```
39
+
40
+ All torrents based on status
41
+
42
+ ```ruby
43
+ Transmission.paused # status 0
44
+ Transmission.queued # status 3
45
+ Transmission.downloading # status 4
46
+ Transmission.seeding # status 6
47
+ ```
48
+
49
+ All torrents with error
50
+
51
+ ```ruby
52
+ Transmission.error
53
+ ```
54
+
55
+ All hashes of all torrents
56
+
57
+ ```ruby
58
+ Transmission.hashes
59
+ ```
60
+
61
+ Find torrents by name, hash, id or tracker
62
+
63
+ ```ruby
64
+ Transmission.find_by_name('Ubuntu')
65
+ Transmission.find_by_hash('fe086f9b15e4956a671ab9b9c5da526e3d3b270c')
66
+ Transmission.find_by_id(5)
67
+ Transmission.find_by_tracker('open.demonii.com')
68
+ ```
69
+
70
+ ### Single torrent methods
71
+
72
+ ```ruby
73
+ t = Transmission.all.first
74
+ ```
75
+
76
+ Basic attributes
77
+
78
+ ```ruby
79
+ t.name
80
+ # => "ubuntu-16.04-desktop-amd64.iso"
81
+ t.path
82
+ # => "/Users/epistrephein/Downloads/ubuntu-16.04-desktop-amd64.iso"
83
+ t.id
84
+ # => 13
85
+ t.hash
86
+ # => "4344503b7e797ebf31582327a5baae35b11bda01"
87
+ ```
88
+
89
+ Status
90
+
91
+ ```ruby
92
+ t.paused?
93
+ # => false
94
+ t.queued?
95
+ # => false
96
+ t.downloading?
97
+ # => true
98
+ t.seeding?
99
+ # => false
100
+ t.finished?
101
+ # => false
102
+ t.completed?
103
+ # => false
104
+ t.incomplete?
105
+ # => false
106
+ t.error?
107
+ # => false
108
+ ```
109
+
110
+ Size
111
+
112
+ ```ruby
113
+ t.length
114
+ # => 1485881344
115
+ t.valid
116
+ # => 18232
117
+ t.percent_downloaded
118
+ # => 1.2
119
+ t.percent_uploaded
120
+ # => 0.1
121
+ t.percent_ratio
122
+ # => 0.1
123
+ t.ratio
124
+ # => -1.0
125
+ ```
126
+
127
+ Speed
128
+
129
+ ```ruby
130
+ t.speed_download
131
+ # => 12
132
+ t.speed_upload
133
+ # => 9
134
+ ```
135
+
136
+ Ratio & ETA
137
+
138
+ ```ruby
139
+ t.ratio
140
+ # => -1.0
141
+ t.eta
142
+ ```
143
+
144
+ Files and folders
145
+
146
+ ```ruby
147
+ t.file?
148
+ t.folder?
149
+ t.files
150
+ t.content
151
+ t.biggest
152
+ t.smallest
153
+ ```
154
+
155
+ Magnet link
156
+
157
+ ```ruby
158
+ t.magnet
159
+ ```
160
+
161
+ Trackers
162
+
163
+ ```ruby
164
+ t.trackers
165
+ ```
166
+
167
+ Actions
168
+
169
+ ```ruby
170
+ t.reload!
171
+ t.remove!
172
+ t.remove_data!
173
+ ```
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ task default: [:spec]
2
+
3
+ task :spec do
4
+ system 'rspec'
5
+ end
@@ -0,0 +1,11 @@
1
+ require_relative 'transmission/rpc'
2
+ require_relative 'transmission/model'
3
+ require_relative 'transmission/config'
4
+ require_relative 'transmission/fields'
5
+ require_relative 'transmission/arguments'
6
+ require_relative 'transmission/utils'
7
+ require_relative 'transmission/extensions'
8
+
9
+ module Transmission
10
+ VERSION = '0.1.0'.freeze
11
+ end
@@ -0,0 +1,50 @@
1
+ require_relative 'arguments/torrent_add'
2
+ require_relative 'arguments/torrent_set'
3
+ require_relative 'arguments/session_set'
4
+ require_relative 'arguments/location_set'
5
+ require_relative 'utils'
6
+
7
+ module Transmission
8
+ class Arguments
9
+ class InvalidArgument < StandardError; end
10
+
11
+ attr_accessor :arguments
12
+
13
+ ATTRIBUTES = []
14
+
15
+ def initialize(arguments = nil)
16
+ @arguments = arguments.inject({}) do |attributes, (key, value)|
17
+ key = key.to_s
18
+ found = self.class::ATTRIBUTES.select { |attr| attr[:field] == key }
19
+ raise Transmission::Arguments::InvalidArgument, key if found.empty?
20
+ attributes[key] = value
21
+ attributes
22
+ end if arguments
23
+ @arguments = self.class::ATTRIBUTES if arguments.nil?
24
+ end
25
+
26
+ def to_arguments
27
+ @arguments
28
+ end
29
+
30
+ class << self
31
+ include Transmission::Utils
32
+
33
+ def is_valid?(key)
34
+ is_valid_key? key, self::ATTRIBUTES
35
+ end
36
+
37
+ def real_key(key)
38
+ option_key key, self::ATTRIBUTES
39
+ end
40
+
41
+ def filter(arguments)
42
+ arguments.inject({}) do |hash, (key, value)|
43
+ found = self::ATTRIBUTES.select { |attr| attr[:field] == key.to_s }
44
+ hash[key] = value unless found.empty?
45
+ hash
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,11 @@
1
+ module Transmission
2
+ class Arguments
3
+ class LocationSet < Transmission::Arguments
4
+ ATTRIBUTES = [
5
+ { field: 'ids' },
6
+ { field: 'location' },
7
+ { field: 'move' }
8
+ ].freeze
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,56 @@
1
+ module Transmission
2
+ class Arguments
3
+ class SessionSet < Transmission::Arguments
4
+ ATTRIBUTES = [
5
+ { field: 'alt-speed-down' },
6
+ { field: 'alt-speed-enabled' },
7
+ { field: 'alt-speed-time-begin' },
8
+ { field: 'alt-speed-time-enabled' },
9
+ { field: 'alt-speed-time-end' },
10
+ { field: 'alt-speed-time-day' },
11
+ { field: 'alt-speed-up' },
12
+ { field: 'blocklist-url' },
13
+ { field: 'blocklist-update' },
14
+ { field: 'blocklist-enabled' },
15
+ { field: 'cache-size-mb' },
16
+ { field: 'download-dir' },
17
+ { field: 'download-queue-size' },
18
+ { field: 'download-queue-enabled' },
19
+ { field: 'dht-enabled' },
20
+ { field: 'encryption' },
21
+ { field: 'required' },
22
+ { field: 'preferred' },
23
+ { field: 'tolerated' },
24
+ { field: 'idle-seeding-limit' },
25
+ { field: 'idle-seeding-limit-enabled' },
26
+ { field: 'incomplete-dir' },
27
+ { field: 'incomplete-dir-enabled' },
28
+ { field: 'lpd-enabled' },
29
+ { field: 'peer-limit-global' },
30
+ { field: 'peer-limit-per-torrent' },
31
+ { field: 'pex-enabled' },
32
+ { field: 'peer-port' },
33
+ { field: 'peer-port-random-on-start' },
34
+ { field: 'port-forwarding-enabled' },
35
+ { field: 'queue-stalled-enabled' },
36
+ { field: 'queue-stalled-minutes' },
37
+ { field: 'rename-partial-files' },
38
+ { field: 'script-torrent-done-filename' },
39
+ { field: 'script-torrent-done-enabled' },
40
+ { field: 'done' },
41
+ { field: 'seedRatioLimit' },
42
+ { field: 'seedRatioLimited' },
43
+ { field: 'seed-queue-size' },
44
+ { field: 'seed-queue-enabled' },
45
+ { field: 'speed-limit-down' },
46
+ { field: 'speed-limit-down-enabled' },
47
+ { field: 'speed-limit-up' },
48
+ { field: 'speed-limit-up-enabled' },
49
+ { field: 'start-added-torrents' },
50
+ { field: 'trash-original-torrent-files' },
51
+ { field: 'units' },
52
+ { field: 'utp-enabled' }
53
+ ].freeze
54
+ end
55
+ end
56
+ end