dc_address_lookup 0.1.0

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: f181d968548753a0c74c76ccd6f3faba519888a5
4
+ data.tar.gz: 1f2f4fd41beb2fb6cf0a9218a1472286f1aebd4e
5
+ SHA512:
6
+ metadata.gz: 364c0f5114556101606b9dfb862d0407b150f16a900907cdb37c63735b6b30d43fe261ad9305d4b9d9affc502f84ab0865ed3ccd62ad5a502cdeb1c88d584fcc
7
+ data.tar.gz: 9120f379ebcb5c1bb4456262afa90c841ebdd75f5911963d7f7335df80b2c045c7aa605057ce1eb8c2b37830b1437e219e79ce1e7514f0ada3a752faae0d47d5
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
+ *.gem
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.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dc_address_lookup.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Ben Balter
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,47 @@
1
+ # DC Address Lookup
2
+
3
+ *A Ruby gem to look up Washington, D.C. addresses in the master address registry, an official city database*
4
+
5
+ ## Installation
6
+
7
+ Add the following to your project's Gemfile:
8
+
9
+ `gem 'dc_address_lookup'`
10
+
11
+ Then run
12
+
13
+ `bundle install`
14
+
15
+ ## Usage
16
+
17
+ ```ruby
18
+ location = DcAddressLookup.lookup "1600 Pennsylvania Ave NW"
19
+ => #<DcAddressLookup::Location>
20
+
21
+ location.fulladdress
22
+ => "1600 PENNSYLVANIA AVENUE NW"
23
+
24
+ location.stname
25
+ => "PENNSYLVANIA"
26
+
27
+ location.street_type
28
+ => "AVENUE"
29
+
30
+ location.anc
31
+ => "2A"
32
+
33
+ location.ward
34
+ => 2
35
+
36
+ location.psa
37
+ => "Police Service Area 207"
38
+
39
+ location.zipcode
40
+ => 20500
41
+
42
+ location.latitude
43
+ => 38.89766766
44
+
45
+ location.longitude
46
+ => -77.03654468
47
+ ```
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
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dc_address_lookup/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dc_address_lookup"
8
+ spec.version = DcAddressLookup::VERSION
9
+ spec.authors = ["Ben Balter"]
10
+ spec.email = ["ben.balter@github.com"]
11
+
12
+ spec.summary = "A Ruby gem to look up Washington, D.C. addresses in the master address registry, an official city database"
13
+ spec.homepage = "https://github.com/benbalter/dc-address-lookup"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "typhoeus"
22
+ spec.add_dependency "nokogiri"
23
+ spec.add_dependency "addressable"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.10"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec"
28
+ spec.add_development_dependency "pry"
29
+
30
+ end
@@ -0,0 +1,7 @@
1
+ module DcAddressLookup
2
+ class Client
3
+ def lookup(query)
4
+ Query.new(query).response.location
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,44 @@
1
+ module DcAddressLookup
2
+ class Location
3
+ def self.from_table(xml)
4
+ location = self.new
5
+
6
+ xml.children.each do |node|
7
+ next if node.node_name == "text"
8
+ key = node.name.downcase
9
+ value = node.text.gsub(/\A#{key.split("_").first}\b/i, "").squeeze("\s").strip
10
+ value = value.to_i if value.to_i.to_s == value
11
+ value = value.to_f if value.to_f.to_s == value
12
+ location.data[key] = value
13
+ end
14
+
15
+ location
16
+ end
17
+
18
+ def method_missing(method_sym, *arguments, &block)
19
+ if has_property?(method_sym)
20
+ data[method_sym.to_s]
21
+ else
22
+ super
23
+ end
24
+ end
25
+
26
+ def respond_to?(method_sym, include_private = false)
27
+ if has_property?(method_sym)
28
+ true
29
+ else
30
+ super
31
+ end
32
+ end
33
+
34
+ def data
35
+ @data ||= {}
36
+ end
37
+
38
+ private
39
+
40
+ def has_property?(property)
41
+ data.keys.include?(property.to_s)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,27 @@
1
+ module DcAddressLookup
2
+ class HttpError < StandardError; end
3
+
4
+ class Query
5
+
6
+ attr_reader :query
7
+
8
+ def initialize(query)
9
+ @query = query
10
+ end
11
+
12
+ def response
13
+ raise HttpError unless raw_response.success?
14
+ @response ||= Response.new(raw_response.body)
15
+ end
16
+
17
+ private
18
+
19
+ def uri
20
+ DcAddressLookup::QUERY_TEMPLATE.expand query: { str: query }
21
+ end
22
+
23
+ def raw_response
24
+ @raw_response ||= Typhoeus.get uri, TYPHOEUS_OPTIONS
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,28 @@
1
+ module DcAddressLookup
2
+ class Response
3
+
4
+ attr_reader :body
5
+
6
+ def initialize(body)
7
+ @body = body
8
+ end
9
+
10
+ def location
11
+ @location ||= Location.from_table(table)
12
+ end
13
+
14
+ private
15
+
16
+ def document
17
+ doc ||= begin
18
+ doc = Nokogiri::XML(body) { |config| config.strict.nonet }
19
+ doc.remove_namespaces!
20
+ doc
21
+ end
22
+ end
23
+
24
+ def table
25
+ document.xpath("ReturnObject//returnDataset//diffgram//NewDataSet//Table1")
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module DcAddressLookup
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,24 @@
1
+ require 'nokogiri'
2
+ require 'typhoeus'
3
+ require 'addressable/uri'
4
+ require "addressable/template"
5
+ require "dc_address_lookup/version"
6
+ require "dc_address_lookup/client"
7
+ require "dc_address_lookup/query"
8
+ require "dc_address_lookup/response"
9
+ require "dc_address_lookup/location"
10
+
11
+ module DcAddressLookup
12
+ ENDPOINT = "http://citizenatlas.dc.gov/newwebservices/locationverifier.asmx/findLocation"
13
+ QUERY_TEMPLATE = Addressable::Template.new "#{ENDPOINT}{?query*}"
14
+ TYPHOEUS_OPTIONS = {
15
+ accept_encoding: "gzip",
16
+ headers: {
17
+ "User-Agent" => "Mozilla/5.0 (compatible; dc-address-lookup/#{DcAddressLookup::VERSION}; +https://github.com/benbalter/dc-address-lookup)"
18
+ }
19
+ }
20
+
21
+ def self.lookup(address)
22
+ Client.new.lookup(address)
23
+ end
24
+ end
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ENV["DEBUG"] = "1"
4
+ require "bundler/setup"
5
+ require "dc_address_lookup"
6
+
7
+ client = DcAddressLookup::Client.new
8
+
9
+ require "pry"
10
+ Pry.start
data/script/release ADDED
@@ -0,0 +1,38 @@
1
+ #!/bin/sh
2
+ # Tag and push a release.
3
+
4
+ set -e
5
+
6
+ # Make sure we're in the project root.
7
+
8
+ cd $(dirname "$0")/..
9
+
10
+ # Build a new gem archive.
11
+
12
+ rm -rf dc_address_lookup-*.gem
13
+ gem build -q dc_address_lookup.gemspec
14
+
15
+ # Make sure we're on the master branch.
16
+
17
+ (git branch | grep -q '* master') || {
18
+ echo "Only release from the master branch."
19
+ exit 1
20
+ }
21
+
22
+ # Figure out what version we're releasing.
23
+
24
+ tag=v`ls dc_address_lookup-*.gem | sed 's/^dc_address_lookup-\(.*\)\.gem$/\1/'`
25
+
26
+ # Make sure we haven't released this version before.
27
+
28
+ git fetch -t origin
29
+
30
+ (git tag -l | grep -q "$tag") && {
31
+ echo "Whoops, there's already a '${tag}' tag."
32
+ exit 1
33
+ }
34
+
35
+ # Tag it and bag it.
36
+
37
+ gem push dc_address_lookup-*.gem && git tag "$tag" &&
38
+ git push origin master && git push origin "$tag"
data/script/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
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dc_address_lookup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ben Balter
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-12-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: typhoeus
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: addressable
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '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: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
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
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description:
112
+ email:
113
+ - ben.balter@github.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - dc_address_lookup.gemspec
126
+ - lib/dc_address_lookup.rb
127
+ - lib/dc_address_lookup/client.rb
128
+ - lib/dc_address_lookup/location.rb
129
+ - lib/dc_address_lookup/query.rb
130
+ - lib/dc_address_lookup/response.rb
131
+ - lib/dc_address_lookup/version.rb
132
+ - script/console
133
+ - script/release
134
+ - script/setup
135
+ homepage: https://github.com/benbalter/dc-address-lookup
136
+ licenses:
137
+ - MIT
138
+ metadata: {}
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ requirements: []
154
+ rubyforge_project:
155
+ rubygems_version: 2.5.1
156
+ signing_key:
157
+ specification_version: 4
158
+ summary: A Ruby gem to look up Washington, D.C. addresses in the master address registry,
159
+ an official city database
160
+ test_files: []