#![allow(missing_docs, unused_variables, trivial_casts)] extern crate timezynk_bridge_models; #[allow(unused_extern_crates)] extern crate futures; #[allow(unused_extern_crates)] #[macro_use] extern crate swagger; #[allow(unused_extern_crates)] extern crate clap; extern crate tokio_core; extern crate uuid; use swagger::{ContextBuilder, EmptyContext, XSpanIdString, Has, Push, AuthData}; #[allow(unused_imports)] use futures::{Future, future, Stream, stream}; use tokio_core::reactor; #[allow(unused_imports)] use timezynk_bridge_models::{ApiNoContext, ContextWrapperExt, ApiError, DataSinksGetResponse, DataSinksPostResponse, DataSourcesGetResponse, DataSourcesPostResponse, EntitiesEntityIdChangesGetResponse, EntitiesEntityIdChangesPostResponse, EntitiesEntityIdNextSyncGetResponse, EntitiesEntityIdNextSyncPutResponse, EntitiesEntityIdPutResponse, EntitiesGetResponse, DataSourcesDataSourceIdSynchronizationStateGetResponse }; use clap::{App, Arg}; fn main() { let matches = App::new("client") .arg(Arg::with_name("operation") .help("Sets the operation to run") .possible_values(&[ "DataSinksGet", "DataSinksPost", "DataSourcesGet", "DataSourcesPost", "EntitiesEntityIdChangesGet", "EntitiesEntityIdChangesPost", "EntitiesEntityIdNextSyncGet", "EntitiesEntityIdNextSyncPut", "EntitiesEntityIdPut", "EntitiesGet", "DataSourcesDataSourceIdSynchronizationStateGet", ]) .required(true) .index(1)) .arg(Arg::with_name("https") .long("https") .help("Whether to use HTTPS or not")) .arg(Arg::with_name("host") .long("host") .takes_value(true) .default_value("localhost") .help("Hostname to contact")) .arg(Arg::with_name("port") .long("port") .takes_value(true) .default_value("80") .help("Port to contact")) .get_matches(); let mut core = reactor::Core::new().unwrap(); let is_https = matches.is_present("https"); let base_url = format!("{}://{}:{}", if is_https { "https" } else { "http" }, matches.value_of("host").unwrap(), matches.value_of("port").unwrap()); let client = if matches.is_present("https") { // Using Simple HTTPS timezynk_bridge_models::Client::try_new_https(core.handle(), &base_url, "examples/ca.pem") .expect("Failed to create HTTPS client") } else { // Using HTTP timezynk_bridge_models::Client::try_new_http(core.handle(), &base_url) .expect("Failed to create HTTP client") }; let context: make_context_ty!(ContextBuilder, EmptyContext, Option, XSpanIdString) = make_context!(ContextBuilder, EmptyContext, None as Option, XSpanIdString(self::uuid::Uuid::new_v4().to_string())); let client = client.with_context(context); match matches.value_of("operation") { Some("DataSinksGet") => { let result = core.run(client.data_sinks_get()); println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has).get().clone()); }, Some("DataSinksPost") => { let result = core.run(client.data_sinks_post(None)); println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has).get().clone()); }, Some("DataSourcesGet") => { let result = core.run(client.data_sources_get()); println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has).get().clone()); }, Some("DataSourcesPost") => { let result = core.run(client.data_sources_post(None)); println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has).get().clone()); }, Some("EntitiesEntityIdChangesGet") => { let result = core.run(client.entities_entity_id_changes_get("entity_id_example".to_string())); println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has).get().clone()); }, Some("EntitiesEntityIdChangesPost") => { let result = core.run(client.entities_entity_id_changes_post("entity_id_example".to_string(), Some(&Vec::new()))); println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has).get().clone()); }, Some("EntitiesEntityIdNextSyncGet") => { let result = core.run(client.entities_entity_id_next_sync_get("entity_id_example".to_string())); println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has).get().clone()); }, Some("EntitiesEntityIdNextSyncPut") => { let result = core.run(client.entities_entity_id_next_sync_put("entity_id_example".to_string(), Some("body_example".to_string()))); println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has).get().clone()); }, Some("EntitiesEntityIdPut") => { let result = core.run(client.entities_entity_id_put("entity_id_example".to_string())); println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has).get().clone()); }, Some("EntitiesGet") => { let result = core.run(client.entities_get()); println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has).get().clone()); }, Some("DataSourcesDataSourceIdSynchronizationStateGet") => { let result = core.run(client.data_sources_data_source_id_synchronization_state_get("data_source_id_example".to_string())); println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &Has).get().clone()); }, _ => { panic!("Invalid operation provided") } } }