--- title: "Demo" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{demo} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) ``` ```{r setup} library(ODataQuery) ``` ## Introduction Here I'll show some examples to use this package ## Create service ```{r} service <- ODataQuery$new("https://services.odata.org/V4/TripPinServiceRW") service$all() ``` ## Entity set ```{r} people_entity <- service$path("People") # Get first page people_entity$retrieve(count=TRUE) # Get all pages people_entity$select("UserName", "FirstName", "LastName")$all() ``` ## Singleton ```{r} russellwhyte <- people_entity$get("russellwhyte") first_person <- people_entity$top(1)$one() head(first_person) russellwhyte_friends <- russellwhyte$path("Friends") russellwhyte_friends$all() ``` ## Function call ```{r} get_nearest_airport <- service$func('GetNearestAirport') get_nearest_airport(lat = 33, lon = -118) ``` ## Querying ```{r} people_query <- people_entity$ top(5)$ select('FirstName', 'LastName')$ filter(Concurrency.gt = 500)$ expand('Friends($count=true)')$ orderby('LastName') people_query$all() ``` ## Other endpoints ### Statistics, the Netherlands ```{r eval=FALSE} opendata_service <- ODataQuery$new("http://beta-odata4.cbs.nl/") entity_81589NED <- opendata_service$path("CBS", "81589NED", Observations") dataset_81589NED <- entity_81589NED$all() ``` ### Northwind (OData v2) Connecting with older OData v2 works, but some features have been changed. ```{r eval=FALSE} northwind_service <- ODataQuery$new("https://services.odata.org/V2/Northwind/Northwind.svc/") customer_entity <- northwind_service$path("Customers") customer_entity$ select("CompanyName", "Address", "Phone")$ filter(Country.eq = "Germany", City.eq = "Berlin") ``` ### The Hague So far, I haven't been able to figure out how their data model works, but at least we can connect to it. ```{r eval=FALSE} denhaag_service <- ODataQuery$new("https://denhaag.incijfers.nl/jiveservices/odata/") denhaag_service$path('DataSources') ```