melissa 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.jruby-version +1 -1
- data/Gemfile.lock +4 -7
- data/README.md +37 -10
- data/lib/melissa.rb +12 -16
- data/lib/melissa/addr_obj_live.rb +61 -53
- data/lib/melissa/addr_obj_mock.rb +1 -1
- data/lib/melissa/config.rb +3 -14
- data/lib/melissa/geo_point.rb +10 -0
- data/lib/melissa/geo_point_live.rb +68 -60
- data/lib/melissa/geo_point_mock.rb +4 -4
- data/lib/melissa/railtie.rb +16 -2
- data/lib/melissa/version.rb +1 -1
- data/test/addr_obj_test.rb +29 -29
- data/test/geo_point_test.rb +15 -17
- data/test/melissa_test.rb +22 -21
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 625ef678d1c9036881ab0e7b91ebef31bcb1e035
|
4
|
+
data.tar.gz: f7d15d546fa2f2bb82ac905d661751ed379ac400
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1427c544d18ff571008eff0bd169d2da64ba3d883d8c9082efe71ab2e1438e8df626c69d193e3e96c3904a837c231f1257024d67cff08155cd7f20882507850
|
7
|
+
data.tar.gz: 09730130a065c514854b6fff3ea91d4fccc4d526df0a86dd95178585379a3c36cd14fb39a91754c9e915b329c922916ea46f2445ca3283486d637781f93e3800
|
data/.jruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
jruby-1.7.
|
1
|
+
jruby-1.7.19
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
melissa (0.0.
|
4
|
+
melissa (0.0.2)
|
5
5
|
activesupport
|
6
6
|
ffi
|
7
7
|
minitest
|
@@ -9,7 +9,7 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
activesupport (4.2.
|
12
|
+
activesupport (4.2.1)
|
13
13
|
i18n (~> 0.7)
|
14
14
|
json (~> 1.7, >= 1.7.7)
|
15
15
|
minitest (~> 5.1)
|
@@ -17,11 +17,9 @@ GEM
|
|
17
17
|
tzinfo (~> 1.1)
|
18
18
|
ansi (1.5.0)
|
19
19
|
builder (3.2.2)
|
20
|
-
ffi (1.9.
|
21
|
-
ffi (1.9.6-java)
|
20
|
+
ffi (1.9.8)
|
22
21
|
i18n (0.7.0)
|
23
22
|
json (1.8.2)
|
24
|
-
json (1.8.2-java)
|
25
23
|
minitest (5.4.0)
|
26
24
|
minitest-reporters (1.0.8)
|
27
25
|
ansi
|
@@ -32,8 +30,7 @@ GEM
|
|
32
30
|
rake (10.4.2)
|
33
31
|
ruby-progressbar (1.7.1)
|
34
32
|
shoulda-context (1.2.1)
|
35
|
-
thread_safe (0.3.
|
36
|
-
thread_safe (0.3.4-java)
|
33
|
+
thread_safe (0.3.5)
|
37
34
|
tzinfo (1.2.2)
|
38
35
|
thread_safe (~> 0.1)
|
39
36
|
|
data/README.md
CHANGED
@@ -79,10 +79,10 @@ the values to validate each other.
|
|
79
79
|
```ruby
|
80
80
|
#create AddrObj
|
81
81
|
valid_addr_obj = ::Melissa.addr_obj(
|
82
|
-
:
|
83
|
-
:
|
84
|
-
:
|
85
|
-
:
|
82
|
+
address: '9802 Brompton Dr',
|
83
|
+
city: 'Tampa',
|
84
|
+
state: 'Fl',
|
85
|
+
zip: '33626'
|
86
86
|
)
|
87
87
|
#use it to get deliverypoint
|
88
88
|
deliverypoint = valid_addr_obj.delivery_point
|
@@ -97,8 +97,14 @@ the values to validate each other.
|
|
97
97
|
|
98
98
|
```
|
99
99
|
|
100
|
-
The calls to Melissa Data library will be attempted only if
|
101
|
-
|
100
|
+
The calls to Melissa Data library will be attempted only if melissa gem config mode is set to live, and Melissa Data
|
101
|
+
library is loaded. This is the default mode for the gem.
|
102
|
+
|
103
|
+
```
|
104
|
+
Melissa.config.mode = :live
|
105
|
+
```
|
106
|
+
|
107
|
+
Otherwise mock objects can be used. This way there is no need to install Melissa Data library on development machine.
|
102
108
|
The following rules are used in mocking AddrObj Library:
|
103
109
|
1. if zip_code is present, addres object is valid.
|
104
110
|
2. to mock delivery point: "#{zip_code}1234#{last 2 digits of zip code}".
|
@@ -107,13 +113,34 @@ The following rules are used in mocking AddrObj Library:
|
|
107
113
|
Mocked GeoPoint object will return following values:
|
108
114
|
|
109
115
|
```ruby
|
110
|
-
@latitude =
|
111
|
-
@longitude = -
|
112
|
-
@time_zone_code = '
|
113
|
-
@resultcodes = ['
|
116
|
+
@latitude = 27.850397
|
117
|
+
@longitude = -82.659555
|
118
|
+
@time_zone_code = '05'
|
119
|
+
@resultcodes = ['GS05']
|
114
120
|
@is_valid = true
|
115
121
|
```
|
116
122
|
|
123
|
+
To use melissa gem from rails application, see railtie.rb, and create melissa.yml in the application, based
|
124
|
+
on the example below:
|
125
|
+
|
126
|
+
```
|
127
|
+
default: &defaults
|
128
|
+
config_path: /etc/melissa
|
129
|
+
mode: live
|
130
|
+
|
131
|
+
production:
|
132
|
+
<<: *defaults
|
133
|
+
|
134
|
+
release:
|
135
|
+
<<: *defaults
|
136
|
+
|
137
|
+
hotfix:
|
138
|
+
<<: *defaults
|
139
|
+
```
|
140
|
+
|
141
|
+
By using this set up the attempt to call Melissa data library will be made in production, release and hotfix environments,
|
142
|
+
and mock objects will be used in test and development.
|
143
|
+
|
117
144
|
## Meta
|
118
145
|
|
119
146
|
* Code: `git clone git://github.com/smarinskaya/melissa.git`
|
data/lib/melissa.rb
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
require "melissa/config"
|
2
|
+
require "melissa/version"
|
3
|
+
require 'melissa/addr_obj'
|
4
|
+
require 'melissa/geo_point'
|
5
|
+
require 'melissa/addr_obj_live'
|
6
|
+
require 'melissa/geo_point_live'
|
7
|
+
require 'melissa/addr_obj_mock'
|
8
|
+
require 'melissa/geo_point_mock'
|
9
|
+
require 'melissa/railtie' if defined?(Rails)
|
10
|
+
|
1
11
|
module Melissa
|
2
12
|
|
3
13
|
class << self
|
@@ -6,7 +16,6 @@ module Melissa
|
|
6
16
|
|
7
17
|
def self.addr_obj(attrs)
|
8
18
|
if config.mode == :live
|
9
|
-
raise LoadError, "Melissa AddrObj was not loaded!" unless config.addr_obj_lib_loaded
|
10
19
|
AddrObjLive.new(attrs)
|
11
20
|
else
|
12
21
|
AddrObjMock.new(attrs)
|
@@ -15,7 +24,6 @@ module Melissa
|
|
15
24
|
|
16
25
|
def self.geo_point(attrs)
|
17
26
|
if config.mode == :live
|
18
|
-
raise LoadError, "Melissa GeoPoint object was not loaded!" unless config.geo_point_lib_loaded
|
19
27
|
GeoPointLive.new(attrs)
|
20
28
|
else
|
21
29
|
GeoPointMock.new(attrs)
|
@@ -35,23 +43,11 @@ module Melissa
|
|
35
43
|
end
|
36
44
|
end
|
37
45
|
|
38
|
-
|
39
|
-
|
40
|
-
require "melissa/version"
|
41
|
-
require "melissa/config"
|
42
|
-
require 'melissa/addr_obj'
|
43
|
-
require 'melissa/geo_point'
|
44
|
-
require 'melissa/addr_obj_live'
|
45
|
-
require 'melissa/geo_point_live'
|
46
|
-
require 'melissa/addr_obj_mock'
|
47
|
-
require 'melissa/geo_point_mock'
|
48
|
-
|
49
|
-
|
50
|
-
#valid_address_obj = ::Melissa.adrr_obj(:address => 'valid street', :city => 'Tampa', :state => 'FL', :zip => '33626')
|
46
|
+
#valid_address_obj = ::Melissa.addr_obj(address: 'valid street', city: 'Tampa', state: 'FL', zip: '33626')
|
51
47
|
#puts "addr=#{valid_address_obj.address}"
|
52
48
|
#puts "deliverypoint=#{valid_address_obj.delivery_point}"
|
53
49
|
|
54
50
|
#g = ::Melissa.geo_point(valid_address_obj)
|
55
51
|
#puts "lat,long=#{g.latitude},#{g.longitude}"
|
56
52
|
#or
|
57
|
-
#g = ::Melissa.geo_point(:
|
53
|
+
#g = ::Melissa.geo_point(zip: 'zip', plus4: 'plus4', delivery_point_code: 'delivery_point_code')
|
@@ -2,10 +2,12 @@ require 'ffi'
|
|
2
2
|
|
3
3
|
module Melissa
|
4
4
|
class AddrObjLive < AddrObj
|
5
|
-
|
5
|
+
|
6
|
+
def self.lib_loaded?
|
7
|
+
return @lib_loaded if defined?(@lib_loaded)
|
6
8
|
extend FFI::Library
|
7
9
|
|
8
|
-
ffi_lib Melissa.config.addr_obj_lib
|
10
|
+
ffi_lib Melissa.config.addr_obj_lib
|
9
11
|
attr_functions = @@melissa_attributes.map { |name| ["mdAddrGet#{name}".to_sym, [:pointer], :string] }
|
10
12
|
|
11
13
|
functions = attr_functions + [
|
@@ -43,75 +45,81 @@ module Melissa
|
|
43
45
|
|
44
46
|
# Get all the attributes out up-front so we can destroy the h_addr_lib object
|
45
47
|
class_eval <<-EOS
|
46
|
-
|
47
|
-
|
48
|
-
|
48
|
+
define_method(:fill_attributes) do |h_addr_lib|
|
49
|
+
#{@@melissa_attributes.map { |name| "@#{name.underscore} = mdAddrGet#{name}(h_addr_lib)" }.join("\n")}
|
50
|
+
end
|
49
51
|
EOS
|
52
|
+
rescue LoadError => e
|
53
|
+
puts "WARNING: #{Melissa.config.addr_obj_lib} could not be loaded"
|
54
|
+
return @lib_loaded = false
|
55
|
+
else
|
56
|
+
return @lib_loaded = true
|
57
|
+
end
|
50
58
|
|
51
|
-
|
59
|
+
def self.with_mdaddr
|
60
|
+
raise "Unable to load melissa library #{Melissa.config.addr_obj_lib}" unless self.lib_loaded?
|
61
|
+
raise "Unable to find the license for Melissa Data library #{Melissa.config.license}" unless Melissa.config.license.present?
|
62
|
+
raise "Unable to find data files for Melissa Data library #{Melissa.config.data_path}" unless Melissa.config.data_path.present?
|
63
|
+
begin
|
52
64
|
h_addr_lib = mdAddrCreate
|
53
65
|
mdAddrSetLicenseString(h_addr_lib, Melissa.config.license)
|
54
66
|
mdAddrSetPathToUSFiles(h_addr_lib, Melissa.config.data_path)
|
55
67
|
mdAddrInitializeDataFiles(h_addr_lib)
|
56
68
|
yield h_addr_lib
|
57
69
|
ensure
|
58
|
-
mdAddrDestroy(h_addr_lib)
|
70
|
+
mdAddrDestroy(h_addr_lib) if h_addr_lib
|
59
71
|
end
|
72
|
+
end
|
60
73
|
|
61
|
-
|
62
|
-
|
74
|
+
#This function returns a date value corresponding to the date when the current license
|
75
|
+
#string expires.
|
63
76
|
|
64
|
-
|
65
|
-
|
66
|
-
|
77
|
+
def self.license_expiration_date
|
78
|
+
Date.parse(with_mdaddr { |h_addr_lib| mdAddrGetLicenseExpirationDate(h_addr_lib) })
|
79
|
+
end
|
67
80
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
81
|
+
def self.days_until_license_expiration
|
82
|
+
#I compare Date objects. I think it is more accurate.
|
83
|
+
#self.license_expiration_date returns string in format: "YYYY-MM-DD"
|
84
|
+
(self.license_expiration_date - Date.today).to_i
|
85
|
+
end
|
73
86
|
|
74
|
-
|
75
|
-
|
76
|
-
|
87
|
+
# U.S. Only — This function returns a date value representing the
|
88
|
+
# date when the current U.S. data files expire. This date enables you to confirm that the
|
89
|
+
# data files you are using are the latest available.
|
77
90
|
|
78
|
-
|
79
|
-
|
80
|
-
|
91
|
+
def self.data_expiration_date
|
92
|
+
Date.strptime(with_mdaddr { |h_addr_lib| mdAddrGetExpirationDate(h_addr_lib) }, '%m-%d-%Y')
|
93
|
+
end
|
81
94
|
|
82
|
-
|
83
|
-
|
84
|
-
|
95
|
+
def self.days_until_data_expiration
|
96
|
+
(self.data_expiration_date - Date.today).to_i
|
97
|
+
end
|
85
98
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
end
|
99
|
+
def initialize(opts)
|
100
|
+
self.class.with_mdaddr do |h_addr_lib|
|
101
|
+
# clear any properties from a previous call
|
102
|
+
mdAddrClearProperties(h_addr_lib)
|
103
|
+
|
104
|
+
mdAddrSetCompany(h_addr_lib, opts[:company] || '');
|
105
|
+
mdAddrSetAddress(h_addr_lib, opts[:address] || '');
|
106
|
+
mdAddrSetAddress2(h_addr_lib, opts[:address2] || '');
|
107
|
+
mdAddrSetSuite(h_addr_lib, opts[:suite] || '');
|
108
|
+
mdAddrSetCity(h_addr_lib, opts[:city] || '');
|
109
|
+
mdAddrSetState(h_addr_lib, opts[:state] || '');
|
110
|
+
mdAddrSetZip(h_addr_lib, opts[:zip] || '');
|
111
|
+
mdAddrSetUrbanization(h_addr_lib, opts[:urbanization] || '');
|
112
|
+
mdAddrSetCountryCode(h_addr_lib, opts[:country_code] || '');
|
113
|
+
mdAddrVerifyAddress(h_addr_lib);
|
114
|
+
|
115
|
+
@resultcodes = mdAddrGetResults(h_addr_lib).split(',')
|
116
|
+
fill_attributes(h_addr_lib)
|
105
117
|
end
|
118
|
+
end
|
106
119
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
end
|
111
|
-
rescue LoadError => e
|
112
|
-
Melissa.config.addr_obj_lib_loaded = false
|
113
|
-
else
|
114
|
-
Melissa.config.addr_obj_lib_loaded = true
|
120
|
+
def valid?
|
121
|
+
# Make sure there is at least 1 good code and no bad codes
|
122
|
+
(@resultcodes & @@good_codes).present? && (@resultcodes & @@bad_codes).empty?
|
115
123
|
end
|
116
124
|
end
|
117
125
|
end
|
data/lib/melissa/config.rb
CHANGED
@@ -6,8 +6,7 @@ module Melissa
|
|
6
6
|
|
7
7
|
class Config
|
8
8
|
|
9
|
-
attr_accessor :mode, :license, :data_path, :addr_obj_lib, :
|
10
|
-
attr_accessor :geo_point_lib, :geo_point_lib_loaded
|
9
|
+
attr_accessor :mode, :license, :data_path, :addr_obj_lib, :geo_point_lib
|
11
10
|
|
12
11
|
def initialize
|
13
12
|
#It is recommended to read the following config options from environment variables
|
@@ -15,9 +14,10 @@ module Melissa
|
|
15
14
|
#The license string should be entered as an environment variable named
|
16
15
|
#MD_LICENSE. This allows you to update your license string without editing
|
17
16
|
#and recompiling your code
|
17
|
+
self.mode = :live
|
18
18
|
|
19
|
+
self.home = ENV['MELISSA_HOME'] || '/usr/local/dqs'
|
19
20
|
self.config_path = ENV['MELISSA_CONFIG_PATH'] if ENV['MELISSA_CONFIG_PATH']
|
20
|
-
self.home = ENV['MELISSA_HOME'] if ENV['MELISSA_HOME']
|
21
21
|
@data_path = ENV['MELISSA_DATA_PATH'] if ENV['MELISSA_DATA_PATH']
|
22
22
|
@addr_obj_lib = ENV['MELISSA_ADDR_OBJ_LIB'] if ENV['MELISSA_ADDR_OBJ_LIB']
|
23
23
|
@geo_point_lib = ENV['MELISSA_GEO_POINT_LIB'] if ENV['MELISSA_GEO_POINT_LIB']
|
@@ -48,16 +48,5 @@ module Melissa
|
|
48
48
|
@geo_point_lib = "#{home}/GeoObj/libmdGeo.so"
|
49
49
|
@data_path = "#{home}/data"
|
50
50
|
end
|
51
|
-
|
52
|
-
def addr_obj_lib_loaded=(value)
|
53
|
-
@addr_obj_lib_loaded = value
|
54
|
-
@mode ||= :live if value
|
55
|
-
end
|
56
|
-
|
57
|
-
def geo_point_library_loaded=(value)
|
58
|
-
@geo_point_lib_loaded = value
|
59
|
-
@mode ||= :live if value
|
60
|
-
end
|
61
51
|
end
|
62
52
|
end
|
63
|
-
|
data/lib/melissa/geo_point.rb
CHANGED
@@ -58,6 +58,16 @@ module Melissa
|
|
58
58
|
@is_valid
|
59
59
|
end
|
60
60
|
|
61
|
+
#Added this method to have an ability to stub latitude if needed
|
62
|
+
def latitude
|
63
|
+
@latitude
|
64
|
+
end
|
65
|
+
|
66
|
+
#Added this method to have an ability to stub longitude if needed
|
67
|
+
def longitude
|
68
|
+
@longitude
|
69
|
+
end
|
70
|
+
|
61
71
|
def time_zone_offset
|
62
72
|
GeoPoint.time_zone_offset(self.time_zone_code, @addr_obj.state)
|
63
73
|
end
|
@@ -2,9 +2,11 @@ require 'ffi'
|
|
2
2
|
|
3
3
|
module Melissa
|
4
4
|
class GeoPointLive < GeoPoint
|
5
|
-
extend FFI::Library
|
6
5
|
|
7
|
-
|
6
|
+
def self.lib_loaded?
|
7
|
+
return @lib_loaded if defined?(@lib_loaded)
|
8
|
+
extend FFI::Library
|
9
|
+
|
8
10
|
ffi_lib Melissa.config.geo_point_lib
|
9
11
|
attr_functions = @@melissa_attributes.map { |name| ["mdGeoGet#{name}".to_sym, [:pointer], :string] }
|
10
12
|
|
@@ -38,8 +40,18 @@ module Melissa
|
|
38
40
|
#{@@melissa_attributes.map { |name| "@#{name.underscore} = mdGeoGet#{name}(mdGeo)" }.join("\n")}
|
39
41
|
end
|
40
42
|
EOS
|
43
|
+
rescue LoadError => e
|
44
|
+
puts "WARNING: #{Melissa.config.geo_point_lib} could not be loaded"
|
45
|
+
return @lib_loaded = false
|
46
|
+
else
|
47
|
+
return @lib_loaded = true
|
48
|
+
end
|
41
49
|
|
42
|
-
|
50
|
+
def self.with_mdgeo
|
51
|
+
raise "Unable to load melissa library #{Melissa.config.addr_obj_lib}" unless self.lib_loaded?
|
52
|
+
raise "Unable to find the license for Melissa Data library #{Melissa.config.license}" unless Melissa.config.license.present?
|
53
|
+
raise "Unable to find data files for Melissa Data library #{Melissa.config.data_path}" unless Melissa.config.data_path.present?
|
54
|
+
begin
|
43
55
|
mdGeo = mdGeoCreate
|
44
56
|
mdGeoSetLicenseString(mdGeo, Melissa.config.license)
|
45
57
|
mdGeoSetPathToGeoCodeDataFiles(mdGeo, Melissa.config.data_path)
|
@@ -52,75 +64,71 @@ module Melissa
|
|
52
64
|
ensure
|
53
65
|
mdGeoDestroy(mdGeo) if mdGeo
|
54
66
|
end
|
67
|
+
end
|
55
68
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
69
|
+
#This function returns a date value corresponding to the date when the current license
|
70
|
+
#string expires.
|
71
|
+
def self.license_expiration_date
|
72
|
+
Date.parse(with_mdgeo { |mdGeo| mdGeoGetLicenseExpirationDate(mdGeo) })
|
73
|
+
end
|
61
74
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
75
|
+
def self.days_until_license_expiration
|
76
|
+
#I compare Date objects. I think it is more accurate.
|
77
|
+
#self.license_expiration_date returns string in format: "YYYY-MM-DD"
|
78
|
+
(self.license_expiration_date - Date.today).to_i
|
79
|
+
end
|
67
80
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
81
|
+
# his function returns a date value representing the
|
82
|
+
# date when the current data files expire. This date enables you to confirm that the
|
83
|
+
# data files you are using are the latest available.
|
84
|
+
def self.expiration_date
|
85
|
+
Date.parse(with_mdgeo { |mdGeo| mdGeoGetExpirationDate(mdGeo)})
|
86
|
+
end
|
74
87
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
88
|
+
def self.days_until_data_expiration
|
89
|
+
#I compare Date objects. I think it is more accurate.
|
90
|
+
#self.license_expiration_date returns string in format: "YYYY-MM-DD"
|
91
|
+
(self.expiration_date - Date.today).to_i
|
92
|
+
end
|
80
93
|
|
81
|
-
|
82
|
-
|
94
|
+
def initialize(opts)
|
95
|
+
@is_valid = false
|
83
96
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
97
|
+
self.class.with_mdgeo do |mdGeo|
|
98
|
+
if opts.kind_of?(AddrObj)
|
99
|
+
mdGeoGeoPoint(mdGeo, opts.zip || '', opts.plus4 || '', opts.delivery_point_code || '')
|
100
|
+
elsif opts.kind_of?(Hash)
|
101
|
+
mdGeoGeoPoint(mdGeo, opts[:zip] || '', opts[:plus4] || '', opts[:delivery_point_code] || '')
|
102
|
+
else
|
103
|
+
raise "Invalid call to GeoPoint, unknown object #{opts.inspect}"
|
104
|
+
end
|
105
|
+
@resultcodes = mdGeoGetResults(mdGeo).split(',')
|
106
|
+
fatals = @resultcodes & @@fatal_codes
|
107
|
+
@is_valid = fatals.blank?
|
108
|
+
if @is_valid
|
109
|
+
fill_attributes(mdGeo)
|
110
|
+
# Convert from strings to actual types
|
111
|
+
if @latitude.blank?
|
112
|
+
@latitude = nil
|
89
113
|
else
|
90
|
-
|
114
|
+
@latitude = @latitude.to_f
|
91
115
|
end
|
92
|
-
@
|
93
|
-
|
94
|
-
@is_valid = fatals.blank?
|
95
|
-
if @is_valid
|
96
|
-
fill_attributes(mdGeo)
|
97
|
-
# Convert from strings to actual types
|
98
|
-
if @latitude.blank?
|
99
|
-
@latitude = nil
|
100
|
-
else
|
101
|
-
@latitude = @latitude.to_f
|
102
|
-
end
|
103
|
-
if @longitude.blank?
|
104
|
-
@longitude = nil
|
105
|
-
else
|
106
|
-
@longitude = @longitude.to_f
|
107
|
-
end
|
108
|
-
if @latitude == 0.0 && @longitude == 0.0
|
109
|
-
@latitude = nil
|
110
|
-
@longitude = nil
|
111
|
-
@is_valid = false
|
112
|
-
end
|
116
|
+
if @longitude.blank?
|
117
|
+
@longitude = nil
|
113
118
|
else
|
114
|
-
|
115
|
-
|
116
|
-
|
119
|
+
@longitude = @longitude.to_f
|
120
|
+
end
|
121
|
+
if @latitude == 0.0 && @longitude == 0.0
|
122
|
+
@latitude = nil
|
123
|
+
@longitude = nil
|
124
|
+
@is_valid = false
|
125
|
+
end
|
126
|
+
else
|
127
|
+
fatals.each do |fatal_code|
|
128
|
+
raise "FATAL ERROR Melissa GeoPoint returned #{fatal_code}-#{@@codes[fatal_code]}"
|
117
129
|
end
|
118
130
|
end
|
119
131
|
end
|
120
|
-
rescue LoadError => e
|
121
|
-
Melissa.config.geo_point_library_loaded = false
|
122
|
-
else
|
123
|
-
Melissa.config.geo_point_library_loaded = true
|
124
132
|
end
|
125
133
|
end
|
126
134
|
end
|
@@ -18,10 +18,10 @@ module Melissa
|
|
18
18
|
else
|
19
19
|
raise "Invalid call to GeoPoint, unknown object #{addr_obj.inspect}"
|
20
20
|
end
|
21
|
-
@latitude =
|
22
|
-
@longitude = -
|
23
|
-
@time_zone_code = '
|
24
|
-
@resultcodes = ['
|
21
|
+
@latitude = 27.850397
|
22
|
+
@longitude = -82.659555
|
23
|
+
@time_zone_code = '05'
|
24
|
+
@resultcodes = ['GS05']
|
25
25
|
@is_valid = true
|
26
26
|
end
|
27
27
|
end
|
data/lib/melissa/railtie.rb
CHANGED
@@ -1,10 +1,24 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'erb'
|
3
|
+
|
1
4
|
module Melissa
|
2
5
|
class Railtie < Rails::Railtie #:nodoc:
|
3
6
|
# Make the Melissa config available in the Rails application config
|
4
7
|
config.before_configuration do
|
5
|
-
config_file = Rails.root.join('config', 'melissa.
|
8
|
+
config_file = Rails.root.join('config', 'melissa.yml')
|
6
9
|
if config_file.file?
|
7
|
-
|
10
|
+
full_config = YAML.load(ERB.new(File.read(config_file)).result(binding))
|
11
|
+
config_hash = full_config[ENV['MELISSA_ENV'] || Rails.env]
|
12
|
+
if config_hash
|
13
|
+
config_hash.each do |key, value|
|
14
|
+
value = value.to_sym if key == 'mode'
|
15
|
+
Melissa.config.send("#{key}=", value)
|
16
|
+
end
|
17
|
+
else
|
18
|
+
Melissa.config.mode = :mock
|
19
|
+
end
|
20
|
+
else
|
21
|
+
Melissa.config.mode = :mock
|
8
22
|
end
|
9
23
|
end
|
10
24
|
end
|
data/lib/melissa/version.rb
CHANGED
data/test/addr_obj_test.rb
CHANGED
@@ -5,17 +5,17 @@ class AddrObjTest < Minitest::Test
|
|
5
5
|
|
6
6
|
describe "live mode" do
|
7
7
|
before do
|
8
|
-
Melissa.config.mode = :live
|
8
|
+
Melissa.config.mode = :live
|
9
9
|
end
|
10
10
|
|
11
11
|
describe "valid?" do
|
12
12
|
it 'handles valid data' do
|
13
|
-
skip "Not run
|
13
|
+
skip "Not run, Melissa library not loaded" unless Melissa::AddrObjLive.lib_loaded?
|
14
14
|
valid_address = Melissa.addr_obj(
|
15
|
-
:
|
16
|
-
:
|
17
|
-
:
|
18
|
-
:
|
15
|
+
address: '2517 Surfwood Dr',
|
16
|
+
city: 'Las Vegas',
|
17
|
+
state: 'NV',
|
18
|
+
zip: '89128'
|
19
19
|
)
|
20
20
|
assert valid_address.valid?
|
21
21
|
assert_equal '2517 Surfwood Dr', valid_address.address
|
@@ -24,13 +24,13 @@ class AddrObjTest < Minitest::Test
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'flags invalid data' do
|
27
|
-
skip "Not run
|
27
|
+
skip "Not run, Melissa library not loaded" unless Melissa::AddrObjLive.lib_loaded?
|
28
28
|
# Zip points to Schenectady, NY
|
29
29
|
invalid_address = Melissa.addr_obj(
|
30
|
-
:
|
31
|
-
:
|
32
|
-
:
|
33
|
-
:
|
30
|
+
address: '123 Who Dr',
|
31
|
+
city: 'WhoVille',
|
32
|
+
state: 'IN',
|
33
|
+
zip: '12345'
|
34
34
|
)
|
35
35
|
assert !invalid_address.valid?
|
36
36
|
end
|
@@ -38,12 +38,12 @@ class AddrObjTest < Minitest::Test
|
|
38
38
|
|
39
39
|
describe "delivery_point" do
|
40
40
|
it 'sets delivery point for valid data' do
|
41
|
-
skip "Not run
|
41
|
+
skip "Not run, Melissa library not loaded" unless Melissa::AddrObjLive.lib_loaded?
|
42
42
|
valid_address = Melissa.addr_obj(
|
43
|
-
:
|
44
|
-
:
|
45
|
-
:
|
46
|
-
:
|
43
|
+
address: '2517 Surfwood Dr',
|
44
|
+
city: 'Las Vegas',
|
45
|
+
state: 'NV',
|
46
|
+
zip: '89128'
|
47
47
|
)
|
48
48
|
assert_equal '89128718217', valid_address.delivery_point
|
49
49
|
end
|
@@ -51,7 +51,7 @@ class AddrObjTest < Minitest::Test
|
|
51
51
|
|
52
52
|
describe 'number of days till licence expires' do
|
53
53
|
it 'checks if we have more than 30 days till license expiration date' do
|
54
|
-
skip "Not run
|
54
|
+
skip "Not run, Melissa library not loaded" unless Melissa::AddrObjLive.lib_loaded?
|
55
55
|
valid_address = Melissa.addr_obj(
|
56
56
|
:address => '2517 Surfwood Dr',
|
57
57
|
:city => 'Las Vegas',
|
@@ -70,10 +70,10 @@ class AddrObjTest < Minitest::Test
|
|
70
70
|
describe "valid?" do
|
71
71
|
it 'handles valid data' do
|
72
72
|
valid_address = Melissa.addr_obj(
|
73
|
-
:
|
74
|
-
:
|
75
|
-
:
|
76
|
-
:
|
73
|
+
address: '9802 Brompton Dr',
|
74
|
+
city: 'Tampa',
|
75
|
+
state: 'Fl',
|
76
|
+
zip: '33626'
|
77
77
|
)
|
78
78
|
assert valid_address.valid?
|
79
79
|
assert_equal '9802 Brompton Dr', valid_address.address
|
@@ -84,10 +84,10 @@ class AddrObjTest < Minitest::Test
|
|
84
84
|
it 'flags invalid data' do
|
85
85
|
# Zip points to Schenectady, NY
|
86
86
|
invalid_address = Melissa.addr_obj(
|
87
|
-
:
|
88
|
-
:
|
89
|
-
:
|
90
|
-
:
|
87
|
+
address: '123 Who Dr',
|
88
|
+
city: 'WhoVille',
|
89
|
+
state: 'IN',
|
90
|
+
zip: ''
|
91
91
|
)
|
92
92
|
assert !invalid_address.valid?
|
93
93
|
end
|
@@ -96,10 +96,10 @@ class AddrObjTest < Minitest::Test
|
|
96
96
|
describe "delivery_point" do
|
97
97
|
it 'sets delivery point for valid data' do
|
98
98
|
valid_address = Melissa.addr_obj(
|
99
|
-
:
|
100
|
-
:
|
101
|
-
:
|
102
|
-
:
|
99
|
+
address: '9802 Brompton Dr',
|
100
|
+
city: 'Tampa',
|
101
|
+
state: 'Fl',
|
102
|
+
zip: '33626'
|
103
103
|
)
|
104
104
|
assert_equal '33626123426', valid_address.delivery_point
|
105
105
|
end
|
data/test/geo_point_test.rb
CHANGED
@@ -5,17 +5,17 @@ class GeoPointTest < Minitest::Test
|
|
5
5
|
|
6
6
|
describe Melissa::GeoPoint do
|
7
7
|
before do
|
8
|
-
Melissa.config.mode = :live
|
8
|
+
Melissa.config.mode = :live
|
9
9
|
end
|
10
10
|
|
11
11
|
describe 'valid?' do
|
12
12
|
it 'creates valid GeoPoint object from valid Address Object' do
|
13
|
-
skip "Not run
|
13
|
+
skip "Not run, Melissa library not loaded" unless Melissa::GeoPointLive.lib_loaded?
|
14
14
|
valid_addr_obj = Melissa.addr_obj(
|
15
|
-
:
|
16
|
-
:
|
17
|
-
:
|
18
|
-
:
|
15
|
+
address: '2517 SURFWOOD DR',
|
16
|
+
city: 'LAS VEGAS',
|
17
|
+
state: 'NV',
|
18
|
+
zip: '89128'
|
19
19
|
)
|
20
20
|
geo_point_obj = Melissa.geo_point(valid_addr_obj)
|
21
21
|
assert geo_point_obj.valid?
|
@@ -28,11 +28,11 @@ class GeoPointTest < Minitest::Test
|
|
28
28
|
#=> 480
|
29
29
|
end
|
30
30
|
it 'creates valid GeoPoint object from the Hash' do
|
31
|
-
skip "Not run
|
31
|
+
skip "Not run, Melissa library not loaded" unless Melissa::GeoPointLive.lib_loaded?
|
32
32
|
geo_point_obj= Melissa.geo_point(
|
33
|
-
:
|
34
|
-
:
|
35
|
-
:
|
33
|
+
zip: '89128',
|
34
|
+
plus4: '7182',
|
35
|
+
delivery_point_code: '17'
|
36
36
|
)
|
37
37
|
|
38
38
|
assert geo_point_obj.valid?
|
@@ -48,12 +48,12 @@ class GeoPointTest < Minitest::Test
|
|
48
48
|
|
49
49
|
describe 'number of days till licence expires' do
|
50
50
|
it 'checks if we have more than 30 days till license expiration date' do
|
51
|
-
skip "Not run
|
51
|
+
skip "Not run, Melissa library not loaded" unless Melissa::GeoPointLive.lib_loaded?
|
52
52
|
valid_addr_obj = Melissa.addr_obj(
|
53
|
-
:
|
54
|
-
:
|
55
|
-
:
|
56
|
-
:
|
53
|
+
address: '2517 SURFWOOD DR',
|
54
|
+
city: 'LAS VEGAS',
|
55
|
+
state: 'NV',
|
56
|
+
zip: '89128'
|
57
57
|
)
|
58
58
|
geo_point = Melissa.geo_point(valid_addr_obj)
|
59
59
|
assert_operator 30, :<, geo_point.class.days_until_license_expiration
|
@@ -61,5 +61,3 @@ class GeoPointTest < Minitest::Test
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
64
|
-
|
65
|
-
|
data/test/melissa_test.rb
CHANGED
@@ -4,17 +4,17 @@ class MelissaTest < Minitest::Test
|
|
4
4
|
|
5
5
|
describe 'Melissa.addr_obj' do
|
6
6
|
before do
|
7
|
-
Melissa.config.mode = :live
|
7
|
+
Melissa.config.mode = :live
|
8
8
|
end
|
9
9
|
|
10
10
|
describe "live mode" do
|
11
11
|
it 'initializes AddrObjLive object' do
|
12
|
-
skip "Not run
|
12
|
+
skip "Not run, Melissa library not loaded" unless Melissa::AddrObjLive.lib_loaded?
|
13
13
|
valid_address = Melissa.addr_obj(
|
14
|
-
:
|
15
|
-
:
|
16
|
-
:
|
17
|
-
:
|
14
|
+
address: '9802 Brompton Dr',
|
15
|
+
city: 'Tampa',
|
16
|
+
state: 'Fl',
|
17
|
+
zip: '33626'
|
18
18
|
)
|
19
19
|
assert_kind_of Melissa::AddrObjLive, valid_address
|
20
20
|
end
|
@@ -27,10 +27,10 @@ class MelissaTest < Minitest::Test
|
|
27
27
|
|
28
28
|
it 'initializes AddrObjMock object' do
|
29
29
|
valid_address = Melissa.addr_obj(
|
30
|
-
:
|
31
|
-
:
|
32
|
-
:
|
33
|
-
:
|
30
|
+
address: '9802 Brompton Dr',
|
31
|
+
city: 'Tampa',
|
32
|
+
state: 'Fl',
|
33
|
+
zip: '33626'
|
34
34
|
)
|
35
35
|
assert_kind_of Melissa::AddrObjMock, valid_address
|
36
36
|
end
|
@@ -39,17 +39,18 @@ class MelissaTest < Minitest::Test
|
|
39
39
|
|
40
40
|
describe 'Melissa.geo_point' do
|
41
41
|
before do
|
42
|
-
Melissa.config.mode = :live
|
42
|
+
Melissa.config.mode = :live
|
43
43
|
end
|
44
44
|
|
45
45
|
describe "live mode" do
|
46
46
|
it 'initializes GeoPointLive object' do
|
47
|
-
skip "Not run
|
47
|
+
skip "Not run, Melissa library not loaded" unless Melissa::AddrObjLive.lib_loaded?
|
48
|
+
skip "Not run, Melissa library not loaded" unless Melissa::GeoPointLive.lib_loaded?
|
48
49
|
valid_addr_obj = Melissa.addr_obj(
|
49
|
-
:
|
50
|
-
:
|
51
|
-
:
|
52
|
-
:
|
50
|
+
address: '9802 Brompton Dr',
|
51
|
+
city: 'Tampa',
|
52
|
+
state: 'Fl',
|
53
|
+
zip: '33626'
|
53
54
|
)
|
54
55
|
geo_point_obj = Melissa.geo_point(valid_addr_obj)
|
55
56
|
assert_kind_of Melissa::GeoPointLive, geo_point_obj
|
@@ -63,14 +64,14 @@ class MelissaTest < Minitest::Test
|
|
63
64
|
|
64
65
|
it 'initializes GeoPointMock object' do
|
65
66
|
valid_addr_obj = Melissa.addr_obj(
|
66
|
-
:
|
67
|
-
:
|
68
|
-
:
|
69
|
-
:
|
67
|
+
address: '9802 Brompton Dr',
|
68
|
+
city: 'Tampa',
|
69
|
+
state: 'Fl',
|
70
|
+
zip: '33626'
|
70
71
|
)
|
71
72
|
geo_point_obj = Melissa.geo_point(valid_addr_obj)
|
72
73
|
assert_kind_of Melissa::GeoPointMock, geo_point_obj
|
73
74
|
end
|
74
75
|
end
|
75
76
|
end
|
76
|
-
end
|
77
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: melissa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brad Pardee
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-04
|
12
|
+
date: 2015-05-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|