Unverified Commit 7d140b1e authored by Doug's avatar Doug Committed by GitHub
Browse files

Refactored MediaLive code example (#555)

* Refactored MediaLive code example to use common example pattern; re-ordered crates in Cargo.toml

* Refactored MediaPackage code examples to use common example pattern; re-ordered crates in Cargo.toml
parent 771b0f2d
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ edition = "2018"

[dependencies]
medialive = { package = "aws-sdk-medialive", path = "../../build/aws-sdk/medialive" }
aws-types = { path = "../../build/aws-sdk/aws-types" }
tokio = { version = "1", features = ["full"] }
# used only to enable basic logging:
env_logger = "0.8.2"
structopt = { version = "0.3", default-features = false }
tracing-subscriber = { version = "0.2.16", features = ["fmt"] }
 No newline at end of file
+47 −3
Original line number Diff line number Diff line
@@ -3,10 +3,54 @@
 * SPDX-License-Identifier: Apache-2.0.
 */

/// Lists your AWS Elemental MediaLive input names and ARNs.
use aws_types::region::ProvideRegion;
use medialive::{Client, Config, Error, Region, PKG_VERSION};
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
struct Opt {
    /// The default AWS Region.
    #[structopt(short, long)]
    default_region: Option<String>,

    /// Whether to display additional information.
    #[structopt(short, long)]
    verbose: bool,
}

/// Lists your AWS Elemental MediaLive input names and ARNs in the Region.
/// # Arguments
///
/// * `[-d DEFAULT-REGION]` - The Region in which the client is created.
///    If not supplied, uses the value of the **AWS_REGION** environment variable.
///    If the environment variable is not set, defaults to **us-west-2**.
/// * `[-v]` - Whether to display additional information.
#[tokio::main]
async fn main() -> Result<(), medialive::Error> {
    let client = medialive::Client::from_env();
async fn main() -> Result<(), Error> {
    tracing_subscriber::fmt::init();

    let Opt {
        default_region,
        verbose,
    } = Opt::from_args();

    let region = default_region
        .as_ref()
        .map(|region| Region::new(region.clone()))
        .or_else(|| aws_types::region::default_provider().region())
        .unwrap_or_else(|| Region::new("us-west-2"));

    println!();

    if verbose {
        println!("MediaLive version: {}", PKG_VERSION);
        println!("Region:            {:?}", &region);
        println!();
    }

    let conf = Config::builder().region(region).build();
    let client = Client::from_conf(conf);

    let input_list = client.list_inputs().send().await?;

    for i in input_list.inputs.unwrap_or_default() {
+3 −2
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ edition = "2018"

[dependencies]
mediapackage = { package = "aws-sdk-mediapackage", path = "../../build/aws-sdk/mediapackage" }
aws-types = { path = "../../build/aws-sdk/aws-types" }
tokio = { version = "1", features = ["full"] }
# used only to enable basic logging:
env_logger = "0.8.2"
 No newline at end of file
structopt = { version = "0.3", default-features = false }
tracing-subscriber = { version = "0.2.16", features = ["fmt"] }
 No newline at end of file
+47 −2
Original line number Diff line number Diff line
@@ -4,9 +4,54 @@
 */

/// Lists your AWS Elemental MediaPackage endpoint URLs.
use aws_types::region::ProvideRegion;
use mediapackage::{Client, Config, Error, Region, PKG_VERSION};
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
struct Opt {
    /// The default AWS Region.
    #[structopt(short, long)]
    default_region: Option<String>,

    /// Whether to display additional information.
    #[structopt(short, long)]
    verbose: bool,
}

/// Lists your AWS Elemental MediaPackage endpoint descriptions and URLs.
/// # Arguments
///
/// * `[-d DEFAULT-REGION]` - The Region in which the client is created.
///    If not supplied, uses the value of the **AWS_REGION** environment variable.
///    If the environment variable is not set, defaults to **us-west-2**.
/// * `[-v]` - Whether to display additional information.
#[tokio::main]
async fn main() -> Result<(), mediapackage::Error> {
    let client = mediapackage::Client::from_env();
async fn main() -> Result<(), Error> {
    tracing_subscriber::fmt::init();

    let Opt {
        default_region,
        verbose,
    } = Opt::from_args();

    let region = default_region
        .as_ref()
        .map(|region| Region::new(region.clone()))
        .or_else(|| aws_types::region::default_provider().region())
        .unwrap_or_else(|| Region::new("us-west-2"));

    println!();

    if verbose {
        println!("MediaPackage version: {}", PKG_VERSION);
        println!("Region:               {:?}", &region);
        println!();
    }

    let conf = Config::builder().region(region).build();
    let client = Client::from_conf(conf);

    let or_endpoints = client.list_origin_endpoints().send().await?;

    for e in or_endpoints.origin_endpoints.unwrap_or_default() {
+46 −2
Original line number Diff line number Diff line
@@ -3,10 +3,54 @@
 * SPDX-License-Identifier: Apache-2.0.
 */

use aws_types::region::ProvideRegion;
use mediapackage::{Client, Config, Error, Region, PKG_VERSION};
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
struct Opt {
    /// The default AWS Region.
    #[structopt(short, long)]
    default_region: Option<String>,

    /// Whether to display additional information.
    #[structopt(short, long)]
    verbose: bool,
}

/// Lists your AWS Elemental MediaPackage channel ARNs and descriptions.
/// # Arguments
///
/// * `[-d DEFAULT-REGION]` - The Region in which the client is created.
///    If not supplied, uses the value of the **AWS_REGION** environment variable.
///    If the environment variable is not set, defaults to **us-west-2**.
/// * `[-v]` - Whether to display additional information.
#[tokio::main]
async fn main() -> Result<(), mediapackage::Error> {
    let client = mediapackage::Client::from_env();
async fn main() -> Result<(), Error> {
    tracing_subscriber::fmt::init();

    let Opt {
        default_region,
        verbose,
    } = Opt::from_args();

    let region = default_region
        .as_ref()
        .map(|region| Region::new(region.clone()))
        .or_else(|| aws_types::region::default_provider().region())
        .unwrap_or_else(|| Region::new("us-west-2"));

    println!();

    if verbose {
        println!("MediaPackage version: {}", PKG_VERSION);
        println!("Region:               {:?}", &region);
        println!();
    }

    let conf = Config::builder().region(region).build();
    let client = Client::from_conf(conf);

    let list_channels = client.list_channels().send().await?;

    for c in list_channels.channels.unwrap_or_default() {