summaryrefslogtreecommitdiffstats
path: root/rust/fatcat-api/examples/client.rs
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-05-15 00:33:33 -0700
committerBryan Newbold <bnewbold@robocracy.org>2018-05-15 00:33:36 -0700
commit33a4cce0b97832f5f0301b318a0a50073ce6b615 (patch)
tree1b6ba7ec5944d2be2d746510e743a7934f453cd0 /rust/fatcat-api/examples/client.rs
parent4a1d8f20ab91fda0f4794131144915d0c5214268 (diff)
downloadfatcat-33a4cce0b97832f5f0301b318a0a50073ce6b615.tar.gz
fatcat-33a4cce0b97832f5f0301b318a0a50073ce6b615.zip
revert to v2.3.1 codegen
This reverts back to something compatible with Iron and simple (blocking) parallelism, instead of the new async hyper 0.11 stuff.
Diffstat (limited to 'rust/fatcat-api/examples/client.rs')
-rw-r--r--rust/fatcat-api/examples/client.rs415
1 files changed, 133 insertions, 282 deletions
diff --git a/rust/fatcat-api/examples/client.rs b/rust/fatcat-api/examples/client.rs
index 6f7aa151..6693a3b1 100644
--- a/rust/fatcat-api/examples/client.rs
+++ b/rust/fatcat-api/examples/client.rs
@@ -1,350 +1,201 @@
#![allow(missing_docs, unused_variables, trivial_casts)]
-extern crate clap;
extern crate fatcat;
#[allow(unused_extern_crates)]
extern crate futures;
#[allow(unused_extern_crates)]
extern crate swagger;
-extern crate tokio_core;
#[allow(unused_extern_crates)]
extern crate uuid;
+extern crate clap;
-use clap::{App, Arg};
#[allow(unused_imports)]
-use fatcat::{ApiError, ApiNoContext, ContainerIdGetResponse, ContainerLookupGetResponse,
- ContainerPostResponse, ContextWrapperExt, CreatorIdGetResponse,
- CreatorLookupGetResponse, CreatorPostResponse, EditgroupIdAcceptPostResponse,
- EditgroupIdGetResponse, EditgroupPostResponse, EditorUsernameChangelogGetResponse,
- EditorUsernameGetResponse, FileIdGetResponse, FileLookupGetResponse,
- FilePostResponse, ReleaseIdGetResponse, ReleaseLookupGetResponse,
- ReleasePostResponse, WorkIdGetResponse, WorkPostResponse};
+use futures::{Future, future, Stream, stream};
#[allow(unused_imports)]
-use futures::{future, stream, Future, Stream};
-use tokio_core::reactor;
+use fatcat::{ApiNoContext, ContextWrapperExt,
+ ApiError,
+ ContainerIdGetResponse,
+ ContainerLookupGetResponse,
+ ContainerPostResponse,
+ CreatorIdGetResponse,
+ CreatorLookupGetResponse,
+ CreatorPostResponse,
+ EditgroupIdAcceptPostResponse,
+ EditgroupIdGetResponse,
+ EditgroupPostResponse,
+ EditorUsernameChangelogGetResponse,
+ EditorUsernameGetResponse,
+ FileIdGetResponse,
+ FileLookupGetResponse,
+ FilePostResponse,
+ ReleaseIdGetResponse,
+ ReleaseLookupGetResponse,
+ ReleasePostResponse,
+ WorkIdGetResponse,
+ WorkPostResponse
+ };
+use clap::{App, Arg};
fn main() {
let matches = App::new("client")
- .arg(
- Arg::with_name("operation")
- .help("Sets the operation to run")
- .possible_values(&[
- "ContainerIdGet",
- "ContainerLookupGet",
- "ContainerPost",
- "CreatorIdGet",
- "CreatorLookupGet",
- "CreatorPost",
- "EditgroupIdAcceptPost",
- "EditgroupIdGet",
- "EditgroupPost",
- "EditorUsernameChangelogGet",
- "EditorUsernameGet",
- "FileIdGet",
- "FileLookupGet",
- "FilePost",
- "ReleaseIdGet",
- "ReleaseLookupGet",
- "ReleasePost",
- "WorkIdGet",
- "WorkPost",
- ])
- .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("api.fatcat.wiki")
- .help("Hostname to contact"),
- )
- .arg(
- Arg::with_name("port")
- .long("port")
- .takes_value(true)
- .default_value("8080")
- .help("Port to contact"),
- )
+ .arg(Arg::with_name("operation")
+ .help("Sets the operation to run")
+ .possible_values(&[
+ "ContainerIdGet",
+ "ContainerLookupGet",
+ "ContainerPost",
+ "CreatorIdGet",
+ "CreatorLookupGet",
+ "CreatorPost",
+ "EditgroupIdAcceptPost",
+ "EditgroupIdGet",
+ "EditgroupPost",
+ "EditorUsernameChangelogGet",
+ "EditorUsernameGet",
+ "FileIdGet",
+ "FileLookupGet",
+ "FilePost",
+ "ReleaseIdGet",
+ "ReleaseLookupGet",
+ "ReleasePost",
+ "WorkIdGet",
+ "WorkPost",
+])
+ .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("api.fatcat.wiki")
+ .help("Hostname to contact"))
+ .arg(Arg::with_name("port")
+ .long("port")
+ .takes_value(true)
+ .default_value("8080")
+ .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") {
+ let base_url = format!("{}://{}:{}",
+ if is_https { "https" } else { "http" },
+ matches.value_of("host").unwrap(),
+ matches.value_of("port").unwrap());
+ let client = if is_https {
// Using Simple HTTPS
- fatcat::Client::try_new_https(core.handle(), &base_url, "examples/ca.pem")
+ fatcat::Client::try_new_https(&base_url, "examples/ca.pem")
.expect("Failed to create HTTPS client")
} else {
// Using HTTP
- fatcat::Client::try_new_http(core.handle(), &base_url)
+ fatcat::Client::try_new_http(&base_url)
.expect("Failed to create HTTP client")
};
// Using a non-default `Context` is not required; this is just an example!
- let client = client.with_context(fatcat::Context::new_with_span_id(
- self::uuid::Uuid::new_v4().to_string(),
- ));
+ let client = client.with_context(fatcat::Context::new_with_span_id(self::uuid::Uuid::new_v4().to_string()));
match matches.value_of("operation") {
+
Some("ContainerIdGet") => {
- let result = core.run(client.container_id_get("id_example".to_string()));
- println!(
- "{:?} (X-Span-ID: {:?})",
- result,
- client
- .context()
- .x_span_id
- .clone()
- .unwrap_or(String::from("<none>"))
- );
- }
+ let result = client.container_id_get("id_example".to_string()).wait();
+ println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
+ },
Some("ContainerLookupGet") => {
- let result = core.run(client.container_lookup_get("issn_example".to_string()));
- println!(
- "{:?} (X-Span-ID: {:?})",
- result,
- client
- .context()
- .x_span_id
- .clone()
- .unwrap_or(String::from("<none>"))
- );
- }
+ let result = client.container_lookup_get("issn_example".to_string()).wait();
+ println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
+ },
Some("ContainerPost") => {
- let result = core.run(client.container_post(None));
- println!(
- "{:?} (X-Span-ID: {:?})",
- result,
- client
- .context()
- .x_span_id
- .clone()
- .unwrap_or(String::from("<none>"))
- );
- }
+ let result = client.container_post(None).wait();
+ println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
+ },
Some("CreatorIdGet") => {
- let result = core.run(client.creator_id_get("id_example".to_string()));
- println!(
- "{:?} (X-Span-ID: {:?})",
- result,
- client
- .context()
- .x_span_id
- .clone()
- .unwrap_or(String::from("<none>"))
- );
- }
+ let result = client.creator_id_get("id_example".to_string()).wait();
+ println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
+ },
Some("CreatorLookupGet") => {
- let result = core.run(client.creator_lookup_get("orcid_example".to_string()));
- println!(
- "{:?} (X-Span-ID: {:?})",
- result,
- client
- .context()
- .x_span_id
- .clone()
- .unwrap_or(String::from("<none>"))
- );
- }
+ let result = client.creator_lookup_get("orcid_example".to_string()).wait();
+ println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
+ },
Some("CreatorPost") => {
- let result = core.run(client.creator_post(None));
- println!(
- "{:?} (X-Span-ID: {:?})",
- result,
- client
- .context()
- .x_span_id
- .clone()
- .unwrap_or(String::from("<none>"))
- );
- }
+ let result = client.creator_post(None).wait();
+ println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
+ },
Some("EditgroupIdAcceptPost") => {
- let result = core.run(client.editgroup_id_accept_post(56));
- println!(
- "{:?} (X-Span-ID: {:?})",
- result,
- client
- .context()
- .x_span_id
- .clone()
- .unwrap_or(String::from("<none>"))
- );
- }
+ let result = client.editgroup_id_accept_post(56).wait();
+ println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
+ },
Some("EditgroupIdGet") => {
- let result = core.run(client.editgroup_id_get(56));
- println!(
- "{:?} (X-Span-ID: {:?})",
- result,
- client
- .context()
- .x_span_id
- .clone()
- .unwrap_or(String::from("<none>"))
- );
- }
+ let result = client.editgroup_id_get(56).wait();
+ println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
+ },
Some("EditgroupPost") => {
- let result = core.run(client.editgroup_post());
- println!(
- "{:?} (X-Span-ID: {:?})",
- result,
- client
- .context()
- .x_span_id
- .clone()
- .unwrap_or(String::from("<none>"))
- );
- }
+ let result = client.editgroup_post().wait();
+ println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
+ },
Some("EditorUsernameChangelogGet") => {
- let result =
- core.run(client.editor_username_changelog_get("username_example".to_string()));
- println!(
- "{:?} (X-Span-ID: {:?})",
- result,
- client
- .context()
- .x_span_id
- .clone()
- .unwrap_or(String::from("<none>"))
- );
- }
+ let result = client.editor_username_changelog_get("username_example".to_string()).wait();
+ println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
+ },
Some("EditorUsernameGet") => {
- let result = core.run(client.editor_username_get("username_example".to_string()));
- println!(
- "{:?} (X-Span-ID: {:?})",
- result,
- client
- .context()
- .x_span_id
- .clone()
- .unwrap_or(String::from("<none>"))
- );
- }
+ let result = client.editor_username_get("username_example".to_string()).wait();
+ println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
+ },
Some("FileIdGet") => {
- let result = core.run(client.file_id_get("id_example".to_string()));
- println!(
- "{:?} (X-Span-ID: {:?})",
- result,
- client
- .context()
- .x_span_id
- .clone()
- .unwrap_or(String::from("<none>"))
- );
- }
+ let result = client.file_id_get("id_example".to_string()).wait();
+ println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
+ },
Some("FileLookupGet") => {
- let result = core.run(client.file_lookup_get("sha1_example".to_string()));
- println!(
- "{:?} (X-Span-ID: {:?})",
- result,
- client
- .context()
- .x_span_id
- .clone()
- .unwrap_or(String::from("<none>"))
- );
- }
+ let result = client.file_lookup_get("sha1_example".to_string()).wait();
+ println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
+ },
Some("FilePost") => {
- let result = core.run(client.file_post(None));
- println!(
- "{:?} (X-Span-ID: {:?})",
- result,
- client
- .context()
- .x_span_id
- .clone()
- .unwrap_or(String::from("<none>"))
- );
- }
+ let result = client.file_post(None).wait();
+ println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
+ },
Some("ReleaseIdGet") => {
- let result = core.run(client.release_id_get("id_example".to_string()));
- println!(
- "{:?} (X-Span-ID: {:?})",
- result,
- client
- .context()
- .x_span_id
- .clone()
- .unwrap_or(String::from("<none>"))
- );
- }
+ let result = client.release_id_get("id_example".to_string()).wait();
+ println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
+ },
Some("ReleaseLookupGet") => {
- let result = core.run(client.release_lookup_get("doi_example".to_string()));
- println!(
- "{:?} (X-Span-ID: {:?})",
- result,
- client
- .context()
- .x_span_id
- .clone()
- .unwrap_or(String::from("<none>"))
- );
- }
+ let result = client.release_lookup_get("doi_example".to_string()).wait();
+ println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
+ },
Some("ReleasePost") => {
- let result = core.run(client.release_post(None));
- println!(
- "{:?} (X-Span-ID: {:?})",
- result,
- client
- .context()
- .x_span_id
- .clone()
- .unwrap_or(String::from("<none>"))
- );
- }
+ let result = client.release_post(None).wait();
+ println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
+ },
Some("WorkIdGet") => {
- let result = core.run(client.work_id_get("id_example".to_string()));
- println!(
- "{:?} (X-Span-ID: {:?})",
- result,
- client
- .context()
- .x_span_id
- .clone()
- .unwrap_or(String::from("<none>"))
- );
- }
+ let result = client.work_id_get("id_example".to_string()).wait();
+ println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
+ },
Some("WorkPost") => {
- let result = core.run(client.work_post(None));
- println!(
- "{:?} (X-Span-ID: {:?})",
- result,
- client
- .context()
- .x_span_id
- .clone()
- .unwrap_or(String::from("<none>"))
- );
- }
+ let result = client.work_post(None).wait();
+ println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
+ },
- _ => panic!("Invalid operation provided"),
+ _ => {
+ panic!("Invalid operation provided")
+ }
}
}
+