brreg 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a6e30a9269501b25a98364724e53ee31dd23dd9e
4
- data.tar.gz: 47dfc36c49d85f61561f66a66079267abb93d109
2
+ SHA256:
3
+ metadata.gz: 9d20871bf9a0c7bf08e2ee2331ed03bb0ce2a3dd2545d7b28b0c150e57c206e4
4
+ data.tar.gz: 6d21f7ba3b987eeb013f3df2e0c3e1116159250f616e20641854381a6c73c832
5
5
  SHA512:
6
- metadata.gz: 9829df08b4b3841748a0e0d4aa65c2582b0bf1b02ef73598430e55480d950b160b77162205111f7ae27f58f4104d90ddfdd6b9f85c56b1a1436aae4963081bd1
7
- data.tar.gz: 72e009f56e37d35baa2b1206c68cd13990b2aa9d6e19dd9ece184a4d6f61279b572650bf9f9f19ba9df625aa8a955235072f9c9470f0d899dd81d9914ed9bc94
6
+ metadata.gz: '0499839d05a11289b5f09b07f091f4c6c26972e9a3d96a67185ffc87068a5edb41ac0bf23378c4e2f73d0612faf2950c38476dab926173b2d2c3880958d625f2'
7
+ data.tar.gz: f2ed13bce171af06b19ea3eefd838dc690943511a1c5a85efeb27523f6287057b13acb643a191d1c8fa9011e80846821fdfc990ef2121fe8614074e6ff4dfffb
data/bin/brreg CHANGED
@@ -10,7 +10,7 @@ opts = OptionParser.new do |opt|
10
10
  opt.banner = "Usage: brreg [options] OR brreg orgnr/query/domain"
11
11
 
12
12
  opt.on('-n', '--orgnr ORGNR', 'Organisasjonsnummer') do |orgnr|
13
- cli_params[:orgnr] = orgnr.to_i
13
+ cli_params[:orgnr] = orgnr
14
14
  end
15
15
 
16
16
  opt.on('-q', '--query QUERY', 'Firmanavn') do |query|
@@ -30,11 +30,10 @@ rescue OptionParser::InvalidOption, OptionParser::MissingArgument
30
30
  exit
31
31
  end
32
32
 
33
- def numeric?(object)
34
- true if Float(object) rescue false
33
+ def is_orgnr?(object)
34
+ object.class == String && object.gsub(/\D/, '').length == 9
35
35
  end
36
36
 
37
-
38
37
  if cli_params.length > 0
39
38
  if cli_params[:orgnr]
40
39
  Brreg.find_by_orgnr(cli_params[:orgnr])
@@ -44,9 +43,9 @@ if cli_params.length > 0
44
43
  Brreg.find_by_domain( cli_params[:domain])
45
44
  end
46
45
  elsif ARGV.length > 0
47
- input = ARGV.first
48
- if numeric?(input)
49
- Brreg.find_by_orgnr( input.to_i )
46
+ input = ARGV.join(' ')
47
+ if is_orgnr?(input)
48
+ Brreg.find_by_orgnr( input )
50
49
  elsif input.include?('.no')
51
50
  Brreg.find_by_domain( input )
52
51
  else
data/brreg.gemspec CHANGED
@@ -17,6 +17,6 @@ Gem::Specification.new do |spec|
17
17
  spec.executables = "brreg"
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.add_development_dependency "bundler", "~> 1.10"
21
- spec.add_development_dependency "rake", "~> 10.0"
20
+ spec.add_development_dependency "bundler"
21
+ spec.add_development_dependency "rake"
22
22
  end
data/lib/brreg/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Brreg
2
- VERSION = "0.4.1"
2
+ VERSION = "0.5.0"
3
3
  end
data/lib/brreg.rb CHANGED
@@ -3,34 +3,36 @@ require 'net/http'
3
3
  require 'json'
4
4
 
5
5
  module Brreg
6
- BrregURI = 'https://hotell.difi.no/api/json/brreg/enhetsregisteret'
6
+ BrregURI = 'https://data.brreg.no/enhetsregisteret/api/enheter'
7
7
  def self.find_by_orgnr(orgnr)
8
- if !orgnr || orgnr.class != String
9
- puts "Ugyldig verdi"
10
- return false
11
- end
12
- if orgnr
13
- orgnr = orgnr.gsub(/\D/, '')
14
- end
15
- if orgnr.empty?
8
+ if !orgnr
16
9
  puts "Ugyldig verdi"
17
10
  return false
11
+ else
12
+ if orgnr.class == String
13
+ orgnr = orgnr.gsub(/\D/, '')
14
+ if orgnr.empty? || orgnr.length != 9
15
+ puts "Ugyldig verdi"
16
+ return false
17
+ end
18
+ end
18
19
  end
19
- res = get_json( { :orgnr => orgnr } )
20
+ res = get_json( { :organisasjonsnummer => orgnr } )
20
21
  if res.is_a?(Net::HTTPSuccess)
21
22
  jsonres = JSON.parse(res.body)
22
- if jsonres['posts'].to_i > 0
23
- company = jsonres['entries'].first
23
+ matches = jsonres['_embedded']['enheter']
24
+ if matches.length > 0
25
+ company = matches.first
24
26
  puts "\n"
25
27
  puts "\e[32mViser oppføring for orgnr #{orgnr}\e[0m"
26
28
  puts "\n"
27
29
  puts company['navn']
28
- puts company['forretningsadr']
29
- puts company['forradrpostnr'] + ' ' + company['forradrpoststed']
30
+ puts company['forretningsadresse']['adresse']
31
+ puts company['forretningsadresse']['postnummer'] + ' ' + company['forretningsadresse']['poststed']
30
32
  if !company['postadresse'].empty?
31
33
  puts 'Postadresse:'
32
- puts company['postadresse']
33
- puts company['ppostnr'] + ' ' + company['ppoststed']
34
+ puts company['postadresse']['adresse']
35
+ puts company['postadresse']['postnummer'] + ' ' + company['postadresse']['poststed']
34
36
  end
35
37
  else
36
38
  puts "Fant ingen oppføring for #{orgnr}"
@@ -44,7 +46,7 @@ module Brreg
44
46
  if res.gsub('Id Number').first
45
47
  orgnr = /\Id Number..................:\s(\d{9})/
46
48
  if res.match(orgnr)
47
- Brreg.find_by_orgnr( res.scan(orgnr).first.first.to_i )
49
+ Brreg.find_by_orgnr( res.scan(orgnr).first.first )
48
50
  puts "\nBasert på Whois fra domenet #{domain}"
49
51
  else
50
52
  puts "Domenet har ikke et vanlig orgnr."
@@ -60,17 +62,17 @@ module Brreg
60
62
  puts "\n"
61
63
  puts "\e[32mTreff i Enhetsregisteret basert på søket '#{query}'\e[0m"
62
64
  puts "\n"
63
- res = self.get_json( { :query => query } )
65
+ res = self.get_json( { :navn => query } )
64
66
  if res.is_a?(Net::HTTPSuccess)
65
67
  jsonres = JSON.parse(res.body)
66
- matches = jsonres['posts'].to_i
67
- if matches > 0
68
- if matches == 1
68
+ matches = jsonres['_embedded']['enheter']
69
+ if matches.length > 0
70
+ if matches.length == 1
69
71
  puts "Fant 1 oppføring"
70
- Brreg.find_by_orgnr( jsonres['entries'].first['orgnr'] )
72
+ Brreg.find_by_orgnr( matches.first['organisasjonsnummer'] )
71
73
  else
72
- for entry in jsonres['entries']
73
- puts entry['orgnr'] + ' ' + entry['navn']
74
+ for entry in matches
75
+ puts entry['organisasjonsnummer'] + ' ' + entry['navn']
74
76
  end
75
77
  end
76
78
  else
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brreg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Espen Antonsen
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-03 00:00:00.000000000 Z
11
+ date: 2024-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.10'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.10'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '0'
41
41
  description: Search Norwegian companies
42
42
  email:
43
43
  - espen@inspired.no
@@ -60,7 +60,7 @@ files:
60
60
  homepage: http://github.com/espen/brreg
61
61
  licenses: []
62
62
  metadata: {}
63
- post_install_message:
63
+ post_install_message:
64
64
  rdoc_options: []
65
65
  require_paths:
66
66
  - lib
@@ -75,9 +75,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  - !ruby/object:Gem::Version
76
76
  version: '0'
77
77
  requirements: []
78
- rubyforge_project:
79
- rubygems_version: 2.6.4
80
- signing_key:
78
+ rubygems_version: 3.5.16
79
+ signing_key:
81
80
  specification_version: 4
82
81
  summary: Search Enhetsregisteret i Brønnøysundsregisteret
83
82
  test_files: []