Closed dpastoor closed 2 years ago
some tests:
regular:
❯ go run main.go daily dplyr ggplot2
Package: dplyr
2022-01-13: 55223
2022-01-14: 50035
2022-01-15: 28902
2022-01-16: 28955
2022-01-17: 46963
2022-01-18: 55283
2022-01-19: 59652
Package: ggplot2
2022-01-13: 73446
2022-01-14: 70471
2022-01-15: 50345
2022-01-16: 50184
2022-01-17: 67054
2022-01-18: 74793
2022-01-19: 81060
with json:
❯ go run main.go daily dplyr ggplot2 --json
[
{
"downloads": [
{
"day": "2022-01-13",
"downloads": 55223
},
{
"day": "2022-01-14",
"downloads": 50035
},
{
"day": "2022-01-15",
"downloads": 28902
},
{
"day": "2022-01-16",
"downloads": 28955
},
{
"day": "2022-01-17",
"downloads": 46963
},
{
"day": "2022-01-18",
"downloads": 55283
},
{
"day": "2022-01-19",
"downloads": 59652
}
],
"start": "2022-01-13",
"end": "2022-01-19",
"package": "dplyr"
},
{
"downloads": [
{
"day": "2022-01-13",
"downloads": 73446
},
{
"day": "2022-01-14",
"downloads": 70471
},
{
"day": "2022-01-15",
"downloads": 50345
},
{
"day": "2022-01-16",
"downloads": 50184
},
{
"day": "2022-01-17",
"downloads": 67054
},
{
"day": "2022-01-18",
"downloads": 74793
},
{
"day": "2022-01-19",
"downloads": 81060
}
],
"start": "2022-01-13",
"end": "2022-01-19",
"package": "ggplot2"
}
]
nonsense package names just return 0 downloads, rather than an error, so "error checking" for invalid packages isn't really a thing. https://github.com/r-hub/cranlogs.app/issues/18
I also filed: https://github.com/r-hub/cranlogs.app/issues/41 which came up when I originally removed a "/" to do a gut check on the status code properly erroring (it didn't) then was getting mysterious marshalling errors instead
kk the 404 is now added in: https://github.com/r-hub/cranlogs.app/pull/42
This refactors daily to take advantage of don't need to make multiple requests as its valid to include a comma separated package list
This is also why (to your question/comment in the code) why even for a single package it returns an array, to keep the return structure consistent whether single or multiple packages (i presume at least)
In addition, I added the conditional capability to return json - this would make it easier to interact with this in programmatic settings/compose with other tools