Skip to content

Commit 8a4a63d

Browse files
committed
Merge pull request #10 from theckman/match_api_changes
Update ASN support to match changes to ipdata.co API
2 parents 3f8c5d0 + 44eac33 commit 8a4a63d

3 files changed

Lines changed: 48 additions & 21 deletions

File tree

client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
)
2020

2121
// Version is the package version
22-
const Version = "0.6.0"
22+
const Version = "0.6.1"
2323

2424
// fqpn is the Fully Qualified Package Name for use in the client's User-Agent
2525
const fqpn = "github.com/theckman/go-ipdata"

client_test.go

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,14 @@ func Test_client_Lookup(t *testing.T) {
229229
name: "valid_address",
230230
i: "76.14.47.42",
231231
o: IP{
232-
IP: "76.14.47.42",
233-
ASN: "AS11404",
232+
IP: "76.14.47.42",
233+
ASN: ASN{
234+
ASN: "AS11404",
235+
Name: "vanoppen.biz LLC",
236+
Domain: "wavebroadband.com",
237+
Route: "76.14.0.0/17",
238+
Type: "isp",
239+
},
234240
Organization: "vanoppen.biz LLC",
235241
City: "San Francisco",
236242
Region: "California",
@@ -556,8 +562,14 @@ func Test_decodeIP(t *testing.T) {
556562
name: "valid_json",
557563
i: testJSONValid,
558564
o: IP{
559-
IP: "76.14.47.42",
560-
ASN: "AS11404",
565+
IP: "76.14.47.42",
566+
ASN: ASN{
567+
ASN: "AS11404",
568+
Name: "vanoppen.biz LLC",
569+
Domain: "wavebroadband.com",
570+
Route: "76.14.0.0/17",
571+
Type: "isp",
572+
},
561573
Organization: "vanoppen.biz LLC",
562574
City: "San Francisco",
563575
Region: "California",
@@ -729,20 +741,26 @@ func Test_decodeIP(t *testing.T) {
729741
}
730742

731743
var testJSONValid = `{
732-
"ip": "76.14.47.42",
733-
"city": "San Francisco",
734-
"region": "California",
735-
"country_name": "United States",
736-
"country_code": "US",
737-
"continent_name": "North America",
738-
"continent_code": "NA",
739-
"latitude": 37.723,
740-
"longitude": -122.4842,
741-
"asn": "AS11404",
742-
"organisation": "vanoppen.biz LLC",
743-
"postal": "94132",
744-
"calling_code": "1",
745-
"flag": "https://ipdata.co/flags/us.png",
744+
"ip": "76.14.47.42",
745+
"city": "San Francisco",
746+
"region": "California",
747+
"country_name": "United States",
748+
"country_code": "US",
749+
"continent_name": "North America",
750+
"continent_code": "NA",
751+
"latitude": 37.723,
752+
"longitude": -122.4842,
753+
"asn": {
754+
"asn": "AS11404",
755+
"name": "vanoppen.biz LLC",
756+
"domain": "wavebroadband.com",
757+
"route": "76.14.0.0/17",
758+
"type": "isp"
759+
},
760+
"organisation": "vanoppen.biz LLC",
761+
"postal": "94132",
762+
"calling_code": "1",
763+
"flag": "https://ipdata.co/flags/us.png",
746764
"emoji_unicode": "U+1F1FA U+1F1F8",
747765
"is_eu": true,
748766
"languages": [

types.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017 Tim Heckman
1+
// Copyright (c) 2017, 2019 Tim Heckman
22
// Use of this source code is governed by the MIT License that can be found in
33
// the LICENSE file at the root of this repository.
44

@@ -8,7 +8,7 @@ package ipdata
88
// API.
99
type IP struct {
1010
IP string `json:"ip"`
11-
ASN string `json:"asn"`
11+
ASN ASN `json:"asn"`
1212
Organization string `json:"organisation"`
1313

1414
City string `json:"city"`
@@ -45,6 +45,15 @@ func (ip IP) String() string {
4545
return ip.IP
4646
}
4747

48+
// ASN represents the Autonomous System Number data returned from the API.
49+
type ASN struct {
50+
ASN string `json:"asn"`
51+
Name string `json:"name"`
52+
Domain string `json:"domain"`
53+
Route string `json:"route"`
54+
Type string `json:"type"`
55+
}
56+
4857
// Language represents the language object within the JSON response from the
4958
// API. This provides information about the language(s) where that IP resides.
5059
type Language struct {

0 commit comments

Comments
 (0)