Browse Source

web service

master
boB Rudis 3 years ago
parent
commit
b42607c1e3
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 2
      NAMESPACE
  2. 19
      R/h2c.R
  3. 2
      R/httr2curl-package.R
  4. 10
      README.md

2
NAMESPACE

@ -5,5 +5,5 @@ export(h2c)
import(httr) import(httr)
import(processx) import(processx)
import(rvest) import(rvest)
import(xm2) import(xml2)
importFrom(magrittr,"%>%") importFrom(magrittr,"%>%")

19
R/h2c.R

@ -38,18 +38,14 @@ h2c <- function(complete_httr_verb_call, use_web_service = FALSE) {
httr::POST( httr::POST(
url = "https://curl.se/h2c/", url = "https://curl.se/h2c/",
httr:::content_type_json(), httr::user_agent("curl/7.64.1"),
body = list( httr::accept("*/*"),
http = res httr::content_type("application/x-www-form-urlencoded"),
), body = sprintf("http=%s", curl::curl_escape(res)),
encode = "form" encode = "raw"
) -> res1 ) -> res1
pg <- httr::content(res1) trimws(rawToChar(res1$content))
rvest::html_nodes(pg, xpath = ".//p[contains(., 'Command:')]/following-sibling::div[1]") %>%
rvest::html_text() %>%
trimws()
} else { } else {
@ -65,7 +61,8 @@ h2c <- function(complete_httr_verb_call, use_web_service = FALSE) {
stdin = out stdin = out
) -> res ) -> res
res$stdout trimws(res$stdout)
} }
} }

2
R/httr2curl-package.R

@ -8,5 +8,5 @@
#' @name httr2curl #' @name httr2curl
#' @keywords internal #' @keywords internal
#' @author Bob Rudis (bob@@rud.is) #' @author Bob Rudis (bob@@rud.is)
#' @import httr processx rvest xm2 #' @import httr processx rvest xml2
"_PACKAGE" "_PACKAGE"

10
README.md

@ -61,8 +61,7 @@ h2c(
) )
) )
) )
## [1] "/var/folders/bx/41ph1lms22q9mc83j5tx4bg80000gn/T//RtmpFs8uvt/fileced55b4fcbba" ## [1] "curl --http2 --header \"Accept: application/json, text/xml, application/xml, */*\" --compressed --user-agent \"AppleTV6,2/11.1\" \"https://rud.is/?a=b&c=1\""
## [1] "curl --http2 --header \"Accept: application/json, text/xml, application/xml, */*\" --compressed --user-agent \"AppleTV6,2/11.1\" \"https://rud.is/?a=b&c=1\"\n"
``` ```
### Using the web service ### Using the web service
@ -79,18 +78,17 @@ h2c(
), ),
use_web_service = TRUE use_web_service = TRUE
) )
## [1] "/var/folders/bx/41ph1lms22q9mc83j5tx4bg80000gn/T//RtmpFs8uvt/fileced53c5bb06" ## [1] "curl --header \"Accept: application/json, text/xml, application/xml, */*\" --compressed --user-agent \"AppleTV6,2/11.1\" \"https://rud.is/?a=b&c=1\""
## NULL
``` ```
## httr2curl Metrics ## httr2curl Metrics
| Lang | \# Files | (%) | LoC | (%) | Blank lines | (%) | \# Lines | (%) | | Lang | \# Files | (%) | LoC | (%) | Blank lines | (%) | \# Lines | (%) |
|:-----|---------:|-----:|----:|-----:|------------:|-----:|---------:|-----:| |:-----|---------:|-----:|----:|-----:|------------:|-----:|---------:|-----:|
| R | 5 | 0.36 | 52 | 0.25 | 21 | 0.25 | 40 | 0.26 | | R | 5 | 0.36 | 49 | 0.24 | 21 | 0.25 | 40 | 0.26 |
| Rmd | 1 | 0.07 | 29 | 0.14 | 19 | 0.23 | 35 | 0.23 | | Rmd | 1 | 0.07 | 29 | 0.14 | 19 | 0.23 | 35 | 0.23 |
| YAML | 1 | 0.07 | 22 | 0.11 | 2 | 0.02 | 2 | 0.01 | | YAML | 1 | 0.07 | 22 | 0.11 | 2 | 0.02 | 2 | 0.01 |
| SUM | 7 | 0.50 | 103 | 0.50 | 42 | 0.50 | 77 | 0.50 | | SUM | 7 | 0.50 | 100 | 0.50 | 42 | 0.50 | 77 | 0.50 |
clock Package Metrics for httr2curl clock Package Metrics for httr2curl

Loading…
Cancel
Save