forked from gungoren/apple-search-ads-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
geo.go
101 lines (87 loc) · 3.73 KB
/
geo.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
Copyright (C) 2021 Mehmet Gungoren.
This file is part of apple-search-ads-go, a package for working with Apple's
Search Ads API.
apple-search-ads-go is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
apple-search-ads-go is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with apple-search-ads-go. If not, see <http://www.gnu.org/licenses/>.
*/
package asa
import (
"context"
)
// GeoService handles communication with build-related methods of the Apple Search Ads API
//
// https://developer.apple.com/documentation/apple_search_ads/search_apps_and_geolocations
type GeoService service
// GeoEntityType is the locations available for targeting.
type GeoEntityType string
const (
// GeoEntityTypeCountry is for a geo targeting locations on Country.
GeoEntityTypeCountry GeoEntityType = "Country"
// GeoEntityTypeAdminArea is for a geo targeting locations on AdminArea.
GeoEntityTypeAdminArea GeoEntityType = "AdminArea"
// GeoEntityTypeLocality is for a geo targeting locations on Locality.
GeoEntityTypeLocality GeoEntityType = "Locality"
)
// SearchGeoQuery defines query parameter for SearchGeos endpoint.
type SearchGeoQuery struct {
Limit int32 `url:"limit,omitempty"`
Offset int32 `url:"offset,omitempty"`
Query string `url:"query,omitempty"`
CountryCode string `url:"countrycode,omitempty"`
Entity GeoEntityType `url:"entity,omitempty"`
}
// SearchEntityListResponse is the response details of geosearch requests
//
// https://developer.apple.com/documentation/apple_search_ads/searchentitylistresponse
type SearchEntityListResponse struct {
SearchEntities []*SearchEntity `json:"data,omitempty"`
Error *ErrorResponseBody `json:"error,omitempty"`
Pagination *PageDetail `json:"pagination,omitempty"`
}
// SearchEntity is the list of geolocations that includes the geoidentifier and entity type
//
// https://developer.apple.com/documentation/apple_search_ads/searchentity
type SearchEntity struct {
DisplayName string `json:"displayName,omitempty"`
Entity string `json:"entity,omitempty"`
ID string `json:"id,omitempty"`
}
// SearchGeos Fetches a list of geolocations for audience refinement
//
// https://developer.apple.com/documentation/apple_search_ads/search_for_geolocations
func (s *GeoService) SearchGeos(ctx context.Context, params *SearchGeoQuery) (*SearchEntityListResponse, *Response, error) {
url := "search/geo"
res := new(SearchEntityListResponse)
resp, err := s.client.get(ctx, url, ¶ms, res)
return res, resp, err
}
// ListGeoQuery defines query parameter for GetGeos endpoint.
type ListGeoQuery struct {
Limit int32 `url:"limit,omitempty"`
Offset int32 `url:"offset,omitempty"`
}
// GeoRequest is the geosearch request
//
// https://developer.apple.com/documentation/apple_search_ads/georequest
type GeoRequest struct {
Entity GeoEntityType `json:"entity"`
ID string `json:"id"`
}
// GetGeos Gets geolocation details using a geoidentifier
//
// https://developer.apple.com/documentation/apple_search_ads/get_a_list_of_geolocations
func (s *GeoService) GetGeos(ctx context.Context, query *ListGeoQuery, params []*GeoRequest) (*SearchEntityListResponse, *Response, error) {
url := "search/geo"
res := new(SearchEntityListResponse)
resp, err := s.client.postWithQuery(ctx, url, &query, ¶ms, res)
return res, resp, err
}