Skip to content

Commit f524929

Browse files
committed
convert technologies and categories in strings
1 parent 6d0a616 commit f524929

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,40 @@ APIs for the HTTP Archive Technology Report
1717

1818
### Endpoitns
1919

20+
`GET /technologies`
21+
22+
#### Parameters
23+
24+
The following parameters can be used to filter the data:
25+
26+
- `technology` (`required`): A comma-separated string representing the technology name(s).
27+
- `start` (optional): A string representing the start date in the format `YYYY-MM-DD`.
28+
- `end` (optional): A string representing the end date in the format `YYYY-MM-DD`.
29+
- `geo` (optional): A string representing the geographic location.
30+
- `rank` (optional): An string representing the rank.
31+
- `category` (optional): A comma-separated string representing the category name(s).
32+
33+
#### Response
34+
35+
```bash
36+
curl --request GET \
37+
--url 'https://{HOST}/v1/technologies?start=2022-02-01&end=2022-04-01&technology=Smartsupp&client=mobile'
38+
```
39+
40+
41+
Returns a JSON object with the following schema:
42+
43+
```json
44+
[
45+
{
46+
"client": "mobile",
47+
"similar_technologies": null,
48+
"date": "2022-02-01",
49+
"description": "Smartsupp is a live chat tool that offers visitor recording feature.",
50+
"technology": "Smartsupp",
51+
"category": "Live chat",
52+
"origins": 16840
53+
},
54+
...
55+
]
56+
```

functions/technologies/libs/queries.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
from google.cloud import firestore
44
from .result import Result
5+
from .utils import convert_to_array
56

67
DB = firestore.Client(project=os.environ.get('PROJECT'))
78

@@ -10,19 +11,20 @@ def list_data(params):
1011

1112
query = ref
1213
print("params", params)
14+
1315
if 'start' in params:
1416
query = query.where('date', '>=', params['start'])
1517
if 'end' in params:
1618
query = query.where('date', '<=', params['end'])
1719
if 'geo' in params:
1820
query = query.where('geo', '==', params['geo'])
1921
if 'technology' in params:
20-
params_array = json.loads(params['technology'])
22+
params_array = convert_to_array(params['technology'])
2123
query = query.where('technology', 'in', params_array)
2224
if 'rank' in params:
2325
query = query.where('rank', '==', params['rank'])
2426
if 'category' in params:
25-
params_array = json.loads(params['category'])
27+
params_array = convert_to_array(params['category'])
2628
query = query.where('category', 'in', params_array)
2729

2830
documents = query.stream()

functions/technologies/libs/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ def convert_to_hashes(arr):
1111
hash_dict = {inner_arr[0]: inner_arr[1]}
1212
hashes_arr.append(hash_dict)
1313
return hashes_arr
14+
15+
def convert_to_array(data_string):
16+
list = data_string.split(',')
17+
return list

0 commit comments

Comments
 (0)