Skip to content

Commit

Permalink
Standardize class constructor functions. (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonthegeek authored Nov 15, 2023
1 parent 1ef21ea commit e05b3f6
Show file tree
Hide file tree
Showing 109 changed files with 1,670 additions and 1,656 deletions.
7 changes: 3 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,17 @@ Imports:
Suggests:
testthat (>= 3.0.0)
Remotes:
jonthegeek/stbl,
RConsortium/S7
jonthegeek/stbl
Config/testthat/edition: 3
Config/testthat/parallel: true
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
Collate:
'properties.R'
'security_requirements.R'
'security.R'
'components-security_scheme_details.R'
'components-security_scheme_collection.R'
'components-security_schemes.R'
'components.R'
'servers-server_variables.R'
'servers-string_replacements.R'
Expand Down
40 changes: 20 additions & 20 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Generated by roxygen2: do not edit by hand

export(api_key_security_scheme)
export(as_api_key_security_scheme)
export(as_api_object)
export(as_component_collection)
export(as_components)
export(as_contact)
export(as_info)
export(as_license)
Expand All @@ -14,33 +13,34 @@ export(as_oauth2_token_flow)
export(as_origin)
export(as_rapid)
export(as_scopes)
export(as_security_requirements)
export(as_security)
export(as_security_scheme)
export(as_security_scheme_collection)
export(as_security_scheme_details)
export(as_security_schemes)
export(as_server_variables)
export(as_servers)
export(as_string_replacements)
export(caller_arg)
export(caller_env)
export(class_api_key_security_scheme)
export(class_components)
export(class_contact)
export(class_info)
export(class_license)
export(class_oauth2_authorization_code_flow)
export(class_oauth2_implicit_flow)
export(class_oauth2_security_scheme)
export(class_oauth2_token_flow)
export(class_origin)
export(component_collection)
export(contact)
export(class_rapid)
export(class_scopes)
export(class_security)
export(class_security_scheme_details)
export(class_security_schemes)
export(class_server_variables)
export(class_servers)
export(class_string_replacements)
export(expand_servers)
export(info)
export(license)
export(oauth2_authorization_code_flow)
export(oauth2_implicit_flow)
export(oauth2_security_scheme)
export(oauth2_token_flow)
export(rapid)
export(scopes)
export(security_requirements)
export(security_scheme_collection)
export(security_scheme_details)
export(server_variables)
export(servers)
export(string_replacements)
if (getRversion() < "4.3.0") importFrom("S7", "@")
importFrom(S7,"prop<-")
importFrom(S7,class_any)
Expand Down
4 changes: 2 additions & 2 deletions R/absolute_paths.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ NULL
#' @inheritParams rlang::args_dots_empty
#' @param x The object to update. Must be a `rapid`.
#'
#' @return A `rapid` object as returned by [rapid()], with absolute server
#' @return A `rapid` object as returned by [class_rapid()], with absolute server
#' paths.
#' @export
expand_servers <- S7::new_generic("expand_servers", "x")

S7::method(expand_servers, rapid) <- function(x) {
S7::method(expand_servers, class_rapid) <- function(x) {
if (length(x@servers@url)) {
relative_servers <- .is_relative_url(x@servers@url)
origin_url <- x@info@origin@url
Expand Down
16 changes: 8 additions & 8 deletions R/components-security_scheme-api_key.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ NULL
#' @export
#'
#' @examples
#' api_key_security_scheme(
#' class_api_key_security_scheme(
#' parameter_name = "Authorization",
#' location = "header"
#' )
api_key_security_scheme <- S7::new_class(
class_api_key_security_scheme <- S7::new_class(
name = "api_key_security_scheme",
package = "rapid",
parent = security_scheme,
parent = abstract_security_scheme,
properties = list(
parameter_name = character_scalar_property("parameter_name"),
location = character_scalar_property("location")
Expand All @@ -49,16 +49,16 @@ api_key_security_scheme <- S7::new_class(
}
)

S7::method(length, api_key_security_scheme) <- function(x) {
S7::method(length, class_api_key_security_scheme) <- function(x) {
length(x@parameter_name)
}

#' Coerce lists and character vectors to API key security schemes
#'
#' `as_api_key_security_scheme()` turns an existing object into an
#' `api_key_security_scheme`. This is in contrast with
#' [api_key_security_scheme()], which builds an `api_key_security_scheme` from
#' individual properties.
#' [class_api_key_security_scheme()], which builds an `api_key_security_scheme`
#' from individual properties.
#'
#' @inheritParams rlang::args_dots_empty
#' @inheritParams rlang::args_error_context
Expand All @@ -68,15 +68,15 @@ S7::method(length, api_key_security_scheme) <- function(x) {
#' are ignored.
#'
#' @return An `api_key_security_scheme` as returned by
#' [api_key_security_scheme()].
#' [class_api_key_security_scheme()].
#' @export
as_api_key_security_scheme <- function(x,
...,
arg = caller_arg(x),
call = caller_env()) {
as_api_object(
x,
api_key_security_scheme,
class_api_key_security_scheme,
...,
alternate_names = c("in" = "location", "name" = "parameter_name"),
arg = arg,
Expand Down
24 changes: 12 additions & 12 deletions R/components-security_scheme-oauth2-authorization_code_flow.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@ NULL
#' the OAuth Authorization Code flow. Previously called `accessCode` in OpenAPI
#' 2.0.
#'
#' @inheritParams oauth2_flow
#' @inheritParams abstract_oauth2_flow
#' @inheritParams rlang::args_dots_empty
#' @inheritParams oauth2_implicit_flow
#' @inheritParams oauth2_token_flow
#' @inheritParams class_oauth2_implicit_flow
#' @inheritParams class_oauth2_token_flow
#'
#' @export
#' @examples
#' oauth2_authorization_code_flow(
#' class_oauth2_authorization_code_flow(
#' authorization_url = "https://example.com/authorize",
#' token_url = "https://example.com/token",
#' refresh_url = "https://example.com/refresh",
#' scopes = scopes(
#' scopes = class_scopes(
#' name = c("server:read", "server:write"),
#' description = c("Read server settings", "Write server settings")
#' )
#' )
oauth2_authorization_code_flow <- S7::new_class(
class_oauth2_authorization_code_flow <- S7::new_class(
name = "oauth2_authorization_code_flow",
package = "rapid",
parent = oauth2_flow,
parent = abstract_oauth2_flow,
properties = list(
authorization_url = character_scalar_property("authorization_url"),
token_url = character_scalar_property("token_url")
Expand All @@ -35,7 +35,7 @@ oauth2_authorization_code_flow <- S7::new_class(
token_url = character(),
...,
refresh_url = character(),
scopes = character()) {
scopes = class_scopes()) {
check_dots_empty()
S7::new_object(
S7::S7_object(),
Expand All @@ -56,15 +56,15 @@ oauth2_authorization_code_flow <- S7::new_class(
}
)

S7::method(length, oauth2_authorization_code_flow) <- function(x) {
S7::method(length, class_oauth2_authorization_code_flow) <- function(x) {
length(x@authorization_url)
}

#' Coerce lists and character vectors to OAuth2 authorization code flows
#'
#' `as_oauth2_authorization_code_flow()` turns an existing object into an
#' `oauth2_authorization_code_flow`. This is in contrast with
#' [oauth2_authorization_code_flow()], which builds an
#' [class_oauth2_authorization_code_flow()], which builds an
#' `oauth2_authorization_code_flow` from individual properties.
#'
#' @inheritParams rlang::args_dots_empty
Expand All @@ -75,11 +75,11 @@ S7::method(length, oauth2_authorization_code_flow) <- function(x) {
#' [snakecase::to_snake_case()]. Additional names are ignored.
#'
#' @return An `oauth2_authorization_code_flow` as returned by
#' [oauth2_authorization_code_flow()].
#' [class_oauth2_authorization_code_flow()].
#' @export
as_oauth2_authorization_code_flow <- function(x,
...,
arg = caller_arg(x),
call = caller_env()) {
as_api_object(x, oauth2_authorization_code_flow, ..., arg = arg, call = call)
as_api_object(x, class_oauth2_authorization_code_flow, ..., arg = arg, call = call)
}
12 changes: 6 additions & 6 deletions R/components-security_scheme-oauth2-flow.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ NULL
#' @param refresh_url Character scalar (optional). The URL to be used for
#' obtaining refresh tokens. This must be in the form of a URL. The OAuth2
#' standard requires the use of TLS.
#' @param scopes An optional [scopes()] object with the available scopes for the
#' OAuth2 security scheme.
#' @param scopes An optional [class_scopes()] object with the available scopes
#' for the OAuth2 security scheme.
#'
#' @keywords internal
#' @seealso [oauth2_token_flow()], [oauth2_implicit_flow()], and
#' [oauth2_authorization_code_flow()]
oauth2_flow <- S7::new_class(
#' @seealso [class_oauth2_token_flow()], [class_oauth2_implicit_flow()], and
#' [class_oauth2_authorization_code_flow()]
abstract_oauth2_flow <- S7::new_class(
name = "oauth2_flow",
package = "rapid",
properties = list(
refresh_url = character_scalar_property("refresh_url"),
scopes = scopes
scopes = class_scopes
),
abstract = TRUE
)
18 changes: 9 additions & 9 deletions R/components-security_scheme-oauth2-implicit_flow.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@ NULL
#' An `oauth2_implicit_flow` object describes the configuration for the OAuth
#' Implicit flow.
#'
#' @inheritParams oauth2_flow
#' @inheritParams abstract_oauth2_flow
#' @inheritParams rlang::args_dots_empty
#' @param authorization_url Character vector (required). The authorization URL
#' to be used for this flow. This must be in the form of a URL. The OAuth2
#' standard requires the use of TLS.
#'
#' @export
#' @examples
#' oauth2_implicit_flow(
#' class_oauth2_implicit_flow(
#' authorization_url = "https://example.com/authorize",
#' refresh_url = "https://example.com/refresh"
#' )
oauth2_implicit_flow <- S7::new_class(
class_oauth2_implicit_flow <- S7::new_class(
name = "oauth2_implicit_flow",
package = "rapid",
parent = oauth2_flow,
parent = abstract_oauth2_flow,
properties = list(
authorization_url = character_scalar_property("authorization_url")
),
constructor = function(authorization_url = character(),
...,
refresh_url = character(),
scopes = character()) {
scopes = class_scopes()) {
check_dots_empty()
S7::new_object(
S7::S7_object(),
Expand All @@ -47,14 +47,14 @@ oauth2_implicit_flow <- S7::new_class(
}
)

S7::method(length, oauth2_implicit_flow) <- function(x) {
S7::method(length, class_oauth2_implicit_flow) <- function(x) {
length(x@authorization_url)
}

#' Coerce lists and character vectors to OAuth2 implicit flows
#'
#' `as_oauth2_implicit_flow()` turns an existing object into an
#' `oauth2_implicit_flow`. This is in contrast with [oauth2_implicit_flow()],
#' `oauth2_implicit_flow`. This is in contrast with [class_oauth2_implicit_flow()],
#' which builds an `oauth2_implicit_flow` from individual properties.
#'
#' @inheritParams rlang::args_dots_empty
Expand All @@ -64,11 +64,11 @@ S7::method(length, oauth2_implicit_flow) <- function(x) {
#' names that can be coerced to those names via [snakecase::to_snake_case()].
#' Additional names are ignored.
#'
#' @return An `oauth2_implicit_flow` as returned by [oauth2_implicit_flow()].
#' @return An `oauth2_implicit_flow` as returned by [class_oauth2_implicit_flow()].
#' @export
as_oauth2_implicit_flow <- function(x,
...,
arg = caller_arg(x),
call = caller_env()) {
as_api_object(x, oauth2_implicit_flow, ..., arg = arg, call = call)
as_api_object(x, class_oauth2_implicit_flow, ..., arg = arg, call = call)
}
14 changes: 7 additions & 7 deletions R/components-security_scheme-oauth2-scopes.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#' @seealso [as_scopes()] for coercing objects to `scopes`.
#' @export
#' @examples
#' scopes(
#' class_scopes(
#' name = c(
#' "https://www.googleapis.com/auth/youtube",
#' "https://www.googleapis.com/auth/youtube.channel-memberships.creator",
Expand All @@ -30,7 +30,7 @@
#' "View private information of your YouTube channel"
#' )
#' )
scopes <- S7::new_class(
class_scopes <- S7::new_class(
name = "scopes",
package = "rapid",
properties = list(
Expand All @@ -54,20 +54,20 @@ scopes <- S7::new_class(
}
)

S7::method(length, scopes) <- function(x) {
S7::method(length, class_scopes) <- function(x) {
length(x@name)
}

#' Coerce lists and character vectors to scopes
#'
#' `as_scopes()` turns an existing object into a `scopes`. This is in contrast
#' with [scopes()], which builds a `scopes` from individual properties.
#' with [class_scopes()], which builds a `scopes` from individual properties.
#'
#' @inheritParams rlang::args_dots_empty
#' @inheritParams rlang::args_error_context
#' @param x The object to coerce. Must be coercible to a named character vector.
#'
#' @return A `scopes` as returned by [scopes()].
#' @return A `scopes` as returned by [class_scopes()].
#' @export
as_scopes <- S7::new_generic("as_scopes", "x")

Expand All @@ -84,7 +84,7 @@ S7::method(
call = call
)
}
scopes(
class_scopes(
name = names(x),
description = unname(x)
)
Expand All @@ -94,5 +94,5 @@ S7::method(as_scopes, class_any) <- function(x,
...,
arg = caller_arg(x),
call = caller_env()) {
as_api_object(x, scopes, ..., arg = arg, call = call)
as_api_object(x, class_scopes, ..., arg = arg, call = call)
}
Loading

0 comments on commit e05b3f6

Please sign in to comment.