mirror of
https://github.com/hanzo-go/sendgrid.git
synced 2026-10-30 15:05:38 +00:00
138 lines
3.6 KiB
Go
138 lines
3.6 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/hanzoai/sendgrid-go"
|
|
"log"
|
|
"os"
|
|
)
|
|
|
|
// Retrieveallrecentaccessattempts : Retrieve all recent access attempts
|
|
// GET /access_settings/activity
|
|
func Retrieveallrecentaccessattempts() {
|
|
apiKey := os.Getenv("YOUR_SENDGRID_APIKEY")
|
|
host := "https://api.sendgrid.com"
|
|
request := sendgrid.GetRequest(apiKey, "/v3/access_settings/activity", host)
|
|
request.Method = "GET"
|
|
queryParams := make(map[string]string)
|
|
queryParams["limit"] = "1"
|
|
request.QueryParams = queryParams
|
|
response, err := sendgrid.API(request)
|
|
if err != nil {
|
|
log.Println(err)
|
|
} else {
|
|
fmt.Println(response.StatusCode)
|
|
fmt.Println(response.Body)
|
|
fmt.Println(response.Headers)
|
|
}
|
|
}
|
|
|
|
// AddoneormoreIPstothewhitelist : Add one or more IPs to the whitelist
|
|
// POST /access_settings/whitelist
|
|
func AddoneormoreIPstothewhitelist() {
|
|
apiKey := os.Getenv("YOUR_SENDGRID_APIKEY")
|
|
host := "https://api.sendgrid.com"
|
|
request := sendgrid.GetRequest(apiKey, "/v3/access_settings/whitelist", host)
|
|
request.Method = "POST"
|
|
request.Body = []byte(` {
|
|
"ips": [
|
|
{
|
|
"ip": "192.168.1.1"
|
|
},
|
|
{
|
|
"ip": "192.*.*.*"
|
|
},
|
|
{
|
|
"ip": "192.168.1.3/32"
|
|
}
|
|
]
|
|
}`)
|
|
response, err := sendgrid.API(request)
|
|
if err != nil {
|
|
log.Println(err)
|
|
} else {
|
|
fmt.Println(response.StatusCode)
|
|
fmt.Println(response.Body)
|
|
fmt.Println(response.Headers)
|
|
}
|
|
}
|
|
|
|
// RetrievealistofcurrentlywhitelistedIPs : Retrieve a list of currently whitelisted IPs
|
|
// GET /access_settings/whitelist
|
|
func RetrievealistofcurrentlywhitelistedIPs() {
|
|
apiKey := os.Getenv("YOUR_SENDGRID_APIKEY")
|
|
host := "https://api.sendgrid.com"
|
|
request := sendgrid.GetRequest(apiKey, "/v3/access_settings/whitelist", host)
|
|
request.Method = "GET"
|
|
response, err := sendgrid.API(request)
|
|
if err != nil {
|
|
log.Println(err)
|
|
} else {
|
|
fmt.Println(response.StatusCode)
|
|
fmt.Println(response.Body)
|
|
fmt.Println(response.Headers)
|
|
}
|
|
}
|
|
|
|
// RemoveoneormoreIPsfromthewhitelist : Remove one or more IPs from the whitelist
|
|
// DELETE /access_settings/whitelist
|
|
func RemoveoneormoreIPsfromthewhitelist() {
|
|
apiKey := os.Getenv("YOUR_SENDGRID_APIKEY")
|
|
host := "https://api.sendgrid.com"
|
|
request := sendgrid.GetRequest(apiKey, "/v3/access_settings/whitelist", host)
|
|
request.Method = "DELETE"
|
|
request.Body = []byte(` {
|
|
"ids": [
|
|
1,
|
|
2,
|
|
3
|
|
]
|
|
}`)
|
|
response, err := sendgrid.API(request)
|
|
if err != nil {
|
|
log.Println(err)
|
|
} else {
|
|
fmt.Println(response.StatusCode)
|
|
fmt.Println(response.Body)
|
|
fmt.Println(response.Headers)
|
|
}
|
|
}
|
|
|
|
// RetrieveaspecificwhitelistedIP : Retrieve a specific whitelisted IP
|
|
// GET /access_settings/whitelist/{rule_id}
|
|
func RetrieveaspecificwhitelistedIP() {
|
|
apiKey := os.Getenv("YOUR_SENDGRID_APIKEY")
|
|
host := "https://api.sendgrid.com"
|
|
request := sendgrid.GetRequest(apiKey, "/v3/access_settings/whitelist/{rule_id}", host)
|
|
request.Method = "GET"
|
|
response, err := sendgrid.API(request)
|
|
if err != nil {
|
|
log.Println(err)
|
|
} else {
|
|
fmt.Println(response.StatusCode)
|
|
fmt.Println(response.Body)
|
|
fmt.Println(response.Headers)
|
|
}
|
|
}
|
|
|
|
// RemoveaspecificIPfromthewhitelist : Remove a specific IP from the whitelist
|
|
// DELETE /access_settings/whitelist/{rule_id}
|
|
func RemoveaspecificIPfromthewhitelist() {
|
|
apiKey := os.Getenv("YOUR_SENDGRID_APIKEY")
|
|
host := "https://api.sendgrid.com"
|
|
request := sendgrid.GetRequest(apiKey, "/v3/access_settings/whitelist/{rule_id}", host)
|
|
request.Method = "DELETE"
|
|
response, err := sendgrid.API(request)
|
|
if err != nil {
|
|
log.Println(err)
|
|
} else {
|
|
fmt.Println(response.StatusCode)
|
|
fmt.Println(response.Body)
|
|
fmt.Println(response.Headers)
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
// add your function calls here
|
|
}
|