nzbmatrix 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -40,7 +40,7 @@ module Nzbmatrix
40
40
  params = { :search => search_term }.merge(opts).merge(@creds)
41
41
  response = RestClient.get("#{BASE_URL}/search.php", :params => params)
42
42
  @parser.parse(response).map do |parsed|
43
- SearchResult.new(parsed)
43
+ SearchResult.new(parsed, self)
44
44
  end
45
45
  end
46
46
 
@@ -2,6 +2,7 @@ module Nzbmatrix
2
2
  class SearchResult
3
3
 
4
4
  require "time"
5
+ require "fileutils"
5
6
 
6
7
  attr_accessor :id
7
8
  attr_accessor :name
@@ -18,7 +19,9 @@ module Nzbmatrix
18
19
  attr_accessor :image_url
19
20
  attr_accessor :region
20
21
 
21
- def initialize(api_response)
22
+ def initialize(api_response, client)
23
+ @client = client
24
+
22
25
  @id = api_response["NZBID"].to_i
23
26
  @name = api_response["NZBNAME"]
24
27
  @link = api_response["LINK"]
@@ -36,6 +39,17 @@ module Nzbmatrix
36
39
  @region = api_response["REGION"].to_i
37
40
  end
38
41
 
42
+ def download(path = nil)
43
+ path ||= Dir.pwd
44
+ path = File.expand_path(path)
45
+ FileUtils.mkdir_p(path)
46
+
47
+ nzb = @client.download(id)
48
+ File.open(File.join(path, "#{name}.nzb"), "w") { |f| f.write(nzb) }
49
+
50
+ id
51
+ end
52
+
39
53
  def has_nfo?
40
54
  !!@nfo
41
55
  end
@@ -1,3 +1,3 @@
1
1
  module Nzbmatrix
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -22,7 +22,7 @@ module Nzbmatrix
22
22
  "REGION" => "0",
23
23
  }
24
24
 
25
- result = SearchResult.new(response)
25
+ result = SearchResult.new(response, nil)
26
26
  result.id.should eq(396552)
27
27
  result.name.should eq("Dark Angel S01 WS AC3 DVDRip XviD SFM")
28
28
  result.link.should eq("nzbmatrix.com/nzb-details.php?id=396552&hit=1")
@@ -40,5 +40,50 @@ module Nzbmatrix
40
40
  result.image_url.should eq("http://img132.imageshack.us/img132/3606/mv5bmtmxnja2mzk3nl5bml5kj5.jpg")
41
41
  result.region.should eq(0)
42
42
  end
43
+
44
+ describe "#download" do
45
+ let(:name) { "Asd asd" }
46
+ let(:id) { 1234567 }
47
+ let(:contents) { "asdasd" }
48
+ let(:client_stub) do
49
+ client_stub = double("client")
50
+ client_stub.should_receive(:download).with(id).and_return(contents)
51
+
52
+ client_stub
53
+ end
54
+ let(:result) do
55
+ result = SearchResult.new({}, client_stub)
56
+ result.id = id
57
+ result.name = name
58
+
59
+ result
60
+ end
61
+
62
+ context "no path given" do
63
+ after { File.unlink("#{name}.nzb") }
64
+
65
+ it "allows you to download the nzb" do
66
+ result.download.should == id
67
+
68
+ File.file?("#{name}.nzb").should be_true
69
+ File.read("#{name}.nzb").should == contents
70
+ end
71
+ end
72
+
73
+ context "path given" do
74
+ let(:path) { "/tmp" }
75
+ let(:file_path) { File.join(path, "#{name}.nzb") }
76
+
77
+ after { File.unlink(file_path) }
78
+
79
+ it "allows you to specify a path to download the file to" do
80
+ result.download(path).should == id
81
+
82
+ File.file?(file_path).should be_true
83
+ File.read(file_path).should == contents
84
+ end
85
+ end
86
+ end
43
87
  end
88
+
44
89
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nzbmatrix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-06-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
16
- requirement: &18107400 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *18107400
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rake
27
- requirement: &18105260 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *18105260
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: rspec
38
- requirement: &18102920 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,7 +53,12 @@ dependencies:
43
53
  version: '2'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *18102920
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '2'
47
62
  description: Interact with the nzbmatrix api
48
63
  email:
49
64
  - bedlamp@gmail.com
@@ -79,7 +94,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
79
94
  version: '0'
80
95
  segments:
81
96
  - 0
82
- hash: -2461971318538082917
97
+ hash: 4151075312609276286
83
98
  required_rubygems_version: !ruby/object:Gem::Requirement
84
99
  none: false
85
100
  requirements:
@@ -88,10 +103,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
103
  version: '0'
89
104
  segments:
90
105
  - 0
91
- hash: -2461971318538082917
106
+ hash: 4151075312609276286
92
107
  requirements: []
93
108
  rubyforge_project:
94
- rubygems_version: 1.8.11
109
+ rubygems_version: 1.8.23
95
110
  signing_key:
96
111
  specification_version: 3
97
112
  summary: nzbmatrix api gem