From 8fac0e87cdc00e504a3c5c8f4d573a88afb0c587 Mon Sep 17 00:00:00 2001 From: Janez Troha Date: Mon, 17 Apr 2023 14:56:33 +0200 Subject: [PATCH] Update to new API --- cron/cron.go | 10 ++++++---- cron/cron_test.go | 5 ++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/cron/cron.go b/cron/cron.go index 16f85b0..7aa44b8 100644 --- a/cron/cron.go +++ b/cron/cron.go @@ -2,6 +2,7 @@ package cron import ( "fmt" + "net/url" "os" "github.com/imroc/req" @@ -21,7 +22,8 @@ func (c *Cron) header() req.Header { } func (c *Cron) url(verb string) string { - return fmt.Sprintf("https://sentry.io/api/0/organizations/%s/monitors/%s/%s/", c.Team, c.Monitor, verb) + s, _ := url.JoinPath("https://sentry.io/api/0/organizations/", c.Team, "monitors", c.Monitor, verb) + return s } func NewMonitor(team, monitor string) Cron { @@ -35,7 +37,7 @@ func NewMonitor(team, monitor string) Cron { } func (m *Cron) Start() error { - _, err := req.Post(m.url("checkins"), m.header(), started.json()) + _, err := req.Post(m.url("/checkins/"), m.header(), started.json()) return err } @@ -43,10 +45,10 @@ func (m *Cron) Stop() error { // handle crash if err := recover(); err != nil { - req.Put(m.url("latest"), m.header(), errored.json()) + req.Put(m.url("/checkins/latest"), m.header(), errored.json()) return nil } - _, err := req.Put(m.url("latest"), m.header(), finished.json()) + _, err := req.Put(m.url("/checkins/latest"), m.header(), finished.json()) return err } diff --git a/cron/cron_test.go b/cron/cron_test.go index a56f3f0..a9e0331 100644 --- a/cron/cron_test.go +++ b/cron/cron_test.go @@ -10,9 +10,8 @@ func TestCron_url(t *testing.T) { verb string want string }{ - {"started", Cron{"team", "dsn", "monitor"}, "checkins", "https://sentry.io/api/0/organizations/team/monitors/monitor/checkins/"}, - {"ok", Cron{"team", "dsn", "monitor"}, "latest", "https://sentry.io/api/0/organizations/team/monitors/monitor/latest/"}, - {"errored", Cron{"team", "dsn", "monitor"}, "latest", "https://sentry.io/api/0/organizations/team/monitors/monitor/latest/"}, + {"started", Cron{"team", "dsn", "monitor"}, "/checkins/", "https://sentry.io/api/0/organizations/team/monitors/monitor/checkins/"}, + {"ok", Cron{"team", "dsn", "monitor"}, "/checkins/latest/", "https://sentry.io/api/0/organizations/team/monitors/monitor/checkins/latest/"}, } for _, tt := range tests {