nzbmatrix 0.0.1 → 0.0.2

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/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
data/Rakefile CHANGED
@@ -1,2 +1,7 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+ require "rspec/core/rake_task"
4
+
5
+ RSpec::Core::RakeTask.new
6
+
7
+ task :default => :spec
@@ -0,0 +1,33 @@
1
+ module Nzbmatrix
2
+ class ApiResponseParser
3
+
4
+ def parse(response)
5
+ parsed = response.split(/^\|$/).map do |block|
6
+ parse_block(block)
7
+ end
8
+
9
+ parsed.reject do |hash|
10
+ hash.empty?
11
+ end
12
+ end
13
+
14
+ def parse_block(block)
15
+ block.split("\n").inject({}) do |h, line|
16
+ if (parsed = parse_line(line))
17
+ key, value = parsed
18
+ h[key] = value
19
+ end
20
+
21
+ h
22
+ end
23
+ end
24
+
25
+ def parse_line(line)
26
+ unless line.empty?
27
+ key, value = line.split(":", 2)
28
+ value.gsub!(/;$/, "") unless value.nil?
29
+ [key, value]
30
+ end
31
+ end
32
+ end
33
+ end
@@ -2,12 +2,17 @@ module Nzbmatrix
2
2
  require 'rest_client'
3
3
 
4
4
  class Client
5
+
6
+ require "nzbmatrix/api_response_parser"
7
+ require "nzbmatrix/search_result"
8
+
5
9
  BASE_URL = "https://api.nzbmatrix.com/v1.1"
6
10
 
7
11
  def initialize(username, api_key)
8
12
  @username = username
9
13
  @api_key = api_key
10
14
  @creds = { :username => @username, :apikey => @api_key }
15
+ @parser = ApiResponseParser.new
11
16
  end
12
17
 
13
18
  def download(nzb_id)
@@ -32,7 +37,11 @@ module Nzbmatrix
32
37
  # :englishonly => 1 if added the search will only return ENGLISH and UNKNOWN matches
33
38
  # :searchin => SEARCH FIELD default name. possible options: name, subject, weblink
34
39
  def search(search_term, opts = {})
35
- RestClient.get "#{BASE_URL}/search.php", :params => { :search => search_term }.merge(opts).merge(@creds)
40
+ params = { :search => search_term }.merge(opts).merge(@creds)
41
+ response = RestClient.get("#{BASE_URL}/search.php", :params => params)
42
+ @parser.parse(response).map do |parsed|
43
+ SearchResult.new(parsed)
44
+ end
36
45
  end
37
46
 
38
47
  def account
@@ -0,0 +1,47 @@
1
+ module Nzbmatrix
2
+ class SearchResult
3
+
4
+ require "time"
5
+
6
+ attr_accessor :id
7
+ attr_accessor :name
8
+ attr_accessor :link
9
+ attr_accessor :size
10
+ attr_accessor :index_date
11
+ attr_accessor :usenet_date
12
+ attr_accessor :category
13
+ attr_accessor :group
14
+ attr_accessor :comments
15
+ attr_accessor :hits
16
+ attr_accessor :weblink
17
+ attr_accessor :language
18
+ attr_accessor :image_url
19
+ attr_accessor :region
20
+
21
+ def initialize(api_response)
22
+ @id = api_response["NZBID"].to_i
23
+ @name = api_response["NZBNAME"]
24
+ @link = api_response["LINK"]
25
+ @size = api_response["SIZE"].to_f
26
+ @index_date = Time.parse(api_response["INDEX_DATE"]) rescue nil
27
+ @usenet_date = Time.parse(api_response["USENET_DATE"]) rescue nil
28
+ @category = api_response["CATEGORY"]
29
+ @group = api_response["GROUP"]
30
+ @comments = api_response["COMMENTS"].to_i
31
+ @hits = api_response["HITS"].to_i
32
+ @nfo = api_response["NFO"] == "yes"
33
+ @weblink = api_response["WEBLINK"]
34
+ @language = api_response["LANGUAGE"]
35
+ @image_url = api_response["IMAGE"]
36
+ @region = api_response["REGION"].to_i
37
+ end
38
+
39
+ def has_nfo?
40
+ !!@nfo
41
+ end
42
+
43
+ def has_image?
44
+ !!@image_url
45
+ end
46
+ end
47
+ end
@@ -1,3 +1,3 @@
1
1
  module Nzbmatrix
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/nzbmatrix.gemspec CHANGED
@@ -18,4 +18,5 @@ Gem::Specification.new do |gem|
18
18
  gem.add_runtime_dependency "rest-client"
19
19
 
20
20
  gem.add_development_dependency "rake"
21
+ gem.add_development_dependency "rspec", ">= 2"
21
22
  end
@@ -0,0 +1,118 @@
1
+ require "nzbmatrix/api_response_parser"
2
+
3
+ module Nzbmatrix
4
+ describe ApiResponseParser do
5
+
6
+ let(:parser) { ApiResponseParser.new }
7
+
8
+ it "parses their format into an array of hashes" do
9
+ response = <<EOF
10
+ NZBID:828303;
11
+ NZBNAME:Dark Angel S01 WS AC3 DVDRip XviD SFM;
12
+ LINK:nzbmatrix.com/nzb-details.php?id=828303&hit=1;
13
+ SIZE:9645389250.56;
14
+ INDEX_DATE:2011-01-24 23:22:02;
15
+ USENET_DATE:2011-01-24 11:11:31;
16
+ CATEGORY:TV > SD;
17
+ GROUP:alt.binaries.multimedia;
18
+ COMMENTS:0;
19
+ HITS:0;
20
+ NFO:yes;
21
+ WEBLINK:;
22
+ LANGUAGE:English;
23
+ IMAGE:;
24
+ REGION:0;
25
+ |
26
+ NZBID:734263;
27
+ NZBNAME:Dark Angel S01;
28
+ LINK:nzbmatrix.com/nzb-details.php?id=734263&hit=1;
29
+ SIZE:8328367308.8;
30
+ INDEX_DATE:2010-09-17 10:38:48;
31
+ USENET_DATE:2010-09-15 11:35:11;
32
+ CATEGORY:TV > SD;
33
+ GROUP:alt.binaries.x;
34
+ COMMENTS:0;
35
+ HITS:0;
36
+ NFO:;
37
+ WEBLINK:;
38
+ LANGUAGE:English;
39
+ IMAGE:http://img265.imageshack.us/img265/8043/darkangelshow.jpg;
40
+ REGION:0;
41
+ |
42
+ NZBID:396552;
43
+ NZBNAME:Dark Angel S01 WS AC3 DVDRip XviD SFM;
44
+ LINK:nzbmatrix.com/nzb-details.php?id=396552&hit=1;
45
+ SIZE:9628517662.72;
46
+ INDEX_DATE:2009-02-06 21:09:44;
47
+ USENET_DATE:2009-02-06 1:55:56;
48
+ CATEGORY:TV > SD;
49
+ GROUP:alt.binaries.multimedia;
50
+ COMMENTS:1;
51
+ HITS:849;
52
+ NFO:yes;
53
+ WEBLINK:http://former.imdb.com/title/tt0204993/;
54
+ LANGUAGE:English;
55
+ IMAGE:http://img132.imageshack.us/img132/3606/mv5bmtmxnja2mzk3nl5bml5kj5.jpg;
56
+ REGION:0;
57
+ |
58
+ EOF
59
+
60
+ one = {
61
+ "NZBID" => "828303",
62
+ "NZBNAME" => "Dark Angel S01 WS AC3 DVDRip XviD SFM",
63
+ "LINK" => "nzbmatrix.com/nzb-details.php?id=828303&hit=1",
64
+ "SIZE" => "9645389250.56",
65
+ "INDEX_DATE" => "2011-01-24 23:22:02",
66
+ "USENET_DATE" => "2011-01-24 11:11:31",
67
+ "CATEGORY" => "TV > SD",
68
+ "GROUP" => "alt.binaries.multimedia",
69
+ "COMMENTS" => "0",
70
+ "HITS" => "0",
71
+ "NFO" => "yes",
72
+ "WEBLINK" => "",
73
+ "LANGUAGE" => "English",
74
+ "IMAGE" => "",
75
+ "REGION" => "0",
76
+ }
77
+
78
+ two = {
79
+ "NZBID" => "734263",
80
+ "NZBNAME" => "Dark Angel S01",
81
+ "LINK" => "nzbmatrix.com/nzb-details.php?id=734263&hit=1",
82
+ "SIZE" => "8328367308.8",
83
+ "INDEX_DATE" => "2010-09-17 10:38:48",
84
+ "USENET_DATE" => "2010-09-15 11:35:11",
85
+ "CATEGORY" => "TV > SD",
86
+ "GROUP" => "alt.binaries.x",
87
+ "COMMENTS" => "0",
88
+ "HITS" => "0",
89
+ "NFO" => "",
90
+ "WEBLINK" => "",
91
+ "LANGUAGE" => "English",
92
+ "IMAGE" => "http://img265.imageshack.us/img265/8043/darkangelshow.jpg",
93
+ "REGION" => "0",
94
+ }
95
+
96
+ three = {
97
+ "NZBID" => "396552",
98
+ "NZBNAME" => "Dark Angel S01 WS AC3 DVDRip XviD SFM",
99
+ "LINK" => "nzbmatrix.com/nzb-details.php?id=396552&hit=1",
100
+ "SIZE" => "9628517662.72",
101
+ "INDEX_DATE" => "2009-02-06 21:09:44",
102
+ "USENET_DATE" => "2009-02-06 1:55:56",
103
+ "CATEGORY" => "TV > SD",
104
+ "GROUP" => "alt.binaries.multimedia",
105
+ "COMMENTS" => "1",
106
+ "HITS" => "849",
107
+ "NFO" => "yes",
108
+ "WEBLINK" => "http://former.imdb.com/title/tt0204993/",
109
+ "LANGUAGE" => "English",
110
+ "IMAGE" => "http://img132.imageshack.us/img132/3606/mv5bmtmxnja2mzk3nl5bml5kj5.jpg",
111
+ "REGION" => "0",
112
+ }
113
+
114
+ expected = [one, two, three]
115
+ parser.parse(response).should eq(expected)
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,44 @@
1
+ require "nzbmatrix/search_result"
2
+
3
+ module Nzbmatrix
4
+ describe SearchResult do
5
+
6
+ it "maps an api response nicely" do
7
+ response = {
8
+ "NZBID" => "396552",
9
+ "NZBNAME" => "Dark Angel S01 WS AC3 DVDRip XviD SFM",
10
+ "LINK" => "nzbmatrix.com/nzb-details.php?id=396552&hit=1",
11
+ "SIZE" => "9628517662.72",
12
+ "INDEX_DATE" => "2009-02-06 21:09:44",
13
+ "USENET_DATE" => "2009-02-06 1:55:56",
14
+ "CATEGORY" => "TV > SD",
15
+ "GROUP" => "alt.binaries.multimedia",
16
+ "COMMENTS" => "1",
17
+ "HITS" => "849",
18
+ "NFO" => "yes",
19
+ "WEBLINK" => "http://former.imdb.com/title/tt0204993/",
20
+ "LANGUAGE" => "English",
21
+ "IMAGE" => "http://img132.imageshack.us/img132/3606/mv5bmtmxnja2mzk3nl5bml5kj5.jpg",
22
+ "REGION" => "0",
23
+ }
24
+
25
+ result = SearchResult.new(response)
26
+ result.id.should eq(396552)
27
+ result.name.should eq("Dark Angel S01 WS AC3 DVDRip XviD SFM")
28
+ result.link.should eq("nzbmatrix.com/nzb-details.php?id=396552&hit=1")
29
+ result.size.should eq(9628517662.72)
30
+ result.index_date.should eq(Time.parse("2009-02-06 21:09:44"))
31
+ result.usenet_date.should eq(Time.parse("2009-02-06 01:55:56"))
32
+ result.category.should eq("TV > SD")
33
+ result.group.should eq("alt.binaries.multimedia")
34
+ result.comments.should eq(1)
35
+ result.hits.should eq(849)
36
+ result.has_nfo?.should be_true
37
+ result.weblink.should eq("http://former.imdb.com/title/tt0204993/")
38
+ result.language.should eq("English")
39
+ result.has_image?.should be_true
40
+ result.image_url.should eq("http://img132.imageshack.us/img132/3606/mv5bmtmxnja2mzk3nl5bml5kj5.jpg")
41
+ result.region.should eq(0)
42
+ end
43
+ end
44
+ 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.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-05 00:00:00.000000000 Z
12
+ 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: !ruby/object:Gem::Requirement
16
+ requirement: &18107400 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,15 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
24
+ version_requirements: *18107400
30
25
  - !ruby/object:Gem::Dependency
31
26
  name: rake
32
- requirement: !ruby/object:Gem::Requirement
27
+ requirement: &18105260 !ruby/object:Gem::Requirement
33
28
  none: false
34
29
  requirements:
35
30
  - - ! '>='
@@ -37,12 +32,18 @@ dependencies:
37
32
  version: '0'
38
33
  type: :development
39
34
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
35
+ version_requirements: *18105260
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &18102920 !ruby/object:Gem::Requirement
41
39
  none: false
42
40
  requirements:
43
41
  - - ! '>='
44
42
  - !ruby/object:Gem::Version
45
- version: '0'
43
+ version: '2'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *18102920
46
47
  description: Interact with the nzbmatrix api
47
48
  email:
48
49
  - bedlamp@gmail.com
@@ -51,14 +52,19 @@ extensions: []
51
52
  extra_rdoc_files: []
52
53
  files:
53
54
  - .gitignore
55
+ - .travis.yml
54
56
  - Gemfile
55
57
  - LICENSE
56
58
  - README.md
57
59
  - Rakefile
58
60
  - lib/nzbmatrix.rb
61
+ - lib/nzbmatrix/api_response_parser.rb
59
62
  - lib/nzbmatrix/client.rb
63
+ - lib/nzbmatrix/search_result.rb
60
64
  - lib/nzbmatrix/version.rb
61
65
  - nzbmatrix.gemspec
66
+ - spec/api_response_parser_spec.rb
67
+ - spec/search_result_spec.rb
62
68
  homepage: https://github.com/timsjoberg/nzbmatrix
63
69
  licenses: []
64
70
  post_install_message:
@@ -73,7 +79,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
73
79
  version: '0'
74
80
  segments:
75
81
  - 0
76
- hash: 1279914395091359415
82
+ hash: -2461971318538082917
77
83
  required_rubygems_version: !ruby/object:Gem::Requirement
78
84
  none: false
79
85
  requirements:
@@ -82,11 +88,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
88
  version: '0'
83
89
  segments:
84
90
  - 0
85
- hash: 1279914395091359415
91
+ hash: -2461971318538082917
86
92
  requirements: []
87
93
  rubyforge_project:
88
- rubygems_version: 1.8.23
94
+ rubygems_version: 1.8.11
89
95
  signing_key:
90
96
  specification_version: 3
91
97
  summary: nzbmatrix api gem
92
- test_files: []
98
+ test_files:
99
+ - spec/api_response_parser_spec.rb
100
+ - spec/search_result_spec.rb