difi 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: eaa1f807f13561215a9b78661327b651f460820f
4
+ data.tar.gz: 3f740b1f0446e8254221477a2a527b352173cf50
5
+ SHA512:
6
+ metadata.gz: a1fd367fe6b607e6a672aa4f0c8a6afcc6fcd54503a9a69ef0f73260f432abcf1fdebb08094af6984860e2c07cccdfd35c51f71c9dcdf853eea769862e6e158a
7
+ data.tar.gz: 1622665100444df340c3d54f64b9389caa06584a3cfb41a52278908d28614d28ba157c493c8b1836b849e320ff7a6db317200919b6cb7e75d27b5d79c7be3e54
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in difi.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Runar Ingebrigtsen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,78 @@
1
+ # Difi
2
+
3
+ The Norwegian government has started publishing a lot of data through a central API.
4
+ Information can be found at http://data.norge.no/
5
+
6
+ This gem makes use of the public APIs to provide easy access to public data.
7
+
8
+ Such as the Business Registry.
9
+
10
+ As a bonus, the Difi gem provides Zip codes as maintained by Erik Bolstad:
11
+ http://www.erikbolstad.no/geo/noreg/postnummer/
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ gem 'difi'
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install difi
26
+
27
+ ## Usage
28
+
29
+ Example: search the Norwegian Business Registry for a given Business (Voit AS):
30
+
31
+ Brreg::Enhetsregisteret.search query: "Voit AS"
32
+ => {"entries"=>
33
+ [{"nkode2"=>"",
34
+ "nkode1"=>"62.020",
35
+ "tlf_mobil"=>"",
36
+ "organisasjonsform"=>"AS",
37
+ "ppoststed"=>"",
38
+ "tvangsavvikling"=>"N",
39
+ "forretningsadr"=>"Lyngveien 5",
40
+ "regifriv"=>"N",
41
+ "orgnr"=>"811754862",
42
+ "forradrland"=>"Norge",
43
+ "stiftelsesdato"=>"25.02.2013",
44
+ "forradrkommnr"=>"1805",
45
+ "konkurs"=>"N",
46
+ "regdato"=>"30.03.2013",
47
+ "avvikling"=>"N",
48
+ "regifr"=>"J",
49
+ "forradrpoststed"=>"NARVIK",
50
+ "ppostland"=>"",
51
+ "forradrkommnavn"=>"NARVIK",
52
+ "forradrpostnr"=>"8514",
53
+ "navn"=>"VOIT AS",
54
+ "regnskap"=>"",
55
+ "url"=>"",
56
+ "sektorkode"=>"2100",
57
+ "regimva"=>"J",
58
+ "ppostnr"=>"",
59
+ "postadresse"=>"",
60
+ "nkode3"=>"",
61
+ "regiaa"=>"J",
62
+ "tlf"=>""}],
63
+ "page"=>1,
64
+ "pages"=>1,
65
+ "posts"=>1}
66
+
67
+ The result is a Hash with the complete public information about the business.
68
+ This is collected from the public JSON API at http://hotell.difi.no/
69
+
70
+ ## Contributing
71
+
72
+ 1. Fork it
73
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
74
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
75
+ 4. Push to the branch (`git push origin my-new-feature`)
76
+ 5. Create new Pull Request
77
+
78
+ I would love some help on extending the API support.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'difi/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "difi"
8
+ spec.version = Difi::VERSION
9
+ spec.authors = ["Runar Ingebrigtsen"]
10
+ spec.email = ["runar@rin.no"]
11
+ spec.description = %q{Exploit public information from the Norwegian Agency for Public Management and eGovernment (Difi)}
12
+ spec.summary = %q{Query the Difi API}
13
+ spec.homepage = "https://github.com/voitmore/difi"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake", '~> 0'
23
+ spec.add_dependency "faraday", "~> 0.9"
24
+ spec.add_dependency "excon", "~> 0.31"
25
+ end
@@ -0,0 +1,14 @@
1
+ # Brreg datasets
2
+ module Brreg
3
+ class Registry
4
+ extend Difi
5
+ end
6
+
7
+ # The public Norwegian business registry dataset
8
+ class Enhetsregisteret < Registry
9
+ end
10
+
11
+ # The public Norwegian business registry dataset - sub units
12
+ class Underenheter < Registry
13
+ end
14
+ end
@@ -0,0 +1,60 @@
1
+ require "difi/version"
2
+
3
+ # General methods for working with the public APIs at http://hotell.difi.no
4
+ #
5
+ # This module is meant to extend a Difi registry class.
6
+ #
7
+ # For instance the Brreg::Enhetsregisteret class
8
+ module Difi
9
+ require 'json'
10
+ require 'faraday'
11
+ require 'excon'
12
+ require 'brreg'
13
+
14
+ # The API source URL
15
+ def url
16
+ @@url ||= "http://hotell.difi.no/api/json/"
17
+ end
18
+
19
+ # The API connection
20
+ def conn
21
+ @@conn ||= Faraday.new(:url => 'http://sushi.com') do |faraday|
22
+ faraday.request :url_encoded # form-encode POST params
23
+ faraday.response :logger # log requests to STDOUT
24
+ faraday.adapter :excon # make requests with Excon
25
+ end
26
+ end
27
+
28
+ # The current dataset
29
+ def dataset
30
+ self.to_s.downcase.sub("::", "/")
31
+ end
32
+
33
+ # Perform a GET HTTP query on the current dataset
34
+ def get(query)
35
+ @@response = conn.get("#{url}/#{dataset}#{query}")
36
+ end
37
+
38
+ # Return the fields of the current dataset
39
+ def fields
40
+ get "/fields"
41
+ json
42
+ end
43
+
44
+ # Search for entries from the current dataset with the given fields
45
+ # Input is expected to be a Hash
46
+ def search(fields)
47
+ get "?" + URI.escape(fields.collect{|k,v| "#{k}=#{v}"}.join('&'))
48
+ json
49
+ end
50
+
51
+ # Return the last HTTP response
52
+ def response
53
+ @@response
54
+ end
55
+
56
+ # Return the last HTTP response body as JSON
57
+ def json
58
+ JSON.parse @@response.body
59
+ end
60
+ end
@@ -0,0 +1,3 @@
1
+ module Difi
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,37 @@
1
+ require 'csv'
2
+
3
+ # Norwegian zip codes
4
+ class Posten
5
+ extend Difi
6
+
7
+ # The URL to the geo-tagged zip code database by Erik Bolstad
8
+ def self.url
9
+ @@url = "http://www.erikbolstad.no/postnummer-koordinatar/txt/postnummer.csv"
10
+ end
11
+
12
+ # Get the zip code database
13
+ def self.get
14
+ conn.get url
15
+ end
16
+
17
+ def self.response
18
+ @@response ||= get
19
+ end
20
+
21
+ # Return zip codes for the given counties
22
+ def self.zipcodes(*county)
23
+ @@result = parse.collect {|l| l if county.include?(l[8]) }.compact
24
+ end
25
+
26
+ def self.data
27
+ @@data ||= response.body
28
+ end
29
+
30
+ def self.lines
31
+ @@lines ||= data.gsub(/\t/, ',').split("\n")
32
+ end
33
+
34
+ def self.parse
35
+ @@all_lines ||= lines.collect {|l| l.parse_csv }
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: difi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Runar Ingebrigtsen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.9'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.9'
55
+ - !ruby/object:Gem::Dependency
56
+ name: excon
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.31'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.31'
69
+ description: Exploit public information from the Norwegian Agency for Public Management
70
+ and eGovernment (Difi)
71
+ email:
72
+ - runar@rin.no
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - difi.gemspec
83
+ - lib/brreg.rb
84
+ - lib/difi.rb
85
+ - lib/difi/version.rb
86
+ - lib/posten.rb
87
+ homepage: https://github.com/voitmore/difi
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.2.2
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Query the Difi API
111
+ test_files: []