melissa_data 0.2.7 → 0.2.8

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: 615be792d85354cc55724784cae3bef94ba30171
4
- data.tar.gz: 4d061759d4a70063d46541bfaee7f49e8393b14e
3
+ metadata.gz: 68459eb8fb64d7cc1612776aa90f35682409d57d
4
+ data.tar.gz: e160890a75ae9cf0f7e5c69d47bbb42b461fc0b2
5
5
  SHA512:
6
- metadata.gz: 28c08dc9bf345321110fd01bc19f6d9deaabd94bbba2ad3f5f9549e830c189a3bc51a4715c925a28361279cec9f0248bda6f35c1f8f6e6590de61a9e7524ee1a
7
- data.tar.gz: ac693a9a7d7c1548583ba33ca087b1543b6c71ce53d9829f992e1af46e8290367df37d33a48572134f6f64471ba0e18afcb6803a47b69258363bae0fef15ff2a
6
+ metadata.gz: 4c1fc3d2a632d2f08e0d0ed1c78b8b5192e52405fcac42ef6a5db85105ac9a115ed87ef19d7f22d1e90b16df68392b4186f2b47e4811f50fd57f672bb70d1524
7
+ data.tar.gz: 885d3694737462e8346a154592bee6847b88f48e26d82a705d466e451e2c72d376e554ceb94788302526241cc5500736be44c14d95b333b686348478128f6745
@@ -4,9 +4,11 @@ require "melissa_data/web_smart/response_processor"
4
4
  require "melissa_data/web_smart/client"
5
5
  require "melissa_data/web_smart/property_api"
6
6
  require "melissa_data/config"
7
+ require "melissa_data/geo_lookup/geocoder"
7
8
 
8
9
  require 'rest-client'
9
10
  require 'nokogiri'
11
+ require 'geokit'
10
12
 
11
13
  module MelissaData
12
14
  include MelissaData::Config
@@ -6,16 +6,18 @@ module MelissaData
6
6
 
7
7
  # @!attribute web_smart_id
8
8
  # @return [String] web smart id to be used
9
- attr_accessor :web_smart_id
9
+ attr_accessor :web_smart_id, :google_maps_api_key
10
10
 
11
11
  # Configures web_smart_id and property_api_url
12
12
  # Usage example:
13
13
  # MelissaData.configure do |config|
14
- # config.web_smart_id = ENV['MELISSA_DATA_WEB_SMART_ID']
14
+ # config.web_smart_id = ENV['MELISSA_DATA_WEB_SMART_ID']
15
+ # config.google_maps_api_key = ENV['MELISSA_DATA_WEB_SMART_ID']
15
16
  # end
16
17
  #
17
18
  # Alternate way:
18
- # MelissaData.web_smart_id = ENV['MELISSA_DATA_WEB_SMART_ID']
19
+ # MelissaData.web_smart_id = ENV['MELISSA_DATA_WEB_SMART_ID']
20
+ # MelissaData.google_maps_api_key = ENV['MELISSA_DATA_WEB_SMART_ID']
19
21
  #
20
22
  # @param <api_key> [String] web smart id to use
21
23
  def configure
@@ -0,0 +1,22 @@
1
+ module MelissaData
2
+ module GeoLookup
3
+ module Geocoder
4
+ extend self
5
+
6
+ def address_to_coordinates(address)
7
+ Geokit::Geocoders::GoogleGeocoder.api_key = MelissaData.google_maps_api_key
8
+ lat_long = Geokit::Geocoders::GoogleGeocoder.geocode(address)
9
+ .ll
10
+ .split(",")
11
+ .map(&:to_f)
12
+ { latitude: lat_long.first, longitude: lat_long.last }
13
+ end
14
+
15
+ def coordinates?(response)
16
+ lat = response[:property_address][:latitude]
17
+ long = response[:property_address][:longitude]
18
+ lat != nil && long != nil
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,3 +1,3 @@
1
1
  module MelissaData
2
- VERSION = "0.2.7"
2
+ VERSION = "0.2.8"
3
3
  end
@@ -9,11 +9,15 @@ module MelissaData
9
9
  end
10
10
 
11
11
  def property_by_apn(fips:, apn:)
12
- process(@client.property_by_apn(fips: fips, apn: apn), 'property')
12
+ res = process(@client.property_by_apn(fips: fips, apn: apn), 'property')
13
+ add_coordinates(res) unless MelissaData::GeoLookup::Geocoder.coordinates? res
14
+ res
13
15
  end
14
16
 
15
17
  def property_by_address_key(address_key:)
16
- process(@client.property_by_address_key(address_key: address_key), 'property')
18
+ res = process(@client.property_by_address_key(address_key: address_key), 'property')
19
+ add_coordinates(res) unless MelissaData::GeoLookup::Geocoder.coordinates? res
20
+ res
17
21
  end
18
22
 
19
23
  def address(address:, city:, state:, zip:, country: "USA")
@@ -24,6 +28,16 @@ module MelissaData
24
28
  country: country))
25
29
  process(resp, 'address')
26
30
  end
31
+
32
+ def add_coordinates(response)
33
+ addr = response[:property_address][:address]
34
+ city = response[:property_address][:city]
35
+ state = response[:property_address][:state]
36
+ zip = response[:property_address][:zip]
37
+ full_address = "#{addr}, #{city}, #{state}, #{zip}"
38
+ MelissaData::GeoLookup::Geocoder
39
+ .address_to_coordinates(full_address)
40
+ end
27
41
  end
28
42
  end
29
43
  end
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_runtime_dependency "nokogiri"
23
23
  spec.add_runtime_dependency "rest-client"
24
+ spec.add_runtime_dependency "geokit"
24
25
 
25
26
  spec.add_development_dependency "bundler", "~> 1.10"
26
27
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: melissa_data
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Grayson
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2015-10-27 00:00:00.000000000 Z
12
+ date: 2015-12-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -39,6 +39,20 @@ dependencies:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: geokit
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
42
56
  - !ruby/object:Gem::Dependency
43
57
  name: bundler
44
58
  requirement: !ruby/object:Gem::Requirement
@@ -135,6 +149,7 @@ files:
135
149
  - config/property_success_codes.yml
136
150
  - lib/melissa_data.rb
137
151
  - lib/melissa_data/config.rb
152
+ - lib/melissa_data/geo_lookup/geocoder.rb
138
153
  - lib/melissa_data/version.rb
139
154
  - lib/melissa_data/web_smart/client.rb
140
155
  - lib/melissa_data/web_smart/property_api.rb