transmission-rpc-ruby 0.1.0 → 0.2.0

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: 4917b1b8a5ad7da8273c58280fac4f25996e6334
4
- data.tar.gz: fb8415abcd21be4158c10195b2d2a2fa0ae9dc6e
3
+ metadata.gz: f40dbe21491bbcdd4f6aa056748678819a81347f
4
+ data.tar.gz: af1ac8e0854ab433daa58c1b56a8b6966cbfa9e2
5
5
  SHA512:
6
- metadata.gz: 65366f6cafbce62cd391596bcec5c5455adf8e2edb6730e92031b74e11f9c10c1984c8f258906d9c592b04433c0fde71d34e28615d56ae932cdfa43426dd5d89
7
- data.tar.gz: 70fd3fcfe593fa9c9ae34b07fe3be75a292fd596f64f957dc036b1306fbc6b94b1cd4091242a9b53be6e0a0a4927f6abb8b9ee2b2236dd3b29ffca6340a0dade
6
+ metadata.gz: d9e982241cd3efef6e490d678bf1404ae8d0e21d6bdd33fe3480d451599dee377ece0c889b2eb95194ce83d1be49e4290f747560346247f0b96a29a04b404a44
7
+ data.tar.gz: 7c458a66cf283b4b006d1bbd82d8cba6efe820b370917561866773ad3bbfb8048092419a8eac9a666395d7f49a9c18fc994b9c46c885cd3ed0687cc2502900de
data/.rspec CHANGED
@@ -1,3 +1,2 @@
1
1
  --color
2
- --warnings
3
2
  --require spec_helper
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
data/Gemfile CHANGED
@@ -5,7 +5,8 @@ gem 'faraday', '~> 0.9'
5
5
  group :development, :test do
6
6
 
7
7
  gem 'rspec', '~> 3.2'
8
- gem 'webmock', '~> 1.20'
8
+ gem 'webmock', '~> 1.21'
9
9
  gem 'rake', '~> 10.4'
10
+ gem 'coveralls', require: false
10
11
 
11
12
  end
@@ -1,14 +1,32 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- addressable (2.3.7)
4
+ addressable (2.3.8)
5
+ coveralls (0.7.12)
6
+ multi_json (~> 1.10)
7
+ rest-client (>= 1.6.8, < 2)
8
+ simplecov (~> 0.9.1)
9
+ term-ansicolor (~> 1.3)
10
+ thor (~> 0.19.1)
5
11
  crack (0.4.2)
6
12
  safe_yaml (~> 1.0.0)
7
13
  diff-lcs (1.2.5)
14
+ docile (1.1.5)
15
+ domain_name (0.5.23)
16
+ unf (>= 0.0.5, < 1.0.0)
8
17
  faraday (0.9.1)
9
18
  multipart-post (>= 1.2, < 3)
19
+ http-cookie (1.0.2)
20
+ domain_name (~> 0.5)
21
+ mime-types (2.4.3)
22
+ multi_json (1.11.0)
10
23
  multipart-post (2.0.0)
24
+ netrc (0.10.3)
11
25
  rake (10.4.2)
26
+ rest-client (1.8.0)
27
+ http-cookie (>= 1.0.2, < 2.0)
28
+ mime-types (>= 1.16, < 3.0)
29
+ netrc (~> 0.7)
12
30
  rspec (3.2.0)
13
31
  rspec-core (~> 3.2.0)
14
32
  rspec-expectations (~> 3.2.0)
@@ -23,7 +41,19 @@ GEM
23
41
  rspec-support (~> 3.2.0)
24
42
  rspec-support (3.2.2)
25
43
  safe_yaml (1.0.4)
26
- webmock (1.20.4)
44
+ simplecov (0.9.2)
45
+ docile (~> 1.1.0)
46
+ multi_json (~> 1.0)
47
+ simplecov-html (~> 0.9.0)
48
+ simplecov-html (0.9.0)
49
+ term-ansicolor (1.3.0)
50
+ tins (~> 1.0)
51
+ thor (0.19.1)
52
+ tins (1.3.5)
53
+ unf (0.1.4)
54
+ unf_ext
55
+ unf_ext (0.0.6)
56
+ webmock (1.21.0)
27
57
  addressable (>= 2.3.6)
28
58
  crack (>= 0.3.2)
29
59
 
@@ -31,7 +61,8 @@ PLATFORMS
31
61
  ruby
32
62
 
33
63
  DEPENDENCIES
64
+ coveralls
34
65
  faraday (~> 0.9)
35
66
  rake (~> 10.4)
36
67
  rspec (~> 3.2)
37
- webmock (~> 1.20)
68
+ webmock (~> 1.21)
data/README.md CHANGED
@@ -1,78 +1,172 @@
1
1
  # Transmission RPC Ruby
2
2
 
3
- First primitive version.
3
+ [![Build Status](https://travis-ci.org/transmission-rails/transmission-rpc-ruby.svg?branch=master)](https://travis-ci.org/transmission-rails/transmission-rpc-ruby) [![Code Climate](https://codeclimate.com/github/transmission-rails/transmission-rpc-ruby/badges/gpa.svg)](https://codeclimate.com/github/transmission-rails/transmission-rpc-ruby) [![Dependency Status](https://gemnasium.com/transmission-rails/transmission-rpc-ruby.svg)](https://gemnasium.com/transmission-rails/transmission-rpc-ruby) [![Coverage Status](https://coveralls.io/repos/transmission-rails/transmission-rpc-ruby/badge.svg?branch=master)](https://coveralls.io/r/transmission-rails/transmission-rpc-ruby?branch=master)
4
4
 
5
- There is a couple of these RPC wrappers around already, but I am looking for a nice object oriented solution.
5
+ Transmission RPC Ruby is a Ruby library to communicate with Transmission RPC (bittorrent client).
6
+ This library is based on this [spec](https://trac.transmissionbt.com/browser/trunk/extras/rpc-spec.txt) and currently supports RPC versions >= 14
6
7
 
7
- Main aim for this project => Object Oriented solution for Transmission RPC connection.
8
+ ## Installation
8
9
 
9
- This Project follows the RPC spec for transmission under `https://trac.transmissionbt.com/browser/trunk/extras/rpc-spec.txt` and is planning on supporting release version >= 2.40 and RPC version >= 14
10
+ gem install transmission-rpc-ruby
10
11
 
11
- ## Examples (Currently working)
12
+ Then require it
12
13
 
13
- To use the `Model` classes you need to set up some configs first
14
+ require 'transmission'
15
+
16
+ ## Getting started
17
+
18
+ To get started with this gem you need to decide if you are using this library to connect to one or multiple transmission daemons.
19
+ __Both is possible__
20
+
21
+ ### Single connection
22
+
23
+ Just set up a single configuration with will be used throughout any library calls
14
24
 
15
25
  Transmission::Config.set host: 'some.host', port: 9091, ssl: false, credentials: {username: 'transmission', password: '********'}
16
26
 
17
- Now all models will use the globally set configs
27
+ torrents = Transmission::Model::Torrent.all
28
+
29
+ ### Multiple connections
30
+
31
+ Introducing the `Transmission::RPC` class, which represent all the raw rpc connection requests.
32
+
33
+ rpc = Transmission::RPC.new host: 'some.host', port: 9091, ssl: false, credentials: {username: 'transmission', password: '********'}
34
+
35
+ torrents = Transmission::Model::Torrent.all connector: rpc
36
+
37
+ This Object can be passed to the `Transmission::Model` classes. Examples are shown below.
38
+
39
+ ### Configuration options
40
+
41
+ Both `Transmission::Config` and `Transmission::RPC` take the same arguments, these are the default settings:
18
42
 
19
- ### Finding a torrent
43
+ {
44
+ host: 'localhost',
45
+ port: 9091
46
+ path: '/transmission/rpc',
47
+ ssl: false,
48
+ credentials: {username: 'transmission', password: '********'},
49
+ session_id: ''
50
+ }
20
51
 
21
- torrent = Transmission::Model::Torrent.find 1
52
+ ### Torrents
22
53
 
23
- ### Getting all torrents
54
+ To work with torrents you need use the `Transmission::Model::Torrent` class
55
+
56
+ #### Get all torrents
24
57
 
25
58
  torrents = Transmission::Model::Torrent.all
26
59
 
27
- ### Adding a torrent
60
+ If only a few fields are required
61
+
62
+ torrents = Transmission::Model::Torrent.all fields: ['id']
63
+
64
+ #### Find a torrent
65
+
66
+ id = 1
67
+ torrent = Transmission::Model::Torrent.find id
68
+
69
+ If only a few fields are required
70
+
71
+ torrent = Transmission::Model::Torrent.find id, fields: ['id']
72
+
73
+ #### Add a torrent
74
+
75
+ filename = 'http://example.com/torrent.torrent'
76
+ torrent = Transmission::Model::Torrent.add filename: filename
77
+
78
+ __NOTE:__ you can also specify a magnet link instead
79
+
80
+ #### Torrent instance methods
81
+
82
+ id = 1
83
+ torrent = Transmission::Model::Torrent.find(id)
84
+
85
+ torrent.start!
86
+ torrent.start_now!
87
+ torrent.stop!
88
+ torrent.verify!
89
+ torrent.re_announce!
90
+
91
+ torrent.move_up!
92
+ torrent.move_down!
93
+ torrent.move_top!
94
+ torrent.move_bottom!
95
+
96
+ You can access the torrent accessors & mutators via instance methods too
97
+
98
+ # uploadLimited
99
+ torrent.upload_limited
100
+ torrent.upload_limited = true
101
+
102
+ torrent.save!
103
+
104
+ The `save!` method will update the torrent on your remote transmission daemon.
105
+
106
+ To find all the torrent [accessors](https://trac.transmissionbt.com/browser/trunk/extras/rpc-spec.txt#L127) & [mutators](https://trac.transmissionbt.com/browser/trunk/extras/rpc-spec.txt#L90) visit [spec](https://trac.transmissionbt.com/browser/trunk/extras/rpc-spec.txt)
107
+
108
+ ### Session
109
+
110
+ To find out more about the current session use the `Transmission::Model::Session` class.
111
+
112
+ #### Get session
113
+
114
+ session = Transmission::Model::Session.get
115
+
116
+ If only a few fields are required
117
+
118
+ session = Transmission::Model::Session.get fields: ['version']
119
+
120
+ If used with a connector
121
+
122
+ options = {}
123
+ rpc = Transmission::RPC.new options
124
+
125
+ session = Transmission::Model::Session.get connector: rpc
126
+
127
+ #### Change session
128
+
129
+ Like the `Transmission::Model::Torrent` class, you change some session properties
130
+
131
+ session = Transmission::Model::Session.get
132
+
133
+ # alt-speed-enabled
134
+ session.alt_speed_enabled
135
+ session.alt_speed_enabled = true
136
+
137
+ session.save!
138
+
139
+ To find all the session [accessors](https://trac.transmissionbt.com/browser/trunk/extras/rpc-spec.txt#L444) & [mutators](https://trac.transmissionbt.com/browser/trunk/extras/rpc-spec.txt#L514) visit [spec](https://trac.transmissionbt.com/browser/trunk/extras/rpc-spec.txt)
28
140
 
29
- torrent = Transmission::Model::Torrent.add filename: 'http://example.com/some_torrent.torrent'
30
- # or
31
- torrent = Transmission::Model::Torrent.add filename: 'magnet_link'
141
+ ### Session Stats
32
142
 
33
- ### Deleting a torrent
143
+ You can also retrieve some session stats by using the `Transmission::Model::SessionStats` class
34
144
 
35
- torrent = Transmission::Model::Torrent.find 1
36
- # Deletes torrents
37
- torrent.delete!
38
- # Deletes torrent and local data
39
- torrent.delete! true
145
+ session_stats = Transmission::Model::SessionStats.get
40
146
 
41
- ### Dealing with fields
147
+ # activeTorrentCount
148
+ session_stats.active_torrent_count
42
149
 
43
- To limit the amount of fields sent around you can limit the information by passing an array of desired fields
150
+ For session stats there are no mutators. To find out more about the [accessors](https://trac.transmissionbt.com/browser/trunk/extras/rpc-spec.txt#L531) visit the [spec](https://trac.transmissionbt.com/browser/trunk/extras/rpc-spec.txt)
44
151
 
45
- torrent = Transmission::Model::Torrent.all fields: ['id']
152
+ ### RPC Connector
46
153
 
47
- ### Using different connectors
154
+ If it is not desired to use any of the `Transmission::Model` classes you can use the RPC connector
48
155
 
49
- If you are planning on using this lib to connect to multiple transmission daemon instances you can pass your own `Transmission::RPC` instance
156
+ #### Examples
50
157
 
51
- connector = Transmission::RPC.new host: 'some.host', port: 9091, ssl: false, credentials: {username: 'transmission', password: '********'}
52
- torrents = Transmission::Model::Torrent.all connector: connector
158
+ rpc = Transmission::RPC.new host: 'some.host', port: 9091, ssl: false, credentials: {username: 'transmission', password: '********'}
53
159
 
54
- ### Find out Transmission & RPC version
160
+ session_body = rpc.get_session
55
161
 
56
- connector = Transmission::RPC.new host: 'some.host', port: 9091, ssl: false, credentials: {username: 'transmission', password: '********'}
57
- session = connector.session
58
- session.rpc_version #=> 14
59
- session.version #=> "2.52"
162
+ ids = [1, 2, 3]
60
163
 
61
- ## Examples (Currently NOT working but desired)
164
+ torrent_bodies = rpc.get_torrent ids
165
+ rpc.start_torrents ids
62
166
 
63
- ### Torrent instance methods
167
+ For more methods check out `lib/transmission/rpc.rb`
64
168
 
65
- torrent = Transmission::Model::Torrent.find 1
66
- torrent.move_up
67
- torrent.move_down
68
- torrent.move_top
69
- torrent.move_bottom
70
- torrent.start
71
- torrent.start_now
72
- torrent.stop
73
- torrent.verify
74
- torrent.re_announce
75
- torrent.finished?
76
- torrent.to_json
169
+ ## Contribute
77
170
 
78
- ### This project is still WIP!!
171
+ Please help make this gem awesome! If you have any suggestions or feedback either create an issue or PR.
172
+ Just make sure you run the tests before.
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ task :default => [:spec]
2
+
1
3
  task :spec do
2
4
  system 'rspec'
3
5
  end
@@ -1,8 +1,10 @@
1
1
  require File.join(File.dirname(__FILE__), 'transmission', 'rpc')
2
2
  require File.join(File.dirname(__FILE__), 'transmission', 'model')
3
3
  require File.join(File.dirname(__FILE__), 'transmission', 'config')
4
+ require File.join(File.dirname(__FILE__), 'transmission', 'fields')
4
5
  require File.join(File.dirname(__FILE__), 'transmission', 'arguments')
6
+ require File.join(File.dirname(__FILE__), 'transmission', 'utils')
5
7
 
6
8
  module Transmission
7
- VERSION = '0.1.0'
9
+ VERSION = '0.2.0'
8
10
  end
@@ -1,9 +1,7 @@
1
1
  require File.join(File.dirname(__FILE__), 'arguments', 'torrent_add')
2
- require File.join(File.dirname(__FILE__), 'arguments', 'torrent_get')
3
2
  require File.join(File.dirname(__FILE__), 'arguments', 'torrent_set')
4
- require File.join(File.dirname(__FILE__), 'arguments', 'session_get')
5
3
  require File.join(File.dirname(__FILE__), 'arguments', 'session_set')
6
- require File.join(File.dirname(__FILE__), 'arguments', 'session_stats')
4
+ require File.join(File.dirname(__FILE__), 'utils')
7
5
 
8
6
  module Transmission
9
7
  class Arguments
@@ -11,10 +9,15 @@ module Transmission
11
9
 
12
10
  attr_accessor :arguments
13
11
 
12
+ ATTRIBUTES = []
13
+
14
14
  def initialize(arguments = nil)
15
- @arguments = arguments.inject([]) do |attributes, attribute|
16
- raise Transmission::Arguments::InvalidArgument unless self.class::ATTRIBUTES.include? attribute
17
- attributes << attribute
15
+ @arguments = arguments.inject({}) do |attributes, (key, value)|
16
+ key = key.to_s
17
+ found = self.class::ATTRIBUTES.select { |attr| attr[:field] == key }
18
+ raise Transmission::Arguments::InvalidArgument, key if found.empty?
19
+ attributes[key] = value
20
+ attributes
18
21
  end if arguments
19
22
  @arguments = self.class::ATTRIBUTES if arguments.nil?
20
23
  end
@@ -23,5 +26,25 @@ module Transmission
23
26
  @arguments
24
27
  end
25
28
 
29
+ class << self
30
+ include Transmission::Utils
31
+
32
+ def is_valid?(key)
33
+ is_valid_key? key, self::ATTRIBUTES
34
+ end
35
+
36
+ def real_key(key)
37
+ option_key key, self::ATTRIBUTES
38
+ end
39
+
40
+ def filter(arguments)
41
+ arguments.inject({}) do |hash, (key, value)|
42
+ found = self::ATTRIBUTES.select { |attr| attr[:field] == key.to_s }
43
+ hash[key] = value unless found.empty?
44
+ hash
45
+ end
46
+ end
47
+ end
48
+
26
49
  end
27
50
  end
@@ -3,54 +3,54 @@ module Transmission
3
3
  class SessionSet < Transmission::Arguments
4
4
 
5
5
  ATTRIBUTES = [
6
- 'alt-speed-down',
7
- 'alt-speed-enabled',
8
- 'alt-speed-time-begin',
9
- 'alt-speed-time-enabled',
10
- 'alt-speed-time-end',
11
- 'alt-speed-time-day',
12
- 'alt-speed-up',
13
- 'blocklist-url',
14
- 'blocklist-update',
15
- 'blocklist-enabled',
16
- 'cache-size-mb',
17
- 'download-dir',
18
- 'download-queue-size',
19
- 'download-queue-enabled',
20
- 'dht-enabled',
21
- 'encryption',
22
- 'required',
23
- 'preferred',
24
- 'tolerated',
25
- 'idle-seeding-limit',
26
- 'idle-seeding-limit-enabled',
27
- 'incomplete-dir',
28
- 'incomplete-dir-enabled',
29
- 'lpd-enabled',
30
- 'peer-limit-global',
31
- 'peer-limit-per-torrent',
32
- 'pex-enabled',
33
- 'peer-port',
34
- 'peer-port-random-on-start',
35
- 'port-forwarding-enabled',
36
- 'queue-stalled-enabled',
37
- 'queue-stalled-minutes',
38
- 'rename-partial-files',
39
- 'script-torrent-done-filename',
40
- 'script-torrent-done-enabled',
41
- 'done',
42
- 'seedRatioLimit',
43
- 'seedRatioLimited',
44
- 'seed-queue-size',
45
- 'seed-queue-enabled',
46
- 'speed-limit-down',
47
- 'speed-limit-down-enabled',
48
- 'speed-limit-up',
49
- 'speed-limit-up-enabled',
50
- 'start-added-torrents',
51
- 'trash-original-torrent-files',
52
- 'units',
53
- 'utp-enabled'
6
+ {field: 'alt-speed-down'},
7
+ {field: 'alt-speed-enabled'},
8
+ {field: 'alt-speed-time-begin'},
9
+ {field: 'alt-speed-time-enabled'},
10
+ {field: 'alt-speed-time-end'},
11
+ {field: 'alt-speed-time-day'},
12
+ {field: 'alt-speed-up'},
13
+ {field: 'blocklist-url'},
14
+ {field: 'blocklist-update'},
15
+ {field: 'blocklist-enabled'},
16
+ {field: 'cache-size-mb'},
17
+ {field: 'download-dir'},
18
+ {field: 'download-queue-size'},
19
+ {field: 'download-queue-enabled'},
20
+ {field: 'dht-enabled'},
21
+ {field: 'encryption'},
22
+ {field: 'required'},
23
+ {field: 'preferred'},
24
+ {field: 'tolerated'},
25
+ {field: 'idle-seeding-limit'},
26
+ {field: 'idle-seeding-limit-enabled'},
27
+ {field: 'incomplete-dir'},
28
+ {field: 'incomplete-dir-enabled'},
29
+ {field: 'lpd-enabled'},
30
+ {field: 'peer-limit-global'},
31
+ {field: 'peer-limit-per-torrent'},
32
+ {field: 'pex-enabled'},
33
+ {field: 'peer-port'},
34
+ {field: 'peer-port-random-on-start'},
35
+ {field: 'port-forwarding-enabled'},
36
+ {field: 'queue-stalled-enabled'},
37
+ {field: 'queue-stalled-minutes'},
38
+ {field: 'rename-partial-files'},
39
+ {field: 'script-torrent-done-filename'},
40
+ {field: 'script-torrent-done-enabled'},
41
+ {field: 'done'},
42
+ {field: 'seedRatioLimit'},
43
+ {field: 'seedRatioLimited'},
44
+ {field: 'seed-queue-size'},
45
+ {field: 'seed-queue-enabled'},
46
+ {field: 'speed-limit-down'},
47
+ {field: 'speed-limit-down-enabled'},
48
+ {field: 'speed-limit-up'},
49
+ {field: 'speed-limit-up-enabled'},
50
+ {field: 'start-added-torrents'},
51
+ {field: 'trash-original-torrent-files'},
52
+ {field: 'units'},
53
+ {field: 'utp-enabled'}
54
54
  ]
55
55
 
56
56
  end