transmission-simple 0.0.1
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/.gitignore +3 -0
- data/Gemfile +4 -0
- data/Rakefile +2 -0
- data/lib/transmission-simple.rb +11 -0
- data/lib/transmission-simple/api.rb +53 -0
- data/lib/transmission-simple/error.rb +3 -0
- data/lib/transmission-simple/torrent.rb +23 -0
- data/lib/transmission-simple/version.rb +3 -0
- data/transmission-simple.gemspec +22 -0
- metadata +98 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'net/http'
|
|
3
|
+
require 'net/https'
|
|
4
|
+
require 'uri'
|
|
5
|
+
require 'json'
|
|
6
|
+
require 'ostruct'
|
|
7
|
+
require 'active_support/inflector'
|
|
8
|
+
|
|
9
|
+
require 'transmission-simple/error'
|
|
10
|
+
require 'transmission-simple/torrent'
|
|
11
|
+
require 'transmission-simple/api'
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
module TransmissionSimple
|
|
2
|
+
class Api
|
|
3
|
+
attr :endpoint, true
|
|
4
|
+
attr :session, true
|
|
5
|
+
|
|
6
|
+
def initialize( endpoint )
|
|
7
|
+
@endpoint = URI.parse(endpoint)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def send_request(request_name, options )
|
|
11
|
+
http = Net::HTTP.new(endpoint.host, endpoint.port)
|
|
12
|
+
# http.set_debug_output STDOUT
|
|
13
|
+
http.start do |http|
|
|
14
|
+
request = Net::HTTP::Post.new(endpoint.path, {'X-Transmission-Session-Id' => (session or ''), 'Content-Type' => 'application/json' })
|
|
15
|
+
request.body = {:method => request_name}.merge(:arguments => options).to_json
|
|
16
|
+
request.basic_auth *endpoint.userinfo.split(':') if endpoint.userinfo
|
|
17
|
+
|
|
18
|
+
results = http.request(request)
|
|
19
|
+
|
|
20
|
+
if results.code == '409'
|
|
21
|
+
@session = results['x-transmission-session-id']
|
|
22
|
+
return send_request(request_name, options)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
json_results = JSON.parse(results.body)
|
|
26
|
+
if json_results['result'] && json_results['result'] == 'success'
|
|
27
|
+
if json_results['arguments']
|
|
28
|
+
if json_results['arguments']['torrents']
|
|
29
|
+
[].tap do |torrents|
|
|
30
|
+
json_results['arguments']['torrents'].each {|t| torrents << Torrent.new(t) }
|
|
31
|
+
end
|
|
32
|
+
else
|
|
33
|
+
json_results['arguments']
|
|
34
|
+
end
|
|
35
|
+
else
|
|
36
|
+
{}
|
|
37
|
+
end
|
|
38
|
+
else
|
|
39
|
+
raise Transmission::Error.new( json_results['result'] )
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def method_missing(method, *arguments)
|
|
45
|
+
send_request(transmissionize(method), arguments.shift )
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
protected
|
|
49
|
+
def transmissionize(method)
|
|
50
|
+
ActiveSupport::Inflector.dasherize(method.to_s.dasherize)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module TransmissionSimple
|
|
2
|
+
class Torrent < OpenStruct
|
|
3
|
+
def initialize( data = {} )
|
|
4
|
+
super(rubyize(data))
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
private
|
|
8
|
+
def rubyize( object )
|
|
9
|
+
case object
|
|
10
|
+
when Hash
|
|
11
|
+
{}.tap do |rekeyed|
|
|
12
|
+
object.each_pair {|k,v| rekeyed[ActiveSupport::Inflector.underscore(k)] = ( v.is_a?(Hash) ? OpenStruct.new(rubyize(v)) : rubyize(v) )}
|
|
13
|
+
end
|
|
14
|
+
when Array
|
|
15
|
+
[].tap do |rubyized|
|
|
16
|
+
object.each {|v| rubyized << (v.is_a?(Hash) ? OpenStruct.new(rubyize(v)) : rubyize(v)) }
|
|
17
|
+
end
|
|
18
|
+
else
|
|
19
|
+
object
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
|
3
|
+
require "transmission-simple/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |s|
|
|
6
|
+
s.name = "transmission-simple"
|
|
7
|
+
s.version = TransmissionSimple::VERSION
|
|
8
|
+
s.platform = Gem::Platform::RUBY
|
|
9
|
+
s.authors = ["Jon Moses"]
|
|
10
|
+
s.email = ["jon@burningbush.us"]
|
|
11
|
+
s.homepage = "http://github.com/jmoses/transmission-simple"
|
|
12
|
+
s.summary = %q{Simple REST based client for Transmissions's RPC functionality}
|
|
13
|
+
s.description = %q{Simple REST based client for Transmissions's RPC functionality}
|
|
14
|
+
|
|
15
|
+
s.files = `git ls-files`.split("\n")
|
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
18
|
+
s.require_paths = ["lib"]
|
|
19
|
+
|
|
20
|
+
s.add_dependency 'json'
|
|
21
|
+
s.add_dependency 'activesupport'
|
|
22
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: transmission-simple
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
prerelease: false
|
|
5
|
+
segments:
|
|
6
|
+
- 0
|
|
7
|
+
- 0
|
|
8
|
+
- 1
|
|
9
|
+
version: 0.0.1
|
|
10
|
+
platform: ruby
|
|
11
|
+
authors:
|
|
12
|
+
- Jon Moses
|
|
13
|
+
autorequire:
|
|
14
|
+
bindir: bin
|
|
15
|
+
cert_chain: []
|
|
16
|
+
|
|
17
|
+
date: 2010-11-19 00:00:00 -05:00
|
|
18
|
+
default_executable:
|
|
19
|
+
dependencies:
|
|
20
|
+
- !ruby/object:Gem::Dependency
|
|
21
|
+
name: json
|
|
22
|
+
prerelease: false
|
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
|
24
|
+
none: false
|
|
25
|
+
requirements:
|
|
26
|
+
- - ">="
|
|
27
|
+
- !ruby/object:Gem::Version
|
|
28
|
+
segments:
|
|
29
|
+
- 0
|
|
30
|
+
version: "0"
|
|
31
|
+
type: :runtime
|
|
32
|
+
version_requirements: *id001
|
|
33
|
+
- !ruby/object:Gem::Dependency
|
|
34
|
+
name: activesupport
|
|
35
|
+
prerelease: false
|
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
|
37
|
+
none: false
|
|
38
|
+
requirements:
|
|
39
|
+
- - ">="
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
segments:
|
|
42
|
+
- 0
|
|
43
|
+
version: "0"
|
|
44
|
+
type: :runtime
|
|
45
|
+
version_requirements: *id002
|
|
46
|
+
description: Simple REST based client for Transmissions's RPC functionality
|
|
47
|
+
email:
|
|
48
|
+
- jon@burningbush.us
|
|
49
|
+
executables: []
|
|
50
|
+
|
|
51
|
+
extensions: []
|
|
52
|
+
|
|
53
|
+
extra_rdoc_files: []
|
|
54
|
+
|
|
55
|
+
files:
|
|
56
|
+
- .gitignore
|
|
57
|
+
- Gemfile
|
|
58
|
+
- Rakefile
|
|
59
|
+
- lib/transmission-simple.rb
|
|
60
|
+
- lib/transmission-simple/api.rb
|
|
61
|
+
- lib/transmission-simple/error.rb
|
|
62
|
+
- lib/transmission-simple/torrent.rb
|
|
63
|
+
- lib/transmission-simple/version.rb
|
|
64
|
+
- transmission-simple.gemspec
|
|
65
|
+
has_rdoc: true
|
|
66
|
+
homepage: http://github.com/jmoses/transmission-simple
|
|
67
|
+
licenses: []
|
|
68
|
+
|
|
69
|
+
post_install_message:
|
|
70
|
+
rdoc_options: []
|
|
71
|
+
|
|
72
|
+
require_paths:
|
|
73
|
+
- lib
|
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
75
|
+
none: false
|
|
76
|
+
requirements:
|
|
77
|
+
- - ">="
|
|
78
|
+
- !ruby/object:Gem::Version
|
|
79
|
+
segments:
|
|
80
|
+
- 0
|
|
81
|
+
version: "0"
|
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
|
+
none: false
|
|
84
|
+
requirements:
|
|
85
|
+
- - ">="
|
|
86
|
+
- !ruby/object:Gem::Version
|
|
87
|
+
segments:
|
|
88
|
+
- 0
|
|
89
|
+
version: "0"
|
|
90
|
+
requirements: []
|
|
91
|
+
|
|
92
|
+
rubyforge_project:
|
|
93
|
+
rubygems_version: 1.3.7
|
|
94
|
+
signing_key:
|
|
95
|
+
specification_version: 3
|
|
96
|
+
summary: Simple REST based client for Transmissions's RPC functionality
|
|
97
|
+
test_files: []
|
|
98
|
+
|