diff --git a/api/api.go b/api/api.go index ec97d6f..d4e8fe1 100644 --- a/api/api.go +++ b/api/api.go @@ -34,10 +34,14 @@ type resultResponse struct { Message string `json:"message"` } -func NewAPI(c Config) API { - a := API{username: c.Username, token: c.Token} +// Constructs a new Name.com API +// +// If dev = true, then the API uses the development +// API, instead of the production API. +func NewNameAPI(username, token string, dev bool) API { + a := API{username: username, token: token} - if c.Debug { + if dev { a.baseUrl = devUrl } else { a.baseUrl = productionUrl @@ -46,6 +50,11 @@ func NewAPI(c Config) API { return a } +// Constructs a new Name.com API from a configuration +func NewAPIFromConfig(c Config) API { + return NewNameAPI(c.Username, c.Token, c.Dev) +} + func (api API) performRequest(method, url string, body io.Reader) (response []byte, err error) { var client http.Client req, err := http.NewRequest(method, url, body) @@ -65,6 +74,7 @@ func (api API) performRequest(method, url string, body io.Reader) (response []by return ioutil.ReadAll(resp.Body) } +// Returns a slice of DNS records associated with a given hostname. func (api API) GetRecords(hostname string) (records []DNSRecord, err error) { resp, err := api.performRequest("GET", fmt.Sprintf("%s%s%s", api.baseUrl, "api/dns/list/", hostname), nil) if err != nil { diff --git a/api/config.go b/api/config.go index b4ae90b..dff73e9 100644 --- a/api/config.go +++ b/api/config.go @@ -6,7 +6,7 @@ import ( ) type Config struct { - Debug bool `json:"debug"` + Dev bool `json:"dev"` Domains []string `json:"domains"` Interval int `json:"interval"` Token string `json:"token"` diff --git a/api/config_test.go b/api/config_test.go index 3fce800..0495a13 100644 --- a/api/config_test.go +++ b/api/config_test.go @@ -10,10 +10,10 @@ var expectedConfigs []Config func init() { expectedConfigs = []Config{ Config{ - Username: "debug-account", + Username: "dev-account", Token: "asdasdasdasdasdad", Interval: 60, - Debug: true, + Dev: true, Domains: []string{"test.com", "fake.com"}, }, Config{ diff --git a/api/config_test.json b/api/config_test.json index fbad18f..298283a 100644 --- a/api/config_test.json +++ b/api/config_test.json @@ -1,10 +1,10 @@ { "configs": [ { - "username": "debug-account", + "username": "dev-account", "token": "asdasdasdasdasdad", "interval": 60, - "debug": true, + "dev": true, "domains": [ "test.com", "fake.com" ] }, {