Skip to content
Snippets Groups Projects
Commit 11ca0a61 authored by Thomas Schneider's avatar Thomas Schneider
Browse files

Fix incorrect API usage

Because documentation by example, yay.
parent c86d6b9d
No related branches found
No related tags found
No related merge requests found
Pipeline #4167 passed
......@@ -5,6 +5,7 @@ import (
"fmt"
"net/http"
"net/url"
"strings"
"time"
)
......@@ -81,16 +82,12 @@ func (c *Client) do(method string, endpoint string, params url.Values) (*http.Re
c.Client = http.DefaultClient
}
u, err := url.Parse(ApiBase + endpoint)
if err != nil {
return nil, err
}
u.RawQuery = params.Encode()
r, err := http.NewRequest(method, u.String(), nil)
r, err := http.NewRequest(method, ApiBase+endpoint,
strings.NewReader(params.Encode()))
if err != nil {
return nil, err
}
r.Header.Set("Content-Type", "application/x-www-form-urlencoded")
r.Header.Set("PRIVATE-TOKEN", c.ApiToken)
res, err := c.Client.Do(r)
......@@ -100,7 +97,7 @@ func (c *Client) do(method string, endpoint string, params url.Values) (*http.Re
func (c *Client) ListZones(search *string) ([]Zone, error) {
q := url.Values{}
if search != nil {
q.Set("search", url.QueryEscape(*search))
q.Set("search", *search)
}
res, err := c.do("GET", "list_zones", q)
......@@ -117,10 +114,10 @@ func (c *Client) ListZones(search *string) ([]Zone, error) {
func (c *Client) ListRecords(zone *int, search *string) ([]Record, error) {
q := url.Values{}
if zone != nil {
q.Add("zone_id", url.QueryEscape(fmt.Sprintf("%d", *zone)))
q.Add("zone_id", fmt.Sprintf("%d", *zone))
}
if search != nil {
q.Add("search", url.QueryEscape(*search))
q.Add("search", *search)
}
res, err := c.do("GET", "list_records", q)
......@@ -136,7 +133,7 @@ func (c *Client) ListRecords(zone *int, search *string) ([]Record, error) {
func (c *Client) DeployZone(zone int) (Zone, error) {
q := url.Values{}
q.Set("zone_id", url.QueryEscape(fmt.Sprintf("%d", zone)))
q.Set("zone_id", fmt.Sprintf("%d", zone))
res, err := c.do("POST", "deploy_zone", q)
if err != nil {
......@@ -151,7 +148,7 @@ func (c *Client) DeployZone(zone int) (Zone, error) {
func (c *Client) CreateRecord(content string) (Record, error) {
q := url.Values{}
q.Set("record_content", url.QueryEscape(content))
q.Set("record_content", content)
res, err := c.do("POST", "create_record", q)
if err != nil {
......@@ -166,8 +163,8 @@ func (c *Client) CreateRecord(content string) (Record, error) {
func (c *Client) UpdateRecord(record int, content string) (Record, error) {
q := url.Values{}
q.Set("record_id", url.QueryEscape(fmt.Sprintf("%d", record)))
q.Set("record_content", url.QueryEscape(content))
q.Set("record_id", fmt.Sprintf("%d", record))
q.Set("record_content", content)
res, err := c.do("POST", "update_record", q)
if err != nil {
......@@ -182,7 +179,7 @@ func (c *Client) UpdateRecord(record int, content string) (Record, error) {
func (c *Client) DestroyRecord(record int) (Record, error) {
q := url.Values{}
q.Set("record_id", url.QueryEscape(fmt.Sprintf("%d", record)))
q.Set("record_id", fmt.Sprintf("%d", record))
res, err := c.do("DELETE", "destroy_record", q)
if err != nil {
......@@ -197,7 +194,7 @@ func (c *Client) DestroyRecord(record int) (Record, error) {
func (c *Client) RestoreRecord(record int) (Record, error) {
q := url.Values{}
q.Set("record_id", url.QueryEscape(fmt.Sprintf("%d", record)))
q.Set("record_id", fmt.Sprintf("%d", record))
res, err := c.do("POST", "restore_record", q)
if err != nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment