-
Notifications
You must be signed in to change notification settings - Fork 1
/
maps.go
52 lines (42 loc) · 1.85 KB
/
maps.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package biteship
import (
"fmt"
"net/http"
"net/url"
)
type Area struct {
ID string `json:"id"`
PostalCode uint `json:"postal_code"`
CountryName string `json:"country_name"`
CountryCode string `json:"country_code"`
AdministrativeDivisionLevel1Name string `json:"administrative_division_level_1_name"`
AdministrativeDivisionLevel1Type string `json:"administrative_division_level_1_type"`
AdministrativeDivisionLevel2Name string `json:"administrative_division_level_2_name"`
AdministrativeDivisionLevel2Type string `json:"administrative_division_level_2_type"`
AdministrativeDivisionLevel3Name string `json:"administrative_division_level_3_name"`
AdministrativeDivisionLevel3Type string `json:"administrative_division_level_3_type"`
AdministrativeDivisionLevel4Name string `json:"administrative_division_level_4_name"`
AdministrativeDivisionLevel4Type string `json:"administrative_division_level_4_type"`
}
type RetrieveAreaResponse struct {
Success bool `json:"success"`
Object string `json:"object"`
Areas []Area `json:"areas"`
}
func (client *Client) RetrieveArea(countries, input string) (*RetrieveAreaResponse, *Error) {
var response RetrieveAreaResponse
v := url.Values{}
v.Set("countries", countries)
v.Set("input", input)
if err := client.HttpRequest.Call(http.MethodGet, fmt.Sprintf("%s/v1/maps/areas?%s", client.BiteshipUrl, v.Encode()), client.SecretKey, nil, &response); err != nil {
return nil, err
}
return &response, nil
}
func (client *Client) RetrieveAreaByID(id string) (*RetrieveAreaResponse, *Error) {
var response RetrieveAreaResponse
if err := client.HttpRequest.Call(http.MethodGet, fmt.Sprintf("%s/v1/maps/areas/%s", client.BiteshipUrl, id), client.SecretKey, nil, &response); err != nil {
return nil, err
}
return &response, nil
}