forked from olivere/mapquest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapquest.go
60 lines (51 loc) · 1.47 KB
/
mapquest.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
package mapquest
import (
"net/http"
"net/url"
"strings"
)
const (
Host = "open.mapquestapi.com"
UserAgent = "MapQuest Open Data API Google Go Client v0.1"
)
func apiURL(path ...string) *url.URL {
u := new(url.URL)
u.Scheme = "https"
u.Host = Host
u.Path = "/" + strings.Join(path, "/")
return u
}
// Client is the entry point to all services of the MapQuest Open Data API.
// See https://developer.mapquest.com/documentation/open/ for details about
// what you can do with the MapQuest API.
type Client struct {
httpClient *http.Client
key string
}
// NewClient creates a new client for accessing the MapQuest API. You need
// to specify your AppKey here.
func NewClient(key string) *Client {
return &Client{
key: key,
httpClient: http.DefaultClient,
}
}
// SetHTTPClient allows the caller to specify a special http.Client for
// invoking the MapQuest API. If you do not specify a http.Client, the
// http.DefaultClient from net/http is used.
func (c *Client) SetHTTPClient(client *http.Client) {
if client == nil {
client = http.DefaultClient
}
c.httpClient = client
}
// HTTPClient returns the registered http.Client. Notice that nil can
// be returned here.
func (c *Client) HTTPClient() *http.Client {
return c.httpClient
}
// StaticMap gives access to the MapQuest static map API
// described here: https://developer.mapquest.com/documentation/open/static-map-api/v5/
func (c *Client) StaticMap() *StaticMapAPI {
return &StaticMapAPI{c: c}
}