-
Notifications
You must be signed in to change notification settings - Fork 1
/
nomics.go
64 lines (51 loc) · 1.42 KB
/
nomics.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
package nomics
import (
"net/http"
)
const (
APIBase = "https://api.nomics.com/v1"
CurrenciesTickerRoute = "currencies/ticker"
CurrenciesMetadataRoute = "currencies"
MarketsRoute = "markets"
MarketCapHistoryRoute = "market-cap/history"
GlobalVolumeHistoryRoute = "volume/history"
FiatExchangeRatesRoute = "exchange-rates"
FiatExchangeRatesHistoryRoute = "exchange-rates/history"
)
// Noimcs defines the supported subset of the nomics API.
type Nomics interface {
APIBase() string
APIKey() string
Client() *http.Client
SetClient(client *http.Client)
}
// NomicsBase bundles data needed by a large number of methods in order to interact with the nomics API.
type NomicsBase struct {
apiBase string
apiKey string
client *http.Client
}
// NewNomics creates a new client instance.
func NewNomics(apiKey string) *NomicsBase {
return &NomicsBase{
apiBase: APIBase,
apiKey: apiKey,
client: http.DefaultClient,
}
}
// APIBase returns the API Base URL configured for this client.
func (nm *NomicsBase) APIBase() string {
return nm.apiBase
}
// ApiKey returns the API key configured for this client.
func (nm *NomicsBase) APIKey() string {
return nm.apiKey
}
// Client returns the HTTP client configured for this client.
func (nm *NomicsBase) Client() *http.Client {
return nm.client
}
// SetClient updates the HTTP client for this client.
func (nm *NomicsBase) SetClient(c *http.Client) {
nm.client = c
}