transmission-rpc-ruby-ext 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 66baaca80a270473f4376d93b17afe57752e4141
4
- data.tar.gz: 44d49c586066b362dfd039c4172786f21741877b
3
+ metadata.gz: a17cf176257c2e0add6e0a68b10dcdb9b9453132
4
+ data.tar.gz: de082e8070b0d69044a764a5b628b6c2d67ef8cb
5
5
  SHA512:
6
- metadata.gz: 0bc47e4df2187ef7fc082b3339559792a86f123812a406d091ae1b79ce813e143440a5f2628ea4000fa906a70c22723533340af2cc2f2dd3a7617d090aac682e
7
- data.tar.gz: c2b07193fd83431021f1990887549d620532f5de469042198924f6ae5e07502d6fbb5cb22524304847e95838b14f08865604e4948278af8ff9514c0663430173
6
+ metadata.gz: 28503d810fa4bba2b6fd8ad44ed9094519cd81f34aa6063e4100525451aeeb6788e5dccdfe88c303beb529aeb59130756e248abab6b114f6b751f61cd3ea0133
7
+ data.tar.gz: e6b65db7064efe047dfe72d325d5e69f8ea1de2680c5c18b078e40828b6f1b49960ae14939e9f0d59087d78fcb7f537c0a27ecdd6fdfdd03bd63d4826c250f58
data/.travis.yml CHANGED
@@ -3,3 +3,4 @@ rvm:
3
3
  - 2.2
4
4
  - 2.1
5
5
  - 2.0
6
+ - ruby-head
data/CHANGELOG.md CHANGED
@@ -1,3 +1,24 @@
1
- ## v0.1.0 (2016-12-28)
1
+ # Change Log
2
2
 
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](http://keepachangelog.com/)
6
+ and this project adheres to [Semantic Versioning](http://semver.org/).
7
+
8
+ ## 0.1.1 - 2016-12-31
9
+ ### Added
10
+ - Add `pretty_length`, `pretty_valid` and `pretty_eta` methods.
11
+ - Add `peers`, `peers_seeding` and `peers_leeching` methods.
12
+ - Add better documentation and comments.
13
+ - Add some specs for extensions.
14
+
15
+ ### Changed
16
+ - Minimum ruby version is now `2.0`.
17
+ - Refactor `is_multi?` to `multi?` for best practice compliance.
18
+ - Refactor `is_valid_key?` to for best practice compliance
19
+
20
+ ### Removed
21
+ - Remove `finished?` method (overridden in extensions)
22
+
23
+ ## 0.1.0 - 2016-12-28
3
24
  - Initial fork and basic additions.
data/LICENSE CHANGED
@@ -1,4 +1,7 @@
1
- Copyright (c) 2015 Tommaso Barbato
1
+ MIT License
2
+
3
+ Copyright (c) 2016 Tommaso Barbato
4
+ Portions copyright (c) 2015 Max Hoffmann
2
5
 
3
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
7
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # Transmission RPC Ruby Extended
2
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)
3
+ [![Gem Version](https://badge.fury.io/rb/transmission-rpc-ruby-ext.svg)](https://badge.fury.io/rb/transmission-rpc-ruby-ext) [![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
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.
5
+ This is a fork of [transmission-rpc-ruby](https://github.com/transmission-rails/transmission-rpc-ruby) with some shortcut methods added and revised codebase.
6
+
7
+ Documentation for the original gem can be found in the [upstream repository](https://github.com/transmission-rails/transmission-rpc-ruby).
6
8
 
7
9
  ## Installation
8
10
 
@@ -16,9 +18,18 @@ Then require it
16
18
  require 'transmission'
17
19
  ```
18
20
 
19
- ## Additions
21
+ If both `transmission-rpc-ruby` and `transmission-rpc-ruby-ext` gems are installed, specify the gem to require to avoid namespace conflict.
22
+
23
+ ```ruby
24
+ gem 'transmission-rpc-ruby-ext'
25
+ require 'transmission'
26
+ ```
27
+
28
+ ## Extensions
29
+
30
+ ### Transmission selectors
20
31
 
21
- Get an array of all torrents
32
+ All torrents
22
33
 
23
34
  ```ruby
24
35
  Transmission.all
@@ -49,7 +60,7 @@ Transmission.seeding # status 6
49
60
  All torrents with error
50
61
 
51
62
  ```ruby
52
- Transmission.error
63
+ Transmission.errors
53
64
  ```
54
65
 
55
66
  All hashes of all torrents
@@ -61,34 +72,17 @@ Transmission.hashes
61
72
  Find torrents by name, hash, id or tracker
62
73
 
63
74
  ```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')
75
+ Transmission.find_by_name('ubuntu')
76
+ Transmission.find_by_hash('9f9165d9a281a9b8e782cd5176bbcc8256fd1871')
77
+ Transmission.find_by_id(1)
78
+ Transmission.find_by_tracker('torrent.ubuntu.com')
68
79
  ```
69
80
 
70
- ### Single torrent methods
81
+ ### Torrent status
71
82
 
72
83
  ```ruby
73
84
  t = Transmission.all.first
74
- ```
75
-
76
- Basic attributes
77
85
 
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
86
  t.paused?
93
87
  # => false
94
88
  t.queued?
@@ -107,67 +101,127 @@ t.error?
107
101
  # => false
108
102
  ```
109
103
 
104
+ ### Torrent attributes
105
+
106
+ Basic attributes
107
+
108
+ ```ruby
109
+ t = Transmission.all.first
110
+
111
+ t.name
112
+ # => "ubuntu-16.04.1-desktop-amd64.iso"
113
+ t.path
114
+ # => "/Users/epistrephein/Downloads/ubuntu-16.04-desktop-amd64.iso"
115
+ t.id
116
+ # => 1
117
+ t.hash
118
+ # => "9f9165d9a281a9b8e782cd5176bbcc8256fd1871"
119
+ ```
120
+
110
121
  Size
111
122
 
112
123
  ```ruby
113
124
  t.length
114
- # => 1485881344
125
+ # => 1513308160
115
126
  t.valid
116
- # => 18232
127
+ # => 582696960
117
128
  t.percent_downloaded
118
- # => 1.2
129
+ # => 0.39
119
130
  t.percent_uploaded
120
- # => 0.1
131
+ # => 0.0
121
132
  t.percent_ratio
122
- # => 0.1
123
- t.ratio
124
- # => -1.0
133
+ # => nil
125
134
  ```
126
135
 
127
136
  Speed
128
137
 
129
138
  ```ruby
130
139
  t.speed_download
131
- # => 12
140
+ # => 14477000
132
141
  t.speed_upload
133
- # => 9
142
+ # => 0
134
143
  ```
135
144
 
136
145
  Ratio & ETA
137
146
 
138
147
  ```ruby
139
148
  t.ratio
140
- # => -1.0
149
+ # => 0.0
141
150
  t.eta
151
+ # => 85
142
152
  ```
143
153
 
144
154
  Files and folders
145
155
 
146
156
  ```ruby
147
157
  t.file?
158
+ # => true
148
159
  t.folder?
160
+ # => false
149
161
  t.files
162
+ # => ["/Users/epistrephein/Downloads/ubuntu-16.04-desktop-amd64.iso"]
150
163
  t.content
164
+ # => ["ubuntu-16.04.1-desktop-amd64.iso"]
151
165
  t.biggest
166
+ # => ["ubuntu-16.04.1-desktop-amd64.iso", 1513308160]
152
167
  t.smallest
168
+ # => ["ubuntu-16.04.1-desktop-amd64.iso", 1513308160]
169
+ ```
170
+
171
+ Peers
172
+
173
+ ```ruby
174
+ t.peers
175
+ # => 11
176
+ t.peers_seeding
177
+ # => 9
178
+ t.peers_leeching
179
+ # => 0
180
+ ```
181
+
182
+ Errors
183
+
184
+ ```ruby
185
+ t.error
186
+ # => nil
153
187
  ```
154
188
 
155
189
  Magnet link
156
190
 
157
191
  ```ruby
158
192
  t.magnet
193
+ # => "magnet:?xt=urn:btih:9f9165d9a281a9b8e782cd5176bbcc8256fd1871&dn=ubuntu-16.04.1-desktop-amd64.iso&tr=http%3A%2F%2Ftorrent.ubuntu.com%3A6969%2Fannounce&tr=http%3A%2F%2Fipv6.torrent.ubuntu.com%3A6969%2Fannounce"
159
194
  ```
160
195
 
161
196
  Trackers
162
197
 
163
198
  ```ruby
164
199
  t.trackers
200
+ # => ["torrent.ubuntu.com", "ipv6.torrent.ubuntu.com"]
165
201
  ```
166
202
 
167
- Actions
203
+ ### Torrent prettified attributes
204
+
205
+ ```ruby
206
+ t.pretty_length
207
+ # => "1.51GB"
208
+ t.pretty_valid
209
+ # => "582.7MB"
210
+ t.pretty_eta
211
+ # => "1 minutes, 25 seconds"
212
+ ```
213
+
214
+ ### Torrent actions
168
215
 
169
216
  ```ruby
170
217
  t.reload!
171
218
  t.remove!
172
219
  t.remove_data!
173
220
  ```
221
+
222
+ ## Contributing
223
+
224
+ Contributions are welcome and encouraged. Feel free to open an issue or submit a pull request.
225
+
226
+ ## License
227
+ [MIT License](LICENSE)
data/lib/transmission.rb CHANGED
@@ -7,5 +7,5 @@ require_relative 'transmission/utils'
7
7
  require_relative 'transmission/extensions'
8
8
 
9
9
  module Transmission
10
- VERSION = '0.1.0'.freeze
10
+ VERSION = '0.1.1'.freeze
11
11
  end
@@ -31,7 +31,7 @@ module Transmission
31
31
  include Transmission::Utils
32
32
 
33
33
  def is_valid?(key)
34
- is_valid_key? key, self::ATTRIBUTES
34
+ valid_key? key, self::ATTRIBUTES
35
35
  end
36
36
 
37
37
  def real_key(key)
@@ -1,4 +1,5 @@
1
1
  require_relative 'extensions/torrent_actions'
2
2
  require_relative 'extensions/torrent_attributes'
3
+ require_relative 'extensions/torrent_prettify'
3
4
  require_relative 'extensions/torrent_status'
4
- require_relative 'extensions/transmission'
5
+ require_relative 'extensions/transmission_selectors'
@@ -1,11 +1,13 @@
1
1
  module Transmission
2
2
  module Model
3
3
  class Torrent
4
+ # Removes torrent.
4
5
  def remove!
5
6
  connector.remove_torrent @ids
6
7
  @deleted = true
7
8
  end
8
9
 
10
+ # Removes torrent and trashes data files.
9
11
  def remove_data!
10
12
  connector.remove_torrent @ids, true
11
13
  @deleted = true
@@ -1,95 +1,135 @@
1
1
  module Transmission
2
2
  module Model
3
3
  class Torrent
4
- # torrent attributes methods
4
+ # Returns torrent name.
5
5
  def name
6
6
  attributes['name']
7
7
  end
8
8
 
9
+ # Returns torrent full download path.
9
10
  def path
10
11
  dir = File.expand_path(attributes['downloadDir'])
11
12
  File.join(dir, name)
12
13
  end
13
14
 
15
+ # Returns torrent id.
14
16
  def id
15
17
  attributes['id']
16
18
  end
17
19
 
20
+ # Returns torrent hash.
18
21
  def hash
19
22
  attributes['hashString']
20
23
  end
21
24
 
25
+ # Returns torrent size (in bytes).
22
26
  def length
23
27
  attributes['totalSize']
24
28
  end
25
29
 
30
+ # Returns torrent downloaded files size (in bytes).
26
31
  def valid
27
32
  attributes['haveValid']
28
33
  end
29
34
 
35
+ # Returns torrent downloaded files percent.
30
36
  def percent_downloaded
31
37
  (attributes['haveValid'] * 1.0 / attributes['totalSize']).round(2)
32
38
  end
33
39
 
40
+ # Returns torrent uploaded files percent.
34
41
  def percent_uploaded
35
42
  (attributes['uploadedEver'] * 1.0 / attributes['totalSize']).round(2)
36
43
  end
37
44
 
45
+ # Returns torrent ratio percent if session ratio is set.
38
46
  def percent_ratio
39
47
  session = Transmission::Model::Session.get
40
48
  return unless session.seed_ratio_limited
41
49
  (attributes['uploadRatio'] * 1.0 / session.seed_ratio_limit).round(2)
42
50
  end
43
51
 
52
+ # Returns torrent download speed (in bytes).
44
53
  def speed_download
45
54
  attributes['rateDownload']
46
55
  end
47
56
 
57
+ # Returns torrent upload speed (in bytes).
48
58
  def speed_upload
49
59
  attributes['rateUpload']
50
60
  end
51
61
 
62
+ # Returns torrent ratio.
52
63
  def ratio
53
64
  (attributes['uploadRatio'] * 1.0).round(2)
54
65
  end
55
66
 
67
+ # Returns torrent eta (in seconds).
56
68
  def eta
57
- pretty_time(attributes['eta']) if attributes['eta'] > 0
69
+ attributes['eta']
58
70
  end
59
71
 
72
+ # Returns true if torrent is a single file.
60
73
  def file?
61
74
  name = attributes['name']
62
75
  files = attributes['files']
63
76
  files.size == 1 && files.first['name'] == name
64
77
  end
65
78
 
79
+ # Returns true if torrent is a folder.
66
80
  def folder?
67
81
  !file?
68
82
  end
69
83
 
84
+ # Returns all torrent files full path.
70
85
  def files
71
86
  dir = File.absolute_path(attributes['downloadDir'])
72
87
  attributes['files'].map { |f| File.join(dir, f['name']) }
73
88
  end
74
89
 
90
+ # Returns torrent files names.
75
91
  def content
76
92
  files.map { |f| File.basename(f) }
77
93
  end
78
94
 
95
+ # Returns torrent biggest file and size.
79
96
  def biggest
80
97
  b = attributes['files'].max_by { |f| f['length'] }
81
98
  [File.basename(b['name']), b['length']]
82
99
  end
83
100
 
101
+ # Returns torrent smallest file and size.
84
102
  def smallest
85
103
  b = attributes['files'].min_by { |f| f['length'] }
86
104
  [File.basename(b['name']), b['length']]
87
105
  end
88
106
 
107
+ # Returns torrent peers.
108
+ def peers
109
+ attributes['peersConnected'].size
110
+ end
111
+
112
+ # Returns torrent seeding peers.
113
+ def peers_seeding
114
+ attributes['peersSendingToUs']
115
+ end
116
+
117
+ # Returns torrent leeching peers.
118
+ def peers_leeching
119
+ attributes['peersGettingFromUs']
120
+ end
121
+
122
+ # Returns torrent error string.
123
+ def error
124
+ attributes['errorString'] if error?
125
+ end
126
+
127
+ # Returns torrent magnet link.
89
128
  def magnet
90
129
  attributes['magnetLink']
91
130
  end
92
131
 
132
+ # Returns torrent trackers.
93
133
  def trackers
94
134
  url_regex = /([-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b)(?:[-a-zA-Z0-9@:%_\+.~#?&\/=]*)/i
95
135
  attributes['trackers'].map do |r|
@@ -0,0 +1,57 @@
1
+ module Transmission
2
+ module Model
3
+ class Torrent
4
+ # Returns prettified torrent size.
5
+ def pretty_length
6
+ pretty_size(length)
7
+ end
8
+
9
+ # Returns prettified downloaded files size.
10
+ def pretty_valid
11
+ pretty_size(valid)
12
+ end
13
+
14
+ # Returns prettified eta.
15
+ def pretty_eta
16
+ pretty_time(attributes['eta']) if attributes['eta'] > 0
17
+ end
18
+
19
+ private
20
+
21
+ # Converts filesize to proper units.
22
+ def pretty_size(size)
23
+ {
24
+ 'B' => 1000**1,
25
+ 'KB' => 1000**2,
26
+ 'MB' => 1000**3,
27
+ 'GB' => 1000**4,
28
+ 'TB' => 1000**5
29
+ }.each_pair do |e, s|
30
+ return "#{(size.to_f / (s / 1000)).round(2)}#{e}" if size < s
31
+ end
32
+ end
33
+
34
+ # Convert seconds in seconds/minutes/hours.
35
+ def pretty_time(seconds)
36
+ mm, ss = seconds.divmod(60)
37
+ hh, mm = mm.divmod(60)
38
+ dd, hh = hh.divmod(24)
39
+ eta = {
40
+ days: dd, hours: hh, minutes: mm, seconds: ss
41
+ }.delete_if { |_k, v| v.zero? }
42
+ eta.to_a.map { |e| e.reverse.join(' ') }.join(', ')
43
+ end
44
+
45
+ # Converts status code in status name.
46
+ def status_name
47
+ ['paused', 'check wait', 'check', 'download wait', 'download',
48
+ 'seed wait', 'seed', 'isolated'].at(status)
49
+ end
50
+
51
+ # Converts status code in status symbol.
52
+ def status_symbol
53
+ ['❚❚', '~', '⟳', '⥥', '⬇', '⥣', '⬆', '✘'].at(status)
54
+ end
55
+ end
56
+ end
57
+ end
@@ -1,39 +1,47 @@
1
1
  module Transmission
2
2
  module Model
3
3
  class Torrent
4
- # torrent status methods
4
+ # Returns true if torrent is paused.
5
5
  def paused?
6
6
  attributes['status'] == 0
7
7
  end
8
8
 
9
+ # Returns true if torrent is queued.
9
10
  def queued?
10
11
  attributes['status'] == 3
11
12
  end
12
13
 
14
+ # Returns true if torrent is downloading.
13
15
  def downloading?
14
16
  attributes['status'] == 4
15
17
  end
16
18
 
19
+ # Returns true if torrent is seeding.
17
20
  def seeding?
18
21
  attributes['status'] == 6
19
22
  end
20
23
 
24
+ # Returns true if torrent is isolated.
21
25
  def isolated?
22
26
  attributes['status'] == 7
23
27
  end
24
28
 
29
+ # Returns true if torrent is finished.
25
30
  def finished?
26
31
  attributes['isFinished']
27
32
  end
28
33
 
34
+ # Returns true if torrent is completed.
29
35
  def completed?
30
36
  attributes['percentDone'] >= 1
31
37
  end
32
38
 
39
+ # Returns true if torrent is not completed.
33
40
  def incomplete?
34
41
  attributes['percentDone'] < 1
35
42
  end
36
43
 
44
+ # Returns true if torrent has errors.
37
45
  def error?
38
46
  attributes['error'] != 0
39
47
  end
@@ -1,5 +1,5 @@
1
1
  module Transmission
2
- # list torrents methods
2
+ # Returns all torrents.
3
3
  def self.all(connector = nil)
4
4
  t = Transmission::Model::Torrent.all connector: connector
5
5
  case t.ids.size
@@ -9,56 +9,69 @@ module Transmission
9
9
  end
10
10
  end
11
11
 
12
+ # Returns all finished torrents.
12
13
  def self.finished
13
14
  all.select { |t| t.attributes['isFinished'] }
14
15
  end
15
16
 
17
+ # Returns all completed torrents.
16
18
  def self.completed
17
19
  all.select { |t| t.attributes['percentDone'] >= 1 }
18
20
  end
19
21
 
22
+ # Returns all incomplete torrents.
20
23
  def self.incomplete
21
24
  all.select { |t| t.attributes['percentDone'] < 1 }
22
25
  end
23
26
 
27
+ # Returns all paused torrents.
24
28
  def self.paused
25
29
  all.select { |t| t.attributes['status'] == 0 }
26
30
  end
27
31
 
32
+ # Returns all queued torrents.
28
33
  def self.queued
29
34
  all.select { |t| t.attributes['status'] == 3 }
30
35
  end
31
36
 
37
+ # Returns all downloading torrents.
32
38
  def self.downloading
33
39
  all.select { |t| t.attributes['status'] == 4 }
34
40
  end
35
41
 
42
+ # Returns all seeding torrents.
36
43
  def self.seeding
37
44
  all.select { |t| t.attributes['status'] == 6 }
38
45
  end
39
46
 
40
- def self.error
47
+ # Returns all torrents with errors.
48
+ def self.errors
41
49
  all.select { |t| t.attributes['error'] != 0 }
42
50
  end
43
51
 
52
+ # Returns the hash of every torrents.
44
53
  def self.hashes
45
54
  all.map { |t| t.attributes['hashString'] }
46
55
  end
47
56
 
48
- # find torrents methods
57
+ # Returns all torrents whose name matches +name+.
49
58
  def self.find_by_name(name)
50
59
  re = name.split(' ').join('.*')
51
60
  all.select { |t| t.attributes['name'] =~ /#{re}/i }
52
61
  end
53
62
 
63
+ # Returns all torrents whose hash matches +hash+.
54
64
  def self.find_by_hash(hash)
55
- all.select { |t| t.attributes['hashString'].casecmp(hash) == 0 }
65
+ all.select { |t| t.attributes['hashString'].casecmp(hash).zero? }
56
66
  end
57
67
 
68
+ # Returns all torrents whose id matches +id+.
58
69
  def self.find_by_id(id)
59
70
  all.select { |t| t.attributes['id'] == id }
60
71
  end
61
72
 
73
+ # Returns all torrents whose trackers match +tracker+.
74
+ # FIXME: regex matching is not very precise.
62
75
  def self.find_by_tracker(tracker)
63
76
  url_regex = /([-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b)(?:[-a-zA-Z0-9@:%_\+.~#?&\/=]*)/i
64
77
  re = tracker.split(' ').join('.*')
@@ -71,12 +84,4 @@ module Transmission
71
84
  trackers.any? { |r| r =~ /#{re}/i }
72
85
  end
73
86
  end
74
-
75
- # add torrents methods
76
- def self.add(file, connector = nil)
77
- Transmission::Model::Torrent.add(
78
- connector: connector,
79
- arguments: { filename: file }
80
- )
81
- end
82
87
  end
@@ -30,7 +30,7 @@ module Transmission
30
30
  include Transmission::Utils
31
31
 
32
32
  def is_valid?(key)
33
- is_valid_key? key, self::ATTRIBUTES
33
+ valid_key? key, self::ATTRIBUTES
34
34
  end
35
35
 
36
36
  def real_key(key)
@@ -71,15 +71,10 @@ module Transmission
71
71
  connector.torrent_set_location @ids, location: new_location, move: move
72
72
  end
73
73
 
74
- def is_multi?
74
+ def multi?
75
75
  @ids.size > 1
76
76
  end
77
77
 
78
- # Note: this is overidden by extensions.
79
- # def finished?
80
- # percent_done == 1
81
- # end
82
-
83
78
  def reload!
84
79
  torrents = Torrent.find @ids, connector: @connector
85
80
  @ids = torrents.ids
@@ -89,7 +84,7 @@ module Transmission
89
84
  end
90
85
 
91
86
  def to_json
92
- if is_multi?
87
+ if multi?
93
88
  @torrents.inject([]) do |torrents, torrent|
94
89
  torrents << torrent.to_json
95
90
  end
@@ -1,6 +1,6 @@
1
1
  module Transmission
2
2
  module Utils
3
- def is_valid_key?(key, attributes)
3
+ def valid_key?(key, attributes)
4
4
  !attributes.select do |attribute|
5
5
  option_keys(key).include? attribute[:field]
6
6
  end.empty?
@@ -0,0 +1,28 @@
1
+ describe Transmission::Model::Torrent do
2
+ describe 'extensions' do
3
+ let(:torrent) { Transmission::Model::Torrent.new([{
4
+ 'name' => 'ubuntu-16.04.1-desktop-amd64.iso',
5
+ 'downloadDir' => '/home/user/downloads',
6
+ 'id' => 1,
7
+ 'hashString' => '9f9165d9a281a9b8e782cd5176bbcc8256fd1871'
8
+ }], nil) }
9
+
10
+ describe 'with any torrent' do
11
+ it 'should have a name' do
12
+ expect(torrent.name).not_to be_nil
13
+ expect(torrent.name).to be_a(String)
14
+ end
15
+
16
+ it 'should have a path' do
17
+ expect(torrent.path).not_to be_nil
18
+ expect(torrent.path).to eq(
19
+ '/home/user/downloads/ubuntu-16.04.1-desktop-amd64.iso'
20
+ )
21
+ end
22
+
23
+ it 'should have an hash' do
24
+ expect(torrent.hash).not_to be_nil
25
+ end
26
+ end
27
+ end
28
+ end
@@ -17,7 +17,7 @@ describe Transmission::Model::Torrent do
17
17
  @rpc = Transmission::RPC.new
18
18
  stub_rpc_request
19
19
  .with(body: torrent_get_body)
20
- .to_return(successful_response( arguments: { torrents: [{ id: 1 }] }))
20
+ .to_return(successful_response(arguments: { torrents: [{ id: 1 }] }))
21
21
  end
22
22
 
23
23
  it 'should return a Torrent model instance' do
@@ -193,7 +193,7 @@ describe Transmission::Model::Torrent do
193
193
  stub_get_torrent({ ids: [1, 2] }, [{ id: 1 }, { id: 2 }])
194
194
  stub_rpc_request
195
195
  .with(body: torrent_remove_body(:ids => [1, 2], 'delete-local-data' => false))
196
- .to_return(successful_response(arguments: { torrents: [{ id: 1 }, { id: 2 }]} ))
196
+ .to_return(successful_response(arguments: { torrents: [{ id: 1 }, { id: 2 }] }))
197
197
  end
198
198
 
199
199
  it 'should remove the torrent files' do
@@ -204,19 +204,19 @@ describe Transmission::Model::Torrent do
204
204
  end
205
205
  end
206
206
 
207
- describe '#is_multi?' do
208
- let(:torrents) { Transmission::Model::Torrent.new([{'id' => 1}, {'id' => 2}], nil) }
209
- let(:torrent) { Transmission::Model::Torrent.new([{'id' => 1}], nil) }
207
+ describe '#multi?' do
208
+ let(:torrents) { Transmission::Model::Torrent.new([{ 'id' => 1 }, { 'id' => 2 }], nil) }
209
+ let(:torrent) { Transmission::Model::Torrent.new([{ 'id' => 1 }], nil) }
210
210
 
211
211
  describe 'with multiple torrents' do
212
212
  it 'should return true' do
213
- expect(torrents.is_multi?).to eq(true)
213
+ expect(torrents.multi?).to eq(true)
214
214
  end
215
215
  end
216
216
 
217
217
  describe 'with single torrent' do
218
218
  it 'should return false' do
219
- expect(torrent.is_multi?).to eq(false)
219
+ expect(torrent.multi?).to eq(false)
220
220
  end
221
221
  end
222
222
  end
@@ -233,7 +233,7 @@ describe Transmission::Model::Torrent do
233
233
 
234
234
  describe 'with single torrent' do
235
235
  it 'should return false' do
236
- expect(torrent.to_json).to eq({ 'id' => 1 })
236
+ expect(torrent.to_json).to eq('id' => 1)
237
237
  end
238
238
  end
239
239
  end
@@ -256,11 +256,11 @@ describe Transmission::Model::Torrent do
256
256
  end
257
257
 
258
258
  describe '#method_missing' do
259
- let(:torrent) { Transmission::Model::Torrent.new([{'id' => 1, 'name' => 'some name', 'some-key' => 'some-value'}], nil) }
259
+ let(:torrent) { Transmission::Model::Torrent.new([{ 'id' => 1, 'name' => 'some name', 'some-key' => 'some-value' }], nil) }
260
260
 
261
261
  before :each do
262
- stub_const("Transmission::Fields::TorrentGet::ATTRIBUTES", [{field: 'id'}, {field: 'name'}, {field: 'some-key'}])
263
- stub_const("Transmission::Arguments::TorrentSet::ATTRIBUTES", [{field: 'name'}])
262
+ stub_const('Transmission::Fields::TorrentGet::ATTRIBUTES', [{ field: 'id' }, { field: 'name' }, { field: 'some-key' }])
263
+ stub_const('Transmission::Arguments::TorrentSet::ATTRIBUTES', [{ field: 'name' }])
264
264
  end
265
265
 
266
266
  describe 'with existing attributes' do
@@ -292,14 +292,14 @@ describe Transmission::Model::Torrent do
292
292
  end
293
293
 
294
294
  describe '#save!' do
295
- let(:rpc) {Transmission::RPC.new}
295
+ let(:rpc) { Transmission::RPC.new }
296
296
 
297
297
  before :each do
298
- stub_const("Transmission::Arguments::TorrentSet::ATTRIBUTES", [{field: 'name'}, {field: 'ids'}])
299
- stub_get_torrent({ids: [1]}, [{id: 1, name: 'test', comment: 'comment'}])
298
+ stub_const('Transmission::Arguments::TorrentSet::ATTRIBUTES', [{ field: 'name' }, { field: 'ids' }])
299
+ stub_get_torrent({ ids: [1] }, [{ id: 1, name: 'test', comment: 'comment' }])
300
300
  stub_rpc_request
301
- .with(body: torrent_set_body({name: 'new value', ids: [1]}))
302
- .to_return(successful_response)
301
+ .with(body: torrent_set_body(name: 'new value', ids: [1]))
302
+ .to_return(successful_response)
303
303
  end
304
304
 
305
305
  it 'should send the right parameters' do
@@ -310,28 +310,28 @@ describe Transmission::Model::Torrent do
310
310
  end
311
311
 
312
312
  [
313
- {method: 'start!', rpc_method: 'torrent-start'},
314
- {method: 'start_now!', rpc_method: 'torrent-start-now'},
315
- {method: 'stop!', rpc_method: 'torrent-stop'},
316
- {method: 'verify!', rpc_method: 'torrent-verify'},
317
- {method: 're_announce!', rpc_method: 'torrent-reannounce'},
318
- {method: 'move_up!', rpc_method: 'queue-move-up'},
319
- {method: 'move_down!', rpc_method: 'queue-move-down'},
320
- {method: 'move_top!', rpc_method: 'queue-move-top'},
321
- {method: 'move_bottom!', rpc_method: 'queue-move-bottom'}
313
+ { method: 'start!', rpc_method: 'torrent-start' },
314
+ { method: 'start_now!', rpc_method: 'torrent-start-now' },
315
+ { method: 'stop!', rpc_method: 'torrent-stop' },
316
+ { method: 'verify!', rpc_method: 'torrent-verify' },
317
+ { method: 're_announce!', rpc_method: 'torrent-reannounce' },
318
+ { method: 'move_up!', rpc_method: 'queue-move-up' },
319
+ { method: 'move_down!', rpc_method: 'queue-move-down' },
320
+ { method: 'move_top!', rpc_method: 'queue-move-top' },
321
+ { method: 'move_bottom!', rpc_method: 'queue-move-bottom' }
322
322
  ].each do |object|
323
323
  describe "##{object[:method]}" do
324
- let(:rpc) {Transmission::RPC.new}
324
+ let(:rpc) { Transmission::RPC.new }
325
325
 
326
326
  [
327
- {ids: [1], response: [{id: 1}], text: ''},
328
- {ids: [1, 2], response: [{id: 1}, {id: 2}], text: 'with multiple ids'}
327
+ { ids: [1], response: [{ id: 1 }], text: '' },
328
+ { ids: [1, 2], response: [{ id: 1 }, { id: 2 }], text: 'with multiple ids' }
329
329
  ].each do |args|
330
330
  before :each do
331
- stub_get_torrent({ids: args[:ids]}, args[:response])
331
+ stub_get_torrent({ ids: args[:ids] }, args[:response])
332
332
  stub_rpc_request
333
- .with(body: torrent_method_body(object[:rpc_method], {ids: args[:ids]}))
334
- .to_return(successful_response)
333
+ .with(body: torrent_method_body(object[:rpc_method], ids: args[:ids]))
334
+ .to_return(successful_response)
335
335
  end
336
336
 
337
337
  it "should #{object[:method]} torrent #{args[:text]}" do
@@ -341,5 +341,4 @@ describe Transmission::Model::Torrent do
341
341
  end
342
342
  end
343
343
  end
344
-
345
344
  end
@@ -1,7 +1,5 @@
1
1
  describe Transmission::RPC::Connector do
2
-
3
2
  describe '#new' do
4
-
5
3
  describe 'without parameters' do
6
4
  before :each do
7
5
  @connector = Transmission::RPC::Connector.new
@@ -18,7 +16,16 @@ describe Transmission::RPC::Connector do
18
16
 
19
17
  describe 'with parameters' do
20
18
  before :each do
21
- @connector = Transmission::RPC::Connector.new host: 'some.host', port: 8888, ssl: true, path: '/path', credentials: {username: 'a', password: 'b'}
19
+ @connector = Transmission::RPC::Connector.new(
20
+ host: 'some.host',
21
+ port: 8888,
22
+ ssl: true,
23
+ path: '/path',
24
+ credentials: {
25
+ username: 'a',
26
+ password: 'b'
27
+ }
28
+ )
22
29
  end
23
30
 
24
31
  it 'should create an RPC object with given parameters' do
@@ -26,22 +33,20 @@ describe Transmission::RPC::Connector do
26
33
  expect(@connector.port).to eq(8888)
27
34
  expect(@connector.ssl).to eq(true)
28
35
  expect(@connector.path).to eq('/path')
29
- expect(@connector.credentials).to eq({username: 'a', password: 'b'})
36
+ expect(@connector.credentials).to eq(username: 'a', password: 'b')
30
37
  end
31
38
  end
32
-
33
39
  end
34
40
 
35
41
  describe '#post' do
36
-
37
42
  describe 'when session ID has not been acquired yet' do
38
43
  before :each do
39
44
  @connector = Transmission::RPC::Connector.new
40
45
  stub_rpc_request
41
- .to_return(conflict_response({headers: {'x-transmission-session-id' => 'abc'}}))
46
+ .to_return(conflict_response(headers: { 'x-transmission-session-id' => 'abc' }))
42
47
  stub_rpc_request
43
- .with(headers: {'x-transmission-session-id' => 'abc'})
44
- .to_return(successful_response)
48
+ .with(headers: { 'x-transmission-session-id' => 'abc' })
49
+ .to_return(successful_response)
45
50
  end
46
51
 
47
52
  it 'should save the transmission session ID' do
@@ -54,7 +59,7 @@ describe Transmission::RPC::Connector do
54
59
  before :each do
55
60
  @connector = Transmission::RPC::Connector.new
56
61
  stub_rpc_request
57
- .to_return(successful_response)
62
+ .to_return(successful_response)
58
63
  end
59
64
 
60
65
  it 'should respond successfully' do
@@ -67,7 +72,7 @@ describe Transmission::RPC::Connector do
67
72
  before :each do
68
73
  @connector = Transmission::RPC::Connector.new
69
74
  stub_rpc_request
70
- .to_return(unauthorized_response)
75
+ .to_return(unauthorized_response)
71
76
  end
72
77
 
73
78
  it 'should raise auth error' do
@@ -76,7 +81,5 @@ describe Transmission::RPC::Connector do
76
81
  }.to raise_error(Transmission::RPC::Connector::AuthError)
77
82
  end
78
83
  end
79
-
80
84
  end
81
-
82
- end
85
+ end
@@ -7,28 +7,28 @@ describe Transmission::Utils do
7
7
 
8
8
  subject { utils.new }
9
9
 
10
- describe '.is_valid_key?' do
10
+ describe '.valid_key?' do
11
11
  describe 'with dashes' do
12
- let(:arguments) {[{field: 'test-me'}]}
12
+ let(:arguments) { [{ field: 'test-me' }] }
13
13
 
14
14
  it 'should find valid key' do
15
- expect(subject.is_valid_key?('test_me', arguments)).to eq(true)
15
+ expect(subject.valid_key?('test_me', arguments)).to eq(true)
16
16
  end
17
17
  end
18
18
 
19
19
  describe 'with camelcase' do
20
- let(:arguments) {[{field: 'testMe'}]}
20
+ let(:arguments) { [{ field: 'testMe' }] }
21
21
 
22
22
  it 'should find valid key' do
23
- expect(subject.is_valid_key?('test_me', arguments)).to eq(true)
23
+ expect(subject.valid_key?('test_me', arguments)).to eq(true)
24
24
  end
25
25
  end
26
26
 
27
27
  describe 'with invalid key' do
28
- let(:arguments) {[{field: 'testMe'}]}
28
+ let(:arguments) { [{ field: 'testMe' }] }
29
29
 
30
30
  it 'should not find any key' do
31
- expect(subject.is_valid_key?('i_dont_exit', arguments)).to eq(false)
31
+ expect(subject.valid_key?('i_dont_exit', arguments)).to eq(false)
32
32
  end
33
33
  end
34
34
  end
@@ -43,7 +43,7 @@ describe Transmission::Utils do
43
43
 
44
44
  describe '.option_key' do
45
45
  describe 'with dashes' do
46
- let(:arguments) {[{field: 'test-me'}]}
46
+ let(:arguments) { [{ field: 'test-me' }] }
47
47
 
48
48
  it 'should return the correct key' do
49
49
  expect(subject.option_key('test_me', arguments)).to eq('test-me')
@@ -51,7 +51,7 @@ describe Transmission::Utils do
51
51
  end
52
52
 
53
53
  describe 'with camelcase' do
54
- let(:arguments) {[{field: 'testMe'}]}
54
+ let(:arguments) { [{ field: 'testMe' }] }
55
55
 
56
56
  it 'should return the correct key' do
57
57
  expect(subject.option_key('test_me', arguments)).to eq('testMe')
@@ -59,7 +59,7 @@ describe Transmission::Utils do
59
59
  end
60
60
 
61
61
  describe 'with invalid key' do
62
- let(:arguments) {[{field: 'testMe'}]}
62
+ let(:arguments) { [{ field: 'testMe' }] }
63
63
 
64
64
  it 'should return nil' do
65
65
  expect(subject.option_key('i_dont_exit', arguments)).to eq(nil)
@@ -1,17 +1,24 @@
1
- Gem::Specification.new do |s|
2
- s.name = 'transmission-rpc-ruby-ext'
3
- s.version = '0.1.0'
4
- s.date = '2016-12-28'
5
- s.summary = 'Extended version of transmission-rpc-ruby.'
6
- s.description = 'A fork of transmission-rpc-ruby with some shortcut methods added.'
7
- s.authors = ['Tommaso Barbato']
8
- s.email = 'epistrephein@gmail.com'
9
- s.files = `git ls-files`.split($/)
10
- s.homepage = 'https://github.com/epistrephein/transmission-rpc-ruby-ext'
11
- s.license = 'MIT'
12
- s.require_paths = ['lib']
13
- s.add_dependency 'faraday', '~> 0.10'
14
- s.add_development_dependency 'rspec', '~> 3.5'
15
- s.add_development_dependency 'webmock', '~> 2.3'
16
- s.add_development_dependency 'rake', '~> 12.0'
1
+ Gem::Specification.new do |spec|
2
+ spec.name = 'transmission-rpc-ruby-ext'
3
+ spec.version = '0.1.1'
4
+ spec.date = '2016-12-31'
5
+
6
+ spec.authors = ['Tommaso Barbato']
7
+ spec.email = 'epistrephein@gmail.com'
8
+
9
+ spec.summary = 'Extended fork of transmission-rpc-ruby.'
10
+ spec.description = 'A fork of transmission-rpc-ruby with shortcut methods and revised codebase.'
11
+ spec.homepage = 'https://github.com/epistrephein/transmission-rpc-ruby-ext'
12
+ spec.license = 'MIT'
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
+ spec.require_paths = ['lib']
17
+
18
+ spec.required_ruby_version = '>= 2.0'
19
+
20
+ spec.add_dependency 'faraday', '~> 0.10'
21
+ spec.add_development_dependency 'rspec', '~> 3.5'
22
+ spec.add_development_dependency 'webmock', '~> 2.3'
23
+ spec.add_development_dependency 'rake', '~> 12.0'
17
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: transmission-rpc-ruby-ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tommaso Barbato
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-28 00:00:00.000000000 Z
11
+ date: 2016-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -66,7 +66,7 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '12.0'
69
- description: A fork of transmission-rpc-ruby with some shortcut methods added.
69
+ description: A fork of transmission-rpc-ruby with shortcut methods and revised codebase.
70
70
  email: epistrephein@gmail.com
71
71
  executables: []
72
72
  extensions: []
@@ -91,8 +91,9 @@ files:
91
91
  - lib/transmission/extensions.rb
92
92
  - lib/transmission/extensions/torrent_actions.rb
93
93
  - lib/transmission/extensions/torrent_attributes.rb
94
+ - lib/transmission/extensions/torrent_prettify.rb
94
95
  - lib/transmission/extensions/torrent_status.rb
95
- - lib/transmission/extensions/transmission.rb
96
+ - lib/transmission/extensions/transmission_selectors.rb
96
97
  - lib/transmission/fields.rb
97
98
  - lib/transmission/fields/session_get.rb
98
99
  - lib/transmission/fields/session_stats.rb
@@ -107,6 +108,7 @@ files:
107
108
  - spec/helpers/stubs.rb
108
109
  - spec/spec_helper.rb
109
110
  - spec/transmission/arguments_spec.rb
111
+ - spec/transmission/extensions_spec.rb
110
112
  - spec/transmission/fields_spec.rb
111
113
  - spec/transmission/model/session_spec.rb
112
114
  - spec/transmission/model/torrent_spec.rb
@@ -126,7 +128,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
128
  requirements:
127
129
  - - ">="
128
130
  - !ruby/object:Gem::Version
129
- version: '0'
131
+ version: '2.0'
130
132
  required_rubygems_version: !ruby/object:Gem::Requirement
131
133
  requirements:
132
134
  - - ">="
@@ -137,5 +139,15 @@ rubyforge_project:
137
139
  rubygems_version: 2.6.8
138
140
  signing_key:
139
141
  specification_version: 4
140
- summary: Extended version of transmission-rpc-ruby.
141
- test_files: []
142
+ summary: Extended fork of transmission-rpc-ruby.
143
+ test_files:
144
+ - spec/helpers/stubs.rb
145
+ - spec/spec_helper.rb
146
+ - spec/transmission/arguments_spec.rb
147
+ - spec/transmission/extensions_spec.rb
148
+ - spec/transmission/fields_spec.rb
149
+ - spec/transmission/model/session_spec.rb
150
+ - spec/transmission/model/torrent_spec.rb
151
+ - spec/transmission/rpc/connector_spec.rb
152
+ - spec/transmission/rpc_spec.rb
153
+ - spec/transmission/utils_spec.rb