Skip to content

Commit

Permalink
change to using ie proxy settings in GET call
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Fox committed May 21, 2018
1 parent 996fb51 commit c8cf957
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 26 deletions.
22 changes: 13 additions & 9 deletions R/area_types.R
Expand Up @@ -27,7 +27,8 @@
#' @import dplyr
#' @importFrom jsonlite fromJSON
#' @importFrom stats complete.cases
#' @importFrom httr GET content set_config config
#' @importFrom httr GET content set_config config use_proxy
#' @importFrom curl ie_get_proxy_for_url
#' @export
#' @family lookup functions
#' @seealso \code{\link{indicators}} for indicator lookups,
Expand All @@ -47,7 +48,7 @@ area_types <- function(AreaTypeName = NULL, AreaTypeID = NULL, path){
if (missing(path)) path <- "https://fingertips.phe.org.uk/api/"
set_config(config(ssl_verifypeer = 0L))
parentAreas <- paste0(path,"area_types/parent_area_types") %>%
GET %>%
GET(use_proxy(ie_get_proxy_for_url(.))) %>%
content("text") %>%
fromJSON
area_types <- parentAreas[,c("Id", "Name")]
Expand Down Expand Up @@ -88,7 +89,8 @@ area_types <- function(AreaTypeName = NULL, AreaTypeID = NULL, path){
#' @return A data frame of category type ids and their descriptions
#' @import dplyr
#' @importFrom jsonlite fromJSON
#' @importFrom httr GET content set_config config
#' @importFrom httr GET content set_config config use_proxy
#' @importFrom curl ie_get_proxy_for_url
#' @examples
#' # Returns the deprivation category types
#' cats <- category_types()
Expand All @@ -109,7 +111,7 @@ category_types <- function(path) {
if (missing(path)) path <- "https://fingertips.phe.org.uk/api/"
set_config(config(ssl_verifypeer = 0L))
category_types <- paste0(path,"category_types") %>%
GET %>%
GET(use_proxy(ie_get_proxy_for_url(.))) %>%
content("text") %>%
fromJSON %>%
pull(Categories) %>%
Expand All @@ -130,7 +132,8 @@ category_types <- function(path) {
#' @inheritParams indicators
#' @import dplyr
#' @importFrom jsonlite fromJSON
#' @importFrom httr GET content set_config config
#' @importFrom httr GET content set_config config use_proxy
#' @importFrom curl ie_get_proxy_for_url
#' @examples
#' indicator_areatypes()
#' @export
Expand Down Expand Up @@ -163,7 +166,7 @@ indicator_areatypes <- function(IndicatorID, AreaTypeID, path) {
}
set_config(config(ssl_verifypeer = 0L))
areatypes_by_indicators <- path %>%
GET %>%
GET(use_proxy(ie_get_proxy_for_url(.))) %>%
content("text") %>%
fromJSON %>%
as_tibble
Expand All @@ -189,7 +192,8 @@ indicator_areatypes <- function(IndicatorID, AreaTypeID, path) {
#' @inheritParams fingertips_data
#' @import dplyr
#' @importFrom jsonlite fromJSON
#' @importFrom httr GET content set_config config
#' @importFrom httr GET content set_config config use_proxy
#' @importFrom curl ie_get_proxy_for_url
#' @examples
#' nearest_neighbours(AreaCode = "E38000003", AreaTypeID = 153)
#' @export
Expand All @@ -215,7 +219,7 @@ nearest_neighbours <- function(AreaCode, AreaTypeID = 102, path) {
areacheck <- paste0(path,
sprintf("parent_to_child_areas?parent_area_type_id=%s",
AreaTypeID)) %>%
GET %>%
GET(use_proxy(ie_get_proxy_for_url(.))) %>%
content("text") %>%
fromJSON %>%
names
Expand All @@ -227,7 +231,7 @@ nearest_neighbours <- function(AreaCode, AreaTypeID = 102, path) {
AreaTypeID, val, AreaCode))
set_config(config(ssl_verifypeer = 0L))
nearest_neighbours <- path %>%
GET %>%
GET(use_proxy(ie_get_proxy_for_url(.))) %>%
content("text") %>%
fromJSON %>%
pull(Code)
Expand Down
3 changes: 2 additions & 1 deletion R/fingertipsR.R
Expand Up @@ -48,4 +48,5 @@ globalVariables(c("Id",
"nearest_neighbours",
"Code",
"IID",
"Sequence"))
"Sequence",
"."))
4 changes: 3 additions & 1 deletion R/fingertips_data.R
Expand Up @@ -46,6 +46,8 @@
#' fingdata <- fingertips_data(rep(90282,2), ProfileID = c(19,93), AreaCode = "E06000008")
#' fingdata <- fingdata[order(fingdata$TimeperiodSortable, fingdata$Sex),]}
#' @importFrom jsonlite fromJSON
#' @importFrom httr GET content set_config config use_proxy
#' @importFrom curl ie_get_proxy_for_url
#' @family data extract functions
#' @export

Expand Down Expand Up @@ -110,7 +112,7 @@ fingertips_data <- function(IndicatorID = NULL,
areacodes <- AreaTypeID %>%
lapply(function(i) {
paste0(path, "areas/by_area_type?area_type_id=", i) %>%
GET %>%
GET(use_proxy(ie_get_proxy_for_url(.))) %>%
content("text") %>%
fromJSON
}) %>%
Expand Down
9 changes: 5 additions & 4 deletions R/indicator_metadata.R
Expand Up @@ -17,7 +17,8 @@
#' indicator_metadata(ProfileID = 129)}
#' @return The metadata associated with each indicator/domain/profile identified
#' @importFrom utils read.csv
#' @importFrom httr GET content set_config config
#' @importFrom httr GET content set_config config use_proxy
#' @importFrom curl ie_get_proxy_for_url
#' @importFrom readr read_csv
#' @family lookup functions
#' @seealso \code{\link{indicators}} for indicator lookups,
Expand Down Expand Up @@ -48,7 +49,7 @@ indicator_metadata <- function(IndicatorID = NULL,
dataurl <- paste0(path,
paste(IndicatorID, collapse = "%2C"))
indicator_metadata <- dataurl %>%
GET %>%
GET(use_proxy(ie_get_proxy_for_url(.))) %>%
content("parsed",
type = "text/csv",
encoding = "UTF-8",
Expand All @@ -62,7 +63,7 @@ indicator_metadata <- function(IndicatorID = NULL,
indicator_metadata <- paste0(path, DomainID) %>%
lapply(function(dataurl) {
dataurl %>%
GET %>%
GET(use_proxy(ie_get_proxy_for_url(.))) %>%
content("parsed",
type = "text/csv",
encoding = "UTF-8",
Expand All @@ -78,7 +79,7 @@ indicator_metadata <- function(IndicatorID = NULL,
indicator_metadata <- paste0(path, ProfileID) %>%
lapply(function(dataurl) {
dataurl %>%
GET %>%
GET(use_proxy(ie_get_proxy_for_url(.))) %>%
content("parsed",
type = "text/csv",
encoding = "UTF-8",
Expand Down
9 changes: 5 additions & 4 deletions R/indicators.R
Expand Up @@ -15,7 +15,8 @@
#' indicators(ProfileID = 19)}
#' @import dplyr
#' @importFrom jsonlite fromJSON
#' @importFrom httr GET content set_config config
#' @importFrom httr GET content set_config config use_proxy
#' @importFrom curl ie_get_proxy_for_url
#' @family lookup functions
#' @seealso \code{\link{area_types}} for area type and their parent mappings,
#' \code{\link{indicator_metadata}} for indicator metadata,
Expand Down Expand Up @@ -48,7 +49,7 @@ indicators <- function(ProfileID = NULL,
df <- DomainID %>%
lapply(function(dom) {
dfRaw <- paste0(path,"indicator_metadata/by_group_id?group_ids=",dom) %>%
GET %>%
GET(use_proxy(ie_get_proxy_for_url(.))) %>%
content("text") %>%
fromJSON(flatten = TRUE)
if (length(dfRaw) != 0){
Expand Down Expand Up @@ -143,7 +144,7 @@ indicator_order <- function(DomainID,
ParentAreaCode <- paste0(path,
sprintf("parent_to_child_areas?parent_area_type_id=%s",
ParentAreaTypeID)) %>%
GET %>%
GET(use_proxy(ie_get_proxy_for_url(.))) %>%
content("text") %>%
fromJSON %>%
names
Expand All @@ -162,7 +163,7 @@ indicator_order <- function(DomainID,
ProfileID, DomainID, AreaTypeID, ParentAreaCode))
set_config(config(ssl_verifypeer = 0L))
indicator_order <- path %>%
GET %>%
GET(use_proxy(ie_get_proxy_for_url(.))) %>%
content("text") %>%
fromJSON %>%
select(IID, Sequence, Sex, Age)
Expand Down
2 changes: 1 addition & 1 deletion R/profiles.R
Expand Up @@ -69,7 +69,7 @@ profiles <- function(ProfileID = NULL, ProfileName = NULL, path) {
pull %>%
lapply(function(dataurl) {
dataurl %>%
GET %>%
GET(use_proxy(ie_get_proxy_for_url(.))) %>%
content("text") %>%
fromJSON
}) %>%
Expand Down
15 changes: 9 additions & 6 deletions R/retrieve_data.R
@@ -1,6 +1,7 @@
#' @importFrom jsonlite fromJSON
#' @importFrom utils read.csv
#' @importFrom httr GET content set_config config
#' @importFrom httr GET content set_config config use_proxy
#' @importFrom curl ie_get_proxy_for_url
#' @importFrom readr read_csv
retrieve_indicator <- function(IndicatorIDs, ProfileIDs, ChildAreaTypeIDs, ParentAreaTypeIDs, path){
types <- "icccccccccccnnnnnnncccci"
Expand Down Expand Up @@ -30,7 +31,7 @@ retrieve_indicator <- function(IndicatorIDs, ProfileIDs, ChildAreaTypeIDs, Paren
}
}
fingertips_data <- rbind(dataurl %>%
GET %>%
GET(use_proxy(ie_get_proxy_for_url(.))) %>%
content("parsed",
type = "text/csv",
encoding = "UTF-8",
Expand All @@ -44,7 +45,8 @@ retrieve_indicator <- function(IndicatorIDs, ProfileIDs, ChildAreaTypeIDs, Paren

#' @importFrom jsonlite fromJSON
#' @importFrom utils read.csv
#' @importFrom httr GET content set_config config
#' @importFrom httr GET content set_config config use_proxy
#' @importFrom curl ie_get_proxy_for_url
#' @importFrom readr read_csv
retrieve_domain <- function(DomainIDs, ChildAreaTypeIDs, ParentAreaTypeIDs, path){
types <- "icccccccccccnnnnnnncccci"
Expand All @@ -58,7 +60,7 @@ retrieve_domain <- function(DomainIDs, ChildAreaTypeIDs, ParentAreaTypeIDs, path
ChildAreaTypeID,ParentAreaTypeID,DomainID),
"&include_sortable_time_periods=yes")
fingertips_data <- rbind(dataurl %>%
GET %>%
GET(use_proxy(ie_get_proxy_for_url(.))) %>%
content("parsed",
type = "text/csv",
encoding = "UTF-8",
Expand All @@ -72,7 +74,8 @@ retrieve_domain <- function(DomainIDs, ChildAreaTypeIDs, ParentAreaTypeIDs, path

#' @importFrom jsonlite fromJSON
#' @importFrom utils read.csv
#' @importFrom httr GET content set_config config
#' @importFrom httr GET content set_config config use_proxy
#' @importFrom curl ie_get_proxy_for_url
#' @importFrom readr read_csv
retrieve_profile <- function(ProfileIDs, ChildAreaTypeIDs, ParentAreaTypeIDs, path){
types <- "icccccccccccnnnnnnncccci"
Expand All @@ -86,7 +89,7 @@ retrieve_profile <- function(ProfileIDs, ChildAreaTypeIDs, ParentAreaTypeIDs, pa
ChildAreaTypeID,ParentAreaTypeID,ProfileID),
"&include_sortable_time_periods=yes")
fingertips_data <- rbind(dataurl %>%
GET %>%
GET(use_proxy(ie_get_proxy_for_url(.))) %>%
content("parsed",
type = "text/csv",
encoding = "UTF-8",
Expand Down

0 comments on commit c8cf957

Please sign in to comment.