You've already forked email-api-client
We Had To Use Dark Magic To Make This Work
This commit is contained in:
70
client/get.go
Executable file
70
client/get.go
Executable file
@@ -0,0 +1,70 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user