nzbget 0.6.0 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ pkg
2
+ doc
3
+ Manifest
4
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in nzbget.gemspec
4
+ gemspec
@@ -10,18 +10,21 @@ From the version 0.4.0 NZBGet has supported XML-RPC and JSON-RPC. It allows to c
10
10
 
11
11
  == Installation
12
12
 
13
- To install directly from GitHub:
13
+ Either install from Rubygems:
14
14
 
15
- $ gem sources -a http://gems.github.com # you only need to run this once
16
- $ gem install marcbowes-nzbget
15
+ $ gem install nzbget
16
+
17
+ or clone from GitHub:
18
+
19
+ $ git clone git://github.com/marcbowes/nzbget.git && cd nzbget
20
+ $ rake install
17
21
 
18
22
  == Getting started
19
23
 
20
- require 'rubygems'
21
24
  require 'nzbget'
22
25
 
23
- remote = Nzbget.new :uri => 'http://nzbget-server'
24
- puts remote.status
26
+ remote = NZBGet::RemoteConnection.new
27
+ remote.status
25
28
 
26
29
  == License
27
30
 
data/Rakefile CHANGED
@@ -1,14 +1,2 @@
1
- require 'rubygems'
2
- require 'rake'
3
- require 'echoe'
4
-
5
- Echoe.new('nzbget', '0.6.0') do |p|
6
- p.description = "Communicate with NZBGet via RPC."
7
- p.url = "http://github.com/marcbowes/nzbget"
8
- p.author = "Marc Bowes"
9
- p.email = "marcbowes@gmail.com"
10
- p.runtime_dependencies = ['httparty']
11
- end
12
-
13
- Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
14
-
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -1,11 +1,12 @@
1
- require 'rubygems'
2
- require 'httparty'
3
- require File.join(File.dirname(__FILE__), 'httparty/request')
4
- require 'group'
1
+ # -*- coding: utf-8 -*-
5
2
  require 'base64'
3
+ require 'httparty'
4
+ require 'httparty/request'
5
+ require 'nzbget/group'
6
6
 
7
7
  module NZBGet
8
8
  class RemoteConnection
9
+
9
10
  include HTTParty
10
11
 
11
12
  DEFAULT_OPTIONS = {
@@ -22,20 +23,21 @@ module NZBGet
22
23
  uri = URI.parse(@options[:uri])
23
24
  uri.port = @options[:port]
24
25
 
25
- self.class.base_uri uri.to_s
26
- self.class.basic_auth @options[:username], @options[:password]
26
+ self.class.base_uri(uri.to_s)
27
+ self.class.basic_auth(@options[:username], @options[:password])
27
28
 
28
29
  case @options[:method]
29
- when :json
30
- require 'json'
31
- when :xml
32
- raise ArgumentError
33
- else
34
- raise ArgumentError
30
+ when :json
31
+ require 'json'
32
+ when :xml
33
+ raise ArgumentError
34
+ else
35
+ raise ArgumentError
35
36
  end
36
- self.class.format @options[:method]
37
+ self.class.format(@options[:method])
37
38
  end
38
39
 
40
+
39
41
  def enqueue(path, options = {})
40
42
  extname = File.extname(path)
41
43
  raise ArgumentError unless extname.downcase == '.nzb'
@@ -53,35 +55,39 @@ module NZBGet
53
55
  end
54
56
 
55
57
  def groups
56
- send(:listgroups)['result'].collect { |g| NZBGet::Group.new(self, g) }
58
+ groups = []
59
+ send(:listgroups)['result'].each_with_index do |hash, idx|
60
+ groups << NZBGet::Group.new(self, idx, hash)
61
+ end
62
+ groups
57
63
  end
58
64
 
65
+
59
66
  protected
60
67
 
61
- def encode(hash)
62
- hash.send("to_#{@options[:method].to_s}".to_sym)
63
- end
64
-
65
- def method_missing(name, *args)
66
- invoke name, args
67
- end
68
+ def encode(hash)
69
+ hash.send("to_#{@options[:method].to_s}".to_sym)
70
+ end
68
71
 
69
- def invoke(method, params)
70
- #
71
- # According to http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html#RequestHeaders:
72
- #
73
- # Regardless of whether a remote procedure call is made using HTTP GET or POST, the HTTP request message MUST specify the following headers:
74
- # * The User-Agent MUST be specified.
75
- # * For HTTP POST only, the Content-Type MUST be specified and SHOULD read application/json.
76
- # * The Content-Length MUST be specified and correct according to the guidelines and rules laid out in Section 4.4, “Message Length”, of the HTTP specification.
77
- # * The Accept MUST be specified and SHOULD read application/json.
78
- #
79
- # However, NZBGet does not check these headers, so they are not included.
80
- #
81
-
82
- response = self.class.post("/#{@options[:method].to_s}rpc",
83
- :body => encode({ :method => method.to_s, :params => params, :version => '1.1' }))
84
- end
72
+ def method_missing(name, *args)
73
+ invoke name, args
74
+ end
75
+
76
+ def invoke(method, params)
77
+ #
78
+ # According to http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html#RequestHeaders:
79
+ #
80
+ # Regardless of whether a remote procedure call is made using HTTP GET or POST, the HTTP request message MUST specify the following headers:
81
+ # * The User-Agent MUST be specified.
82
+ # * For HTTP POST only, the Content-Type MUST be specified and SHOULD read application/json.
83
+ # * The Content-Length MUST be specified and correct according to the guidelines and rules laid out in Section 4.4, “Message Length”, of the HTTP specification.
84
+ # * The Accept MUST be specified and SHOULD read application/json.
85
+ #
86
+ # However, NZBGet does not check these headers, so they are not included.
87
+ #
85
88
 
89
+ response = self.class.post("/#{@options[:method].to_s}rpc",
90
+ :body => encode({ :method => method.to_s, :params => params, :version => '1.1' }))
91
+ end
86
92
  end
87
93
  end
@@ -1,9 +1,10 @@
1
1
  module NZBGet
2
2
  class Group
3
- attr_accessor :attributes
3
+ attr_accessor :position, :attributes
4
4
 
5
- def initialize(nzbget, hash)
5
+ def initialize(nzbget, position, hash)
6
6
  @nzbget = nzbget
7
+ @position = position
7
8
  @attributes = hash
8
9
  end
9
10
 
@@ -16,7 +17,11 @@ module NZBGet
16
17
  end
17
18
 
18
19
  def downloaded(format = :bytes)
19
- formatted_response [size - remaining, 0].max, format
20
+ formatted_response([size - remaining, 0].max, format)
21
+ end
22
+
23
+ def first?
24
+ @position == 0
20
25
  end
21
26
 
22
27
  def formatted_response(bytes, format)
@@ -64,11 +69,11 @@ module NZBGet
64
69
  end
65
70
 
66
71
  def paused(format = :bytes)
67
- formatted_response @attributes['PausedSizeLo'].to_i, format
72
+ formatted_response(@attributes['PausedSizeMB'] * 1024, format)
68
73
  end
69
74
 
70
75
  def remaining(format = :bytes)
71
- formatted_response @attributes['RemainingSizeLo'].to_i, format
76
+ formatted_response(@attributes['RemainingSizeMB'] * 1024, format)
72
77
  end
73
78
 
74
79
  def resume
@@ -76,7 +81,7 @@ module NZBGet
76
81
  end
77
82
 
78
83
  def size(format = :bytes)
79
- formatted_response @attributes['FileSizeLo'].to_i, format
84
+ formatted_response(@attributes['FileSizeMB'] * 1024, format)
80
85
  end
81
86
 
82
87
  protected
@@ -0,0 +1,3 @@
1
+ module Nzbget
2
+ VERSION = "0.6.2"
3
+ end
@@ -1,33 +1,24 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "nzbget/version"
2
4
 
3
5
  Gem::Specification.new do |s|
4
- s.name = %q{nzbget}
5
- s.version = "0.6.0"
6
-
7
- s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Marc Bowes"]
9
- s.date = %q{2009-10-21}
6
+ s.name = "nzbget"
7
+ s.version = Nzbget::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Marc Bowes"]
10
+ s.email = %q{marcbowes@gmail.com}
11
+ s.homepage = ""
12
+ s.summary = %q{Communicate with NZBGet via RPC.}
10
13
  s.description = %q{Communicate with NZBGet via RPC.}
11
- s.email = %q{marcbowes@gmail.com}
12
- s.extra_rdoc_files = ["README.rdoc", "lib/group.rb", "lib/httparty/request.rb", "lib/nzbget.rb"]
13
- s.files = ["Manifest", "README.rdoc", "Rakefile", "lib/group.rb", "lib/httparty/request.rb", "lib/nzbget.rb", "nzbget.gemspec"]
14
- s.homepage = %q{http://github.com/marcbowes/nzbget}
15
- s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Nzbget", "--main", "README.rdoc"]
16
- s.require_paths = ["lib"]
17
- s.rubyforge_project = %q{nzbget}
18
- s.rubygems_version = %q{1.3.5}
19
- s.summary = %q{Communicate with NZBGet via RPC.}
20
14
 
21
- if s.respond_to? :specification_version then
22
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
- s.specification_version = 3
15
+ s.rubyforge_project = "nzbget"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
24
21
 
25
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
26
- s.add_runtime_dependency(%q<httparty>, [">= 0"])
27
- else
28
- s.add_dependency(%q<httparty>, [">= 0"])
29
- end
30
- else
31
- s.add_dependency(%q<httparty>, [">= 0"])
32
- end
22
+ s.add_dependency("httparty")
23
+ s.add_dependency("json")
33
24
  end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nzbget
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ hash: 3
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 6
9
+ - 2
10
+ version: 0.6.2
5
11
  platform: ruby
6
12
  authors:
7
13
  - Marc Bowes
@@ -9,68 +15,86 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-10-21 00:00:00 +02:00
18
+ date: 2011-05-30 00:00:00 +02:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: httparty
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
17
33
  type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: json
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
20
40
  requirements:
21
41
  - - ">="
22
42
  - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
23
46
  version: "0"
24
- version:
47
+ type: :runtime
48
+ version_requirements: *id002
25
49
  description: Communicate with NZBGet via RPC.
26
50
  email: marcbowes@gmail.com
27
51
  executables: []
28
52
 
29
53
  extensions: []
30
54
 
31
- extra_rdoc_files:
32
- - README.rdoc
33
- - lib/group.rb
34
- - lib/httparty/request.rb
35
- - lib/nzbget.rb
55
+ extra_rdoc_files: []
56
+
36
57
  files:
37
- - Manifest
58
+ - .gitignore
59
+ - Gemfile
38
60
  - README.rdoc
39
61
  - Rakefile
40
- - lib/group.rb
41
62
  - lib/httparty/request.rb
42
63
  - lib/nzbget.rb
64
+ - lib/nzbget/group.rb
65
+ - lib/nzbget/version.rb
43
66
  - nzbget.gemspec
44
67
  has_rdoc: true
45
- homepage: http://github.com/marcbowes/nzbget
68
+ homepage: ""
46
69
  licenses: []
47
70
 
48
71
  post_install_message:
49
- rdoc_options:
50
- - --line-numbers
51
- - --inline-source
52
- - --title
53
- - Nzbget
54
- - --main
55
- - README.rdoc
72
+ rdoc_options: []
73
+
56
74
  require_paths:
57
75
  - lib
58
76
  required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
59
78
  requirements:
60
79
  - - ">="
61
80
  - !ruby/object:Gem::Version
81
+ hash: 3
82
+ segments:
83
+ - 0
62
84
  version: "0"
63
- version:
64
85
  required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
65
87
  requirements:
66
88
  - - ">="
67
89
  - !ruby/object:Gem::Version
68
- version: "1.2"
69
- version:
90
+ hash: 3
91
+ segments:
92
+ - 0
93
+ version: "0"
70
94
  requirements: []
71
95
 
72
96
  rubyforge_project: nzbget
73
- rubygems_version: 1.3.5
97
+ rubygems_version: 1.6.2
74
98
  signing_key:
75
99
  specification_version: 3
76
100
  summary: Communicate with NZBGet via RPC.
data/Manifest DELETED
@@ -1,7 +0,0 @@
1
- Manifest
2
- README.rdoc
3
- Rakefile
4
- lib/group.rb
5
- lib/httparty/request.rb
6
- lib/nzbget.rb
7
- nzbget.gemspec