1use crate::model::EndpointUrl;
2
3#[derive(Debug, Clone, PartialEq, Eq)]
5pub struct FormField {
6 name: String,
7 value: String,
8}
9
10impl FormField {
11 pub fn new(name: impl Into<String>, value: impl Into<String>) -> Self {
13 Self {
14 name: name.into(),
15 value: value.into(),
16 }
17 }
18
19 pub fn name(&self) -> &str {
21 &self.name
22 }
23
24 pub fn value(&self) -> &str {
26 &self.value
27 }
28
29 pub(crate) fn into_pair(self) -> (String, String) {
30 (self.name, self.value)
31 }
32}
33
34#[derive(Debug, Clone, PartialEq, Eq)]
36pub struct PostForm {
37 action: EndpointUrl,
38 fields: Vec<FormField>,
39}
40
41impl PostForm {
42 pub fn new(action: EndpointUrl, fields: Vec<FormField>) -> Self {
44 Self { action, fields }
45 }
46
47 pub fn action(&self) -> &EndpointUrl {
49 &self.action
50 }
51
52 pub fn fields(&self) -> &[FormField] {
54 &self.fields
55 }
56
57 pub fn value(&self, name: &str) -> Option<&str> {
59 self.fields
60 .iter()
61 .find(|field| field.name() == name)
62 .map(FormField::value)
63 }
64}