parent
017a921a4b
commit
7ad5a3a5d6
|
@ -40,5 +40,5 @@ func (q *Model) Alert(builder *django.Builder) ([]*Alert, error) {
|
||||||
|
|
||||||
func (a *Alert) Save() (*internal.Status, error) {
|
func (a *Alert) Save() (*internal.Status, error) {
|
||||||
endpoint := a.model.endpoint("alert")
|
endpoint := a.model.endpoint("alert")
|
||||||
return internal.ResponseStatus(endpoint, Values(a))
|
return internal.ResponseStatus(endpoint, a.model.Values(a))
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,5 +45,5 @@ func (q *Model) Application(builder *django.Builder) ([]*Application, error) {
|
||||||
|
|
||||||
func (a *Application) Save() (*internal.Status, error) {
|
func (a *Application) Save() (*internal.Status, error) {
|
||||||
endpoint := a.model.endpoint("application")
|
endpoint := a.model.endpoint("application")
|
||||||
return internal.ResponseStatus(endpoint, Values(a))
|
return internal.ResponseStatus(endpoint, a.model.Values(a))
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,5 +38,5 @@ func (q *Model) IP(builder *django.Builder) ([]*IP, error) {
|
||||||
|
|
||||||
func (i *IP) Save() (*internal.Status, error) {
|
func (i *IP) Save() (*internal.Status, error) {
|
||||||
endpoint := i.model.endpoint("ip")
|
endpoint := i.model.endpoint("ip")
|
||||||
return internal.ResponseStatus(endpoint, Values(i))
|
return internal.ResponseStatus(endpoint, i.model.Values(i))
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ func (q *Model) NewDjangoBuilder() *django.Builder {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Model) endpoint(model string) string {
|
func (q *Model) endpoint(model string) string {
|
||||||
return fmt.Sprintf("%s/%s", q.URL, model)
|
return fmt.Sprintf("%s/%s/", q.URL, model)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Model) queryEndpoint(model, query string) string {
|
func (q *Model) queryEndpoint(model, query string) string {
|
||||||
|
@ -35,12 +35,25 @@ func (q *Model) queryEndpoint(model, query string) string {
|
||||||
return fmt.Sprintf("%s%s", q.endpoint(model), query)
|
return fmt.Sprintf("%s%s", q.endpoint(model), query)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Values(i interface{}) url.Values {
|
func (q *Model) Values(i interface{}) url.Values {
|
||||||
values := url.Values{}
|
values := url.Values{}
|
||||||
|
values.Set("api", q.Token)
|
||||||
iVal := reflect.ValueOf(i).Elem()
|
iVal := reflect.ValueOf(i).Elem()
|
||||||
typ := iVal.Type()
|
typ := iVal.Type()
|
||||||
for i := 0; i < iVal.NumField(); i++ {
|
for i := 0; i < iVal.NumField(); i++ {
|
||||||
values.Set(strings.ToLower(typ.Field(i).Name), fmt.Sprint(iVal.Field(i)))
|
values.Set(strings.ToLower(typ.Field(i).Tag.Get("json")), PyConvert(iVal.Field(i)))
|
||||||
}
|
}
|
||||||
return values
|
return values
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func PyConvert(value reflect.Value) string {
|
||||||
|
switch value.Kind() {
|
||||||
|
case reflect.Bool:
|
||||||
|
if fmt.Sprint(value) == "true" {
|
||||||
|
return "True"
|
||||||
|
}
|
||||||
|
return "False"
|
||||||
|
default:
|
||||||
|
return fmt.Sprint(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -49,5 +49,5 @@ func (q *Model) Note(builder *django.Builder) ([]*Note, error) {
|
||||||
|
|
||||||
func (n *Note) Save() (*internal.Status, error) {
|
func (n *Note) Save() (*internal.Status, error) {
|
||||||
endpoint := n.model.endpoint("note")
|
endpoint := n.model.endpoint("note")
|
||||||
return internal.ResponseStatus(endpoint, Values(n))
|
return internal.ResponseStatus(endpoint, n.model.Values(n))
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,5 +42,5 @@ func (q *Model) Player(builder *django.Builder) ([]*Player, error) {
|
||||||
|
|
||||||
func (p *Player) Save() (*internal.Status, error) {
|
func (p *Player) Save() (*internal.Status, error) {
|
||||||
endpoint := p.model.endpoint("player")
|
endpoint := p.model.endpoint("player")
|
||||||
return internal.ResponseStatus(endpoint, Values(p))
|
return internal.ResponseStatus(endpoint, p.model.Values(p))
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,5 +62,5 @@ func (q *Model) Ticket(builder *django.Builder) ([]*Ticket, error) {
|
||||||
|
|
||||||
func (t *Ticket) Save() (*internal.Status, error) {
|
func (t *Ticket) Save() (*internal.Status, error) {
|
||||||
endpoint := t.model.endpoint("ticket")
|
endpoint := t.model.endpoint("ticket")
|
||||||
return internal.ResponseStatus(endpoint, Values(t))
|
return internal.ResponseStatus(endpoint, t.model.Values(t))
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,5 +41,5 @@ func (q *Model) TicketNote(builder *django.Builder) ([]*TicketNote, error) {
|
||||||
|
|
||||||
func (t *TicketNote) Save() (*internal.Status, error) {
|
func (t *TicketNote) Save() (*internal.Status, error) {
|
||||||
endpoint := t.model.endpoint("ticketnote")
|
endpoint := t.model.endpoint("ticketnote")
|
||||||
return internal.ResponseStatus(endpoint, Values(t))
|
return internal.ResponseStatus(endpoint, t.model.Values(t))
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,5 +62,5 @@ func (q *Model) UserSettings(builder *django.Builder) ([]*UserSettings, error) {
|
||||||
|
|
||||||
func (u *UserSettings) Save() (*internal.Status, error) {
|
func (u *UserSettings) Save() (*internal.Status, error) {
|
||||||
endpoint := u.model.endpoint("usersettings")
|
endpoint := u.model.endpoint("usersettings")
|
||||||
return internal.ResponseStatus(endpoint, Values(u))
|
return internal.ResponseStatus(endpoint, u.model.Values(u))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue