transmission_api 0.0.3 → 0.0.7
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.
- checksums.yaml +7 -0
- data/Gemfile +1 -1
- data/lib/torrents_fake.json +104 -0
- data/lib/transmission_api.rb +5 -119
- data/lib/transmission_api/client.rb +151 -0
- data/lib/transmission_api/client_fake.rb +39 -0
- data/lib/transmission_api/exception.rb +2 -0
- data/lib/transmission_api/version.rb +2 -2
- data/test/client_fake_test.rb +34 -0
- data/test/{transmission_api_test.rb → client_test.rb} +38 -26
- metadata +29 -19
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 63e739f0537e8f760ee9c79eec35a1f694b7d3b8
|
4
|
+
data.tar.gz: 04aebd70e7c6dc22cab947620cbdff22268520b0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3bd9c7de2663c9f0060187ade806556b1e1d90d35582e5bd17a825c8b67328f0f368c794fc72021a185087fa3cfd4fd770032d71b67aa1aeca93c39f05d0f6f3
|
7
|
+
data.tar.gz: 6c0d49866c5f2d890bb55f67f9d38441d0314b0b1474fe735447f36b3c42c698c8e254db93397b4beb88d859fe2df5ea93e0818a683477084136539dd3f42dbf
|
data/Gemfile
CHANGED
@@ -0,0 +1,104 @@
|
|
1
|
+
[ { "files" : [ { "bytesCompleted" : 27062831,
|
2
|
+
"length" : 52146735,
|
3
|
+
"name" : "No Media Kings - Ghosts With Shit Jobs trailer/Content/TRAILER_3_Cinetic.mov"
|
4
|
+
},
|
5
|
+
{ "bytesCompleted" : 718,
|
6
|
+
"length" : 718,
|
7
|
+
"name" : "No Media Kings - Ghosts With Shit Jobs trailer/Description.txt"
|
8
|
+
},
|
9
|
+
{ "bytesCompleted" : 51,
|
10
|
+
"length" : 51,
|
11
|
+
"name" : "No Media Kings - Ghosts With Shit Jobs trailer/License.txt"
|
12
|
+
}
|
13
|
+
],
|
14
|
+
"hashString" : "77831ec368308f1031434c5581a76fd0c3e06cfd",
|
15
|
+
"name" : "No Media Kings - Ghosts With Shit Jobs trailer",
|
16
|
+
"percentDone" : 0.51890000000000003,
|
17
|
+
"rateDownload" : 0,
|
18
|
+
"rateUpload" : 0,
|
19
|
+
"totalSize" : 52147504
|
20
|
+
},
|
21
|
+
{ "files" : [ { "bytesCompleted" : 24892844,
|
22
|
+
"length" : 24892844,
|
23
|
+
"name" : "Michael Mandiberg - Old News/Content/mandiberg_oldnews.mov"
|
24
|
+
},
|
25
|
+
{ "bytesCompleted" : 237,
|
26
|
+
"length" : 237,
|
27
|
+
"name" : "Michael Mandiberg - Old News/Description.txt"
|
28
|
+
},
|
29
|
+
{ "bytesCompleted" : 669,
|
30
|
+
"length" : 669,
|
31
|
+
"name" : "Michael Mandiberg - Old News/LegalTorrents.txt"
|
32
|
+
},
|
33
|
+
{ "bytesCompleted" : 101,
|
34
|
+
"length" : 101,
|
35
|
+
"name" : "Michael Mandiberg - Old News/License.txt"
|
36
|
+
}
|
37
|
+
],
|
38
|
+
"hashString" : "5f888e119ecb0cf8c25e68925164f533b1007038",
|
39
|
+
"name" : "Michael Mandiberg - Old News",
|
40
|
+
"percentDone" : 1,
|
41
|
+
"rateDownload" : 0,
|
42
|
+
"rateUpload" : 0,
|
43
|
+
"totalSize" : 24893851
|
44
|
+
},
|
45
|
+
{ "files" : [ { "bytesCompleted" : 31103230,
|
46
|
+
"length" : 31103230,
|
47
|
+
"name" : "pearl-jam-life-wasted-video/PearlJamLifeWasted.avi"
|
48
|
+
} ],
|
49
|
+
"hashString" : "1b2162c33001cb3c51d917441e74e313996dff96",
|
50
|
+
"name" : "pearl-jam-life-wasted-video",
|
51
|
+
"percentDone" : 1,
|
52
|
+
"rateDownload" : 0,
|
53
|
+
"rateUpload" : 0,
|
54
|
+
"totalSize" : 31103230
|
55
|
+
},
|
56
|
+
{ "files" : [ { "bytesCompleted" : 31772861,
|
57
|
+
"length" : 31772861,
|
58
|
+
"name" : "thewoolleyman - cinabox-screencast/Content/Cinabox_Screencast.mov"
|
59
|
+
},
|
60
|
+
{ "bytesCompleted" : 309,
|
61
|
+
"length" : 309,
|
62
|
+
"name" : "thewoolleyman - cinabox-screencast/Description.txt"
|
63
|
+
},
|
64
|
+
{ "bytesCompleted" : 669,
|
65
|
+
"length" : 669,
|
66
|
+
"name" : "thewoolleyman - cinabox-screencast/LegalTorrents.txt"
|
67
|
+
},
|
68
|
+
{ "bytesCompleted" : 52,
|
69
|
+
"length" : 52,
|
70
|
+
"name" : "thewoolleyman - cinabox-screencast/License.txt"
|
71
|
+
}
|
72
|
+
],
|
73
|
+
"hashString" : "0032886cdb4b0dcd6e75b5ac6901afda64367e0c",
|
74
|
+
"name" : "thewoolleyman - cinabox-screencast",
|
75
|
+
"percentDone" : 1,
|
76
|
+
"rateDownload" : 0,
|
77
|
+
"rateUpload" : 0,
|
78
|
+
"totalSize" : 31773891
|
79
|
+
},
|
80
|
+
{ "files" : [ { "bytesCompleted" : 0,
|
81
|
+
"length" : 13894821,
|
82
|
+
"name" : "Von Allan Studio - the road to god knows___ trailer/Content/the road to god knows... graphic novel trailer.wmv"
|
83
|
+
},
|
84
|
+
{ "bytesCompleted" : 0,
|
85
|
+
"length" : 1114,
|
86
|
+
"name" : "Von Allan Studio - the road to god knows___ trailer/Description.txt"
|
87
|
+
},
|
88
|
+
{ "bytesCompleted" : 0,
|
89
|
+
"length" : 669,
|
90
|
+
"name" : "Von Allan Studio - the road to god knows___ trailer/LegalTorrents.txt"
|
91
|
+
},
|
92
|
+
{ "bytesCompleted" : 0,
|
93
|
+
"length" : 127,
|
94
|
+
"name" : "Von Allan Studio - the road to god knows___ trailer/License.txt"
|
95
|
+
}
|
96
|
+
],
|
97
|
+
"hashString" : "6d97bb6424d048fe605d3fe558c5c5333cdd6227",
|
98
|
+
"name" : "Von Allan Studio - the road to god knows___ trailer",
|
99
|
+
"percentDone" : 0,
|
100
|
+
"rateDownload" : 0,
|
101
|
+
"rateUpload" : 0,
|
102
|
+
"totalSize" : 13896731
|
103
|
+
}
|
104
|
+
]
|
data/lib/transmission_api.rb
CHANGED
@@ -1,124 +1,10 @@
|
|
1
1
|
require_relative "transmission_api/version"
|
2
|
+
require_relative "transmission_api/client"
|
3
|
+
require_relative "transmission_api/client_fake"
|
4
|
+
require_relative "transmission_api/exception"
|
5
|
+
|
2
6
|
require "httparty"
|
3
7
|
require "json"
|
4
8
|
|
5
|
-
|
6
|
-
attr_accessor :session_id
|
7
|
-
attr_accessor :url
|
8
|
-
attr_accessor :basic_auth
|
9
|
-
attr_accessor :fields
|
10
|
-
attr_accessor :debug_mode
|
11
|
-
|
12
|
-
TORRENT_FIELDS = [
|
13
|
-
"id",
|
14
|
-
"name",
|
15
|
-
"totalSize",
|
16
|
-
"addedDate",
|
17
|
-
"isFinished",
|
18
|
-
"rateDownload",
|
19
|
-
"rateUpload",
|
20
|
-
"percentDone",
|
21
|
-
"files"
|
22
|
-
]
|
23
|
-
|
24
|
-
def initialize(opts)
|
25
|
-
@url = opts[:url]
|
26
|
-
@fields = opts[:fields] || TORRENT_FIELDS
|
27
|
-
@basic_auth = { :username => opts[:username], :password => opts[:password] } if opts[:username]
|
28
|
-
@session_id = "NOT-INITIALIZED"
|
29
|
-
@debug_mode = opts[:debug_mode] || false
|
30
|
-
end
|
31
|
-
|
32
|
-
def all
|
33
|
-
log "get_torrents"
|
34
|
-
|
35
|
-
response =
|
36
|
-
post(
|
37
|
-
:method => "torrent-get",
|
38
|
-
:arguments => {
|
39
|
-
:fields => fields
|
40
|
-
}
|
41
|
-
)
|
42
|
-
|
43
|
-
response["arguments"]["torrents"]
|
44
|
-
end
|
45
|
-
|
46
|
-
def find(id)
|
47
|
-
log "get_torrent: #{id}"
|
48
|
-
|
49
|
-
response =
|
50
|
-
post(
|
51
|
-
:method => "torrent-get",
|
52
|
-
:arguments => {
|
53
|
-
:fields => fields,
|
54
|
-
:ids => [id]
|
55
|
-
}
|
56
|
-
)
|
57
|
-
|
58
|
-
response["arguments"]["torrents"].first
|
59
|
-
end
|
60
|
-
|
61
|
-
def create(filename)
|
62
|
-
log "add_torrent: #{filename}"
|
63
|
-
|
64
|
-
response =
|
65
|
-
post(
|
66
|
-
:method => "torrent-add",
|
67
|
-
:arguments => {
|
68
|
-
:filename => filename
|
69
|
-
}
|
70
|
-
)
|
71
|
-
|
72
|
-
response["arguments"]["torrent-added"]
|
73
|
-
end
|
74
|
-
|
75
|
-
def destroy(id)
|
76
|
-
log "remove_torrent: #{id}"
|
77
|
-
|
78
|
-
response =
|
79
|
-
post(
|
80
|
-
:method => "torrent-remove",
|
81
|
-
:arguments => {
|
82
|
-
:ids => [id],
|
83
|
-
:"delete-local-data" => true
|
84
|
-
}
|
85
|
-
)
|
86
|
-
|
87
|
-
response
|
88
|
-
end
|
89
|
-
|
90
|
-
def post(opts)
|
91
|
-
JSON::parse( http_post(opts).body )
|
92
|
-
end
|
93
|
-
|
94
|
-
def http_post(opts)
|
95
|
-
post_options = {
|
96
|
-
:body => opts.to_json,
|
97
|
-
:headers => { "x-transmission-session-id" => session_id }
|
98
|
-
}
|
99
|
-
post_options.merge!( :basic_auth => basic_auth ) if basic_auth
|
100
|
-
|
101
|
-
log "url: #{url}"
|
102
|
-
log "post_options: #{post_options}"
|
103
|
-
|
104
|
-
response = HTTParty.post( url, post_options )
|
105
|
-
|
106
|
-
log "response.body: #{response.body}"
|
107
|
-
log "response.code: #{response.code}"
|
108
|
-
log "response.message: #{response.message}"
|
109
|
-
log "response.headers: #{response.headers.inspect}"
|
110
|
-
|
111
|
-
# retry connection if session_id incorrect
|
112
|
-
if( response.code == 409 )
|
113
|
-
log "changing session_id"
|
114
|
-
@session_id = response.headers["x-transmission-session-id"]
|
115
|
-
response = http_post(opts)
|
116
|
-
end
|
117
|
-
|
118
|
-
response
|
119
|
-
end
|
120
|
-
|
121
|
-
def log(message)
|
122
|
-
Kernel.puts "[TransmissionApi #{Time.now.strftime( "%F %T" )}] #{message}" if debug_mode
|
123
|
-
end
|
9
|
+
module TransmissionApi
|
124
10
|
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
class TransmissionApi::Client
|
2
|
+
attr_accessor :session_id
|
3
|
+
attr_accessor :url
|
4
|
+
attr_accessor :basic_auth
|
5
|
+
attr_accessor :fields
|
6
|
+
attr_accessor :debug_mode
|
7
|
+
|
8
|
+
TORRENT_FIELDS = [
|
9
|
+
"id",
|
10
|
+
"name",
|
11
|
+
"totalSize",
|
12
|
+
"addedDate",
|
13
|
+
"isFinished",
|
14
|
+
"rateDownload",
|
15
|
+
"rateUpload",
|
16
|
+
"percentDone",
|
17
|
+
"files"
|
18
|
+
]
|
19
|
+
|
20
|
+
def initialize(opts)
|
21
|
+
@url = opts[:url]
|
22
|
+
@fields = opts[:fields] || TORRENT_FIELDS
|
23
|
+
@basic_auth = { :username => opts[:username], :password => opts[:password] } if opts[:username]
|
24
|
+
@session_id = "NOT-INITIALIZED"
|
25
|
+
@debug_mode = opts[:debug_mode] || false
|
26
|
+
end
|
27
|
+
|
28
|
+
def all
|
29
|
+
log "get_torrents"
|
30
|
+
|
31
|
+
response =
|
32
|
+
post(
|
33
|
+
:method => "torrent-get",
|
34
|
+
:arguments => {
|
35
|
+
:fields => fields
|
36
|
+
}
|
37
|
+
)
|
38
|
+
|
39
|
+
response["arguments"]["torrents"]
|
40
|
+
end
|
41
|
+
|
42
|
+
def find(id)
|
43
|
+
log "get_torrent: #{id}"
|
44
|
+
|
45
|
+
response =
|
46
|
+
post(
|
47
|
+
:method => "torrent-get",
|
48
|
+
:arguments => {
|
49
|
+
:fields => fields,
|
50
|
+
:ids => [id]
|
51
|
+
}
|
52
|
+
)
|
53
|
+
|
54
|
+
response["arguments"]["torrents"].first
|
55
|
+
end
|
56
|
+
|
57
|
+
def create(filename)
|
58
|
+
log "add_torrent: #{filename}"
|
59
|
+
|
60
|
+
response =
|
61
|
+
post(
|
62
|
+
:method => "torrent-add",
|
63
|
+
:arguments => {
|
64
|
+
:filename => filename
|
65
|
+
}
|
66
|
+
)
|
67
|
+
|
68
|
+
response["arguments"]["torrent-added"]
|
69
|
+
end
|
70
|
+
|
71
|
+
def destroy(id)
|
72
|
+
log "remove_torrent: #{id}"
|
73
|
+
|
74
|
+
response =
|
75
|
+
post(
|
76
|
+
:method => "torrent-remove",
|
77
|
+
:arguments => {
|
78
|
+
:ids => [id],
|
79
|
+
:"delete-local-data" => true
|
80
|
+
}
|
81
|
+
)
|
82
|
+
|
83
|
+
response
|
84
|
+
end
|
85
|
+
|
86
|
+
def post(opts)
|
87
|
+
response_parsed = JSON::parse( http_post(opts).body )
|
88
|
+
|
89
|
+
if response_parsed["result"] != "success"
|
90
|
+
raise TransmissionApi::Exception, response_parsed["result"]
|
91
|
+
end
|
92
|
+
|
93
|
+
response_parsed
|
94
|
+
end
|
95
|
+
|
96
|
+
def http_post(opts)
|
97
|
+
post_options = {
|
98
|
+
:body => opts.to_json,
|
99
|
+
:headers => { "x-transmission-session-id" => session_id }
|
100
|
+
}
|
101
|
+
post_options.merge!( :basic_auth => basic_auth ) if basic_auth
|
102
|
+
|
103
|
+
log "url: #{url}"
|
104
|
+
log "post_body:"
|
105
|
+
log JSON.parse(post_options[:body]).to_yaml
|
106
|
+
log "------------------"
|
107
|
+
|
108
|
+
response = HTTParty.post( url, post_options )
|
109
|
+
|
110
|
+
log_response response
|
111
|
+
|
112
|
+
# retry connection if session_id incorrect
|
113
|
+
if( response.code == 409 )
|
114
|
+
log "changing session_id"
|
115
|
+
@session_id = response.headers["x-transmission-session-id"]
|
116
|
+
response = http_post(opts)
|
117
|
+
end
|
118
|
+
|
119
|
+
response
|
120
|
+
end
|
121
|
+
|
122
|
+
def log(message)
|
123
|
+
Kernel.puts "[TransmissionApi #{Time.now.strftime( "%F %T" )}] #{message}" if debug_mode
|
124
|
+
end
|
125
|
+
|
126
|
+
def log_response(response)
|
127
|
+
body = nil
|
128
|
+
begin
|
129
|
+
body = JSON.parse(response.body).to_yaml
|
130
|
+
rescue
|
131
|
+
body = response.body
|
132
|
+
end
|
133
|
+
|
134
|
+
headers = response.headers.to_yaml
|
135
|
+
|
136
|
+
log "response.code: #{response.code}"
|
137
|
+
log "response.message: #{response.message}"
|
138
|
+
|
139
|
+
log "response.body_raw:"
|
140
|
+
log response.body
|
141
|
+
log "-----------------"
|
142
|
+
|
143
|
+
log "response.body:"
|
144
|
+
log body
|
145
|
+
log "-----------------"
|
146
|
+
|
147
|
+
log "response.headers:"
|
148
|
+
log headers
|
149
|
+
log "------------------"
|
150
|
+
end
|
151
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class TransmissionApi::ClientFake < TransmissionApi::Client
|
2
|
+
|
3
|
+
attr_reader :torrents
|
4
|
+
|
5
|
+
def initialize(opts)
|
6
|
+
super
|
7
|
+
torrents_path = opts[:torrents_path] || "#{File.dirname(__FILE__)}/../torrents_fake.json"
|
8
|
+
@torrents = JSON.parse(File.read(torrents_path))
|
9
|
+
end
|
10
|
+
|
11
|
+
def all
|
12
|
+
torrents
|
13
|
+
end
|
14
|
+
|
15
|
+
def find(id)
|
16
|
+
torrents.select { |e| e["hashString"] == id }.first
|
17
|
+
end
|
18
|
+
|
19
|
+
def create(filename)
|
20
|
+
torrent = {
|
21
|
+
"files" => [],
|
22
|
+
"hashString" => "77831ec368308f1031434c5581a76fd0c3e06cfd",
|
23
|
+
"name" => "No Media Kings - Ghosts With Shit Jobs trailer",
|
24
|
+
"percentDone" => 0,
|
25
|
+
"rateUpload" => 0,
|
26
|
+
"rateDownload" => 0,
|
27
|
+
"totalSize" => 100
|
28
|
+
}
|
29
|
+
|
30
|
+
torrents << torrent
|
31
|
+
|
32
|
+
torrent
|
33
|
+
end
|
34
|
+
|
35
|
+
def destroy(id)
|
36
|
+
torrents.delete_if { |e| e["hashString"] == id }
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.0.
|
1
|
+
module TransmissionApi
|
2
|
+
VERSION = "0.0.7"
|
3
3
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class ClientFakeTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@client = TransmissionApi::ClientFake.new({})
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_all
|
9
|
+
assert_equal( "77831ec368308f1031434c5581a76fd0c3e06cfd", @client.all.first["hashString"] )
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_find
|
13
|
+
assert_equal( "77831ec368308f1031434c5581a76fd0c3e06cfd", @client.find("77831ec368308f1031434c5581a76fd0c3e06cfd")["hashString"] )
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_create
|
17
|
+
assert_equal( "77831ec368308f1031434c5581a76fd0c3e06cfd", @client.create("filename")["hashString"] )
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_destroy
|
21
|
+
torrents = [
|
22
|
+
{ "hashString" => "A" },
|
23
|
+
{ "hashString" => "B" },
|
24
|
+
{ "hashString" => "C" },
|
25
|
+
]
|
26
|
+
|
27
|
+
@client.expects(:torrents).returns(torrents)
|
28
|
+
|
29
|
+
@client.destroy("B")
|
30
|
+
|
31
|
+
assert_equal(["A", "C"], torrents.map{ |e| e["hashString"] })
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require_relative "test_helper"
|
2
2
|
|
3
|
-
class
|
3
|
+
class ClientTest < Test::Unit::TestCase
|
4
4
|
def setup
|
5
|
-
@
|
5
|
+
@client = TransmissionApi::Client.new( :url => "http://api.url" )
|
6
6
|
end
|
7
7
|
|
8
8
|
def test_post
|
9
|
-
@
|
10
|
-
@
|
9
|
+
@client.stubs(:session_id).returns("SESSION-ID")
|
10
|
+
@client.stubs(:url).returns("http://api.url")
|
11
11
|
|
12
12
|
opts = { :key1 => "value1", :key2 => "value2" }
|
13
13
|
|
@@ -21,18 +21,18 @@ class TransmissionApiTest < Test::Unit::TestCase
|
|
21
21
|
:code => "",
|
22
22
|
:message => "",
|
23
23
|
:headers => "",
|
24
|
-
:body => {"key" => "value"}.to_json
|
24
|
+
:body => {"key" => "value", "result" => "success"}.to_json
|
25
25
|
)
|
26
26
|
|
27
27
|
HTTParty.expects(:post).with( "http://api.url", opts_expected ).returns( response_mock )
|
28
28
|
|
29
|
-
assert_equal "value", @
|
29
|
+
assert_equal "value", @client.post(opts)["key"]
|
30
30
|
end
|
31
31
|
|
32
32
|
def test_post_with_basic_auth
|
33
|
-
@
|
34
|
-
@
|
35
|
-
@
|
33
|
+
@client.stubs(:session_id).returns("SESSION-ID")
|
34
|
+
@client.stubs(:url).returns("http://api.url")
|
35
|
+
@client.stubs(:basic_auth).returns("user_pass")
|
36
36
|
|
37
37
|
opts = { :key1 => "value1" }
|
38
38
|
|
@@ -47,17 +47,17 @@ class TransmissionApiTest < Test::Unit::TestCase
|
|
47
47
|
:code => "",
|
48
48
|
:message => "",
|
49
49
|
:headers => "",
|
50
|
-
:body => {}.to_json
|
50
|
+
:body => {"result" => "success"}.to_json
|
51
51
|
)
|
52
52
|
|
53
53
|
HTTParty.expects(:post).with( "http://api.url", opts_expected ).returns( response_mock )
|
54
54
|
|
55
|
-
@
|
55
|
+
@client.post(opts)
|
56
56
|
end
|
57
57
|
|
58
58
|
def test_post_with_409
|
59
|
-
@
|
60
|
-
@
|
59
|
+
@client.stubs(:url).returns("http://api.url")
|
60
|
+
@client.instance_variable_set(:@session_id, "SESSION-ID")
|
61
61
|
|
62
62
|
opts = { :key1 => "value1" }
|
63
63
|
|
@@ -84,15 +84,15 @@ class TransmissionApiTest < Test::Unit::TestCase
|
|
84
84
|
:code => 200,
|
85
85
|
:message => "",
|
86
86
|
:headers => "",
|
87
|
-
:body => {"key" => "value"}.to_json
|
87
|
+
:body => {"key" => "value", "result" => "success"}.to_json
|
88
88
|
)
|
89
89
|
|
90
90
|
post_sequence = sequence("post_sequence")
|
91
91
|
HTTParty.expects(:post).with( "http://api.url", opts_expected_1 ).returns( response_mock_1 ).in_sequence( post_sequence )
|
92
92
|
HTTParty.expects(:post).with( "http://api.url", opts_expected_2 ).returns( response_mock_2 ).in_sequence( post_sequence )
|
93
93
|
|
94
|
-
assert_equal "value", @
|
95
|
-
assert_equal "NEW-SESSION-ID", @
|
94
|
+
assert_equal "value", @client.post(opts)["key"]
|
95
|
+
assert_equal "NEW-SESSION-ID", @client.instance_variable_get(:@session_id)
|
96
96
|
end
|
97
97
|
|
98
98
|
def test_all
|
@@ -102,10 +102,10 @@ class TransmissionApiTest < Test::Unit::TestCase
|
|
102
102
|
}
|
103
103
|
result = { "arguments" => { "torrents" => "torrents" } }
|
104
104
|
|
105
|
-
@
|
106
|
-
@
|
105
|
+
@client.stubs(:fields).returns("fields")
|
106
|
+
@client.expects(:post).with( opts_expected ).returns( result )
|
107
107
|
|
108
|
-
assert_equal( "torrents", @
|
108
|
+
assert_equal( "torrents", @client.all )
|
109
109
|
end
|
110
110
|
|
111
111
|
def test_find
|
@@ -115,10 +115,10 @@ class TransmissionApiTest < Test::Unit::TestCase
|
|
115
115
|
}
|
116
116
|
result = { "arguments" => { "torrents" => ["torrent1"] } }
|
117
117
|
|
118
|
-
@
|
119
|
-
@
|
118
|
+
@client.stubs(:fields).returns("fields")
|
119
|
+
@client.expects(:post).with( opts_expected ).returns( result )
|
120
120
|
|
121
|
-
assert_equal( "torrent1", @
|
121
|
+
assert_equal( "torrent1", @client.find(1) )
|
122
122
|
end
|
123
123
|
|
124
124
|
def test_create
|
@@ -128,9 +128,9 @@ class TransmissionApiTest < Test::Unit::TestCase
|
|
128
128
|
}
|
129
129
|
result = { "arguments" => { "torrent-added" => "torrent-added" } }
|
130
130
|
|
131
|
-
@
|
131
|
+
@client.expects(:post).with( opts_expected ).returns( result )
|
132
132
|
|
133
|
-
assert_equal( "torrent-added", @
|
133
|
+
assert_equal( "torrent-added", @client.create( "filename" ) )
|
134
134
|
end
|
135
135
|
|
136
136
|
def test_destroy
|
@@ -139,8 +139,20 @@ class TransmissionApiTest < Test::Unit::TestCase
|
|
139
139
|
:arguments => { :ids => [1], :"delete-local-data" => true }
|
140
140
|
}
|
141
141
|
|
142
|
-
@
|
143
|
-
@
|
142
|
+
@client.expects(:post).with( opts_expected )
|
143
|
+
@client.destroy(1)
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_if_not_success_raise_exception
|
147
|
+
result_mock = mock(:body => { "arguments" => {}, "result" => "Wadus error" }.to_json)
|
148
|
+
@client.expects(:http_post).returns(result_mock)
|
149
|
+
|
150
|
+
exception =
|
151
|
+
assert_raise(TransmissionApi::Exception) do
|
152
|
+
@client.create("filename")
|
153
|
+
end
|
154
|
+
|
155
|
+
assert_equal("Wadus error", exception.message)
|
144
156
|
end
|
145
157
|
|
146
158
|
end
|
metadata
CHANGED
@@ -1,38 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: transmission_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.7
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Fernando Guillen
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-01-12 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: httparty
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- - =
|
17
|
+
- - '='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 0.9.0
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.9.0
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
28
|
name: mocha
|
27
|
-
requirement:
|
28
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- - =
|
31
|
+
- - '='
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: 0.13.0
|
33
34
|
type: :development
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.13.0
|
36
41
|
description: small ruby wrapper for the Transmission RPC API
|
37
42
|
email:
|
38
43
|
- fguillen.mail@gmail.com
|
@@ -46,35 +51,40 @@ files:
|
|
46
51
|
- LICENSE
|
47
52
|
- README.md
|
48
53
|
- Rakefile
|
54
|
+
- lib/torrents_fake.json
|
49
55
|
- lib/transmission_api.rb
|
56
|
+
- lib/transmission_api/client.rb
|
57
|
+
- lib/transmission_api/client_fake.rb
|
58
|
+
- lib/transmission_api/exception.rb
|
50
59
|
- lib/transmission_api/version.rb
|
60
|
+
- test/client_fake_test.rb
|
61
|
+
- test/client_test.rb
|
51
62
|
- test/test_helper.rb
|
52
|
-
- test/transmission_api_test.rb
|
53
63
|
- transmission_api.gemspec
|
54
64
|
homepage: https://github.com/fguillen/TransmissionApi
|
55
65
|
licenses: []
|
66
|
+
metadata: {}
|
56
67
|
post_install_message:
|
57
68
|
rdoc_options: []
|
58
69
|
require_paths:
|
59
70
|
- lib
|
60
71
|
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
-
none: false
|
62
72
|
requirements:
|
63
|
-
- -
|
73
|
+
- - '>='
|
64
74
|
- !ruby/object:Gem::Version
|
65
75
|
version: '0'
|
66
76
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
-
none: false
|
68
77
|
requirements:
|
69
|
-
- -
|
78
|
+
- - '>='
|
70
79
|
- !ruby/object:Gem::Version
|
71
80
|
version: '0'
|
72
81
|
requirements: []
|
73
82
|
rubyforge_project:
|
74
|
-
rubygems_version:
|
83
|
+
rubygems_version: 2.0.3
|
75
84
|
signing_key:
|
76
|
-
specification_version:
|
85
|
+
specification_version: 4
|
77
86
|
summary: small ruby wrapper for the Transmission RPC API
|
78
87
|
test_files:
|
88
|
+
- test/client_fake_test.rb
|
89
|
+
- test/client_test.rb
|
79
90
|
- test/test_helper.rb
|
80
|
-
- test/transmission_api_test.rb
|