summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/mattermost/mattermost-server/v5/model/push_response.go
blob: e6e8059bfc0c20ca5fdf950c9bab22e18096e2b1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

package model

import (
	"encoding/json"
	"io"
)

const (
	PUSH_STATUS           = "status"
	PUSH_STATUS_OK        = "OK"
	PUSH_STATUS_FAIL      = "FAIL"
	PUSH_STATUS_REMOVE    = "REMOVE"
	PUSH_STATUS_ERROR_MSG = "error"
)

type PushResponse map[string]string

func NewOkPushResponse() PushResponse {
	m := make(map[string]string)
	m[PUSH_STATUS] = PUSH_STATUS_OK
	return m
}

func NewRemovePushResponse() PushResponse {
	m := make(map[string]string)
	m[PUSH_STATUS] = PUSH_STATUS_REMOVE
	return m
}

func NewErrorPushResponse(message string) PushResponse {
	m := make(map[string]string)
	m[PUSH_STATUS] = PUSH_STATUS_FAIL
	m[PUSH_STATUS_ERROR_MSG] = message
	return m
}

func (me *PushResponse) ToJson() string {
	b, _ := json.Marshal(me)
	return string(b)
}

func PushResponseFromJson(data io.Reader) PushResponse {
	decoder := json.NewDecoder(data)

	var objmap PushResponse
	if err := decoder.Decode(&objmap); err != nil {
		return make(map[string]string)
	} else {
		return objmap
	}
}