mmdb 0.2.1 → 0.3.0
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/ext/mmdb/mmdb.c +31 -19
- 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: 04e83203d350b85813210cb63cd2f47cab9d7f53
|
4
|
+
data.tar.gz: dac172b67b0bfa2c3591a82819f3adf7f24dabec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3e877c123d0f8cab6d60fd405b7b0936f5aa1e0c71c83eefde0419d0b851c2d0b0df716a47d654839b8f87ba2ef84e92e695a3629ab10931a6f65a20067e4f5
|
7
|
+
data.tar.gz: 3e0b05ed42c42590b4aa36a1e07a38a96a62e33729cdbbf8007745483791668131619b9380e1c0f17feb20184105cc3254b8af00198dc4a8c3145049f55d5e49
|
data/ext/mmdb/mmdb.c
CHANGED
@@ -108,14 +108,14 @@ static void
|
|
108
108
|
maxminddb_set_result(VALUE hash, VALUE key, MMDB_entry_data_s *data) {
|
109
109
|
if (data->has_data) {
|
110
110
|
switch (data->type) {
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
111
|
+
case MMDB_DATA_TYPE_UTF8_STRING:
|
112
|
+
rb_hash_aset(hash, key, rb_utf8_str_new(data->utf8_string, data->data_size));
|
113
|
+
break;
|
114
|
+
case MMDB_DATA_TYPE_DOUBLE:
|
115
|
+
rb_hash_aset(hash, key, rb_float_new(data->double_value));
|
116
|
+
break;
|
117
|
+
default:
|
118
|
+
rb_hash_aset(hash, key, Qnil);
|
119
119
|
}
|
120
120
|
} else {
|
121
121
|
rb_hash_aset(hash, key, Qnil);
|
@@ -145,25 +145,37 @@ maxminddb_initialize(int argc, VALUE* argv, VALUE self) {
|
|
145
145
|
|
146
146
|
/**
|
147
147
|
*
|
148
|
-
* mmdb.lookup("123.45.67.89") -> Hash
|
148
|
+
* mmdb.lookup("123.45.67.89") -> Hash (Default values is English)
|
149
|
+
* mmdb.lookup("123.45.67.89", "ja") -> Hash (Values is Japanese)
|
149
150
|
*
|
150
|
-
* TODO:
|
151
|
-
* To receive `opts` argument that have language code and respond specified language data.
|
152
151
|
*/
|
153
152
|
VALUE
|
154
|
-
maxminddb_lookup(VALUE
|
153
|
+
maxminddb_lookup(int argc, VALUE* argv, VALUE self) {
|
155
154
|
VALUE ret;
|
155
|
+
|
156
156
|
int gai_error, mmdb_error;
|
157
|
+
const char *ip, *lang;
|
157
158
|
struct MaxMindDB *ptr = MaxMindDB(self);
|
158
159
|
MMDB_lookup_result_s lookuped;
|
159
160
|
MMDB_entry_data_s data;
|
160
161
|
MMDB_entry_s *entry;
|
161
162
|
|
162
|
-
if (NIL_P(
|
163
|
+
if (NIL_P(argv[0])) {
|
163
164
|
return Qnil;
|
164
165
|
}
|
166
|
+
ip = StringValuePtr(argv[0]);
|
167
|
+
|
168
|
+
switch (argc) {
|
169
|
+
case 1:
|
170
|
+
lang = en;
|
171
|
+
break;
|
172
|
+
case 2:
|
173
|
+
lang = StringValuePtr(argv[1]);
|
174
|
+
break;
|
175
|
+
}
|
176
|
+
|
165
177
|
|
166
|
-
lookuped = MMDB_lookup_string(ptr->mmdb,
|
178
|
+
lookuped = MMDB_lookup_string(ptr->mmdb, ip, &gai_error, &mmdb_error);
|
167
179
|
if (gai_error) {
|
168
180
|
rb_raise(rb_eTypeError, "%s", gai_strerror(gai_error));
|
169
181
|
}
|
@@ -175,16 +187,16 @@ maxminddb_lookup(VALUE self, VALUE ip) {
|
|
175
187
|
ret = rb_hash_new();
|
176
188
|
entry = &lookuped.entry;
|
177
189
|
|
178
|
-
MMDB_get_value(entry, &data, city, names,
|
190
|
+
MMDB_get_value(entry, &data, city, names, lang, NULL);
|
179
191
|
maxminddb_set_result(ret, rb_sym_city, &data);
|
180
192
|
|
181
|
-
MMDB_get_value(entry, &data, country, names,
|
193
|
+
MMDB_get_value(entry, &data, country, names, lang, NULL);
|
182
194
|
maxminddb_set_result(ret, rb_sym_country, &data);
|
183
195
|
|
184
196
|
MMDB_get_value(entry, &data, country, iso_code, NULL);
|
185
197
|
maxminddb_set_result(ret, rb_sym_country_code, &data);
|
186
198
|
|
187
|
-
MMDB_get_value(entry, &data, continent, names,
|
199
|
+
MMDB_get_value(entry, &data, continent, names, lang, NULL);
|
188
200
|
maxminddb_set_result(ret, rb_sym_continent, &data);
|
189
201
|
|
190
202
|
MMDB_get_value(entry, &data, location, latitude, NULL);
|
@@ -213,7 +225,7 @@ maxminddb_lookup(VALUE self, VALUE ip) {
|
|
213
225
|
|
214
226
|
for (i = 0; i < data.data_size; i++) {
|
215
227
|
sprintf(index, "%d", i);
|
216
|
-
MMDB_get_value(entry, &data, subdivisions, index, names,
|
228
|
+
MMDB_get_value(entry, &data, subdivisions, index, names, lang, NULL);
|
217
229
|
if (data.has_data) {
|
218
230
|
if (data.type == MMDB_DATA_TYPE_UTF8_STRING) {
|
219
231
|
rb_ary_push(ary, rb_utf8_str_new(data.utf8_string, data.data_size));
|
@@ -268,7 +280,7 @@ Init_mmdb() {
|
|
268
280
|
rb_define_alloc_func(rb_cMaxMindDB, maxminddb_alloc);
|
269
281
|
|
270
282
|
rb_define_method(rb_cMaxMindDB, "initialize", maxminddb_initialize, -1);
|
271
|
-
rb_define_method(rb_cMaxMindDB, "lookup", maxminddb_lookup, 1);
|
283
|
+
rb_define_method(rb_cMaxMindDB, "lookup", maxminddb_lookup, -1);
|
272
284
|
rb_define_method(rb_cMaxMindDB, "close", maxminddb_close, 0);
|
273
285
|
|
274
286
|
maxminddb_init_rb_variables();
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mmdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yoppi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|