Skip to content

Commit cd730b3

Browse files
authored
Merge pull request #6 from Displacement-Tracking-Matrix/dev
Changes in configurations and dev version 0.1.9000
2 parents c86fe7c + 85abbde commit cd730b3

13 files changed

Lines changed: 121 additions & 47 deletions

‎.github/workflows/pkgdown.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
2222
env:
2323
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
24+
DTMAPIR_KEY: ${{ secrets.DTMAPIR_KEY }}
2425
permissions:
2526
contents: write
2627
steps:

‎.gitignore‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ inst/doc
55
.Renviron
66
.Rhistory
77
/.quarto/
8-
docs
8+
docs

‎DESCRIPTION‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: dtmapi
22
Title: Fetching Data from the 'Displacement Tracking Matrix'
3-
Version: 0.1.0
3+
Version: 0.1.0.9000
44
Authors@R: c(
55
person("Luong Bang", "Tran", email = "lutran@iom.int", role = c("aut")),
66
person("Assad", "Asil Companioni", email = "aasil@iom.int", role = c("aut", "cre")),

‎NEWS.md‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# dtmapi (development version)
2+
* Stylistic and stylistic-adjacent corrections to documentation.
3+
4+
* More elaborate explanation on how to set the subscription key, including
5+
options for non-interactive environments and explicitly introducing the concept
6+
of secrets management.
7+
8+
* Substantial corrections to documentation, including clarification of the environment variable being used (it is `DTM_SUBSCRIPTION_KEY`, not `DTM_API_KEY`).
9+
10+
* Apparently inconsequential change in API endpoint URL used by `get_all_operations()`: from "https://dtmapi.iom.int/v3/displacement/operation-List" to https://dtmapi.iom.int/v3/displacement/operation-list", but worth implementing to be safe and exact.
11+
112
# dtmapi 0.1.0
213

314
* Version 3 of the DTM API requires the use of a valid subscription key in order
@@ -18,4 +29,4 @@ the API.
1829
the `dtmapi` package, but it may technically be used by users to conveniently
1930
return the currently available subscription key. HOWEVER, beware that the string
2031
it returns is plain text and is more easily exposed, e.g. exposed to anyone
21-
visually observing your machine.
32+
visually observing your machine.

‎R/get_all_operations.R‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
get_all_operations <- function() {
1414

1515
tryCatch({
16-
api_url <- "https://dtmapi.iom.int/v3/displacement/operation-List"
16+
api_url <- "https://dtmapi.iom.int/v3/displacement/operation-list"
1717

1818
response <-
1919
request(api_url) |>

‎R/get_subscription_key.R‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
#'
33
#' The DTM API subscription key is returned, provided that it is available in
44
#' the R session as an environment variable. Users will usually need to set
5-
#' the DTM_SUBSCRIPTION_KEY environment variable through a .Renviron file or
6-
#' by calling `set_subscription_key()`.
5+
#' the DTM_SUBSCRIPTION_KEY environment variable through a .Renviron file (or
6+
#' other means) or by calling `set_subscription_key()`.
77
#'
88
#' On the other hand, if the TESTTHAT environment variable is true, indicating
99
#' that unit tests are being run by the package maintainers, then the

‎R/set_subscription_key.R‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#' Set the user's API subscription key in order to make the API calls.
22
#'
3-
#' The API will be stored as an environmental variable named "DTM_API_KEY".
3+
#' The API subscription key will be stored as an environment variable named
4+
#' "DTM_SUBSCRIPTION_KEY".
45
#' @param key
56
#' Either NULL or a string representing the key. NULL is preferable: using it
67
#' will prompt the user to type the subscription key in a graphical user
78
#' interface that masks it.
8-
#' @return Nothing. Creates / overwrites an environmental variable as a side effect.
9+
#' @return Nothing. Creates / overwrites an environment variable as a side effect.
910
#' @export
1011
#' @examples
1112
#' \dontrun{

‎README.Rmd‎

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,23 @@ the [DTM API Portal](https://dtm-apim-portal.iom.int/signin) and follow the
5252
instructions there.
5353

5454
The subscription key is secret and should not be exposed. Once it is obtained,
55-
the subscription key should be set for your current R session, assuming that the
56-
`dtmapi` package is installed. To do this, use run the following in R:
55+
the subscription key should be set for your current R session, assuming that the `dtmapi` package is installed. To do this, the environment variable `DTM_SUBSCRIPTION_KEY` needs to be defined. This can be done either interactively or non-interactively.
56+
57+
The interactive option is to call `set_subscription_key()`, like so:
5758

5859
```{r set_subscription_key_demo, eval = FALSE}
5960
dtmapi::set_subscription_key()
6061
```
6162

62-
At this point, the user will be prompted to input the key (hidden) into a pop-up
63-
field.
63+
At this point, the user will be prompted to input the key (hidden) into a pop-up field.
64+
65+
Some environments are non-interactive, and so running the above will likely result in an error. In such a case, the subscription key may be set non-interactively, by specifying the `key` parameter, like so:
66+
```{r, eval = FALSE}
67+
# Specifying `key` is required for non-interactive use.
68+
dtmapi::set_subscription_key(key = "mysubscriptionkey")
69+
```
70+
71+
However, this option is discouraged and should be avoided as much as possible, because it blatantly exposes the subscription key. The best option would be to engage in good secrets management practices, such as by using a .Renviron file (if applicable). Basic secrets management, and the issue of setting the subscription key in general, is elaborated on in more detail in `vignette("user_guide")`.
6472

6573
## Usage
6674
When the subscription key is set, data on internal displacement may be retrieved through any of the following functions:
@@ -74,8 +82,7 @@ These all retrieve data from the DTM API and return said data in
7482
the form of data frames.
7583

7684
Certain parameters have to be specified to any of these, the most important of which are either the `CountryName` or the `OperationName`. For information on the other parameters
77-
and indeed all functions in `dtmapi`,
78-
[see the documentation here.](https://displacement-tracking-matrix.github.io/dtmapi-R/reference/index.html)
85+
and indeed all functions in `dtmapi`, [see the documentation here.](https://displacement-tracking-matrix.github.io/dtmapi-R/reference/index.html)
7986

8087
As a representative example of the earlier mentioned functions, see the following use of `get_idp_admin_1_data()`:
8188

@@ -117,13 +124,15 @@ head(operations_df)
117124

118125
## User Guide
119126
The information given here is further elaborated on in the user guide to
120-
getting started with `dtmapi`, which is available through the panel at
121-
the top of this page.
127+
getting started with `dtmapi`, which is
128+
accessible through `vignette("user_guide")`.
122129

123130
## Source Code
124-
The source code for `dtmapi` is available on [GitHub](https://github.com/Displacement-tracking-Matrix/dtmapi-R).
131+
The source code for `dtmapi` is available on
132+
[GitHub](https://github.com/Displacement-tracking-Matrix/dtmapi-R).
125133

126134
Feel free to explore the repository, contribute, or raise any issues you may encounter.
127135

128136
## Contact
129-
For any questions or feedback, please reach out to us at [dtmdataconsolidation@iom.int](mailto:dtmdataconsolidation@iom.int).
137+
For any questions or feedback, please reach out to us at
138+
[dtmdataconsolidation@iom.int](mailto:dtmdataconsolidation@iom.int).

‎README.md‎

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@ the instructions there.
5353

5454
The subscription key is secret and should not be exposed. Once it is
5555
obtained, the subscription key should be set for your current R session,
56-
assuming that the `dtmapi` package is installed. To do this, use run the
57-
following in R:
56+
assuming that the `dtmapi` package is installed. To do this, the
57+
environment variable `DTM_SUBSCRIPTION_KEY` needs to be defined. This
58+
can be done either interactively or non-interactively.
59+
60+
The interactive option is to call `set_subscription_key()`, like so:
5861

5962
``` r
6063
dtmapi::set_subscription_key()
@@ -63,6 +66,22 @@ dtmapi::set_subscription_key()
6366
At this point, the user will be prompted to input the key (hidden) into
6467
a pop-up field.
6568

69+
Some environments are non-interactive, and so running the above will
70+
likely result in an error. In such a case, the subscription key may be
71+
set non-interactively, by specifying the `key` parameter, like so:
72+
73+
``` r
74+
# Specifying `key` is required for non-interactive use.
75+
dtmapi::set_subscription_key(key = "mysubscriptionkey")
76+
```
77+
78+
However, this option is discouraged and should be avoided as much as
79+
possible, because it blatantly exposes the subscription key. The best
80+
option would be to engage in good secrets management practices, such as
81+
by using a .Renviron file (if applicable). Basic secrets management, and
82+
the issue of setting the subscription key in general, is elaborated on
83+
in more detail in `vignette("user_guide")`.
84+
6685
## Usage
6786

6887
When the subscription key is set, data on internal displacement may be
@@ -80,8 +99,6 @@ important of which are either the `CountryName` or the `OperationName`.
8099
For information on the other parameters and indeed all functions in
81100
`dtmapi`, [see the documentation
82101
here.](https://displacement-tracking-matrix.github.io/dtmapi-R/reference/index.html)
83-
`dtmapi`, [see the documentation
84-
here.](https://displacement-tracking-matrix.github.io/dtmapi-R/reference/index.html)
85102

86103
As a representative example of the earlier mentioned functions, see the
87104
following use of `get_idp_admin_1_data()`:
@@ -98,12 +115,12 @@ idp_admin1_df <- get_idp_admin1_data(CountryName = "Sudan",
98115
# Display the first few rows of the data frame
99116
head(idp_admin1_df)
100117
#> id operation admin0Name admin0Pcode admin1Name admin1Pcode
101-
#> 1 4277072 Darfur conflict Sudan SDN Blue Nile SD08
102-
#> 2 4277073 Darfur conflict Sudan SDN Blue Nile SD08
103-
#> 3 4277074 Darfur conflict Sudan SDN Blue Nile SD08
104-
#> 4 4277075 Darfur conflict Sudan SDN Blue Nile SD08
105-
#> 5 4255941 Armed Clashes in Sudan Sudan SDN Blue Nile SD08
106-
#> 6 4255942 Armed Clashes in Sudan Sudan SDN Blue Nile SD08
118+
#> 1 4743857 Darfur conflict Sudan SDN Blue Nile SD08
119+
#> 2 4743858 Darfur conflict Sudan SDN Blue Nile SD08
120+
#> 3 4743859 Darfur conflict Sudan SDN Blue Nile SD08
121+
#> 4 4743860 Darfur conflict Sudan SDN Blue Nile SD08
122+
#> 5 4722729 Armed Clashes in Sudan Sudan SDN Blue Nile SD08
123+
#> 6 4722730 Armed Clashes in Sudan Sudan SDN Blue Nile SD08
107124
#> numPresentIdpInd reportingDate yearReportingDate monthReportingDate
108125
#> 1 81693 2021-03-30T00:00:00 2021 3
109126
#> 2 130958 2021-12-31T00:00:00 2021 12
@@ -174,8 +191,8 @@ head(operations_df)
174191
## User Guide
175192

176193
The information given here is further elaborated on in the user guide to
177-
getting started with `dtmapi`, which is available through the panel at
178-
the top of this page.
194+
getting started with `dtmapi`, which is accessible through
195+
`vignette("user_guide")`.
179196

180197
## Source Code
181198

‎_pkgdown.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ navbar:
1818
href: reference/index.html
1919

2020
development:
21-
mode: auto
21+
mode: release

0 commit comments

Comments
 (0)