bbr 1.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e54be15786813b05086deff20063d6eb4c1307e0
4
+ data.tar.gz: d6484c8ec66d05ccad36b06ad859fc7ffcd4121b
5
+ SHA512:
6
+ metadata.gz: b9aa0bbe25272460092a91a126e96139a1c224e159a74b4366fbccc8f6c57fc61d33bbc937e1f23b5594c44306aa70c493ea437fcd372bc51477c4b5bcffa989
7
+ data.tar.gz: 576ee65ced62143e54bab3587307402f5dd89648ea19246aa3c1be013806ee36c6c2bf3be2c59568cce99f39298f1e34783278eb54b63b45e54ae8a350395fb3
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .env
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
4
+ before_install: gem install bundler -v 1.10.6
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## v1.0.0.beta
2
+
3
+ * initial release
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bbr.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Nicolai Seerup
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # Bbr
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/bbr`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'bbr'
13
+
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install bbr
23
+
24
+ ## Usage
25
+
26
+ ### ENVIRONMENT VARIABLES
27
+ ```ruby
28
+ ENV['BBR_USERNAME']='xxxx'
29
+ ENV['BBR_PASSWORD']='xxxx'
30
+ ```
31
+ Contact Nicolai or Jesper for credentials if you are a member of the Abtion Team
32
+
33
+ ```ruby
34
+ BBR.building_data_from_address("Danas Plads 17, 1915 Frederiksberg")
35
+ => {:building_area=>"427", :building_age=>98, :roof_type=>"Tegl", :roof_tilt=>3, :heating=>"FjernvarmeBlokvarme", :heating_source=>"NotDefined", :formatted_heating=>"Fjernvarme", :outer_wall_material=>"Mursten"}
36
+
37
+ ```
38
+
39
+
40
+ ## Development
41
+
42
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
43
+
44
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
45
+
46
+ ## Contributing
47
+
48
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/bbr. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
49
+
50
+
51
+ ## License
52
+
53
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
54
+
55
+ ## TO DO
56
+ write spec
57
+ find more data to output
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bbr.gemspec ADDED
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bbr/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bbr"
8
+ spec.version = Bbr::VERSION
9
+ spec.authors = ["Jesper Sørensen & Nicolai Seerup"]
10
+ spec.email = ["admin@abtion.com"]
11
+
12
+ spec.summary = %q{Ruby wrapper around BBR registerets SOAP API}
13
+ spec.description = %q{Use to pull data from BBR registeret concerning house properties in Denmark. You have to sign up at : https://www.conzoom.eu/ to get at username and password}
14
+ spec.homepage = "https://github.com/abtion/bbr"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.10"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rspec"
33
+ spec.add_development_dependency 'nokogiri', '~> 1.6.6.2'
34
+ spec.add_development_dependency 'dotenv'
35
+ spec.add_development_dependency 'activesupport'
36
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bbr"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/lib/bbr.rb ADDED
@@ -0,0 +1,83 @@
1
+ require "bbr/version"
2
+ require 'active_support/all'
3
+ require 'net/http'
4
+ require 'nokogiri'
5
+ require 'bbr/get_id_from_address'
6
+ require 'bbr/get_building_data_from_id'
7
+
8
+
9
+ module BBR
10
+ def self.building_data_from_address(address)
11
+ building_data_from_bbr_id(bbr_id_from_address(address))
12
+ end
13
+
14
+ def self.bbr_id_from_address(address)
15
+ BBR::GetIdFromAddress.call(address)
16
+ end
17
+
18
+ def self.building_data_from_bbr_id(id)
19
+ BBR::GetBuildingDataFromId.call(id)
20
+ end
21
+
22
+ private
23
+ def request(action, body)
24
+ response = nil
25
+
26
+ 3.times do
27
+ begin
28
+ response = Timeout.timeout(5) { formatted_xml_response(http.post(uri.path, xml(body), headers(action))) }
29
+ rescue
30
+ puts "SOAP-action failed: #{ action }"
31
+ end
32
+ break if response
33
+ end
34
+
35
+ response
36
+ end
37
+
38
+ def formatted_xml_response(response=nil)
39
+ if response.present?
40
+ response = Nokogiri::XML response.body
41
+ response.remove_namespaces!
42
+ else
43
+ nil
44
+ end
45
+ end
46
+
47
+ def xml(body)
48
+ <<-XML
49
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:da="http://services.conzoom.eu/ejendomsdatabasen/v1/da" xmlns:ns="http://services.conzoom.eu/2007/06">
50
+ <soapenv:Header>
51
+ <Security xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
52
+ <UsernameToken>
53
+ <Username>#{ ENV['BBR_USERNAME'] }</Username>
54
+ <Password>#{ ENV['BBR_PASSWORD'] }</Password>
55
+ </UsernameToken>
56
+ </Security>
57
+ </soapenv:Header>
58
+ <soapenv:Body>
59
+ #{ body }
60
+ </soapenv:Body>
61
+ </soapenv:Envelope>
62
+ XML
63
+ end
64
+
65
+ def headers(action)
66
+ {
67
+ 'Content-Type' => 'text/xml;charset=UTF-8',
68
+ 'SOAPAction' => "http://services.conzoom.eu/ejendomsdatabasen/v1/da/IBbrService/#{ action }",
69
+ 'Host' => 'services.conzoom.eu'
70
+ }
71
+ end
72
+
73
+ def uri
74
+ URI.parse("https://services.conzoom.eu/Ejendomsdatabasen/v1/da/BbrService.svc")
75
+ end
76
+
77
+ def http
78
+ http = Net::HTTP.new(uri.host, uri.port)
79
+ http.use_ssl = true
80
+
81
+ http
82
+ end
83
+ end
@@ -0,0 +1,87 @@
1
+ module BBR
2
+ class GetBuildingDataFromId
3
+ extend BBR
4
+
5
+ def self.call(id)
6
+ id.present? ? formatted_response(request(request_action, xml_body(id))) : Hash.new
7
+ end
8
+
9
+ private
10
+ def self.xml_body(id)
11
+ <<-XML
12
+ <da:BygningGetById>
13
+ <da:bbrId>#{ id }</da:bbrId>
14
+ </da:BygningGetById>
15
+ XML
16
+ end
17
+
18
+ def self.request_action
19
+ @request_action ||= 'BygningGetById'
20
+ end
21
+
22
+ def self.formatted_response(response=nil)
23
+ if response.present? && !response.at_xpath("//Fault").try(:content).present?
24
+ {
25
+ building_area: response.at_xpath("//BebyggetAreal").try(:content),
26
+ building_age: (Time.now.year - response.at_xpath("//Opfoerselsaar").try(:content).to_i).to_i,
27
+ roof_type: response.at_xpath("//Tagdaekningsmateriale/Value").try(:content),
28
+ roof_tilt: roof_tilt(response),
29
+ heating: response.at_xpath("//Varmeinstallation/Value").try(:content),
30
+ heating_source: response.at_xpath("//Opvarmningsmiddel/Value").try(:content),
31
+ formatted_heating: formatted_heating(response),
32
+ outer_wall_material: response.at_xpath("//Ydervaegsmateriale/Value").try(:content)
33
+ }
34
+ else
35
+ Hash.new
36
+ end
37
+ end
38
+
39
+ def self.roof_tilt(response)
40
+ floors = response.at_xpath("//AntalEtager").try :content
41
+ material = response.at_xpath("//Tagdaekningsmateriale/Value").try :content
42
+ roof_area = response.at_xpath("//UdnyttetTagetageareal").try :content
43
+
44
+ if floors
45
+ t = floors == 1 ? 2 : 3
46
+ if material == 'BuiltUp'
47
+ t = 1
48
+ elsif roof_area.to_i > 0
49
+ t = 3
50
+ end
51
+ t
52
+ else
53
+ 2
54
+ end
55
+ end
56
+
57
+ def self.formatted_heating(response)
58
+ heating = response.at_xpath("//Varmeinstallation/Value").try :content
59
+ heating_source = response.at_xpath("//Opvarmningsmiddel/Value").try :content
60
+
61
+ case heating
62
+ when 'FjernvarmeBlokvarme'
63
+ 'Fjernvarme'
64
+ when 'ElovneElpaneler'
65
+ 'Elvarme'
66
+ when 'Varmepumpe'
67
+ 'Varmepumpe'
68
+ when 'Gasradiator'
69
+ 'Gas'
70
+ when 'CentralvarmeFraEgetAnlaegEtKammerFyr', 'CentralvarmeMedToFyringsenheder', 'Ovne'
71
+ case heating_source
72
+ when 'Elektricitet'
73
+ 'Elvarme'
74
+ when 'Gasvaerksgas', 'Naturgas'
75
+ 'Gas'
76
+ when 'FastBraendsel', 'Halm'
77
+ 'Træpillefyr/Halmfyr'
78
+ else
79
+ 'Oliefyr'
80
+ end
81
+ else
82
+ "#{ heating } / #{ heating_source }"
83
+ end
84
+ end
85
+ end
86
+
87
+ end
@@ -0,0 +1,31 @@
1
+ module BBR
2
+ class GetIdFromAddress
3
+ extend BBR
4
+
5
+ def self.call(address)
6
+ formatted_response(request(request_action, xml_body(address)))
7
+ end
8
+
9
+ private
10
+ def self.xml_body(address)
11
+ <<-XML
12
+ <da:EnhedSearch>
13
+ <da:inputRecord>
14
+ <ns:Field>
15
+ <ns:Type>EntireAddress</ns:Type>
16
+ <ns:Value>#{ address }</ns:Value>
17
+ </ns:Field>
18
+ </da:inputRecord>
19
+ </da:EnhedSearch>
20
+ XML
21
+ end
22
+
23
+ def self.request_action
24
+ @request_action ||= 'EnhedSearch'
25
+ end
26
+
27
+ def self.formatted_response(response=nil)
28
+ response.present? ? response.at_xpath('//BygningId').try(:content) : nil
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module Bbr
2
+ VERSION = "1.0.0.beta"
3
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bbr
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.beta
5
+ platform: ruby
6
+ authors:
7
+ - Jesper Sørensen & Nicolai Seerup
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-07 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.6.6.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.6.6.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: dotenv
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: activesupport
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: 'Use to pull data from BBR registeret concerning house properties in
98
+ Denmark. You have to sign up at : https://www.conzoom.eu/ to get at username and
99
+ password'
100
+ email:
101
+ - admin@abtion.com
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - ".travis.yml"
109
+ - CHANGELOG.md
110
+ - CODE_OF_CONDUCT.md
111
+ - Gemfile
112
+ - LICENSE.txt
113
+ - README.md
114
+ - Rakefile
115
+ - bbr.gemspec
116
+ - bin/console
117
+ - bin/setup
118
+ - lib/bbr.rb
119
+ - lib/bbr/get_building_data_from_id.rb
120
+ - lib/bbr/get_id_from_address.rb
121
+ - lib/bbr/version.rb
122
+ homepage: https://github.com/abtion/bbr
123
+ licenses:
124
+ - MIT
125
+ metadata:
126
+ allowed_push_host: https://rubygems.org
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">"
139
+ - !ruby/object:Gem::Version
140
+ version: 1.3.1
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.4.3
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: Ruby wrapper around BBR registerets SOAP API
147
+ test_files: []