Skip to content
Permalink
Browse files

allow pushing multiple samples in one api call

  • Loading branch information...
cbrake committed Sep 5, 2019
1 parent 91449cd commit c457088a8f1abb0045425180e83aab101cfd756c
Showing with 374 additions and 964 deletions.
  1. +10 −8 api/devices.go
  2. +2 −2 docs/api.apib
  3. +352 −941 docs/api.html
  4. +10 −13 sim/device.go
@@ -31,18 +31,20 @@ func (h *Devices) processConfig(res http.ResponseWriter, req *http.Request, id s
en.Encode(data.Response{Success: true})
}

func (h *Devices) processSample(res http.ResponseWriter, req *http.Request, id string) {
func (h *Devices) processSamples(res http.ResponseWriter, req *http.Request, id string) {
decoder := json.NewDecoder(req.Body)
var s data.Sample
err := decoder.Decode(&s)
var samples []data.Sample
err := decoder.Decode(&samples)
if err != nil {
http.Error(res, err.Error(), http.StatusBadRequest)
return
}

err = h.db.DeviceSample(id, s)
if err != nil {
http.Error(res, err.Error(), http.StatusInternalServerError)
for _, s := range samples {
err = h.db.DeviceSample(id, s)
if err != nil {
http.Error(res, err.Error(), http.StatusInternalServerError)
}
}

en := json.NewEncoder(res)
@@ -58,9 +60,9 @@ func (h *Devices) ServeHTTP(res http.ResponseWriter, req *http.Request) {
head, req.URL.Path = ShiftPath(req.URL.Path)

switch head {
case "sample":
case "samples":
if req.Method == http.MethodPost {
h.processSample(res, req, id)
h.processSamples(res, req, id)
} else {
http.Error(res, "only POST allowed", http.StatusMethodNotAllowed)
}
@@ -72,7 +72,7 @@ Update config for a particular device
+ Response 200 (application/json)
+ Attributes (StandardResponse)

## Device Sample [/v1/devices/{id}/sample]
## Device Samples [/v1/devices/{id}/samples]

+ Parameters
+ id: 2342 (string) - The ID of the desired device.
@@ -81,7 +81,7 @@ Update config for a particular device
Post samples for a particular device

+ Request (application/json)
+ Attributes (Sample)
+ Attributes (array[Sample])

+ Response 200 (application/json)
+ Attributes (StandardResponse)

0 comments on commit c457088

Please sign in to comment.
You can’t perform that action at this time.