1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
use super::link::LinkType;
use crate::api::MailchimpApi;
use crate::iter::{BuildIter, MailchimpCollection, SimpleFilter};

///
/// Signup form header options
///
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ListSignupFormHeader {
    /// Header image URL.
    #[serde(default)]
    pub image_url: String,
    /// Header text.
    #[serde(default)]
    pub text: String,
    /// Image width, in pixels.
    #[serde(default)]
    pub image_width: String,
    /// Image height, in pixels.
    #[serde(default)]
    pub image_height: String,
    /// Alt text for the image.
    #[serde(default)]
    pub image_alt: String,
    /// The URL that the header image will link to.
    #[serde(default)]
    pub image_link: String,
    /// Image alignment. PV: none left center right
    #[serde(default)]
    pub image_align: String,
    /// Image border width.
    #[serde(default)]
    pub image_border_width: String,
    /// Image border style.
    /// Possible Values: none - solid - dotted - dashed - double - groove - outset - inset - ridge
    #[serde(default)]
    pub image_border_style: String,
    /// Image border color.
    #[serde(default)]
    pub image_border_color: String,
    /// Image link target.
    /// Possible Values: _blank - null
    #[serde(default)]
    pub image_target: String,
}

impl Default for ListSignupFormHeader {
    fn default() -> Self {
        ListSignupFormHeader {
            image_url: "".to_string(),
            text: "".to_string(),
            image_width: "".to_string(),
            image_height: "".to_string(),
            image_alt: "".to_string(),
            image_link: "".to_string(),
            image_align: "".to_string(),
            image_border_width: "".to_string(),
            image_border_style: "".to_string(),
            image_border_color: "".to_string(),
            image_target: "".to_string(),
        }
    }
}

///
/// The signup form body content.
///
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ListSignupFormContent {
    /// The content section name.
    /// Possible Values: signup_message - unsub_message - signup_thank_you_title
    #[serde(default)]
    pub section: String,
    /// The content section text.
    #[serde(default)]
    pub value: String,
}

///
/// An array of objects, each representing an element style for the signup form.
///
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ListSignupFormStyleOptions {
    ///
    /// A string that identifies the property.
    ///
    #[serde(default)]
    pub property: String,
    ///
    /// A string that identifies value of the property.
    ///
    #[serde(default)]
    pub value: String,
}

///
/// An array of objects, each representing an element style for the signup form.
///
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ListSignupFormStyle {
    /// A string that identifies the element selector.
    ///
    /// Possible Values:
    ///     page_background - page_header - page_outer_wrapper - body_background
    ///     body_link_style - forms_buttons - forms_buttons_hovered - forms_field_label
    ///     forms_field_text - forms_required - forms_required_legend - forms_help_text
    ///     forms_errors - monkey_rewards_badge
    ///
    #[serde(default)]
    pub selector: String,
    /// A collection of options for a selector.
    #[serde(default)]
    pub options: Vec<ListSignupFormStyleOptions>,
}

///
/// Signup Forms
///
///  Manage list signup forms.
///
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ListSignupForm {
    /// Options for customizing your signup form header.
    #[serde(default)]
    pub header: ListSignupFormHeader,
    /// The signup form body content.
    #[serde(default)]
    pub contents: Vec<ListSignupFormContent>,
    /// An array of objects, each representing an element style for the signup form.
    #[serde(default)]
    pub styles: Vec<ListSignupFormStyle>,
    /// Signup form URL.
    #[serde(default)]
    pub signup_form_url: String,
    /// The signup form’s list id.
    #[serde(default)]
    pub list_id: String,
    /// A list of link types and descriptions for the API schema documents.
    #[serde(default)]
    pub _links: Vec<LinkType>,
}

///
/// Response for endpoint  GET /lists/{list_id}/members/{subscriber_hash}/activity
///
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct CollectionListSignupForm {
    /// List signup form.
    #[serde(default)]
    pub signup_forms: Vec<ListSignupForm>,
    /// The unique id for the list.
    #[serde(default)]
    pub list_id: String,
    /// The total number of items matching the query regardless of pagination.
    #[serde(default)]
    pub total_items: u64,
    /// A list of link types and descriptions for the API schema documents.
    #[serde(default)]
    pub _links: Vec<LinkType>,
}

impl MailchimpCollection<ListSignupForm> for CollectionListSignupForm {
    /// Total Items
    fn get_total_items(&self) -> u64 {
        self.total_items
    }

    /// Data
    fn get_values(&self) -> Vec<ListSignupForm> {
        self.signup_forms.clone()
    }
}

impl Default for CollectionListSignupForm {
    fn default() -> Self {
        CollectionListSignupForm {
            signup_forms: Vec::new(),
            list_id: "".to_string(),
            total_items: 0,
            _links: Vec::new(),
        }
    }
}

/// ================================= ITER =====================

///
/// ListSignupFormBuilder
///
#[derive(Debug)]
pub struct ListSignupFormBuilder {}

impl BuildIter for ListSignupFormBuilder {
    type Item = ListSignupForm;
    type FilterItem = SimpleFilter;
    type Collection = CollectionListSignupForm;

    ///
    /// Crea un recurso a partir del dato pasado por parámetro
    ///
    fn update_item(&self, data: &Self::Item, _: &MailchimpApi) -> Self::Item {
        let in_data = data.clone();
        in_data
    }
    ///
    /// Actualiza el offset
    ///
    fn update_filter_offset(&self, filter: &Self::FilterItem) -> Self::FilterItem {
        let mut f = filter.clone();
        f.offset = Some(f.count.unwrap() + f.offset.unwrap());
        f
    }
}