Skip to content

Commit 13731b1

Browse files
committed
conver parameters to comma separated string
1 parent f524929 commit 13731b1

File tree

3 files changed

+54
-4
lines changed

3 files changed

+54
-4
lines changed

README.md

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

1818
### Endpoitns
1919

20-
`GET /technologies`
20+
GitHub Copilot: Sure, here's an updated documentation for the `/list_data` endpoint that includes all possible parameters:
21+
22+
# List Data Endpoint
23+
24+
This endpoint returns a list of data from the `adoption` collection in Firestore.
25+
26+
## Edndpointd
27+
28+
### `GET /adoption`
29+
30+
#### Parameters
31+
32+
The following parameters can be used to filter the data:
33+
34+
- `geo` (`required`): A string representing the geographic location.
35+
- `technology` (`required`): A comma-separated string representing the technology name(s).
36+
- `rank` (`required`): An string representing the rank.
37+
- `start` (optional): A string representing the start date in the format `YYYY-MM-DD`.
38+
- `end` (optional): A string representing the end date in the format `YYYY-MM-DD`.
39+
40+
#### Response
41+
42+
```bash
43+
curl --request GET \
44+
--url 'https://{{HOST}}/v1/adoption?start=2023-01-01&end=2023-09-01&geo=Mexico&technology=GoCache&rank=ALL'
45+
```
46+
47+
Returns a JSON object with the following schema:
48+
49+
```json
50+
[
51+
{
52+
"technology": "GoCache",
53+
"geo": "Mexico",
54+
"date": "2023-06-01",
55+
"rank": "ALL",
56+
"adoption": {
57+
"mobile": 19,
58+
"desktop": 11
59+
}
60+
},
61+
...
62+
]
63+
```
64+
65+
66+
### `GET /technologies`
2167

2268
#### Parameters
2369

@@ -34,10 +80,9 @@ The following parameters can be used to filter the data:
3480

3581
```bash
3682
curl --request GET \
37-
--url 'https://{HOST}/v1/technologies?start=2022-02-01&end=2022-04-01&technology=Smartsupp&client=mobile'
83+
--url 'https://{{HOST}}/v1/technologies?start=2022-02-01&end=2022-04-01&category=Live%20chat%2C%20blog&technology=Smartsupp&client=mobile'
3884
```
3985

40-
4186
Returns a JSON object with the following schema:
4287

4388
```json

functions/adoption/libs/queries.py

Lines changed: 2 additions & 1 deletion
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

@@ -17,7 +18,7 @@ def list_data(params):
1718
if 'geo' in params:
1819
query = query.where('geo', '==', params['geo'])
1920
if 'technology' in params:
20-
params_array = json.loads(params['technology'])
21+
params_array = convert_to_array(params['technology'])
2122
query = query.where('technology', 'in', params_array)
2223
if 'rank' in params:
2324
query = query.where('rank', '==', params['rank'])

functions/adoption/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)