Exampling Loading Functions
list_examples
MacroEnergy.list_examples
— Functionlist_examples(; auth::Any)::Vector{String}
List all available examples in the MacroEnergyExamples repository. This function will print the names of all examples and return a vector of their names. These names can be used with download_example
and other methods to download or get information about specific examples.
The auth
parameter can be used to authenticate your requests to the GitHub API. It should be a valid GitHub.OAuth2
object created using the authenticate_github
method, or a GitHub.UsernamePassAuth
or GitHub.JWTAuth
object created using the GitHub.jl package.
download_example
MacroEnergy.download_example
— Functiondownload_example(example_name::String, target_dir::String = pwd(); auth::Any)::Nothing
Download an example from the MacroEnergyExamples repository to a specified target directory. The example_name
should match one of the names listed by list_examples()
. The target_dir
is the directory where the example will be downloaded, defaulting to the current working directory.
The auth
parameter can be used to authenticate your requests to the GitHub API. It should be a valid GitHub.OAuth2
object created using the authenticate_github
method, or a GitHub.UsernamePassAuth
or GitHub.JWTAuth
object created using the GitHub.jl package.
download_examples
MacroEnergy.download_examples
— Functiondownload_examples(target_dir::String = pwd(), pause_seconds::Float64 = 1.0; auth::Any)::Nothing
Download all examples from the MacroEnergyExamples repository to a specified target directory.
The target_dir
is the directory where all examples will be downloaded, defaulting to the current working directory. pause_seconds is the time to pause between downloads to avoid hitting GitHub API rate limits.
The auth
parameter can be used to authenticate your requests to the GitHub API. It should be a valid GitHub.OAuth2
object created using the authenticate_github
method, or a GitHub.UsernamePassAuth
or GitHub.JWTAuth
object created using the GitHub.jl package.
example_readme
MacroEnergy.example_readme
— Functionexample_readme(example_name::String; auth::Any)::Nothing
Display the README.md file for a specific example from the MacroEnergyExamples repository. The example_name
should match one of the names listed by list_examples()
.
The auth
parameter can be used to authenticate your requests to the GitHub API. It should be a valid GitHub.OAuth2
object created using the authenticate_github
method, or a GitHub.UsernamePassAuth
or GitHub.JWTAuth
object created using the GitHub.jl package.
example_contents
MacroEnergy.example_contents
— Functionexample_contents(example_name::String; auth::Any)::Nothing
Display the contents of a specific example from the MacroEnergyExamples repository. The example_name
should match one of the names listed by list_examples()
. This function will print the names of all files in the example directory.
The auth
parameter can be used to authenticate your requests to the GitHub API. It should be a valid GitHub.OAuth2
object created using the authenticate_github
method, or a GitHub.UsernamePassAuth
or GitHub.JWTAuth
object created using the GitHub.jl package.
find_example
MacroEnergy.find_example
— Functionfind_example(example_name::String; auth::Any)::Tuple{GitHub.Content, GitHub.Repo}
Find an example by its name in the MacroEnergyExamples repository. These names can be obtained from list_examples()
. find_example
returns a tuple containing the GitHub.Content
object for the requested examples GitHub directory and the GitHub.Repo
object for the MacroEnergyExamples repository.
The auth
parameter can be used to authenticate your requests to the GitHub API. It should be a valid GitHub.OAuth2
object created using the authenticate_github
method, or a GitHub.UsernamePassAuth
or GitHub.JWTAuth
object created using the GitHub.jl package.
authenticate_github
MacroEnergy.authenticate_github
— Functionauthenticate_github(token::String)::GitHub.OAuth2
Authenticate your downloads from GitHub using a personal access token. This function returns a GitHub.OAuth2
object that can be used for authenticated requests to the GitHub API.
You should create a personal access token in the GitHub settings under Developer settings -> Personal access tokens.
You can use the created OAuth2 token to authenticate your other function calls, for example:
auth = authenticate_github("your_personal_access_token")
list_examples(; auth=auth)
download_example("example_name"; auth=auth)
check_auth
MacroEnergy.check_auth
— Functioncheck_auth(auth::Any)::NamedTuple
Check if the provided authentication object is valid for GitHub API requests. This function returns a NamedTuple containing the auth
object if it is a valid type, or an empty NamedTuple otherwise.
The auth
parameter can be a GitHub.OAuth2
, GitHub.UsernamePassAuth
, or GitHub.JWTAuth
object.
download_gh
MacroEnergy.download_gh
— Functiondownload_gh(dir_path::String, repo::GitHub.Repo, target_dir::String; auth::Any)::Nothing
Download a directory from a GitHub repository to a specified target directory.
The dir_path
is the path to the directory in the repository, repo
is the GitHub.Repo
object, and target_dir
is the local directory where the contents will be downloaded.
download_gh(elem::GitHub.Content, repo::GitHub.Repo, target_dir::String; auth::Any)::Nothing
Attempt to download a single element (file or directory) from a GitHub repository to a specified target directory. If the element is a file, it will be downloaded directly. If it is a directory, the function will recursively download all contents within that directory.
The elem
is a GitHub.Content
object representing the file or directory, repo
is the GitHub.Repo
object, and target_dir
is the local directory where the contents will be downloaded.