retort 0.0.4 → 0.0.5

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.
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (C) 2011 by Marcel C. Morgan
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.rdoc CHANGED
@@ -1,5 +1,35 @@
1
1
  = Retort
2
2
 
3
- rtorrent xmlrpc wrapper written in ruby (1.9). Designed to decouple the
3
+ rtorrent xmlrpc wrapper written in ruby (1.9). Designed to decouple the
4
4
  xmlrpc interface from the underlying ruby objects.
5
5
 
6
+ == Basic usage
7
+
8
+ Update your Gemfile with this and do a bundle install:
9
+
10
+ gem 'retort'
11
+
12
+ To get a list of all torrents:
13
+
14
+ require 'retort'
15
+ Retort::Torrent.all
16
+
17
+ == Contributions
18
+
19
+ To fetch & test the library for development, do:
20
+
21
+ $ git clone https://github.com/mcmorgan/retort
22
+ $ cd retort
23
+ $ bundle
24
+ $ bundle exec rspec spec
25
+
26
+ If you want to contribute, please:
27
+
28
+ * Fork the project.
29
+ * Make your feature addition or bug fix.
30
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
31
+ * Send me a pull request on Github.
32
+
33
+ == Copyright
34
+
35
+ Copyright (c) 2010-2011 Marcel Morgan. See LICENSE for details.
@@ -0,0 +1 @@
1
+ Autotest.add_discovery { "rspec2" }
@@ -1,22 +1,24 @@
1
- module Retort::Conversion
1
+ class Retort::Rtorrent
2
2
 
3
+ TYPES = {
4
+ time: 'to_time',
5
+ date: 'to_date',
6
+ size: 'to_xb'
7
+ }
3
8
 
4
- class Call
5
- TYPES = { time: 'to_time', date: 'to_date', size: 'to_xb' }
6
- attr_accessor :attributes
9
+ attr_accessor :attributes, :attributes_raw
7
10
 
8
11
  def initialize(prefix)
9
12
  @attributes = {}
13
+ @attributes_raw = {}
10
14
  @prefix = prefix
11
15
  end
12
16
 
13
- def method_missing(*args, &block)
14
- property = args.shift
15
- options = args.shift || {}
16
-
17
+ def attribute(property, options = {}, &block)
17
18
  type = options[:type]
18
19
  method_name = options[:name] || property
19
20
  method_name = "#{@prefix}.#{method_name}" unless @prefix.empty?
21
+ @attributes_raw[property] = method_name
20
22
 
21
23
  if TYPES.member? type
22
24
  #Syntax is 'to_*=$.....'. Example : 'to_date=$d.get_creation_date'.
@@ -25,13 +27,14 @@ module Retort::Conversion
25
27
  end
26
28
  @attributes[property] = method_name
27
29
  end
28
- end
29
30
 
30
- def build(prefix="")
31
- c = Call.new prefix
32
- yield c
33
- c.attributes
34
- end
31
+ alias method_missing attribute
32
+
33
+ def self.build(prefix="", &block)
34
+ c = new(prefix)
35
+ c.instance_eval(&block)
36
+ c.attributes
37
+ end
35
38
 
36
39
  end
37
40
 
@@ -14,8 +14,14 @@ module Retort
14
14
  @@service = XMLRPC::Client.new2(config.url)
15
15
  end
16
16
 
17
+ # by default, if configure hasn't been call the url will be defaulted
18
+ # to http://localhost/RPC2
19
+ def service
20
+ @@service ||= XMLRPC::Client.new2("http://elijah/RPC2")
21
+ end
22
+
17
23
  def call(*args)
18
- @@service.call_async *args
24
+ service.call_async *args
19
25
  end
20
26
 
21
27
  end
@@ -2,34 +2,31 @@ module Retort
2
2
 
3
3
  class Exception; end
4
4
 
5
- class Torrent
6
- extend Retort::Conversion
5
+ class Torrent < Rtorrent
7
6
 
8
7
  class << self
9
8
  def attr_mappings
10
-
11
- build(:d) do |t|
12
- t.info_hash name: 'hash'
13
- t.name
14
- t.connection_current
15
- t.size name: 'size_bytes', type: :size
16
- t.completed name: 'completed_bytes', type: :size
17
- t.creation_date name: 'creation_date', type: :date
18
- t.downloaded name: 'bytes_done', type: :size
19
- t.up_rate name: 'up.rate', type: :size
20
- t.down_rate name: 'down.rate', type: :size
21
- t.message name: 'get_message'
22
- t.seeders name: 'peers_complete'
23
- t.leechers name: 'peers_connected'
24
- t.state
25
- t.complete
26
- t.is_active
27
- t.is_hash_checked
28
- t.is_hash_checking
29
- t.is_multi_file
30
- t.is_open
9
+ @@mappings ||= build(:d) do
10
+ info_hash name: 'hash'
11
+ name
12
+ connection_current
13
+ size name: 'size_bytes', type: :size
14
+ completed name: 'completed_bytes', type: :size
15
+ creation_date name: 'creation_date', type: :date
16
+ downloaded name: 'bytes_done', type: :size
17
+ up_rate name: 'up.rate', type: :size
18
+ down_rate name: 'down.rate', type: :size
19
+ message name: 'get_message'
20
+ seeders name: 'peers_complete'
21
+ leechers name: 'peers_connected'
22
+ state
23
+ complete
24
+ is_active
25
+ is_hash_checked
26
+ is_hash_checking
27
+ is_multi_file
28
+ is_open
31
29
  end
32
-
33
30
  end
34
31
 
35
32
  def all(view="main")
@@ -1,3 +1,3 @@
1
1
  module Retort
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/retort.gemspec CHANGED
@@ -17,4 +17,6 @@ Gem::Specification.new do |s|
17
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
+
21
+ s.add_development_dependency "rspec"
20
22
  end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe Retort::Torrent do
4
+ it "has all methods listed" do
5
+ all_methods = Retort::Service.call "system.listMethods"
6
+ torrent_methods = Retort::Torrent.attr_mappings.values.reject {|x| x =~ /\$/}
7
+ x = torrent_methods.reject {|m| all_methods.include?(m)}
8
+ x.size.should == 0
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ require 'bundler/setup'
2
+ require 'retort' # and any other gems you need
3
+
4
+ RSpec.configure do |config|
5
+ # some (optional) config here
6
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: retort
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,19 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-04 00:00:00.000000000Z
13
- dependencies: []
12
+ date: 2011-09-11 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &11591600 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *11591600
14
25
  description: An rTorrent xmlrpc wrapper written in ruby
15
26
  email:
16
27
  - marcel.morgan@gmail.com
@@ -19,10 +30,13 @@ extensions: []
19
30
  extra_rdoc_files: []
20
31
  files:
21
32
  - .gitignore
33
+ - .rspec
22
34
  - .rvmrc
23
35
  - Gemfile
36
+ - LICENSE
24
37
  - README.rdoc
25
38
  - Rakefile
39
+ - autotest/discover.rb
26
40
  - lib/retort.rb
27
41
  - lib/retort/conversion.rb
28
42
  - lib/retort/core_ext.rb
@@ -31,6 +45,8 @@ files:
31
45
  - lib/retort/version.rb
32
46
  - lib/retort/xmlrpc_client.rb
33
47
  - retort.gemspec
48
+ - spec/rtorrent/methods_spec.rb
49
+ - spec/spec_helper.rb
34
50
  homepage: https://github.com/mcmorgan/retort
35
51
  licenses: []
36
52
  post_install_message:
@@ -55,4 +71,6 @@ rubygems_version: 1.8.10
55
71
  signing_key:
56
72
  specification_version: 3
57
73
  summary: An rTorrent xmlrpc wrapper written in ruby
58
- test_files: []
74
+ test_files:
75
+ - spec/rtorrent/methods_spec.rb
76
+ - spec/spec_helper.rb