You've already forked email-api-client
71 lines
1.4 KiB
Go
Executable File
71 lines
1.4 KiB
Go
Executable File
package client
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"strconv"
|
|
)
|
|
|
|
func (client *Client) GetEmails(page uint16, limit uint16) (*EmailResponse, error) {
|
|
response := Response[EmailResponse]{}
|
|
|
|
httpClient := &http.Client{}
|
|
req, _ := http.NewRequest(
|
|
"GET",
|
|
client.config.Endpoint+"/api/email?page="+strconv.Itoa(int(page))+"&limit="+strconv.Itoa(int(limit)),
|
|
nil,
|
|
)
|
|
req.Header.Set("Authorization", client.token.TokenType+" "+client.token.AccessToken)
|
|
get, err := httpClient.Do(req)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if get.StatusCode >= 400 {
|
|
return nil, fmt.Errorf("")
|
|
}
|
|
|
|
body := make([]byte, get.ContentLength)
|
|
_, err = get.Body.Read(body)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
err = json.Unmarshal(body, &response)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &response.Payload, nil
|
|
}
|
|
|
|
func (client *Client) GetEmail(uuid string) (*Email, error) {
|
|
httpClient := &http.Client{}
|
|
req, _ := http.NewRequest(
|
|
"GET",
|
|
client.config.Endpoint+"/api/email/"+uuid,
|
|
nil,
|
|
)
|
|
req.Header.Set("Authorization", client.token.TokenType+" "+client.token.AccessToken)
|
|
get, err := httpClient.Do(req)
|
|
defer get.Body.Close()
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if get.StatusCode >= 400 {
|
|
return nil, fmt.Errorf("")
|
|
}
|
|
|
|
response := Response[Email]{}
|
|
err = json.NewDecoder(get.Body).Decode(&response)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &response.Payload, nil
|
|
}
|