Skip to content

Commit

Permalink
Merge pull request #32 from Comcast/backwardsCompatable
Browse files Browse the repository at this point in the history
Backwards compatable
  • Loading branch information
njharter authored Jul 27, 2017
2 parents 525089b + be81826 commit 6b560f2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/caduceus/caduceus.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func caduceus(arguments []string) int {
mux.Handle("/api/v1/profile", caduceusHandler.Then(profileWrapper))

// Support the old endpoint too.
mux.Handle("/api/v2/notify", caduceusHandler.Then(serverWrapper))
mux.Handle("/api/v2/notify/{deviceid}/event/{eventtype:.*}", caduceusHandler.Then(serverWrapper))

webhookFactory, err := webhook.NewFactory(v)
if err != nil {
Expand Down
9 changes: 4 additions & 5 deletions src/caduceus/senderWrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,16 @@ func (sw *CaduceusSenderWrapper) Queue(req CaduceusRequest) {
case "application/json":
if url, err := url.Parse(req.TargetURL); nil == err {
elements := strings.Split(url.Path, "/")
if 6 < len(elements) &&
if 5 < len(elements) &&
"" == elements[0] &&
"api" == elements[1] &&
"v2" == elements[2] &&
"notification" == elements[3] &&
"device" == elements[4] &&
"notify" == elements[3] &&
// Skip the device id
"event" == elements[6] {
"event" == elements[5] {

eventType := strings.SplitN(url.Path, "/event/", 2)[1]
deviceID := elements[5]
deviceID := elements[4]
// TODO: this looks like it's wrong, we should fill this out
transID := "12345"
sw.mutex.RLock()
Expand Down
6 changes: 3 additions & 3 deletions src/caduceus/senderWrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,17 @@ func TestSwSimple(t *testing.T) {
iot := CaduceusRequest{
Payload: []byte("Hello, world."),
ContentType: "application/json",
TargetURL: "http://foo.com/api/v2/notification/device/mac:112233445566/event/iot",
TargetURL: "http://foo.com/api/v2/notify/mac:112233445566/event/iot",
}
test := CaduceusRequest{
Payload: []byte("Hello, world."),
ContentType: "application/json",
TargetURL: "http://foo.com/api/v2/notification/device/mac:112233445566/event/test",
TargetURL: "http://foo.com/api/v2/notify/mac:112233445566/event/test",
}
wrp := CaduceusRequest{
Payload: buffer.Bytes(),
ContentType: "application/wrp",
TargetURL: "http://foo.com/api/v2/notification/device/mac:112233445566/event/wrp",
TargetURL: "http://foo.com/api/v2/notify/mac:112233445566/event/wrp",
}

trans := &swTransport{}
Expand Down

0 comments on commit 6b560f2

Please sign in to comment.