summaryrefslogtreecommitdiff
path: root/golang/pkg/api/register.go
blob: 4f45cd193697da7a01df69d6ee008d5180ad4de9 (plain)
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
package api

import (
	"encoding/json"
	"fmt"
	"net/url"
)

type RegisterMessage struct {
	//agent
	//contract
	//faction
	//ship
	Token string `json:"token"`
}

func (c *Client) Register(faction, symbol string) (*RegisterMessage, error) {
	type RegisterRequest struct {
		Faction string `json:"faction"`
		Symbol  string `json:"symbol"`
	}
	uriRef := url.URL{Path: "register"}
	msg, err := c.Send("POST", &uriRef, RegisterRequest{
		Faction: faction,
		Symbol:  symbol,
	})
	if err != nil {
		return nil, err
	}
	if msg.Error != nil {
		return nil, msg.Error
	}
	var response RegisterMessage
	if err := json.Unmarshal(msg.Data, &response); err != nil {
		return nil, fmt.Errorf("failed to unmarshal register data: %w", err)
	}
	return &response, nil
}