bartzon-zelda 0.0.0

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.
@@ -0,0 +1,4 @@
1
+ === 0.0.1 2009-08-12
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
@@ -0,0 +1,13 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README.rdoc
5
+ Rakefile
6
+ lib/zelda.rb
7
+ script/console
8
+ script/destroy
9
+ script/generate
10
+ spec/spec.opts
11
+ spec/spec_helper.rb
12
+ spec/zelda_spec.rb
13
+ tasks/rspec.rake
@@ -0,0 +1,7 @@
1
+
2
+ For more information on zelda, see http://zelda.rubyforge.org
3
+
4
+ NOTE: Change this information in PostInstall.txt
5
+ You can also delete it if you don't want it.
6
+
7
+
@@ -0,0 +1,48 @@
1
+ = zelda
2
+
3
+ * http://github.com/#{github_username}/#{project_name}
4
+
5
+ == DESCRIPTION:
6
+
7
+ FIX (describe your package)
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * FIX (list of features or problems)
12
+
13
+ == SYNOPSIS:
14
+
15
+ FIX (code sample of usage)
16
+
17
+ == REQUIREMENTS:
18
+
19
+ * FIX (list of requirements)
20
+
21
+ == INSTALL:
22
+
23
+ * FIX (sudo gem install, anything else)
24
+
25
+ == LICENSE:
26
+
27
+ (The MIT License)
28
+
29
+ Copyright (c) 2009 FIXME full name
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining
32
+ a copy of this software and associated documentation files (the
33
+ 'Software'), to deal in the Software without restriction, including
34
+ without limitation the rights to use, copy, modify, merge, publish,
35
+ distribute, sublicense, and/or sell copies of the Software, and to
36
+ permit persons to whom the Software is furnished to do so, subject to
37
+ the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be
40
+ included in all copies or substantial portions of the Software.
41
+
42
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
43
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,50 @@
1
+ begin
2
+ require 'jeweler'
3
+
4
+ Jeweler::Tasks.new do |s|
5
+ s.name = "zelda"
6
+ s.author = "Bart Zonneveld"
7
+ s.email = "loop" + "@" + "superinfinite.com"
8
+ s.homepage = "http://github.com/bartzon/zelda"
9
+ s.summary = " "
10
+ s.description = " "
11
+
12
+ s.rubyforge_project = "zelda"
13
+ s.extra_rdoc_files = %w[README.rdoc MIT-LICENSE.txt History.txt]
14
+
15
+ # Dependencies
16
+ s.add_dependency "httparty", ">= 0.4.4"
17
+
18
+ # TODO: Add development dependencies
19
+ end
20
+
21
+ Jeweler::RubyforgeTasks.new
22
+ rescue LoadError
23
+ puts "Jeweler not available. Install it with: gem install jeweler"
24
+ end
25
+
26
+ # require 'spec'
27
+ require 'spec/rake/spectask'
28
+ require 'spec/rake/verify_rcov'
29
+
30
+ desc "Run specs"
31
+ Spec::Rake::SpecTask.new do |t|
32
+ t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""]
33
+ t.spec_files = FileList['spec/**/*_spec.rb']
34
+ end
35
+
36
+ desc "Run all specs in spec directory with RCov"
37
+ Spec::Rake::SpecTask.new(:rcov) do |t|
38
+ t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""]
39
+ t.spec_files = FileList['spec/**/*_spec.rb']
40
+ t.rcov = true
41
+ t.rcov_opts = lambda do
42
+ IO.readlines(File.dirname(__FILE__) + "/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
43
+ end
44
+ end
45
+
46
+ if defined?(Jeweler)
47
+ task :spec => :check_dependencies
48
+ end
49
+
50
+ task :default => :spec
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,18 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'httparty'
5
+
6
+ require 'zelda/base'
7
+ require 'zelda/object'
8
+ require 'zelda/request'
9
+ require 'zelda/collection'
10
+ require 'zelda/zender'
11
+ require 'zelda/serie'
12
+
13
+ module Zelda
14
+ VERSION = "0.0.1"
15
+
16
+ class ZeldaError < StandardError; end
17
+ class ZeldaCollectionError < ZeldaError; end
18
+ end
@@ -0,0 +1,4 @@
1
+ module Zelda
2
+ class Base
3
+ end
4
+ end
@@ -0,0 +1,27 @@
1
+ module Zelda
2
+ class Collection
3
+ include Enumerable
4
+
5
+ def self.create(attrs={})
6
+ new(attrs)
7
+ end
8
+
9
+ def initialize(attrs={})
10
+ raise ZeldaCollectionError.new("No prefix specified") unless attrs[:prefix]
11
+ @attrs = attrs
12
+ end
13
+
14
+ def all
15
+ fetch
16
+ end
17
+
18
+ def each
19
+ fetch.each { |result| yield result }
20
+ end
21
+
22
+ private
23
+ def fetch
24
+ @results ||= Zelda::Request.get("#{@attrs[:prefix]}")
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,17 @@
1
+ module Zelda
2
+ class Object
3
+ class << self
4
+ def all
5
+ Zelda::Request.get(url)
6
+ end
7
+
8
+ def find(code)
9
+ new Zelda::Request.get(url(code))
10
+ end
11
+ end
12
+
13
+ def initialize(attrs={})
14
+ @attrs = attrs
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ module Zelda
2
+ class Request
3
+ def self.get(url)
4
+ HTTParty.get parse_url(url)
5
+ end
6
+
7
+ def self.parse_url(*args)
8
+ "http://zelda.omroep.nl/#{ Zelda::API_KEY }/#{ args.join('/') }"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ class Zelda::Serie < Zelda::Object
2
+ def self.url(id=false)
3
+ id ? "series/#{id}" : "series"
4
+ end
5
+
6
+ def name
7
+ @attrs["serie"]["name"]
8
+ end
9
+
10
+ def serieid
11
+ @attrs["serie"]["serieid"]
12
+ end
13
+
14
+ def afleveringen
15
+ @afleveringen ||= Zelda::Collection.create(:prefix => "series/#{serieid}/afleveringen")
16
+ end
17
+ end
@@ -0,0 +1,17 @@
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
9
+
10
+ def code
11
+ @attrs["zender"]["code"]
12
+ end
13
+
14
+ def series
15
+ @series ||= Zelda::Collection.create(:prefix => self.class.url(code) + "/series")
16
+ end
17
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/zelda.rb'}"
9
+ puts "Loading zelda gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,12 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
10
+
11
+ require 'zelda'
12
+ Zelda::API_KEY = '12345'
@@ -0,0 +1,4 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Zelda::Base do
4
+ end
@@ -0,0 +1,32 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Zelda::Collection do
4
+ before(:each) do
5
+ @collection = Zelda::Collection.new(:prefix => "foo")
6
+ end
7
+
8
+ it "should raise an error if a collection is created without a prefix" do
9
+ lambda { Zelda::Collection.create }.should raise_error(Zelda::ZeldaCollectionError, "No prefix specified")
10
+ end
11
+
12
+ it "should create a collection" do
13
+ Zelda::Collection.create(:prefix => "foo").should be_a(Zelda::Collection)
14
+ end
15
+
16
+ it "should call Zelda when asked for all results" do
17
+ Zelda::Request.should_receive(:get).with('foo')
18
+ @collection.all
19
+ end
20
+
21
+ it "should be able to iterate over series correctly" do
22
+ Zelda::Request.should_receive(:get).with("foo").and_return [1,2,3,4]
23
+ results = []
24
+ @collection.each { |serie| results << serie }
25
+ results.should == [1,2,3,4]
26
+ end
27
+
28
+ it "should call Zelda with the correct url" do
29
+ Zelda::Request.should_receive(:get).with("foo")
30
+ @collection.all
31
+ end
32
+ end
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Zelda::Request do
4
+ it "should call HTTParty" do
5
+ HTTParty.should_receive(:get).with("http://zelda.omroep.nl/12345/foo")
6
+ Zelda::Request.get('foo')
7
+ end
8
+
9
+ describe "when returning an url" do
10
+ it "should be correct with 1 args" do
11
+ Zelda::Request.parse_url('foo').should == "http://zelda.omroep.nl/12345/foo"
12
+ end
13
+
14
+ it "should be correct with 2 args" do
15
+ Zelda::Request.parse_url('foo', 'bar').should == "http://zelda.omroep.nl/12345/foo/bar"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,44 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Zelda::Serie do
4
+ describe "when retrieving a list of series" do
5
+ it "should call Zelda with the correct url" do
6
+ Zelda::Request.should_receive(:get).with("series")
7
+ Zelda::Serie.all
8
+ end
9
+ end
10
+
11
+ describe "when retrieving a specific serie" do
12
+ before(:each) do
13
+ serie_attrs = { "serie" => {"serieid" => "POW_00243538", "name" => "3 op reis"} }
14
+ Zelda::Request.stub!(:get).with("series/1").and_return serie_attrs
15
+ end
16
+
17
+ def find_serie
18
+ Zelda::Serie.find(1)
19
+ end
20
+
21
+ it "should call Zelda with the correct url" do
22
+ Zelda::Request.should_receive(:get).with("series/1")
23
+ find_serie
24
+ end
25
+
26
+ it "should return a new Zender" do
27
+ find_serie.should be_a(Zelda::Serie)
28
+ end
29
+
30
+ it "should return the correct name" do
31
+ find_serie.name.should == "3 op reis"
32
+ end
33
+
34
+ it "should raise the correct error for an undefined attribute" do
35
+ lambda { find_serie.foo }.should raise_error(NoMethodError)
36
+ end
37
+
38
+ it "should create the correct collection when asked for afleveringen" do
39
+ serie = find_serie
40
+ Zelda::Collection.should_receive(:create).with({:prefix => "series/POW_00243538/afleveringen"})
41
+ serie.afleveringen
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,44 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Zelda::Zender do
4
+ describe "when retrieving a list of zenders" do
5
+ it "should call Zelda with the correct url" do
6
+ Zelda::Request.should_receive(:get).with("zenders")
7
+ Zelda::Zender.all
8
+ end
9
+ end
10
+
11
+ describe "when retrieving a specific zender" do
12
+ before(:each) do
13
+ zender_attrs = { "zender" => {"code" => "NL1", "name" => "Nederland 1"} }
14
+ Zelda::Request.stub!(:get).with("zenders/1").and_return zender_attrs
15
+ end
16
+
17
+ def find_zender
18
+ Zelda::Zender.find(1)
19
+ end
20
+
21
+ it "should call Zelda with the correct url" do
22
+ Zelda::Request.should_receive(:get).with("zenders/1")
23
+ find_zender
24
+ end
25
+
26
+ it "should return a new Zender" do
27
+ find_zender.should be_a(Zelda::Zender)
28
+ end
29
+
30
+ it "should return the correct name" do
31
+ find_zender.name.should == "Nederland 1"
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
+
38
+ it "should create the correct collection when asked for series" do
39
+ zender = find_zender
40
+ Zelda::Collection.should_receive(:create).with({:prefix => "zenders/NL1/series"})
41
+ zender.series
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
5
+ require 'spec'
6
+ end
7
+ begin
8
+ require 'spec/rake/spectask'
9
+ rescue LoadError
10
+ puts <<-EOS
11
+ To use rspec for testing you must install rspec gem:
12
+ gem install rspec
13
+ EOS
14
+ exit(0)
15
+ end
16
+
17
+ desc "Run the specs under spec/models"
18
+ Spec::Rake::SpecTask.new do |t|
19
+ t.spec_opts = ['--options', "spec/spec.opts"]
20
+ t.spec_files = FileList['spec/**/*_spec.rb']
21
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bartzon-zelda
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Bart Zonneveld
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-13 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: httparty
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.4.4
24
+ version:
25
+ description: ""
26
+ email: loop@superinfinite.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - History.txt
33
+ - README.rdoc
34
+ files:
35
+ - History.txt
36
+ - Manifest.txt
37
+ - PostInstall.txt
38
+ - README.rdoc
39
+ - Rakefile
40
+ - VERSION
41
+ - lib/zelda.rb
42
+ - lib/zelda/base.rb
43
+ - lib/zelda/collection.rb
44
+ - lib/zelda/object.rb
45
+ - lib/zelda/request.rb
46
+ - lib/zelda/serie.rb
47
+ - lib/zelda/zender.rb
48
+ - script/console
49
+ - script/destroy
50
+ - script/generate
51
+ - spec/spec.opts
52
+ - spec/spec_helper.rb
53
+ - spec/zelda/base_spec.rb
54
+ - spec/zelda/collection_spec.rb
55
+ - spec/zelda/request_spec.rb
56
+ - spec/zelda/serie_spec.rb
57
+ - spec/zelda/zender_spec.rb
58
+ - tasks/rspec.rake
59
+ has_rdoc: false
60
+ homepage: http://github.com/bartzon/zelda
61
+ licenses:
62
+ post_install_message:
63
+ rdoc_options:
64
+ - --charset=UTF-8
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ version:
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ version:
79
+ requirements: []
80
+
81
+ rubyforge_project: zelda
82
+ rubygems_version: 1.3.5
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: ""
86
+ test_files:
87
+ - spec/spec_helper.rb
88
+ - spec/zelda/base_spec.rb
89
+ - spec/zelda/collection_spec.rb
90
+ - spec/zelda/request_spec.rb
91
+ - spec/zelda/serie_spec.rb
92
+ - spec/zelda/zender_spec.rb