melissa_data 0.2.14 → 1.0.0

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: 06b64d5d7b8656d81ecf6c0b413cf4cbea7c9534
4
- data.tar.gz: c02651c7504b10bda9ad1607e06bc99b9b257286
3
+ metadata.gz: 5ad99ffda47a41ab5769c579eb119ffae8353114
4
+ data.tar.gz: 5f88c441fc21210d7b458d31cfcb38443956c76f
5
5
  SHA512:
6
- metadata.gz: 2e4c669f5894d837f0740dc5872ad2c936fbf9c873b32923cc5dd1642929bd734e4d9e33d6fdbc9b1370dc0d763c6eaf644ba209b19bf513c4b0c6066b330530
7
- data.tar.gz: 0b1fce5d39861a0accbc6b1136bddddd5330b215deebd03544deec9114c1065300480788fa05a892d686c4c9b6b1d8ad22860fd058b47e953a659284c3e4b1e4
6
+ metadata.gz: 20a2f54106674585fcc5ca4aa1bb9ec479e6d2fb3806985b06cc8b0a812d3df6f90857c84058904ea5e15accb52553faa02d4eb3e13d99e51e5d674e8be4e719
7
+ data.tar.gz: c53bbde3abc59944433c42c495778cf6e2e6a0f13d58abf48c2d3b68f86e8dc5b7c64032086f3489e609933ef13eb98b85dc01759e5c8041d136196b195ccb9e
@@ -1,3 +1,4 @@
1
+ require "active_support/core_ext/hash"
1
2
  require "melissa_data/version"
2
3
  require "melissa_data/web_smart/xml"
3
4
  require "melissa_data/web_smart/response_processor"
@@ -6,8 +7,6 @@ require "melissa_data/web_smart/property_api"
6
7
  require "melissa_data/config"
7
8
  require "melissa_data/geo_lookup/geocoder"
8
9
 
9
- require 'rest-client'
10
- require 'nokogiri'
11
10
  require 'geokit'
12
11
 
13
12
  module MelissaData
@@ -14,7 +14,7 @@ module MelissaData
14
14
  end
15
15
 
16
16
  def coordinates?(response)
17
- if !response[:errors]
17
+ if !response[:errors] && !response[:property_address]&.empty?
18
18
  lat = response.fetch(:property_address)[:latitude]
19
19
  long =response.fetch(:property_address)[:longitude]
20
20
  lat != nil && long != nil
@@ -1,3 +1,3 @@
1
1
  module MelissaData
2
- VERSION = "0.2.14"
2
+ VERSION = '1.0.0'
3
3
  end
@@ -24,7 +24,7 @@ module MelissaData
24
24
 
25
25
  def resolve_response
26
26
  return @response unless success?
27
- add_coordinates(@response) unless MelissaData::GeoLookup::Geocoder.coordinates? @response
27
+ add_coordinates(@response[:records].first) unless MelissaData::GeoLookup::Geocoder.coordinates? @response[:records].first
28
28
  @response
29
29
  end
30
30
 
@@ -42,9 +42,11 @@ module MelissaData
42
42
  city = response.dig(:property_address, :city)
43
43
  state = response.dig(:property_address, :state)
44
44
  zip = response.dig(:property_address, :zip)
45
- full_address = "#{addr}, #{city}, #{state}, #{zip}"
46
- MelissaData::GeoLookup::Geocoder
47
- .address_to_coordinates(full_address)
45
+
46
+ if addr && city && state && zip
47
+ full_address = "#{addr}, #{city}, #{state}, #{zip}"
48
+ MelissaData::GeoLookup::Geocoder.address_to_coordinates(full_address)
49
+ end
48
50
  end
49
51
  end
50
52
  end
@@ -1,40 +1,65 @@
1
- require 'rest-client'
2
- require 'nokogiri'
1
+ require 'faraday'
2
+ require 'typhoeus'
3
3
  require 'json'
4
4
 
5
5
  module MelissaData
6
6
  module WebSmart
7
7
  class PropertyAPI
8
+ USER_AGENT = "MelissaData-Rubygem/#{MelissaData::VERSION}"
9
+ BASE_URL = 'https://property.melissadata.net'
10
+
11
+ def default_connection(url = BASE_URL, json_headers: false)
12
+ Faraday.new(url: url) do |conn|
13
+ conn.response :logger
14
+ conn.headers[:user_agent] = USER_AGENT
15
+
16
+ if json_headers
17
+ conn.headers['Content-Type'] = 'application/json'
18
+ conn.headers['Accept'] = 'application/json'
19
+ end
20
+
21
+ conn.adapter :typhoeus
22
+ end
23
+ end
24
+
8
25
  def property_by_apn(fips:, apn:)
9
- resp = RestClient.get('https://property.melissadata.net/v3/REST/Service.svc/doLookup/',
10
- { params: { id: MelissaData.web_smart_id,
11
- fips: fips,
12
- apn: apn,
13
- opt: "True" } })
14
- PropertyXMLParser.new(Nokogiri::XML(resp)).parse
26
+ raw = default_connection(BASE_URL).get '/v4/WEB/LookupProperty/', {
27
+ id: MelissaData.web_smart_id,
28
+ fips: fips,
29
+ apn: apn,
30
+ format: 'json'
31
+ }
32
+
33
+ res = JSON.parse(raw.body).deep_transform_keys(&:underscore)
34
+ res&.with_indifferent_access
15
35
  end
16
36
 
17
37
  def property_by_address_key(address_key:)
18
- resp = RestClient.get('https://property.melissadata.net/v3/REST/Service.svc/doLookup/',
19
- { params: { id: MelissaData.web_smart_id,
20
- AddressKey: address_key,
21
- opt: "True" } })
22
- PropertyXMLParser.new(Nokogiri::XML(resp)).parse
38
+ raw = default_connection(BASE_URL).get '/v4/WEB/LookupProperty/', {
39
+ id: MelissaData.web_smart_id,
40
+ AddressKey: address_key,
41
+ format: 'json'
42
+ }
43
+
44
+ res = JSON.parse(raw.body).deep_transform_keys(&:underscore)
45
+ res&.with_indifferent_access
23
46
  end
24
47
 
25
48
  def address(address:, city:, state:, zip:, country:)
26
- resp = JSON.parse(RestClient.get("https://personator.melissadata.net/v3/WEB/ContactVerify/doContactVerify",
27
- { params: { id: MelissaData.web_smart_id,
28
- Actions: "Check",
29
- a1: address,
30
- city: city,
31
- state: state,
32
- postal: zip,
33
- ctry: country,
34
- AdvancedAddressCorrection: "on",},
35
- accept: :json,
36
- content_type: :json }))
37
- resp["Records"].first
49
+ raw = default_connection(BASE_URL, json_headers: true)
50
+ .get '/v3/WEB/ContactVerify/doContactVerify', {
51
+ id: MelissaData.web_smart_id,
52
+ Actions: 'Check',
53
+ a1: address,
54
+ city: city,
55
+ state: state,
56
+ postal: zip,
57
+ ctry: country,
58
+ AdvancedAddressCorrection: 'on'
59
+ }
60
+
61
+ res = JSON.parse(raw.body).deep_transform_keys(&:underscore)
62
+ res&.with_indifferent_access[:records]&.first
38
63
  end
39
64
  end
40
65
  end
@@ -31,9 +31,9 @@ module MelissaData
31
31
  def codes(response, resp_type)
32
32
  case resp_type
33
33
  when 'property'
34
- response[:result][:code].split(",")
34
+ response[:records].first[:results].split(',')
35
35
  when 'address'
36
- response[:results].split(",")
36
+ response[:records].first[:results].split(',')
37
37
  end
38
38
  end
39
39
 
@@ -20,13 +20,14 @@ Gem::Specification.new do |spec|
20
20
  spec.require_paths = ["lib"]
21
21
  spec.required_ruby_version = '>= 2.3'
22
22
 
23
- spec.add_runtime_dependency "nokogiri"
24
- spec.add_runtime_dependency "rest-client"
25
- spec.add_runtime_dependency "geokit"
23
+ spec.add_runtime_dependency 'geokit'
24
+ spec.add_runtime_dependency 'activesupport', '~> 4.2.2'
25
+ spec.add_runtime_dependency 'faraday', '~> 0.15.0'
26
+ spec.add_runtime_dependency 'typhoeus', '~> 1.3.0'
26
27
 
27
- spec.add_development_dependency "bundler", "~> 1.10"
28
- spec.add_development_dependency "rake", "~> 10.0"
29
- spec.add_development_dependency "rspec", "~> 3.3"
30
- spec.add_development_dependency "pry"
31
- spec.add_development_dependency "webmock"
28
+ spec.add_development_dependency 'bundler', '~> 1.10'
29
+ spec.add_development_dependency 'rake', '~> 10.0'
30
+ spec.add_development_dependency 'rspec', '~> 3.3'
31
+ spec.add_development_dependency 'pry'
32
+ spec.add_development_dependency 'webmock'
32
33
  end
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.14
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Grayson
@@ -9,10 +9,10 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2017-06-20 00:00:00.000000000 Z
12
+ date: 2018-05-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: nokogiri
15
+ name: geokit
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
18
  - - ">="
@@ -26,33 +26,47 @@ dependencies:
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
- name: rest-client
29
+ name: activesupport
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ">="
32
+ - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '0'
34
+ version: 4.2.2
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ">="
39
+ - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '0'
41
+ version: 4.2.2
42
42
  - !ruby/object:Gem::Dependency
43
- name: geokit
43
+ name: faraday
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ">="
46
+ - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '0'
48
+ version: 0.15.0
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ">="
53
+ - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '0'
55
+ version: 0.15.0
56
+ - !ruby/object:Gem::Dependency
57
+ name: typhoeus
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: 1.3.0
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 1.3.0
56
70
  - !ruby/object:Gem::Dependency
57
71
  name: bundler
58
72
  requirement: !ruby/object:Gem::Requirement