Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.

Commit 5532000

Browse files
authored
Merge pull request #55 from aliaqa256/add-nodwell
Add nodwell in Roam
2 parents c402435 + f363fe2 commit 5532000

3 files changed

Lines changed: 28 additions & 6 deletions

File tree

geofence.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ func (gf *Geofence) Nearby(key string, lat, lon, meters float64) GeofenceQueryBu
2222
}
2323

2424
// Roam geofence
25-
func (gf *Geofence) Roam(key, target, pattern string, meters int) GeofenceQueryBuilder {
26-
return newGeofenceRoamQueryBuilder(gf.client, key, target, pattern, meters)
25+
func (gf *Geofence) Roam(key, target, pattern string, meters int, nodewell bool) GeofenceQueryBuilder {
26+
return newGeofenceRoamQueryBuilder(gf.client, key, target, pattern, meters, nodewell)
2727
}

geofence_query_builder.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type GeofenceQueryBuilder struct {
2020
detectActions []DetectAction
2121
notifyCommands []NotifyCommand
2222
searchOpts searchOpts
23+
isNodwell bool
2324
}
2425

2526
func newGeofenceQueryBuilder(client tile38Client, cmd, key string, area cmd) GeofenceQueryBuilder {
@@ -31,7 +32,7 @@ func newGeofenceQueryBuilder(client tile38Client, cmd, key string, area cmd) Geo
3132
}
3233
}
3334

34-
func newGeofenceRoamQueryBuilder(client tile38Client, key, target, pattern string, meters int) GeofenceQueryBuilder {
35+
func newGeofenceRoamQueryBuilder(client tile38Client, key, target, pattern string, meters int,nodwell bool) GeofenceQueryBuilder {
3536
return GeofenceQueryBuilder{
3637
client: client,
3738
cmd: "NEARBY",
@@ -40,13 +41,19 @@ func newGeofenceRoamQueryBuilder(client tile38Client, key, target, pattern strin
4041
target: target,
4142
pattern: pattern,
4243
meters: meters,
44+
isNodwell: nodwell,
4345
}
4446
}
4547

48+
4649
func (query GeofenceQueryBuilder) toCmd() cmd {
4750
args := []string{query.key}
4851
args = append(args, query.searchOpts.Args()...)
4952
args = append(args, "FENCE")
53+
if query.isNodwell {
54+
args = append(args, "NODWELL")
55+
}
56+
5057
if len(query.detectActions) > 0 {
5158
actions := make([]string, len(query.detectActions))
5259
for i := range query.detectActions {

query_test.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ func TestChannels(t *testing.T) {
1414
Expected string
1515
}{
1616
{
17-
Cmd: channels.SetChan("foo", geofence.Roam("cat", "dog", "*", 50).Actions(Enter, Exit)).toCmd(),
17+
Cmd: channels.SetChan("foo", geofence.Roam("cat", "dog", "*", 50, false).Actions(Enter, Exit)).toCmd(),
1818
Expected: "SETCHAN foo NEARBY cat FENCE DETECT enter,exit ROAM dog * 50",
1919
},
20+
{
21+
Cmd: channels.SetChan("foo", geofence.Roam("cat", "dog", "*", 50, true).Actions(Enter, Exit)).toCmd(),
22+
Expected: "SETCHAN foo NEARBY cat FENCE NODWELL DETECT enter,exit ROAM dog * 50",
23+
},
2024
}
2125

2226
for _, test := range tests {
@@ -32,9 +36,13 @@ func TestHooks(t *testing.T) {
3236
Expected string
3337
}{
3438
{
35-
Cmd: hooks.SetHook("foo", "localhost:1337", geofence.Roam("cat", "dog", "*", 50).Actions(Enter, Exit)).toCmd(),
39+
Cmd: hooks.SetHook("foo", "localhost:1337", geofence.Roam("cat", "dog", "*", 50, false).Actions(Enter, Exit)).toCmd(),
3640
Expected: "SETHOOK foo localhost:1337 NEARBY cat FENCE DETECT enter,exit ROAM dog * 50",
3741
},
42+
{
43+
Cmd: hooks.SetHook("foo", "localhost:1337", geofence.Roam("cat", "dog", "*", 50, true).Actions(Enter, Exit)).toCmd(),
44+
Expected: "SETHOOK foo localhost:1337 NEARBY cat FENCE NODWELL DETECT enter,exit ROAM dog * 50",
45+
},
3846
}
3947

4048
for _, test := range tests {
@@ -107,12 +115,19 @@ func TestGeofence(t *testing.T) {
107115
Expected: "NEARBY fleet CLIP CURSOR 5 FENCE DETECT enter,exit,cross COMMANDS set,del HASHES 5 POINT 10 20 30",
108116
},
109117
{
110-
Cmd: geofence.Roam("agent", "target", "*", 100).
118+
Cmd: geofence.Roam("agent", "target", "*", 100, false).
111119
Distance().
112120
Wherein("price", 20, 30).
113121
WhereEval("foo", "arg1", "arg2").toCmd(),
114122
Expected: "NEARBY agent WHEREIN price 2 20 30 WHEREEVAL foo 2 arg1 arg2 DISTANCE FENCE ROAM target * 100",
115123
},
124+
{
125+
Cmd: geofence.Roam("agent", "target", "*", 100, true).
126+
Distance().
127+
Wherein("price", 20, 30).
128+
WhereEval("foo", "arg1", "arg2").toCmd(),
129+
Expected: "NEARBY agent WHEREIN price 2 20 30 WHEREEVAL foo 2 arg1 arg2 DISTANCE FENCE NODWELL ROAM target * 100",
130+
},
116131
{
117132
Cmd: geofence.Within("foo").
118133
Bounds(10, 20, 30, 40).

0 commit comments

Comments
 (0)