-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: get linguee api external sources
- Loading branch information
1 parent
5457e7a
commit ab19e2c
Showing
3 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#' Retrieve external sources using Linguee Translation API | ||
#' | ||
#' @param query The word or phrase for which you want to retrieve external sources. | ||
#' @param src The source language of the word or phrase. Accepts language codes such as "en", "es", "fr", etc. | ||
#' @param dst The target language for the external source retrieval. Accepts language codes such as "en", "es", "fr", etc. | ||
#' @param limit The maximum number of external sources to retrieve. Defaults to 5. | ||
#' | ||
#' @return A dataframe of external sources with columns: src, dst, src_url, dst_url. | ||
#' | ||
#' @examples | ||
#' \donttest{ | ||
#' linguee_external_sources(query = "hello", src = "en", dst = "es") | ||
#' } | ||
#' | ||
#' @seealso linguee_word_translation, linguee_translation_examples | ||
#' | ||
#' | ||
#' @export | ||
linguee_external_sources <- function(query, src, dst, limit = 5) { | ||
api_root <- "https://linguee-api.fly.dev/api/v2/external_sources" | ||
endpoint <- api_root | ||
|
||
params <- list( | ||
query = query, | ||
src = src, | ||
dst = dst, | ||
limit = limit | ||
) | ||
|
||
response <- httr::GET(url = endpoint, query = params) | ||
|
||
if (response$status_code != 200) { | ||
stop("Error: API request failed with status code ", response$status_code) | ||
} | ||
|
||
external_sources <- httr::content(response, "parsed") | ||
|
||
# Combine the individual lists into a single dataframe | ||
sources_df <- dplyr::bind_rows(external_sources) | ||
|
||
return(sources_df) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.