omniva-api 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: 71d2e3bd02bd35dd6312775f2e2f0e7a991cf3ff
4
+ data.tar.gz: cdedba8d0000eefe31f72e43836ebecd25844241
5
+ SHA512:
6
+ metadata.gz: 67d74a8011424c3f397c1f4f26ccc718e97e1779c431d7c330bdb4746ad529493800e6c0c8c9749286b835223934a0eb66ef2493ac9612870248698503a7837a
7
+ data.tar.gz: fd3aaef3a626f7f90822c5b9cff928c0757ab08e462bc41d76574f46d96fd981f12524b816fb956de7dff0042f1ffda34ef9f3e5e6da5ac0a0bfd1901e3405d3
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ *.gem
15
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniva-api.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Desk Rock
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,135 @@
1
+ # Omniva::API
2
+
3
+ A ruby gem to access Estonian postal service address API
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'omniva-api'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install omniva-api
20
+
21
+ ## Usage
22
+
23
+ ```` ruby
24
+ # Configuration
25
+ Omniva::API.configure do |config|
26
+ config.wsdl = 'wsdl_url'
27
+ config.key = 'secret_key'
28
+ end
29
+
30
+ # Initial data query (counties)
31
+ Omniva::API.call
32
+ # =>
33
+ [
34
+ {
35
+ :aid => "37",
36
+ :tase => "A1",
37
+ :ads_id => "370000000000000000000000000000000",
38
+ :maakond_ehak => "0037",
39
+ :maakond => "Harju maakond",
40
+ :omavalitus_ehak => "0000",
41
+ :omavalitus_liik => nil,
42
+ :omavalitus => nil,
43
+ :asustusyksus_ehak => "0000",
44
+ :asustusyksus_liik => nil,
45
+ :asustusyksus => nil,
46
+ :vaikekoht_liik => nil,
47
+ :vaikekoht => nil,
48
+ :liikluspind_liik => nil,
49
+ :liikluspind => nil,
50
+ :nimetus => nil,
51
+ :aadressinumber => nil,
52
+ :korterinumber => nil,
53
+ :sihtnumber => nil,
54
+ :staatus => nil,
55
+ :aadress => "Eesti Vabariik, Harju maakond",
56
+ :nimekapi_nr => nil,
57
+ :juurdepaasupunkt_nimekiri => nil
58
+ }, {
59
+ ...
60
+ }
61
+ ]
62
+
63
+ # Call with parameters
64
+ Omniva::API.call(nimetus: 'Tallinn')
65
+ # =>
66
+ [
67
+ {
68
+ :aid => "1905378",
69
+ :tase => "A3",
70
+ :ads_id => "377840176000000000000000000000000",
71
+ :maakond_ehak => "0037",
72
+ :maakond => "Harju maakond",
73
+ :omavalitus_ehak => "0784",
74
+ :omavalitus_liik => "linn",
75
+ :omavalitus => "Tallinn",
76
+ :asustusyksus_ehak => "0176",
77
+ :asustusyksus_liik => "linnaosa",
78
+ :asustusyksus => "Haabersti linnaosa",
79
+ :vaikekoht_liik => nil,
80
+ :vaikekoht => nil,
81
+ :liikluspind_liik => nil,
82
+ :liikluspind => nil,
83
+ :nimetus => nil,
84
+ :aadressinumber => nil,
85
+ :korterinumber => nil,
86
+ :sihtnumber => nil,
87
+ :staatus => nil,
88
+ :aadress => "Eesti Vabariik, Harju maakond, Tallinn, Haabersti linnaosa",
89
+ :nimekapi_nr => nil,
90
+ :juurdepaasupunkt_nimekiri => nil
91
+ }, {
92
+ ...
93
+ }
94
+ ]
95
+
96
+ Omniva::API.call(aid: 37)
97
+ # =>
98
+ [
99
+ {
100
+ :aid => "112",
101
+ :tase => "A2",
102
+ :ads_id => "371120000000000000000000000000000",
103
+ :maakond_ehak => "0037",
104
+ :maakond => "Harju maakond",
105
+ :omavalitus_ehak => "0112",
106
+ :omavalitus_liik => "vald",
107
+ :omavalitus => "Aegviidu vald",
108
+ :asustusyksus_ehak => "0000",
109
+ :asustusyksus_liik => nil,
110
+ :asustusyksus => nil,
111
+ :vaikekoht_liik => nil,
112
+ :vaikekoht => nil,
113
+ :liikluspind_liik => nil,
114
+ :liikluspind => nil,
115
+ :nimetus => nil,
116
+ :aadressinumber => nil,
117
+ :korterinumber => nil,
118
+ :sihtnumber => nil,
119
+ :staatus => nil,
120
+ :aadress => "Eesti Vabariik, Harju maakond, Aegviidu vald",
121
+ :nimekapi_nr => nil,
122
+ :juurdepaasupunkt_nimekiri => nil
123
+ }, {
124
+
125
+ }
126
+ ]
127
+ ````
128
+
129
+ ## Contributing
130
+
131
+ 1. Fork it ( https://github.com/[my-github-username]/omniva-api/fork )
132
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
133
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
134
+ 4. Push to the branch (`git push origin my-new-feature`)
135
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+
@@ -0,0 +1,13 @@
1
+ require 'omniva/api/version'
2
+ require 'omniva/api/configuration'
3
+ require 'omniva/api/client'
4
+
5
+ module Omniva
6
+ module API
7
+ InvalidConfiguration = Class.new(StandardError)
8
+
9
+ def self.call(data = nil)
10
+ Client.call(data)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,40 @@
1
+ require 'savon'
2
+
3
+ module Omniva
4
+ module API
5
+ class Client
6
+ def self.call(data = nil)
7
+ validate_config
8
+ data ||= initial_request
9
+ client = Savon.client(wsdl: Omniva::API.config[:wsdl])
10
+ auth = { authPhrase: Omniva::API.config[:key] }
11
+ response = client.call :single_address1, attributes: auth, message: data
12
+ parsed_response(response)
13
+ end
14
+
15
+ def self.validate_config
16
+ messages = {
17
+ wsdl: 'WSDL is missing',
18
+ key: 'Key is missing'
19
+ }
20
+
21
+ messages.each do |key, value|
22
+ fail InvalidConfiguration, value if Omniva::API.config[key].blank?
23
+ end
24
+ end
25
+
26
+ def self.parsed_response(response)
27
+ unwrapped =
28
+ response
29
+ .to_hash
30
+ .fetch(:single_address_response)
31
+ .fetch(:aadress_komponent_nimekiri)
32
+ unwrapped ? unwrapped.fetch(:aadress_komponent) : nil
33
+ end
34
+
35
+ def self.initial_request
36
+ { nimetus: 'Eesti' }
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,20 @@
1
+ module Omniva
2
+ module API
3
+ Configuration = Struct.new(:wsdl, :key) do
4
+ def initialize
5
+ self.wsdl = nil
6
+ self.key = nil
7
+ end
8
+ end
9
+
10
+ def self.configure
11
+ @config = Configuration.new
12
+ yield(@config) if block_given?
13
+ @config
14
+ end
15
+
16
+ def self.config
17
+ @config || configure
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ module Omniva
2
+ module API
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'omniva/api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'omniva-api'
8
+ spec.version = Omniva::API::VERSION
9
+ spec.authors = ['Stanislav Gorski']
10
+ spec.email = ['stanislav.gorski@gmail.com']
11
+ spec.summary = %q{Estonian postal service address API gem}
12
+ spec.description = %q{A ruby gem to access Estonian postal service address API}
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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 = %w(lib)
20
+
21
+ spec.add_dependency 'savon', '~> 2.8.0'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.6'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'awesome_print', '~> 1.6'
26
+ spec.add_development_dependency 'pry', '~> 0.10.0'
27
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniva-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Stanislav Gorski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: savon
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.8.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.8.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: awesome_print
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
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'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.10.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.10.0
83
+ description: A ruby gem to access Estonian postal service address API
84
+ email:
85
+ - stanislav.gorski@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - lib/omniva/api.rb
96
+ - lib/omniva/api/client.rb
97
+ - lib/omniva/api/configuration.rb
98
+ - lib/omniva/api/version.rb
99
+ - omniva-api.gemspec
100
+ homepage: ''
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.2.2
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Estonian postal service address API gem
124
+ test_files: []