GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Fork of jacobat/oiorest
Description: Library for accessing the Danish OIO Rest information
Clone URL: git://github.com/dalager/oiorest.git
Added Adresse model, first version. Search works. See README
Implemented to_param for bunch of models in order to streamline the rather 
inconsistent naming of unique identifiers in OIOREST.dk
Christian Dalager (author)
Sun May 18 04:35:11 -0700 2008
commit  06e8bc0e92c35890a18099b260c0d645cc9c191c
tree    6dc6fe8f9d9784983a43d95ccb1a239d87e468d4
parent  54fbfc69c57d018f518391fd039f6b8af7f08593
0
...
18
19
20
 
 
 
 
 
 
 
 
 
 
 
 
 
21
22
23
24
25
26
 
 
 
27
...
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 
38
39
40
41
42
0
@@ -18,8 +18,23 @@ Postdistrikt.find(8830)
0
 # Search by name
0
 Postdistrikt.find_by_name('borg')
0
 
0
+# Adresser
0
+
0
+# This is a finder with all possible search params.
0
+# returns an Address-light, with a reduced subset of the full Adresse.
0
+Adresse.find(:all, :params => {:vejnavn => "lyongade", :husnr => "19", :postnr => "2300", :vejnr => "4492", :kommunenr => "101", :sognenr => "7084"})
0
+
0
+# direct access
0
+ Adresse.find(9718)
0
+
0
+# find the first hit -- fully expanded address object
0
+Adresse.find(:first,:params => {:vejnavn => "lyongade", :husnr => "19"})
0
+
0
+
0
 
0
 TODO
0
 ========
0
 * lokaliteter => make drill down to full-address level
0
-*
0
\ No newline at end of file
0
+* Unittests against stubbed responses. Should we hack Active Resource to do that?
0
+* Integration tests against oiorest.dk/danmark
0
+* Script to port github commits into subversion on Google Code
0
\ No newline at end of file
...
1
 
 
 
2
3
4
...
8
9
10
11
12
13
14
...
19
20
21
 
22
...
1
2
3
4
5
6
7
...
11
12
13
 
14
15
16
...
21
22
23
24
25
0
@@ -1,4 +1,7 @@
0
 # Include hook code here
0
+
0
+# TODO: autorequire all models
0
+require "models/adresse"
0
 require "models/kommune"
0
 require "models/lokalitet"
0
 require "models/postdistrikt"
0
@@ -8,7 +11,6 @@ require "models/skoledistrikt"
0
 require "models/sogn"
0
 require "models/valgdistrikt"
0
 
0
-
0
 ## Inflections for OIO
0
 Inflector.inflections do |inflect|
0
   inflect.irregular 'kommune', 'kommuner'
0
@@ -19,4 +21,5 @@ Inflector.inflections do |inflect|
0
   inflect.irregular 'skoledistrikt', 'skoledistrikter'
0
   inflect.irregular 'sogn', 'sogne'
0
   inflect.irregular 'valgdistrikt', 'valgdistrikter'
0
+ inflect.irregular 'adresse', 'adresser'
0
 end
...
3
4
5
 
 
 
 
6
7
8
 
 
 
 
 
 
9
10
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
13
14
...
3
4
5
6
7
8
9
10
11
 
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
0
@@ -3,12 +3,36 @@ require 'activeresource'
0
 
0
 module ActiveOIO
0
   class Base < ActiveResource::Base
0
+
0
+
0
+
0
+
0
     self.site = 'http://oiorest.dk/danmark/'
0
 
0
- #self.logger = Logger.new(STDOUT)
0
+# self.logger = Logger.new(STDOUT)
0
+ self.logger = Logger.new('log/oiorest.log', 0, 10000000)
0
+
0
+
0
+
0
+
0
 
0
     class << self
0
 
0
+
0
+
0
+ def find(*arguments)
0
+ scope = arguments.slice!(0)
0
+ options = arguments.slice!(0) || {}
0
+
0
+ case scope
0
+ when :all then find_every(options)
0
+ when :first then find(find_every(options).first.to_param)
0
+ when :one then find_one(options)
0
+ else find_single(scope, options)
0
+ end
0
+ end
0
+
0
+
0
       ## remove .xml from the url
0
       def element_path(id, prefix_options = {}, query_options = nil)
0
         prefix_options, query_options = split_options(prefix_options) if query_options.nil?
...
36
37
38
 
 
 
 
39
...
36
37
38
39
40
41
42
43
0
@@ -36,4 +36,8 @@ class Kommune < ActiveOIO::Base
0
     end
0
     self.attributes['skoledistrikter']
0
   end
0
+
0
+ def to_param
0
+ self.attributes['nr']
0
+ end
0
 end
...
2
3
4
5
6
 
 
 
 
 
7
...
2
3
4
 
 
5
6
7
8
9
10
0
@@ -2,5 +2,8 @@ require 'modules/simple_find'
0
 
0
 class Postdistrikt < ActiveOIO::Base
0
   include SimpleFind
0
-
0
-end
0
+
0
+ def to_param
0
+ self.attributes['nr']
0
+ end
0
+end
0
\ No newline at end of file
...
9
10
11
 
 
 
 
12
13
...
9
10
11
12
13
14
15
16
17
0
@@ -9,5 +9,9 @@ class Region < ActiveOIO::Base
0
       end
0
       self.attributes['kommuner']
0
   end
0
+
0
+ def to_param
0
+ self.attributes['nr']
0
+ end
0
 
0
 end
...
29
30
31
32
 
 
 
 
 
 
33
...
29
30
31
 
32
33
34
35
36
37
38
0
@@ -29,4 +29,9 @@ class Skole < ActiveOIO::Base
0
       newSd
0
     end
0
   end
0
-end
0
+
0
+ def to_param
0
+ self.attributes['institutionsnr']
0
+ end
0
+
0
+end
0
\ No newline at end of file
...
3
4
5
 
 
 
6
...
3
4
5
6
7
8
9
0
@@ -3,4 +3,7 @@ require 'modules/simple_find'
0
 class Sogn < ActiveOIO::Base
0
   include SimpleFind
0
 
0
+ def to_param
0
+ self.attributes['nr']
0
+ end
0
 end
...
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
3
4
5
 
 
 
 
 
 
 
 
 
 
 
 
 
6
7
8
0
@@ -3,19 +3,6 @@ module SimpleFind
0
     def find_by_name(name)
0
       self.find(:all, :params =>{:q => name})
0
     end
0
-
0
- def find(*arguments)
0
- scope = arguments.slice!(0)
0
- options = arguments.slice!(0) || {}
0
-
0
- case scope
0
- when :all then find_every(options)
0
- when :first then find(find_every(options).first.nr)
0
- when :one then find_one(options)
0
- else find_single(scope, options)
0
- end
0
- end
0
-
0
   end
0
 
0
   def self.included(receiver)

Comments

    No one has commented yet.