bartzon-zelda 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -1,17 +1,22 @@
1
1
  $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
- require 'httparty'
4
+ begin
5
+ require 'httparty'
6
+ rescue LoadError
7
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
8
+ gem 'httparty', '>= 0.4.4'
9
+ require 'httparty'
10
+ end
5
11
 
6
- require 'zelda/base'
7
- require 'zelda/object'
8
12
  require 'zelda/request'
9
13
  require 'zelda/zender'
10
14
  require 'zelda/serie'
15
+ require 'zelda/aflevering'
11
16
 
12
17
  module Zelda
13
- VERSION = "0.0.1"
14
-
18
+ VERSION = "0.0.2"
19
+
15
20
  class ZeldaError < StandardError; end
16
21
  class ZeldaCollectionError < ZeldaError; end
17
22
  end
@@ -0,0 +1,15 @@
1
+ module Zelda
2
+ class Aflevering
3
+ def initialize(vars={})
4
+ @attrs = vars
5
+ end
6
+
7
+ def method_missing(method, *args, &block)
8
+ if @attrs[method]
9
+ return @attrs[method]
10
+ else
11
+ super(method, *args, &block)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -5,6 +5,7 @@ module Zelda
5
5
  end
6
6
 
7
7
  def self.parse_url(*args)
8
+ raise "No Zelda::API_KEY specified" unless defined?(Zelda::API_KEY)
8
9
  "http://zelda.omroep.nl/#{ Zelda::API_KEY }/#{ args.join('/') }"
9
10
  end
10
11
  end
@@ -1,25 +1,52 @@
1
- class Zelda::Serie < Zelda::Object
2
- def self.url(id=false)
3
- id ? "series/#{id}" : "series"
4
- end
1
+ module Zelda
2
+ class Serie
3
+ class << self
4
+ def search(query)
5
+ Request.get("series/search/#{query}")['series']
6
+ end
7
+
8
+ def find(id)
9
+ new Request.get("series/#{id}")
10
+ end
11
+
12
+ def all
13
+ Request.get("series")
14
+ end
15
+ end
5
16
 
6
- def name
7
- @attrs["serie"]["name"]
8
- end
17
+ def initialize(attrs={})
18
+ @attrs = attrs
19
+ end
20
+
21
+ def name
22
+ @attrs["serie"]["name"]
23
+ end
9
24
 
10
- def serieid
11
- @attrs["serie"]["serieid"]
12
- end
25
+ def serieid
26
+ @attrs["serie"]["serieid"]
27
+ end
13
28
 
14
- def afleveringen
15
- @afleveringen ||= Zelda::Request.get("series/#{serieid}/afleveringen")["afleveringen"]
16
- end
29
+ def afleveringen
30
+ @afleveringen ||= get_afleveringen()
31
+ end
17
32
 
18
- def upcoming_afleveringen
19
- @upcoming_afleveringen ||= Zelda::Request.get("series/#{serieid}/afleveringen/upcoming")["afleveringen"]
20
- end
33
+ def upcoming_afleveringen
34
+ @upcoming_afleveringen ||= get_afleveringen("upcoming")
35
+ end
36
+
37
+ def past_afleveringen
38
+ @past_afleveringen ||= get_afleveringen("past")
39
+ end
21
40
 
22
- def past_afleveringen
23
- @past_afleveringen ||= Zelda::Request.get("series/#{serieid}/afleveringen/past")["afleveringen"]
41
+ private
42
+ def get_afleveringen(timestamp=nil)
43
+ url = [ "series", serieid, "afleveringen", timestamp ].join("/")
44
+
45
+ objects = []
46
+ Request.get(url)["afleveringen"].each do |vars|
47
+ objects << Zelda::Aflevering.new(vars)
48
+ end
49
+ objects
50
+ end
24
51
  end
25
- end
52
+ end
@@ -1,13 +1,25 @@
1
- class Zelda::Zender < Zelda::Object
2
- def self.url(code=false)
3
- code ? "zenders/#{code}" : "zenders"
4
- end
5
-
6
- def name
7
- @attrs["zender"]["name"]
8
- end
1
+ module Zelda
2
+ class Zender
3
+ class << self
4
+ def find(id)
5
+ new Request.get("zenders/#{id}")
6
+ end
7
+
8
+ def all
9
+ Request.get("zenders")
10
+ end
11
+ end
12
+
13
+ def initialize(attrs={})
14
+ @attrs = attrs
15
+ end
16
+
17
+ def name
18
+ @attrs["zender"]["name"]
19
+ end
9
20
 
10
- def code
11
- @attrs["zender"]["code"]
21
+ def code
22
+ @attrs["zender"]["code"]
23
+ end
12
24
  end
13
- end
25
+ end
@@ -9,4 +9,7 @@ end
9
9
  $:.unshift(File.dirname(__FILE__) + '/../lib')
10
10
 
11
11
  require 'zelda'
12
- Zelda::API_KEY = '12345'
12
+
13
+ module Zelda
14
+ API_KEY = '12345' unless defined?(API_KEY)
15
+ end
@@ -0,0 +1,17 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Zelda::Aflevering do
4
+ it "should accept attributes when being initialized" do
5
+ Zelda::Aflevering.new(:foo => "bar").should be_a(Zelda::Aflevering)
6
+ end
7
+
8
+ it "should respond to the attributes set in the constructor" do
9
+ afl = Zelda::Aflevering.new(:foo => "bar")
10
+ afl.foo.should == 'bar'
11
+ end
12
+
13
+ it "should not respond to attributes not set in the constructor" do
14
+ afl = Zelda::Aflevering.new(:foo => "bar")
15
+ lambda { afl.bar }.should raise_error(NoMethodError)
16
+ end
17
+ end
@@ -5,6 +5,12 @@ describe Zelda::Request do
5
5
  HTTParty.should_receive(:get).with("http://zelda.omroep.nl/12345/foo")
6
6
  Zelda::Request.get('foo')
7
7
  end
8
+
9
+ it "should raise an error without an API key" do
10
+ api_key = Zelda.send(:remove_const, :API_KEY)
11
+ lambda { Zelda::Request.get('foo') }.should raise_error("No Zelda::API_KEY specified")
12
+ Zelda::API_KEY = api_key
13
+ end
8
14
 
9
15
  describe "when returning an url" do
10
16
  it "should be correct with 1 args" do
@@ -12,6 +12,9 @@ describe Zelda::Serie do
12
12
  before(:each) do
13
13
  serie_attrs = { "serie" => {"serieid" => "POW_00243538", "name" => "3 op reis"} }
14
14
  Zelda::Request.stub!(:get).with("series/1").and_return serie_attrs
15
+
16
+ @aflevering = mock("Aflevering")
17
+ Zelda::Aflevering.stub!(:new).and_return @aflevering
15
18
  end
16
19
 
17
20
  def find_serie
@@ -29,20 +32,25 @@ describe Zelda::Serie do
29
32
 
30
33
  it "should send the correct request when asked for afleveringen" do
31
34
  serie = find_serie
32
- Zelda::Request.should_receive(:get).with("series/POW_00243538/afleveringen").and_return("afleveringen" => ["foo"])
33
- serie.afleveringen.should == ["foo"]
35
+ Zelda::Request.should_receive(:get).with("series/POW_00243538/afleveringen/").and_return("afleveringen" => ["foo"])
36
+ serie.afleveringen.should == [@aflevering]
34
37
  end
35
38
 
36
39
  it "should send the correct request when asked for upcoming afleveringen" do
37
40
  serie = find_serie
38
41
  Zelda::Request.should_receive(:get).with("series/POW_00243538/afleveringen/upcoming").and_return("afleveringen" => ["foo"])
39
- serie.upcoming_afleveringen.should == ["foo"]
42
+ serie.upcoming_afleveringen.should == [@aflevering]
40
43
  end
41
44
 
42
45
  it "should send the correct request when asked for past afleveringen" do
43
46
  serie = find_serie
44
47
  Zelda::Request.should_receive(:get).with("series/POW_00243538/afleveringen/past").and_return("afleveringen" => ["foo"])
45
- serie.past_afleveringen.should == ["foo"]
48
+ serie.past_afleveringen.should == [@aflevering]
46
49
  end
47
50
  end
51
+
52
+ it "should send the correct request when searching for series" do
53
+ Zelda::Request.should_receive(:get).with("series/search/foo").and_return("series" => ["foo"])
54
+ Zelda::Serie.search("foo").should == ["foo"]
55
+ end
48
56
  end
@@ -30,9 +30,5 @@ describe Zelda::Zender do
30
30
  it "should return the correct name" do
31
31
  find_zender.name.should == "Nederland 1"
32
32
  end
33
-
34
- it "should raise the correct error for an undefined attribute" do
35
- lambda { find_zender.foo }.should raise_error(NoMethodError)
36
- end
37
33
  end
38
34
  end
@@ -0,0 +1,4 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe Zelda do
4
+ end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{zelda}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Bart Zonneveld"]
12
- s.date = %q{2009-08-13}
12
+ s.date = %q{2009-08-26}
13
13
  s.description = %q{ }
14
14
  s.email = %q{loop@superinfinite.com}
15
15
  s.extra_rdoc_files = [
@@ -25,8 +25,7 @@ Gem::Specification.new do |s|
25
25
  "Rakefile",
26
26
  "VERSION",
27
27
  "lib/zelda.rb",
28
- "lib/zelda/base.rb",
29
- "lib/zelda/object.rb",
28
+ "lib/zelda/aflevering.rb",
30
29
  "lib/zelda/request.rb",
31
30
  "lib/zelda/serie.rb",
32
31
  "lib/zelda/zender.rb",
@@ -35,10 +34,11 @@ Gem::Specification.new do |s|
35
34
  "script/generate",
36
35
  "spec/spec.opts",
37
36
  "spec/spec_helper.rb",
38
- "spec/zelda/base_spec.rb",
37
+ "spec/zelda/aflevering_spec.rb",
39
38
  "spec/zelda/request_spec.rb",
40
39
  "spec/zelda/serie_spec.rb",
41
40
  "spec/zelda/zender_spec.rb",
41
+ "spec/zelda_spec.rb",
42
42
  "tasks/rspec.rake",
43
43
  "zelda.gemspec"
44
44
  ]
@@ -47,13 +47,14 @@ Gem::Specification.new do |s|
47
47
  s.require_paths = ["lib"]
48
48
  s.rubyforge_project = %q{zelda}
49
49
  s.rubygems_version = %q{1.3.5}
50
- s.summary = %q{ }
50
+ s.summary = %q{}
51
51
  s.test_files = [
52
52
  "spec/spec_helper.rb",
53
- "spec/zelda/base_spec.rb",
53
+ "spec/zelda/aflevering_spec.rb",
54
54
  "spec/zelda/request_spec.rb",
55
55
  "spec/zelda/serie_spec.rb",
56
- "spec/zelda/zender_spec.rb"
56
+ "spec/zelda/zender_spec.rb",
57
+ "spec/zelda_spec.rb"
57
58
  ]
58
59
 
59
60
  if s.respond_to? :specification_version then
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bartzon-zelda
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bart Zonneveld
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-13 00:00:00 -07:00
12
+ date: 2009-08-26 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -40,8 +40,7 @@ files:
40
40
  - Rakefile
41
41
  - VERSION
42
42
  - lib/zelda.rb
43
- - lib/zelda/base.rb
44
- - lib/zelda/object.rb
43
+ - lib/zelda/aflevering.rb
45
44
  - lib/zelda/request.rb
46
45
  - lib/zelda/serie.rb
47
46
  - lib/zelda/zender.rb
@@ -50,15 +49,15 @@ files:
50
49
  - script/generate
51
50
  - spec/spec.opts
52
51
  - spec/spec_helper.rb
53
- - spec/zelda/base_spec.rb
52
+ - spec/zelda/aflevering_spec.rb
54
53
  - spec/zelda/request_spec.rb
55
54
  - spec/zelda/serie_spec.rb
56
55
  - spec/zelda/zender_spec.rb
56
+ - spec/zelda_spec.rb
57
57
  - tasks/rspec.rake
58
58
  - zelda.gemspec
59
59
  has_rdoc: false
60
60
  homepage: http://github.com/bartzon/zelda
61
- licenses:
62
61
  post_install_message:
63
62
  rdoc_options:
64
63
  - --charset=UTF-8
@@ -79,13 +78,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
78
  requirements: []
80
79
 
81
80
  rubyforge_project: zelda
82
- rubygems_version: 1.3.5
81
+ rubygems_version: 1.2.0
83
82
  signing_key:
84
83
  specification_version: 3
85
84
  summary: ""
86
85
  test_files:
87
86
  - spec/spec_helper.rb
88
- - spec/zelda/base_spec.rb
87
+ - spec/zelda/aflevering_spec.rb
89
88
  - spec/zelda/request_spec.rb
90
89
  - spec/zelda/serie_spec.rb
91
90
  - spec/zelda/zender_spec.rb
91
+ - spec/zelda_spec.rb
@@ -1,4 +0,0 @@
1
- module Zelda
2
- class Base
3
- end
4
- end
@@ -1,17 +0,0 @@
1
- module Zelda
2
- class Object
3
- class << self
4
- def all
5
- Zelda::Request.get(url)
6
- end
7
-
8
- def find(id)
9
- new Zelda::Request.get(url(id))
10
- end
11
- end
12
-
13
- def initialize(attrs={})
14
- @attrs = attrs
15
- end
16
- end
17
- end
@@ -1,4 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
-
3
- describe Zelda::Base do
4
- end