README.md in mainstreet-0.2.0 vs README.md in mainstreet-0.2.1
- old
+ new
@@ -2,10 +2,12 @@
Address verification for Ruby and Rails
:earth_americas: Supports international addresses
+[](https://travis-ci.org/ankane/mainstreet)
+
## Installation
Add this line to your application’s Gemfile:
```ruby
@@ -58,12 +60,20 @@
class User < ApplicationRecord
validates_address fields: [:street, :street2, :city, :state, :postal_code]
end
```
-For performance, the address is only verified if at least one of the fields changes. The order should be the same as if you were to write the address out.
+The order should be the same as if you were to write the address out.
+For performance, the address is only verified if at least one of the fields changes. Set your own condition with:
+
+```ruby
+class User < ApplicationRecord
+ validates_address if: -> { something_changed? }, ...
+end
+```
+
Geocode the address with:
```ruby
class User < ApplicationRecord
validates_address geocode: true, ...
@@ -94,38 +104,46 @@
MainStreet::AddressVerifier.new(address, country: "France")
```
Here’s the list of [supported countries](https://smartystreets.com/docs/cloud/international-street-api#countries). You can pass the name, ISO-3, ISO-2, or ISO-N code (like `France`, `FRA`, `FR`, or `250`).
-**Note:** You’ll also need to use a fork of Geocoder until [this PR](https://github.com/alexreisner/geocoder/pull/1367) is merged.
-
-```ruby
-gem 'geocoder', github: 'ankane/geocoder', branch: 'smarty_streets_international'
-```
-
For Active Record, use:
```ruby
class User < ApplicationRecord
- validates_address country: "France"
+ validates_address country: "France", ...
end
```
Or use a proc to make it dynamic
```ruby
class User < ApplicationRecord
- validates_address country: -> { country }
+ validates_address country: -> { country }, ...
end
```
-## Data Privacy
+## Internationalization (i18n)
-We recommend encrypting the street information for user addresses. Check out [this article](https://ankane.org/sensitive-data-rails) for more details.
+You can customize error messages with the [i18n](https://github.com/ruby-i18n/i18n) gem. In Rails, add to the appropriate `config/locales` file:
+```yml
+en:
+ mainstreet:
+ errors:
+ messages:
+ unconfirmed: Address can't be confirmed
+ apt_unconfirmed: Apartment or suite can't be confirmed
+ apt_missing: Apartment or suite is missing
+```
+
+## Data Protection
+
+We recommend encrypting street information and postal code (at the very least) for user addresses. [Lockbox](https://github.com/ankane/lockbox) is great for this. Check out [this article](https://ankane.org/sensitive-data-rails) for more details.
+
```ruby
class User < ApplicationRecord
- attr_encrypted :street, key: ...
+ encrypts :street, :postal_code
end
```
## Upgrading