zelda 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,15 @@
1
- ## 1.1.1 (Aug 15, 2011)
1
+ ## 1.2.0 (Aug 15, 2011)
2
2
 
3
3
  Bugfixes:
4
4
 
5
5
  - Fix the response hash key, since it is named after the resource
6
-
6
+ - Zender find works using the code field, not the id.
7
+ - Replaced method_missing with define_method.
8
+
9
+ Features:
10
+
11
+ - Now tested with Travis
12
+
7
13
 
8
14
  ## 1.1.0 (Aug 11, 2011)
9
15
 
data/Gemfile CHANGED
@@ -2,5 +2,6 @@ source "http://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
+ gem 'rake'
5
6
  gem 'httparty'
6
- gem 'rspec'
7
+ gem 'rspec'
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zelda (1.1.0)
4
+ zelda (1.2.0)
5
5
  httparty
6
6
 
7
7
  GEM
@@ -11,6 +11,7 @@ GEM
11
11
  diff-lcs (1.1.2)
12
12
  httparty (0.7.8)
13
13
  crack (= 0.1.8)
14
+ rake (0.9.2)
14
15
  rspec (2.6.0)
15
16
  rspec-core (~> 2.6.0)
16
17
  rspec-expectations (~> 2.6.0)
@@ -25,5 +26,6 @@ PLATFORMS
25
26
 
26
27
  DEPENDENCIES
27
28
  httparty
29
+ rake
28
30
  rspec
29
31
  zelda!
@@ -1,25 +1,12 @@
1
1
  module Zelda
2
2
  # Abstract base class to provide common functionality of Zelda importer classes.
3
- # including method_missing magic to turn an @attributes hash into getters.
3
+ # Every key in the hash is turned into a method, returning the value.
4
4
  class Base
5
5
  def initialize(attributes={})
6
- @attributes = {}
7
-
8
- attributes.each do |key, value|
9
- @attributes[key.to_sym] = value
10
- end
11
- end
12
-
13
- attr_reader :attributes
14
-
15
- # Try both string keys and symbol keys in that order.
16
- def method_missing(method, *args, &block)
17
- if @attributes[method]
18
- return @attributes[method]
19
- elsif @attributes.key?(method)
20
- return nil
21
- else
22
- super(method, *args, &block)
6
+ attributes.each_pair do |key, value|
7
+ self.class.send(:define_method, key) do
8
+ value
9
+ end
23
10
  end
24
11
  end
25
12
  end
@@ -1,11 +1,13 @@
1
1
  module Zelda
2
2
  class Omroep < Zelda::Base
3
3
  class << self
4
+ # Find an omroep by slug, such as +kro+.
4
5
  def find(slug)
5
6
  attrs = Request.get("omroepen/#{slug}")['omroep'] rescue nil
6
7
  attrs ? new(attrs) : nil
7
8
  end
8
9
 
10
+ # Find all omroepen.
9
11
  def all
10
12
  Request.get("omroepen")['omroepen']
11
13
  end
@@ -1,3 +1,3 @@
1
1
  module Zelda
2
- VERSION = "1.1.1"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -1,24 +1,18 @@
1
1
  module Zelda
2
2
  class Zender < Zelda::Base
3
3
  class << self
4
- def find(id)
5
- attrs = Request.get("zenders/#{id}")
4
+ # Find a Zender by code, such as +NL1+ or +101+.
5
+ def find(code)
6
+ attrs = Request.get("zenders/#{code}")['zender'] rescue nil
6
7
  attrs ? new(attrs) : nil
7
8
  end
8
9
 
10
+ # Find all Zenders.
9
11
  def all
10
- Request.get("zenders")
12
+ Request.get("zenders")['zenders']
11
13
  end
12
14
  end
13
15
 
14
- def name
15
- attributes[:zender]["name"]
16
- end
17
-
18
- def code
19
- attributes[:zender]["code"]
20
- end
21
-
22
16
  # Return all Series for this Zender.
23
17
  def series
24
18
  Zelda::Request.get("zenders/#{id}/series")['zender']['series']['serie'].map do |attrs|
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Zelda::Omroep do
4
-
5
4
  it_should_behave_like 'a zelda base model'
6
5
 
7
6
  describe "when retrieving a list of omroepen" do
@@ -5,23 +5,23 @@ describe Zelda::Zender do
5
5
 
6
6
  describe "when retrieving a list of zenders" do
7
7
  it "should call Zelda with the correct url" do
8
- Zelda::Request.should_receive(:get).with("zenders")
9
- Zelda::Zender.all
8
+ Zelda::Request.should_receive(:get).with("zenders").and_return('zenders' => ['zender'])
9
+ Zelda::Zender.all.should == ['zender']
10
10
  end
11
11
  end
12
12
 
13
13
  describe "when retrieving a specific zender" do
14
14
  before(:each) do
15
15
  zender_attrs = { "zender" => {"code" => "NL1", "name" => "Nederland 1"} }
16
- Zelda::Request.stub!(:get).with("zenders/1").and_return zender_attrs
16
+ Zelda::Request.stub!(:get).with("zenders/NL1").and_return zender_attrs
17
17
  end
18
18
 
19
19
  def find_zender
20
- Zelda::Zender.find(1)
20
+ Zelda::Zender.find('NL1')
21
21
  end
22
22
 
23
23
  it "should call Zelda with the correct url" do
24
- Zelda::Request.should_receive(:get).with("zenders/1")
24
+ Zelda::Request.should_receive(:get).with("zenders/NL1")
25
25
  find_zender
26
26
  end
27
27
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: zelda
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.1.1
5
+ version: 1.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Joost Baaij