first commit
This commit is contained in:
47
clublog/clublog.go
Normal file
47
clublog/clublog.go
Normal file
@ -0,0 +1,47 @@
|
||||
package clublog
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"git.rouggy.com/CloudlogUDP/config"
|
||||
"git.rouggy.com/CloudlogUDP/qso"
|
||||
)
|
||||
|
||||
type ClublogAPI struct {
|
||||
Email string `json:"email"`
|
||||
Password string `json:"password"`
|
||||
Callsign string `json:"callsign"`
|
||||
ADIF string `json:"adif"`
|
||||
APIKey string `json:"api"`
|
||||
}
|
||||
|
||||
func SendClublogMsg(qso qso.QSO, config config.Config) {
|
||||
QSOData := qso.Call + qso.Band + qso.Mode + qso.Freq + qso.QSODate + qso.TimeOn + qso.RSTR + qso.RSTS + qso.GridSquare + "<eor>"
|
||||
|
||||
apiUrl := config.Clublog.URL
|
||||
data := url.Values{}
|
||||
data.Set("api", config.Clublog.API)
|
||||
data.Set("email", config.Clublog.EMail)
|
||||
data.Set("password", config.Clublog.Password)
|
||||
data.Set("callsign", config.Clublog.Callsign)
|
||||
data.Set("adif", QSOData)
|
||||
|
||||
u, _ := url.ParseRequestURI(apiUrl)
|
||||
urlStr := u.String()
|
||||
|
||||
client := &http.Client{}
|
||||
r, _ := http.NewRequest(http.MethodPost, urlStr, strings.NewReader(data.Encode())) // URL-encoded payload
|
||||
r.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||
|
||||
resp, _ := client.Do(r)
|
||||
|
||||
if http.StatusOK == 200 {
|
||||
fmt.Println("QSO Uploaded to Clublog")
|
||||
} else {
|
||||
fmt.Printf("Error uploading QSO to Clublog %v", resp.Status)
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user