commit
63a8948267
35
v1/client.go
35
v1/client.go
@ -7,6 +7,8 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/go-querystring/query"
|
||||||
)
|
)
|
||||||
|
|
||||||
// New initialize client
|
// New initialize client
|
||||||
@ -18,6 +20,39 @@ func New(url string, token string) *MgClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TransportChannels returns channels list
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var client = v1.New("https://token.url", "cb8ccf05e38a47543ad8477d49bcba99be73bff503ea6")
|
||||||
|
//
|
||||||
|
// data, status, err := client.TransportChannels{Channels{Active: true}}
|
||||||
|
//
|
||||||
|
// if err != nil {
|
||||||
|
// fmt.Printf("%v", err)
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// fmt.Printf("Status: %v, Channels found: %v", status, len(data))
|
||||||
|
func (c *MgClient) TransportChannels(request Channels) ([]ChannelListItem, int, error) {
|
||||||
|
var resp []ChannelListItem
|
||||||
|
outgoing, _ := query.Values(request)
|
||||||
|
|
||||||
|
data, status, err := c.GetRequest(fmt.Sprintf("/channels?%s", outgoing.Encode()))
|
||||||
|
if err != nil {
|
||||||
|
return resp, status, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := json.Unmarshal(data, &resp); err != nil {
|
||||||
|
return resp, status, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if status > http.StatusCreated || status < http.StatusOK {
|
||||||
|
return resp, status, c.Error(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp, status, err
|
||||||
|
}
|
||||||
|
|
||||||
// ActivateTransportChannel implement channel activation
|
// ActivateTransportChannel implement channel activation
|
||||||
//
|
//
|
||||||
// Example:
|
// Example:
|
||||||
|
@ -19,6 +19,18 @@ func client() *MgClient {
|
|||||||
return New(mgURL, mgToken)
|
return New(mgURL, mgToken)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMgClient_TransportChannels(t *testing.T) {
|
||||||
|
c := client()
|
||||||
|
|
||||||
|
data, status, err := c.TransportChannels(Channels{Active: true})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("%d %v", status, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Logf("Channels found: %v", len(data))
|
||||||
|
}
|
||||||
|
|
||||||
func TestMgClient_ActivateTransportChannel(t *testing.T) {
|
func TestMgClient_ActivateTransportChannel(t *testing.T) {
|
||||||
c := client()
|
c := client()
|
||||||
ch := Channel{
|
ch := Channel{
|
||||||
|
25
v1/types.go
25
v1/types.go
@ -105,6 +105,31 @@ type DeleteResponse struct {
|
|||||||
DectivatedAt time.Time `json:"deactivated_at"`
|
DectivatedAt time.Time `json:"deactivated_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ChannelListItem response struct
|
||||||
|
type ChannelListItem struct {
|
||||||
|
ID uint64 `json:"id"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Name *string `json:"name"`
|
||||||
|
Settings ChannelSettings `json:"settings"`
|
||||||
|
CreatedAt string `json:"created_at"`
|
||||||
|
UpdatedAt *string `json:"updated_at"`
|
||||||
|
ActivatedAt string `json:"activated_at"`
|
||||||
|
DeactivatedAt *string `json:"deactivated_at"`
|
||||||
|
IsActive bool `json:"is_active"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Channels request type
|
||||||
|
type Channels struct {
|
||||||
|
ID int `json:"id,omitempty"`
|
||||||
|
Types []string `json:"types,omitempty"`
|
||||||
|
Active bool `json:"active,omitempty"`
|
||||||
|
Since time.Time `json:"since,omitempty"`
|
||||||
|
Until time.Time `json:"until,omitempty"`
|
||||||
|
TransportID uint64 `json:"transport_id,omitempty"`
|
||||||
|
Sort string `json:"sort,omitempty"`
|
||||||
|
Limit int `json:"limit,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
// User struct
|
// User struct
|
||||||
type User struct {
|
type User struct {
|
||||||
ExternalID string `json:"external_id"`
|
ExternalID string `json:"external_id"`
|
||||||
|
Loading…
Reference in New Issue
Block a user