aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2020-01-02 21:10:55 +0100
committerHarald Eilertsen <haraldei@anduin.net>2020-01-02 21:10:55 +0100
commit16a56f12cd2e66e10f8bb5e2c4026d3a7148e680 (patch)
tree913bd32a563b32302c2e14304460a3cbc9a88a39
parent7f306445cb78d52f598eca1810dc2c5002e34a4a (diff)
downloadrust-zotapi-16a56f12cd2e66e10f8bb5e2c4026d3a7148e680.tar.gz
rust-zotapi-16a56f12cd2e66e10f8bb5e2c4026d3a7148e680.tar.bz2
rust-zotapi-16a56f12cd2e66e10f8bb5e2c4026d3a7148e680.zip
Cargo fmt
-rw-r--r--examples/zot/abconfig.rs2
-rw-r--r--examples/zot/abook.rs15
-rw-r--r--examples/zot/channel_stream.rs29
-rw-r--r--examples/zot/group.rs23
-rw-r--r--examples/zot/item.rs2
-rw-r--r--examples/zot/network_stream.rs29
-rw-r--r--examples/zot/xchan.rs2
-rw-r--r--examples/zotcli.rs53
-rw-r--r--src/abconfig.rs4
-rw-r--r--src/abook.rs4
-rw-r--r--src/client.rs61
-rw-r--r--src/group.rs4
-rw-r--r--src/item.rs18
-rw-r--r--src/lib.rs3
-rw-r--r--src/xchan.rs8
-rw-r--r--tests/zotapi.rs134
16 files changed, 201 insertions, 190 deletions
diff --git a/examples/zot/abconfig.rs b/examples/zot/abconfig.rs
index cc478ef..54d555c 100644
--- a/examples/zot/abconfig.rs
+++ b/examples/zot/abconfig.rs
@@ -21,7 +21,7 @@ pub fn fetch(client: &zotapi::Client) {
match client.abconfig().fetch() {
Ok(payload) => {
println!("{}", payload);
- },
+ }
Err(e) => {
println!("{:?}", e);
}
diff --git a/examples/zot/abook.rs b/examples/zot/abook.rs
index 7e91981..a16f68c 100644
--- a/examples/zot/abook.rs
+++ b/examples/zot/abook.rs
@@ -20,11 +20,10 @@ pub fn fetch(client: &zotapi::Client, raw: bool) {
Ok(payload) => {
if raw {
println!("{}", &payload);
- }
- else {
+ } else {
process(&payload);
}
- },
+ }
Err(e) => {
println!("{:?}", e);
}
@@ -36,12 +35,12 @@ fn process(payload: &str) {
match data {
serde_json::Value::Array(v) => {
for contact in v {
- println!("{} ({}, {})",
- contact["xchan_name"],
- contact["xchan_addr"],
- contact["xchan_network"]);
+ println!(
+ "{} ({}, {})",
+ contact["xchan_name"], contact["xchan_addr"], contact["xchan_network"]
+ );
}
- },
+ }
_ => {
println!("Unexpected data:\n{}", payload);
}
diff --git a/examples/zot/channel_stream.rs b/examples/zot/channel_stream.rs
index a278244..b50f93f 100644
--- a/examples/zot/channel_stream.rs
+++ b/examples/zot/channel_stream.rs
@@ -25,11 +25,10 @@ pub fn fetch(client: &zotapi::Client, raw: bool) {
Ok(payload) => {
if raw {
println!("{}", payload);
- }
- else {
+ } else {
list(&payload);
}
- },
+ }
Err(e) => {
println!("Error getting channel stream: {:?}", e);
}
@@ -43,10 +42,8 @@ fn list(payload: &str) {
print_item(&item);
println!("-----");
}
- },
- Ok(_) => {
- println!("Wrong type returned, expected an array.")
- },
+ }
+ Ok(_) => println!("Wrong type returned, expected an array."),
Err(e) => {
println!("Error: {}", e);
}
@@ -76,8 +73,9 @@ fn get_object_type(item: &serde_json::Value) -> &str {
fn get_tags(item: &serde_json::Value) -> String {
match item["tags"] {
- serde_json::Value::Array(ref v) => {
- v.iter().map(|t| {
+ serde_json::Value::Array(ref v) => v
+ .iter()
+ .map(|t| {
let prefix = match get_str(&t["type"]) {
"hashtag" => "#",
"forum" => "!",
@@ -85,14 +83,11 @@ fn get_tags(item: &serde_json::Value) -> String {
_ => "",
};
format!("{}{}", prefix, get_str(&t["tag"]))
- }).collect::<Vec<_>>().join(", ")
- },
- serde_json::Value::Null => {
- String::new()
- },
- _ => {
- String::from("invalid tags, expected array...")
- }
+ })
+ .collect::<Vec<_>>()
+ .join(", "),
+ serde_json::Value::Null => String::new(),
+ _ => String::from("invalid tags, expected array..."),
}
}
diff --git a/examples/zot/group.rs b/examples/zot/group.rs
index e02fb13..9264cdc 100644
--- a/examples/zot/group.rs
+++ b/examples/zot/group.rs
@@ -15,11 +15,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-use serde_json::{Value, from_str};
+use serde_json::{from_str, Value};
pub fn list(data: &str) {
if let Ok(Value::Array(groups)) = from_str(&data) {
-
println!("Id | Group name | uid | flags | hash");
println!("----+------------------+-----+-------+-------------------------");
@@ -38,34 +37,34 @@ pub fn list(data: &str) {
}
}
- print!("{:>3} | {:16} | {:>3} | {:5} | {}\n",
+ print!(
+ "{:>3} | {:16} | {:>3} | {:5} | {}\n",
group["id"].as_u64().unwrap(),
group["gname"].as_str().unwrap(),
group["uid"].as_u64().unwrap(),
flags,
- group["hash"].as_str().unwrap());
+ group["hash"].as_str().unwrap()
+ );
}
- }
- else {
+ } else {
eprintln!("Invalid data");
}
}
-
pub fn list_members(data: &str) {
if let Ok(Value::Array(members)) = from_str(&data) {
-
println!("Id | Name | Address");
println!("----+-------------------------------+------------------------");
for member in members {
- println!("{:>3} | {:29} | {}",
+ println!(
+ "{:>3} | {:29} | {}",
member["id"].as_u64().unwrap(),
member["xchan_name"].as_str().unwrap(),
- member["xchan_addr"].as_str().unwrap());
+ member["xchan_addr"].as_str().unwrap()
+ );
}
- }
- else {
+ } else {
eprintln!("Invalid data");
}
}
diff --git a/examples/zot/item.rs b/examples/zot/item.rs
index e848af2..dec6c8d 100644
--- a/examples/zot/item.rs
+++ b/examples/zot/item.rs
@@ -39,7 +39,7 @@ pub fn post(client: &zotapi::Client, args: &ArgMatches) {
match msg.create() {
Ok(payload) => {
println!("Raw payload: {}", payload);
- },
+ }
Err(e) => {
println!("Error posting message: {:?}", e);
}
diff --git a/examples/zot/network_stream.rs b/examples/zot/network_stream.rs
index de3b12f..6dc1a0c 100644
--- a/examples/zot/network_stream.rs
+++ b/examples/zot/network_stream.rs
@@ -25,11 +25,10 @@ pub fn fetch(client: &zotapi::Client, raw: bool) {
Ok(payload) => {
if raw {
println!("{}", payload);
- }
- else {
+ } else {
list(&payload);
}
- },
+ }
Err(e) => {
println!("Error getting channel stream: {:?}", e);
}
@@ -43,10 +42,8 @@ fn list(payload: &str) {
print_item(&item);
println!("-----");
}
- },
- Ok(_) => {
- println!("Wrong type returned, expected an array.")
- },
+ }
+ Ok(_) => println!("Wrong type returned, expected an array."),
Err(e) => {
println!("Error: {}", e);
}
@@ -76,8 +73,9 @@ fn get_object_type(item: &serde_json::Value) -> &str {
fn get_tags(item: &serde_json::Value) -> String {
match item["tags"] {
- serde_json::Value::Array(ref v) => {
- v.iter().map(|t| {
+ serde_json::Value::Array(ref v) => v
+ .iter()
+ .map(|t| {
let prefix = match get_str(&t["type"]) {
"hashtag" => "#",
"forum" => "!",
@@ -85,14 +83,11 @@ fn get_tags(item: &serde_json::Value) -> String {
_ => "",
};
format!("{}{}", prefix, get_str(&t["tag"]))
- }).collect::<Vec<_>>().join(", ")
- },
- serde_json::Value::Null => {
- String::new()
- },
- _ => {
- String::from("invalid tags, expected array...")
- }
+ })
+ .collect::<Vec<_>>()
+ .join(", "),
+ serde_json::Value::Null => String::new(),
+ _ => String::from("invalid tags, expected array..."),
}
}
diff --git a/examples/zot/xchan.rs b/examples/zot/xchan.rs
index d37328d..d2d73d0 100644
--- a/examples/zot/xchan.rs
+++ b/examples/zot/xchan.rs
@@ -33,7 +33,7 @@ pub fn fetch(client: &zotapi::Client, _raw: bool, t: Type, id: &str) {
match res {
Ok(payload) => {
println!("{}", payload);
- },
+ }
Err(e) => {
println!("{:?}", e);
}
diff --git a/examples/zotcli.rs b/examples/zotcli.rs
index 2b068e0..14bb9ad 100644
--- a/examples/zotcli.rs
+++ b/examples/zotcli.rs
@@ -15,13 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-use clap::{
- clap_app,
- crate_name,
- crate_version,
- crate_authors,
- crate_description,
-};
+use clap::{clap_app, crate_authors, crate_description, crate_name, crate_version};
use dotenv::dotenv;
use std::env;
use std::str::FromStr;
@@ -86,75 +80,66 @@ fn main() {
("channel", Some(m)) => {
let raw = m.is_present("raw");
zot::channel_stream::fetch(&client, raw);
- },
+ }
("network", Some(m)) => {
let raw = m.is_present("raw");
zot::network_stream::fetch(&client, raw);
- },
+ }
("abconfig", _) => {
zot::abconfig::fetch(&client);
- },
+ }
("abook", Some(m)) => {
let raw = m.is_present("raw");
zot::abook::fetch(&client, raw);
- },
+ }
("group", Some(m)) => {
if let Some(id) = m.value_of("ID") {
let res = client
.group_members()
.by_group_id(u64::from_str(id).unwrap())
- .fetch().unwrap();
+ .fetch()
+ .unwrap();
if m.is_present("raw") {
println!("{}", res);
- }
- else {
+ } else {
zot::group::list_members(&res);
}
- }
- else if let Some(gname) = m.value_of("GNAME") {
- let res = client
- .group_members()
- .by_group_name(gname)
- .fetch().unwrap();
+ } else if let Some(gname) = m.value_of("GNAME") {
+ let res = client.group_members().by_group_name(gname).fetch().unwrap();
if m.is_present("raw") {
println!("{}", res);
- }
- else {
+ } else {
zot::group::list_members(&res);
}
- }
- else {
+ } else {
let res = client.group().fetch().unwrap();
if m.is_present("raw") {
println!("{}", res);
- }
- else {
+ } else {
zot::group::list(&res);
}
}
- },
+ }
("xchan", Some(m)) => {
let raw = m.is_present("raw");
let t = if m.is_present("guid") {
zot::xchan::Type::GUID
- }
- else if m.is_present("hash") {
+ } else if m.is_present("hash") {
zot::xchan::Type::Hash
- }
- else {
+ } else {
zot::xchan::Type::Addr
};
zot::xchan::fetch(&client, raw, t, m.value_of("ID").unwrap());
- },
+ }
("post", Some(m)) => {
zot::item::post(&client, m);
- },
+ }
_ => {
println!("{}", matches.usage());
- },
+ }
}
}
diff --git a/src/abconfig.rs b/src/abconfig.rs
index 78eec4b..f1622c7 100644
--- a/src/abconfig.rs
+++ b/src/abconfig.rs
@@ -25,9 +25,7 @@ pub struct ABConfigFetcher<'a> {
impl<'a> ABConfigFetcher<'a> {
pub fn new(client: &'a Client) -> ABConfigFetcher<'a> {
- ABConfigFetcher {
- client,
- }
+ ABConfigFetcher { client }
}
pub fn fetch(&self) -> Result<String, Error> {
diff --git a/src/abook.rs b/src/abook.rs
index f7469e3..bcedf81 100644
--- a/src/abook.rs
+++ b/src/abook.rs
@@ -25,9 +25,7 @@ pub struct AbookFetcher<'a> {
impl<'a> AbookFetcher<'a> {
pub fn new(client: &'a Client) -> AbookFetcher<'a> {
- AbookFetcher {
- client,
- }
+ AbookFetcher { client }
}
pub fn fetch(&self) -> Result<String, Error> {
diff --git a/src/client.rs b/src/client.rs
index 3a20133..ab021fb 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -15,11 +15,11 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::{
+ abconfig::ABConfigFetcher,
+ abook::AbookFetcher,
error::Error,
group::{GroupFetcher, GroupMembersFetcher},
item::ItemBuilder,
- abook::AbookFetcher,
- abconfig::ABConfigFetcher,
xchan::XChanFetcher,
};
use reqwest::{
@@ -31,14 +31,14 @@ use serde::Serialize;
use std::collections::BTreeMap;
use std::io::Read;
-pub const ZOTAPI_ABOOK_PATH : &str = "/api/z/1.0/abook";
-pub const ZOTAPI_ABCONFIG_PATH : &str = "/api/z/1.0/abconfig";
-pub const ZOTAPI_CHANNEL_STREAM_PATH : &str = "/api/z/1.0/channel/stream";
-pub const ZOTAPI_NETWORK_STREAM_PATH : &str = "/api/z/1.0/network/stream";
-pub const ZOTAPI_GROUP_PATH : &str = "/api/z/1.0/group";
-pub const ZOTAPI_GROUP_MEMBERS_PATH : &str = "/api/z/1.0/group_members";
-pub const ZOTAPI_ITEM_UPDATE_PATH : &str = "/api/z/1.0/item/update";
-pub const ZOTAPI_XCHAN_PATH : &str = "/api/z/1.0/xchan";
+pub const ZOTAPI_ABOOK_PATH: &str = "/api/z/1.0/abook";
+pub const ZOTAPI_ABCONFIG_PATH: &str = "/api/z/1.0/abconfig";
+pub const ZOTAPI_CHANNEL_STREAM_PATH: &str = "/api/z/1.0/channel/stream";
+pub const ZOTAPI_NETWORK_STREAM_PATH: &str = "/api/z/1.0/network/stream";
+pub const ZOTAPI_GROUP_PATH: &str = "/api/z/1.0/group";
+pub const ZOTAPI_GROUP_MEMBERS_PATH: &str = "/api/z/1.0/group_members";
+pub const ZOTAPI_ITEM_UPDATE_PATH: &str = "/api/z/1.0/item/update";
+pub const ZOTAPI_XCHAN_PATH: &str = "/api/z/1.0/xchan";
#[derive(Debug)]
pub struct Client {
@@ -91,22 +91,25 @@ impl Client {
}
fn url<T>(&self, path: &str, args: &T) -> String
- where T: Serialize + std::fmt::Debug
+ where
+ T: Serialize + std::fmt::Debug,
{
let r = self.base_url.clone() + path;
if let Ok(a) = serde_qs::to_string(dbg!(args)) {
r + "?" + &a
- }
- else {
+ } else {
r
}
}
pub fn fetch_stream<T>(&self, path: &str, args: &T) -> Result<String, Error>
- where T: Serialize + std::fmt::Debug
+ where
+ T: Serialize + std::fmt::Debug,
{
let url = dbg!(self.url(path, args));
- let res = self.inner.get(&url)
+ let res = self
+ .inner
+ .get(&url)
.header(ACCEPT, "application/json")
.basic_auth(self.user.clone(), Some(self.pw.clone()))
.send()?;
@@ -115,22 +118,31 @@ impl Client {
}
pub fn post_data<T>(&self, path: &str, data: &T) -> Result<String, Error>
- where T: Serialize + std::fmt::Debug,
+ where
+ T: Serialize + std::fmt::Debug,
{
let url = dbg!(self.url(path, &()));
- let res = dbg!(self.inner.post(&url)
+ let res = dbg!(self
+ .inner
+ .post(&url)
.header(ACCEPT, "application/json")
.header(CONTENT_TYPE, "application/x-www-form-urlencoded")
.basic_auth(self.user.clone(), Some(self.pw.clone()))
.body(serde_qs::to_string(&data)?))
- //.form(&data))
- .send()?;
+ //.form(&data))
+ .send()?;
handle_result(res)
}
- pub fn post_multipart<T>(&self, path: &str, data: &BTreeMap<&str, T>, files: &Vec<&str>) -> Result<String, Error>
- where T: ToString,
+ pub fn post_multipart<T>(
+ &self,
+ path: &str,
+ data: &BTreeMap<&str, T>,
+ files: &Vec<&str>,
+ ) -> Result<String, Error>
+ where
+ T: ToString,
{
let url = dbg!(self.url(path, &()));
let mut form = reqwest::multipart::Form::new();
@@ -143,7 +155,9 @@ impl Client {
form = form.file("media", f).unwrap();
}
- let res = self.inner.post(&url)
+ let res = self
+ .inner
+ .post(&url)
.basic_auth(self.user.clone(), Some(self.pw.clone()))
.multipart(form)
.send()?;
@@ -162,11 +176,10 @@ fn handle_result(mut res: reqwest::Response) -> Result<String, Error> {
let mut body = String::new();
res.read_to_string(&mut body)?;
Ok(body)
- },
+ }
_ => {
eprintln!("Received unknown status: {:?}", res.status());
Err(Error::Unknown)
}
}
}
-
diff --git a/src/group.rs b/src/group.rs
index 43c4d65..98d83d2 100644
--- a/src/group.rs
+++ b/src/group.rs
@@ -34,7 +34,6 @@ impl<'a> GroupFetcher<'a> {
}
}
-
#[derive(Debug, Serialize)]
enum GroupSelector<'a> {
#[serde(rename(serialize = "group_id"))]
@@ -67,6 +66,7 @@ impl<'a> GroupMembersFetcher<'a> {
pub fn fetch(&self) -> Result<String, Error> {
self.client.fetch_stream(
client::ZOTAPI_GROUP_MEMBERS_PATH,
- &self.id.as_ref().unwrap())
+ &self.id.as_ref().unwrap(),
+ )
}
}
diff --git a/src/item.rs b/src/item.rs
index 5507577..3d9ad1e 100644
--- a/src/item.rs
+++ b/src/item.rs
@@ -21,7 +21,6 @@ use crate::{
use serde::Serialize;
use std::collections::BTreeMap;
-
/// Data type for values that an Item can hold.
#[derive(Debug, Serialize)]
#[serde(untagged)]
@@ -85,8 +84,8 @@ fn convert_itemdata_list_with_one_member_to_a_string() {
/// ```
#[derive(Debug)]
pub struct ItemBuilder<'a> {
- client : &'a Client,
- data : BTreeMap<&'a str, ItemData<'a>>,
+ client: &'a Client,
+ data: BTreeMap<&'a str, ItemData<'a>>,
files: Vec<&'a str>,
}
@@ -119,7 +118,9 @@ impl<'a> ItemBuilder<'a> {
/// Set groups allowed to access item
pub fn group_allow(&mut self, group: &'a str) -> &mut ItemBuilder<'a> {
- let groups_allow = self.data.entry("groups_allow")
+ let groups_allow = self
+ .data
+ .entry("groups_allow")
.or_insert(ItemData::List(Vec::<&str>::new()));
groups_allow.push(group);
@@ -130,10 +131,11 @@ impl<'a> ItemBuilder<'a> {
pub fn create(&self) -> Result<String, Error> {
dbg!(self);
if self.files.is_empty() {
- self.client.post_data(client::ZOTAPI_ITEM_UPDATE_PATH, &self.data)
- }
- else {
- self.client.post_multipart(client::ZOTAPI_ITEM_UPDATE_PATH, &self.data, &self.files)
+ self.client
+ .post_data(client::ZOTAPI_ITEM_UPDATE_PATH, &self.data)
+ } else {
+ self.client
+ .post_multipart(client::ZOTAPI_ITEM_UPDATE_PATH, &self.data, &self.files)
}
}
}
diff --git a/src/lib.rs b/src/lib.rs
index e9b6bf9..eb5d897 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -25,8 +25,7 @@ mod xchan;
pub use client::Client;
pub use error::Error;
-pub fn client(url: &str, user: &str, pw: &str) -> Client
-{
+pub fn client(url: &str, user: &str, pw: &str) -> Client {
Client::new(url, user, pw)
}
diff --git a/src/xchan.rs b/src/xchan.rs
index 68f7622..9b920d5 100644
--- a/src/xchan.rs
+++ b/src/xchan.rs
@@ -36,10 +36,7 @@ pub struct XChanFetcher<'a> {
impl<'a> XChanFetcher<'a> {
pub fn new(client: &'a Client) -> XChanFetcher<'a> {
- XChanFetcher {
- client,
- data: None,
- }
+ XChanFetcher { client, data: None }
}
pub fn by_address(&mut self, addr: &'a str) -> &mut XChanFetcher<'a> {
@@ -58,6 +55,7 @@ impl<'a> XChanFetcher<'a> {
}
pub fn fetch(&self) -> Result<String, Error> {
- self.client.fetch_stream(client::ZOTAPI_XCHAN_PATH, &self.data.as_ref().unwrap())
+ self.client
+ .fetch_stream(client::ZOTAPI_XCHAN_PATH, &self.data.as_ref().unwrap())
}
}
diff --git a/tests/zotapi.rs b/tests/zotapi.rs
index d828632..66fe15e 100644
--- a/tests/zotapi.rs
+++ b/tests/zotapi.rs
@@ -17,9 +17,10 @@
use mockito::{mock, Matcher, Mock};
fn mock_with_authorization(method: &str, url: &str) -> Mock {
- mock(method, url)
- .match_header("Authorization",
- Matcher::Exact(format!("Basic {}", base64::encode("testuser:test1234"))))
+ mock(method, url).match_header(
+ "Authorization",
+ Matcher::Exact(format!("Basic {}", base64::encode("testuser:test1234"))),
+ )
}
fn default_mock(method: &str, url: &str) -> Mock {
@@ -81,18 +82,20 @@ fn create_new_post() {
#[test]
fn create_new_post_with_title() {
let m = mock_with_authorization("POST", "/api/z/1.0/item/update")
- .match_body(
- Matcher::AllOf(vec![
- Matcher::UrlEncoded("title".to_string(), "A+title".to_string()),
- Matcher::UrlEncoded("body".to_string(), "This+is+a+test".to_string()),
- ])
- )
+ .match_body(Matcher::AllOf(vec![
+ Matcher::UrlEncoded("title".to_string(), "A+title".to_string()),
+ Matcher::UrlEncoded("body".to_string(), "This+is+a+test".to_string()),
+ ]))
.with_status(200)
.with_header("content-type", "application/json")
.with_body("{}")
.create();
- let _res = client().item().title("A title").body("This is a test").create();
+ let _res = client()
+ .item()
+ .title("A title")
+ .body("This is a test")
+ .create();
m.assert();
}
@@ -106,18 +109,17 @@ fn create_new_post_limited_to_one_privacy_group() {
// For now this test makes no assertions, but at least it runs
// through the code paths it should.
let _m = mock_with_authorization("POST", "/api/z/1.0/item/update")
- .match_body(
- Matcher::AllOf(vec![
- Matcher::UrlEncoded("body".to_string(), "This is a test".to_string()),
- Matcher::UrlEncoded("groups_allow[0]".to_string(), "grouphash".to_string())
- ])
- )
+ .match_body(Matcher::AllOf(vec![
+ Matcher::UrlEncoded("body".to_string(), "This is a test".to_string()),
+ Matcher::UrlEncoded("groups_allow[0]".to_string(), "grouphash".to_string()),
+ ]))
.with_status(200)
.with_header("content-type", "application/json")
.with_body("{}")
.create();
- let _res = client().item()
+ let _res = client()
+ .item()
.body("This is a test")
.group_allow("grouphash")
.create();
@@ -128,25 +130,30 @@ fn create_new_post_limited_to_one_privacy_group() {
#[test]
fn upload_item_with_media_file() {
let m = mock_with_authorization("POST", "/api/z/1.0/item/update")
- .match_header("content-type", Matcher::Regex("^multipart/form-data; boundary=.+$".into()))
+ .match_header(
+ "content-type",
+ Matcher::Regex("^multipart/form-data; boundary=.+$".into()),
+ )
.match_body(Matcher::Regex(
- "--.+\r\n".to_owned() +
- "Content-Disposition: form-data; name=\"body\"\r\n" +
- "\r\nThis is a test\r\n" +
- "--.+\r\n" +
- "Content-Disposition: form-data; name=\"title\"\r\n" +
- "\r\nA title\r\n" +
- "--.+\r\n" +
- "Content-Disposition: form-data; name=\"media\"; filename=\"testfile.txt\"\r\n" +
- "Content-Type: text/plain\r\n" +
- "\r\ntestfile contents\n" +
- "\r\n--.+--\r\n"))
+ "--.+\r\n".to_owned()
+ + "Content-Disposition: form-data; name=\"body\"\r\n"
+ + "\r\nThis is a test\r\n"
+ + "--.+\r\n"
+ + "Content-Disposition: form-data; name=\"title\"\r\n"
+ + "\r\nA title\r\n"
+ + "--.+\r\n"
+ + "Content-Disposition: form-data; name=\"media\"; filename=\"testfile.txt\"\r\n"
+ + "Content-Type: text/plain\r\n"
+ + "\r\ntestfile contents\n"
+ + "\r\n--.+--\r\n",
+ ))
.with_status(200)
.with_header("content-type", "application/json")
.with_body("{}")
.create();
- let _res = client().item()
+ let _res = client()
+ .item()
.title("A title")
.body("This is a test")
.file("tests/fixtures/testfile.txt")
@@ -158,29 +165,34 @@ fn upload_item_with_media_file() {
#[test]
fn upload_item_with_two_files() {
let m = mock_with_authorization("POST", "/api/z/1.0/item/update")
- .match_header("content-type", Matcher::Regex("multipart/form-data; boundary=.+".into()))
+ .match_header(
+ "content-type",
+ Matcher::Regex("multipart/form-data; boundary=.+".into()),
+ )
.match_body(Matcher::Regex(
- "--.+\r\n".to_owned() +
- "Content-Disposition: form-data; name=\"body\"\r\n" +
- "\r\nThis is a test\r\n" +
- "--.+\r\n" +
- "Content-Disposition: form-data; name=\"title\"\r\n" +
- "\r\nA title\r\n" +
- "--.+\r\n" +
- "Content-Disposition: form-data; name=\"media\"; filename=\"testfile.txt\"\r\n" +
- "Content-Type: text/plain\r\n" +
- "\r\ntestfile contents\n" +
- "\r\n--.+\r\n" +
- "Content-Disposition: form-data; name=\"media\"; filename=\"testfile.txt\"\r\n" +
- "Content-Type: text/plain\r\n" +
- "\r\ntestfile contents\n" +
- "\r\n--.+--\r\n"))
+ "--.+\r\n".to_owned()
+ + "Content-Disposition: form-data; name=\"body\"\r\n"
+ + "\r\nThis is a test\r\n"
+ + "--.+\r\n"
+ + "Content-Disposition: form-data; name=\"title\"\r\n"
+ + "\r\nA title\r\n"
+ + "--.+\r\n"
+ + "Content-Disposition: form-data; name=\"media\"; filename=\"testfile.txt\"\r\n"
+ + "Content-Type: text/plain\r\n"
+ + "\r\ntestfile contents\n"
+ + "\r\n--.+\r\n"
+ + "Content-Disposition: form-data; name=\"media\"; filename=\"testfile.txt\"\r\n"
+ + "Content-Type: text/plain\r\n"
+ + "\r\ntestfile contents\n"
+ + "\r\n--.+--\r\n",
+ ))
.with_status(200)
.with_header("content-type", "application/json")
.with_body("{}")
.create();
- let _res = client().item()
+ let _res = client()
+ .item()
.title("A title")
.body("This is a test")
.file("tests/fixtures/testfile.txt")
@@ -193,7 +205,11 @@ fn upload_item_with_two_files() {
#[test]
fn fetch_xchan_by_address() {
let m = default_mock("GET", "/api/z/1.0/xchan?address=test%40test.com");
- let _res = client().xchan().by_address("test@test.com").fetch().unwrap();
+ let _res = client()
+ .xchan()
+ .by_address("test@test.com")
+ .fetch()
+ .unwrap();
m.assert();
}
@@ -207,7 +223,11 @@ fn fetch_xchan_by_hash() {
#[test]
fn fetch_xchan_by_guid() {
let m = default_mock("GET", "/api/z/1.0/xchan?guid=baffebaff-baff-baff");
- let _res = client().xchan().by_guid("baffebaff-baff-baff").fetch().unwrap();
+ let _res = client()
+ .xchan()
+ .by_guid("baffebaff-baff-baff")
+ .fetch()
+ .unwrap();
m.assert();
}
@@ -235,7 +255,10 @@ fn fetch_privacy_groups() {
#[test]
fn fetch_members_of_group_by_group_id() {
let m = mock_with_authorization("GET", "/api/z/1.0/group_members")
- .match_query(Matcher::UrlEncoded("group_id".to_string(), "42".to_string()))
+ .match_query(Matcher::UrlEncoded(
+ "group_id".to_string(),
+ "42".to_string(),
+ ))
.with_status(200)
.with_header("content-type", "application/json")
.with_body("{}")
@@ -248,12 +271,19 @@ fn fetch_members_of_group_by_group_id() {
#[test]
fn fetch_members_of_group_by_group_name() {
let m = mock_with_authorization("GET", "/api/z/1.0/group_members")
- .match_query(Matcher::UrlEncoded("group_name".into(), "Friends+of+pain".into()))
+ .match_query(Matcher::UrlEncoded(
+ "group_name".into(),
+ "Friends+of+pain".into(),
+ ))
.with_status(200)
.with_header("content-type", "application/json")
.with_body("{}")
.create();
- let _res = client().group_members().by_group_name("Friends of pain").fetch().unwrap();
+ let _res = client()
+ .group_members()
+ .by_group_name("Friends of pain")
+ .fetch()
+ .unwrap();
m.assert();
}