// Alert sets the aps alert on the payload.
// This will display a notification alert message to the user.
//
//	{"aps":{"alert":alert}}`
351875
func (p *Payload) Alert(alert interface{}) *Payload {
	p.aps().Alert = alert
	return p
}
629850
func (a *AlertsService) Create(alert *Alert) (*Alert, *http.Response, error) {
	req, err := a.client.NewRequest("POST", "alerts", alert)
	if err != nil {
		return nil, nil, err
	}

	al := new(Alert)
	resp, err := a.client.Do(req, al)
	if err != nil {
		return nil, resp, err
	}

	return al, resp, err
}
1370805
func (s *AlertService) GetAlertByName(name string, opts ...OptionFunc) (*Alert, int, error) {
	id, count, err := s.GetAlertID(name, opts...)
	if err != nil {
		return nil, count, err
	}

	r, count, err := s.GetAlertByID(id, opts...)
	if err != nil {
		return nil, count, err
	}
	return r, count, nil
}
600277
func (w *Writer) Alert(m string) (err error) {
	_, err = w.writeAndRetry(LOG_ALERT, m)
	return err
}
164587
func (l *Logger) Alertf(format string, va ...interface{}) error {
	return l.logMsg(nil, LEVEL_ALERT, format, va...)
}
575570
func (a *AlertsService) Update(alertID uint, alert *Alert) (*http.Response, error) {
	u := fmt.Sprintf("alerts/%d", alertID)
	req, err := a.client.NewRequest("PUT", u, alert)
	if err != nil {
		return nil, err
	}

	return a.client.Do(req, nil)
}
1288331
func (s *AlertService) GenerateAlert(p *GenerateAlertParams) (*GenerateAlertResponse, error) {
	resp, err := s.cs.newRequest("generateAlert", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r GenerateAlertResponse
	if err := json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	// If we have a async client, we need to wait for the async result
	if s.cs.async {
		b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
		if err != nil {
			if err == AsyncTimeoutErr {
				return &r, err
			}
			return nil, err
		}

		if err := json.Unmarshal(b, &r); err != nil {
			return nil, err
		}
	}

	return &r, nil
}
619104
func (a *APS) Map() map[string]interface{} {
	aps := make(map[string]interface{}, 5)

	if !a.Alert.isZero() {
		if a.Alert.isSimple() {
			aps["alert"] = a.Alert.Body
		} else {
			aps["alert"] = a.Alert
		}
	}
	if n, ok := a.Badge.Number(); ok {
		aps["badge"] = n
	}
	if a.Sound != "" {
		aps["sound"] = a.Sound
	}
	if a.ContentAvailable {
		aps["content-available"] = 1
	}
	if a.Category != "" {
		aps["category"] = a.Category
	}
	if a.MutableContent {
		aps["mutable-content"] = 1
	}
	if a.ThreadID != "" {
		aps["thread-id"] = a.ThreadID
	}

	// wrap in "aps" to form the final payload
	return map[string]interface{}{"aps": aps}
}
217737
func NewAlertFromPayload(serializedPayload []byte, pver uint32) (*Alert, error) {
	var alert Alert
	r := bytes.NewReader(serializedPayload)
	err := alert.Deserialize(r, pver)
	if err != nil {
		return nil, err
	}
	return &alert, nil
}
431737
func (cli *OpsGenieClient) AlertV2() (*OpsGenieAlertV2Client, error) {
	cli.makeHTTPTransportSettings()

	alertClient := new(OpsGenieAlertV2Client)
	alertClient.SetOpsGenieClient(*cli)

	if cli.opsGenieAPIURL == "" {
		alertClient.SetOpsGenieAPIUrl(endpointURL)
	}

	return alertClient, nil
}
1066225
func (e *Errors) Notice(format string, a ...interface{}) error {
	return e.add(Notice, format, a...)
}
37559
func (notifier *Notifier) AutoNotify(rawData ...interface{}) {
	if err := recover(); err != nil {
		severity := notifier.getDefaultSeverity(rawData, SeverityError)
		state := HandledState{SeverityReasonHandledPanic, severity, true, ""}
		rawData = notifier.appendStateIfNeeded(rawData, state)
		// We strip the following stackframes as they don't add much
		// information but would mess with the grouping algorithm
		// { "file": "github.com/bugsnag/bugsnag-go/notifier.go", "lineNumber": 116, "method": "(*Notifier).AutoNotify" },
		// { "file": "runtime/asm_amd64.s", "lineNumber": 573, "method": "call32" },
		skipFrames := 2
		notifier.NotifySync(errors.New(err, skipFrames), true, rawData...)
		panic(err)
	}
}
622266
func Notify(title, message, appIcon string) (err error) {
	defer func() {
		e := recover()

		if e == nil {
			return
		}

		if e, ok := e.(*js.Error); ok {
			err = e
		} else {
			panic(e)
		}
	}()

	n := js.Global().Get("Notification")

	opts := js.Global().Get("Object").Invoke()
	opts.Set("body", message)
	opts.Set("icon", pathAbs(appIcon))

	if n.Get("permission").String() == "granted" {
		n.New(js.ValueOf(title), opts)
	} else {
		var f js.Callback
		f = js.NewCallback(func(args []js.Value) {
			if args[0].String() == "granted" {
				n.New(js.ValueOf(title), opts)
			}
			f.Release()
		})

		n.Call("requestPermission", f)
	}

	return
}
444383
func (client *Client) Payload(command Command) (url.Values, error) {
	params, err := prepareValues("", command)
	if err != nil {
		return nil, err
	}
	if hookReq, ok := command.(onBeforeHook); ok {
		if err := hookReq.onBeforeSend(params); err != nil {
			return params, err
		}
	}
	params.Set("apikey", client.APIKey)
	params.Set("command", client.APIName(command))
	params.Set("response", "json")

	if params.Get("expires") == "" && client.Expiration >= 0 {
		params.Set("signatureversion", "3")
		params.Set("expires", time.Now().Add(client.Expiration).Local().Format("2006-01-02T15:04:05-0700"))
	}

	return params, nil
}
1368435
func (c *Conn) sendAlert(err Alert) error {
	c.handshakeMutex.Lock()
	defer c.handshakeMutex.Unlock()

	var level int
	switch err {
	case AlertNoRenegotiation, AlertCloseNotify:
		level = AlertLevelWarning
	default:
		level = AlertLevelError
	}

	buf := []byte{byte(err), byte(level)}
	c.out.WriteRecord(&TLSPlaintext{
		contentType: RecordTypeAlert,
		fragment:    buf,
	})

	// close_notify and end_of_early_data are not actually errors
	if level == AlertLevelWarning {
		return &net.OpError{Op: "local error", Err: err}
	}

	return c.Close()
}
247648
func (f *File) Warn(pos token.Pos, args ...interface{}) {
	fmt.Fprintf(os.Stderr, "%s%s", f.locPrefix(pos), fmt.Sprintln(args...))
}
185692
func (c *Client) GetAlert(ctx context.Context, id string) (*Alert, error) {
	var alert Alert
	path := fmt.Sprintf(alertInfoPath, id)

	req, err := c.NewRequest("GET", path, nil, nil)
	if err != nil {
		return nil, err
	}

	if err := c.Do(ctx, req, &alert); err != nil {
		return nil, err
	}

	return &alert, err
}