Skip to content

Commit

Permalink
ns-api: added list-popular call
Browse files Browse the repository at this point in the history
Added `list-popular` api call in `ns.dpi`
Bump version to 0.0.11

Signed-off-by: Tommaso Bailetti <[email protected]>
  • Loading branch information
Tbaile committed Oct 13, 2023
1 parent 1a18350 commit 30c0211
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/ns-api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=ns-api
PKG_VERSION:=0.0.10
PKG_VERSION:=0.0.11
PKG_RELEASE:=1

PKG_BUILD_DIR:=$(BUILD_DIR)/ns-api-$(PKG_VERSION)
Expand Down
49 changes: 49 additions & 0 deletions packages/ns-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2035,6 +2035,55 @@ Example response:
}
```

### list-popular

List popular applications and protocols:

```bash
api-cli ns.dpi list-popular
```

Data can be limited and paginated by using the `limit` and `page` parameters:

```bash
api-cli ns.dpi list-popular --data '{"limit": 3, "page": 2}'
```

**PLEASE NOTE**: `category` field can be missing in some applications/protocols.

Example response:

```json
{
"values": [
{
"id": 10392,
"name": "netify.apple-siri",
"type": "application",
"category": {
"id": 5,
"name": "business"
}
},
{
"id": 142,
"name": "WhatsApp",
"type": "protocol",
"category": {
"id": 24,
"name": "messaging"
}
},
{
"id": 238,
"name": "Apple/Push",
"type": "protocol"
}
]
}
```


### list-rules

List created rules:
Expand Down
10 changes: 9 additions & 1 deletion packages/ns-api/files/ns.dpi
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ if cmd == 'list':
'applications': 'str',
'protocols': 'str'
},
'list-devices': {}
'list-devices': {},
'list-popular': {
'limit': 32,
'page': 32
}
}))
elif cmd == 'call':
action = sys.argv[2]
Expand All @@ -64,6 +68,10 @@ elif cmd == 'call':
print(json.dumps({'message': 'success'}))
elif action == 'list-devices':
print(json.dumps({'values': dpi.list_devices(e_uci)}))
elif action == 'list-popular':
data = json.JSONDecoder().decode(sys.stdin.read())
result = dpi.list_popular(e_uci, data.get('limit', None), data.get('page', 1))
print(json.dumps({'values': result}))
except KeyError as e:
print(json.dumps(utils.validation_error(e.args[0], 'required')))
except json.JSONDecodeError:
Expand Down

0 comments on commit 30c0211

Please sign in to comment.