dc_address_lookup 0.2.0 → 0.2.1

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
2
  SHA1:
3
- metadata.gz: a92e780b8924d9a689c78786a8f0cc35b14992b0
4
- data.tar.gz: 0490eb6833b8f49bec859f462ffa0711e62f3a4f
3
+ metadata.gz: 677528e5dacce954168dbedb9eefa326950ea723
4
+ data.tar.gz: 9a35c1825f44a12028922afcaa0ceee0ff913ab4
5
5
  SHA512:
6
- metadata.gz: 2dd2ba6c035808119c41e618a8c49bc36a081116859d72843382ca1e2f3e224d5d19aa2a182a0ee81e1796b53c78d2b3274dc6476eb8094758feffdf4c3c4a7c
7
- data.tar.gz: 727ec563285c370c5803a36e6a54c8f85263cd06c1b6491f50f35593474bf7ac3a48567a620fd5da2af232f1460f61f1e2a89c90deb56a80312dfceba13db70d
6
+ metadata.gz: e611b0ac557929f2806d75323393294cd02b7576fb45b3b36745fb6e692939c00acbe37d09a1e736d41e86dfff04fcb5a2ffd9f65859b59cd11750fdb0ec5cf8
7
+ data.tar.gz: f33e20e9cc389b181c121075b0e13b9a4a56b0798d2323433bdb139d69088e89687f82dc6d99f29f3120e306d44ac35dc2130cb5a5f285f9767352daf2e987fe
@@ -20,7 +20,6 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency "rest-client", "~> 1.8"
22
22
  spec.add_dependency "rest-client-components", "~> 1.4"
23
- spec.add_dependency "nokogiri", "~> 1.6"
24
23
  spec.add_dependency "rack-cache", "~> 1.5"
25
24
 
26
25
  spec.add_development_dependency "bundler", "~> 1.10"
@@ -1,7 +1,7 @@
1
- require 'nokogiri'
2
1
  require 'rest-client'
3
2
  require 'restclient/components'
4
3
  require 'rack/cache'
4
+ require 'json'
5
5
 
6
6
  require "dc_address_lookup/version"
7
7
  require "dc_address_lookup/client"
@@ -9,7 +9,8 @@ require "dc_address_lookup/response"
9
9
  require "dc_address_lookup/location"
10
10
 
11
11
  module DcAddressLookup
12
- ENDPOINT = "http://citizenatlas.dc.gov/newwebservices/locationverifier.asmx/findLocation"
12
+ DOMAIN = "http://citizenatlas.dc.gov"
13
+ ENDPOINT = "#{DOMAIN}/newwebservices/locationverifier.asmx/findLocation2"
13
14
 
14
15
  def self.lookup(address)
15
16
  Client.new.lookup(address)
@@ -1,7 +1,8 @@
1
1
  module DcAddressLookup
2
2
  class Client
3
3
  def lookup(query)
4
- response = RestClient.get DcAddressLookup::ENDPOINT, { params: { str: query } }
4
+ params = { f: "json", str: query }
5
+ response = RestClient.get DcAddressLookup::ENDPOINT, { params: params }
5
6
  location = Response.new(response).location
6
7
  location if location.valid?
7
8
  end
@@ -1,14 +1,19 @@
1
1
  module DcAddressLookup
2
2
  class Location
3
- def self.from_table(xml)
3
+ def self.from_table(table)
4
4
  location = self.new
5
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
6
+ table.each do |key,value|
7
+ key = key.downcase
8
+
9
+ if value.class == String
10
+ value = value.gsub(/\A#{key.split("_").first}\b/i, "").squeeze("\s").strip
11
+ value = value.to_i if value =~ /\A[1-9][0-9]*\z/
12
+ value = value.to_f if value =~ /\A[0-9]+\.[0-9]+\z/
13
+ elsif value.class == Float
14
+ value = value.to_i if value.to_s =~ /\A[0-9]+\.0\z/
15
+ end
16
+
12
17
  location.data[key] = value
13
18
  end
14
19
 
@@ -13,16 +13,12 @@ module DcAddressLookup
13
13
 
14
14
  private
15
15
 
16
- def document
17
- doc ||= begin
18
- doc = Nokogiri::XML(body) { |config| config.strict.nonet }
19
- doc.remove_namespaces!
20
- doc
21
- end
16
+ def parsed
17
+ @parsed ||= JSON.parse(body)
22
18
  end
23
19
 
24
20
  def table
25
- document.xpath("ReturnObject//returnDataset//diffgram//NewDataSet//Table1")
21
+ parsed["returnDataset"]["Table1"].first
26
22
  end
27
23
  end
28
24
  end
@@ -1,3 +1,3 @@
1
1
  module DcAddressLookup
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -1,10 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  ENV["DEBUG"] = "1"
4
+ ENV["RESTCLIENT_LOG"] = "stdout"
5
+
4
6
  require "bundler/setup"
5
7
  require "dc_address_lookup"
6
-
7
- client = DcAddressLookup::Client.new
8
-
9
8
  require "pry"
10
9
  Pry.start
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dc_address_lookup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Balter
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-12-17 00:00:00.000000000 Z
11
+ date: 2015-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.4'
41
- - !ruby/object:Gem::Dependency
42
- name: nokogiri
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '1.6'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '1.6'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: rack-cache
57
43
  requirement: !ruby/object:Gem::Requirement