Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/delef/maxminddb.cr
MaxMind DB Reader for Crystal
https://github.com/delef/maxminddb.cr
crystal geoip2 maxmind-db maxmind-geoip
Last synced: about 2 months ago
JSON representation
MaxMind DB Reader for Crystal
- Host: GitHub
- URL: https://github.com/delef/maxminddb.cr
- Owner: delef
- License: mit
- Created: 2018-05-14T23:36:57.000Z (about 6 years ago)
- Default Branch: main
- Last Pushed: 2023-02-03T10:21:35.000Z (over 1 year ago)
- Last Synced: 2024-02-01T15:51:22.312Z (5 months ago)
- Topics: crystal, geoip2, maxmind-db, maxmind-geoip
- Language: Crystal
- Homepage:
- Size: 144 KB
- Stars: 24
- Watchers: 4
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Lists
- awesome-crystal - maxminddb.cr - MaxMindDB reader (Data Formats)
- awesome-crystal - maxminddb.cr - MaxMindDB reader (Data Formats)
- awesome-crystal - maxminddb.cr - parsing MaxMindDB files, including the GeoIP2 (Data Formats)
README
# MaxMindDB.cr
[![Built with Crystal](https://img.shields.io/badge/built%20with-crystal-000000.svg?style=flat-square)](https://crystal-lang.org/)
[![Build Status](https://api.travis-ci.org/delef/maxminddb.cr.svg)](https://travis-ci.org/delef/maxminddb.cr)
[![Releases](https://img.shields.io/github/release/delef/maxminddb.cr.svg?style=flat-square)](https://github.com/delef/maxminddb.cr/releases)Pure Crystal [MaxMind DB](http://maxmind.github.io/MaxMind-DB/) reader, which doesn't require [libmaxminddb](https://github.com/maxmind/libmaxminddb).
**_If you work with GeoIP2, please use: https://github.com/delef/geoip2.cr_**
## Installation
Add this to your application's `shard.yml`:
```yaml
dependencies:
maxminddb:
github: delef/maxminddb.cr
```## Usage
```crystal
require "maxminddb"mmdb = MaxMindDB.open("#{__DIR__}/../data/GeoLite2-City.mmdb")
result = mmdb.get("1.1.1.1")result["city"]["geoname_id"].as_i # => 2151718
result["city"]["names"]["en"].as_s # => "Research"result["continent"]["code"].as_s # => "OC"
result["continent"]["geoname_id"].as_i # => 6255151
result["continent"]["names"]["en"].as_s # => "Oceania"result["country"]["iso_code"].as_s # => "AU"
result["country"]["geoname_id"].as_i # => 2077456
result["country"]["names"]["en"].as_s # => "Australia"result["location"]["accuracy_radius"].as_i # => 1000
result["location"]["latitude"].as_f # => -37.7
result["location"]["longitude"].as_f # => 145.1833
result["location"]["time_zone"].as_s # => "Australia/Melbourne"result["postal"]["code"].as_s # => "3095"
result["registered_country"]["iso_code"].as_s # => "AU"
result["registered_country"]["geoname_id"].as_i # => 2077456
result["registered_country"]["names"]["en"].as_s # => "Australia"result["subdivisions"][0]["iso_code"].as_s # => "VIC"
result["subdivisions"][0]["geoname_id"].as_i # => 2145234
result["subdivisions"][0]["names"]["en"].as_s # => "Victoria"
```## Links
- MaxMind DB file format specification http://maxmind.github.io/MaxMind-DB/
- MaxMind test/sample DB files https://github.com/maxmind/MaxMind-DB
- GeoLite2 Free Downloadable Databases http://dev.maxmind.com/geoip/geoip2/geolite2/## Contributing
1. Fork it ( https://github.com/delef/maxminddb.cr/fork )
2. Create your feature branch (git checkout -b my-new-feature)
3. Commit your changes (git commit -am 'Add some feature')
4. Push to the branch (git push origin my-new-feature)
5. Create a new Pull Request