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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
// This file is part of feed.
//
// Copyright © 2015-2017 Chris Palmer <pennstate5013@gmail.com>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.


#![doc(html_root_url = "https://docs.rs/feed/")]
#![deny(missing_docs)]


//! # feed 3.0
//!
//! This Library is for parsing through a channels field and creating a `Feed`
//! struct containing all elements of a `Channel` based on the channels spec.
//!
//! ## Usage
//! Put this in your Cargo.toml:
//!
//! ```Toml
//! [dependencies]
//! feed = "3.0"
//! ```
//!
//! And put this in your crate root:
//!
//! ```
//! extern crate feed;
//! ```
//!
//! ## Examples
//!
//! ### Reading Feeds
//!
//! ```
//! extern crate rss;
//! extern crate feed;
//!
//! use feed::{FromUrl, ChannelGetters};
//! use rss::Channel;
//!
//! fn main()
//! {
//!     let url = "https://feedpress.me/usererror.xml";
//!
//!     let channel = Channel::from_url(url).unwrap();
//!     println!("Feed Title: {:?}", channel.title());
//! }
//! ```
//!
//! ### Writing Feeds
//!
//! ```
//! extern crate feed;
//!
//! use feed::ChannelBuilder;
//!
//! fn main()
//! {
//!     let description = "Ogg Vorbis audio versions of The Linux ".to_owned()
//!         + "Action Show! A show that covers everything geeks care about in "
//!         + "the computer industry. Get a solid dose of Linux, gadgets, news "
//!         + "events and much more!";
//!
//!     let channel = ChannelBuilder::new()
//!         .title("The Linux Action Show! OGG")
//!         .link("http://www.jupiterbroadcasting.com")
//!         .description(description.as_ref())
//!         .finalize().unwrap();
//!
//!     println!("Feed: {:?}", channel.to_string());
//! }
//! ```
//!
//! ### Validating Feeds
//!
//! ```
//! extern crate feed;
//!
//! use feed::ChannelBuilder;
//!
//! fn main()
//! {
//!     let description = "Ogg Vorbis audio versions of The Linux ".to_owned()
//!         + "Action Show! A show that covers everything geeks care about in "
//!         + "the computer industry. Get a solid dose of Linux, gadgets, news "
//!         + "events and much more!";
//!
//!     let channel = ChannelBuilder::new()
//!         .title("The Linux Action Show! OGG")
//!         .link("http://www.jupiterbroadcasting.com")
//!         .description(description.as_ref())
//!         .validate().unwrap()
//!         .finalize().unwrap();
//!
//!     println!("Feed: {:?}", channel.to_string());
//! }
//! ```
//!
//! ```
//! extern crate rss;
//! extern crate feed;
//!
//! use feed::{FromUrl, Validate};
//! use rss::Channel;
//!
//! fn main()
//! {
//!     let url = "https://feedpress.me/usererror.xml";
//!
//!     let channel = Channel::from_url(url).unwrap();
//!     channel.validate().unwrap();
//! }
//! ```

extern crate chrono;
extern crate curl;
extern crate mime;
extern crate rss;
extern crate url;


mod enums;
pub mod extension;
pub mod channel;
mod utils;


use rss::{Category, Channel, Cloud, Enclosure, Guid, Image, Item, Source, TextInput};
use rss::extension::itunes::{ITunesChannelExtension, ITunesItemExtension};

/// The Getter functions for `Category`
pub trait CategoryGetters
{
    /// Get the category that exists under `Category`.
    fn name(&self) -> String;


    /// Get the optional domain that exists under `Category`.
    fn domain(&self) -> Option<String>;
}


/// This `CategoryBuilder` struct creates the `Category`.
#[derive(Clone, Default)]
pub struct CategoryBuilder
{
    name: String,
    domain: Option<String>,
}


/// From Url function for `Channel`
pub trait FromUrl
{
    /// Construct a `Channel` from a `Url`.
    fn from_url(url: &str) -> Result<Channel, String>;
}


/// Validate function for `Channel`
pub trait Validate
{
    /// Validate `Channel`
    fn validate(&self) -> Result<Channel, String>;
}


/// The Getter functions for `Channel`
pub trait ChannelGetters
{
    /// Get the title that exists under `Channel`.
    fn title(&self) -> String;

    /// Get the link that exists under `Channel`.
    fn link(&self) -> String;

    /// Get the description that exists under `Channel`.
    fn description(&self) -> String;

    /// Get the optional language that exists under `Channel`.
    fn language(&self) -> Option<String>;

    /// Get the optional copyright that exists under `Channel`.
    fn copyright(&self) -> Option<String>;

    /// Get the optional managing editor that exists under `Channel`.
    fn managing_editor(&self) -> Option<String>;

    /// Get the optional web master that exists under `Channel`.
    fn webmaster(&self) -> Option<String>;

    /// Get the optional pub date that exists under `Channel`.
    fn pub_date(&self) -> Option<String>;

    /// Get the optional last build date that exists under `Channel`.
    fn last_build_date(&self) -> Option<String>;

    /// Get the categories that exists under `Channel`.
    fn categories(&self) -> Vec<Category>;

    /// Get the optional generator that exists under `Channel`.
    fn generator(&self) -> Option<String>;

    /// Get the optional docs that exists under `Channel`.
    fn docs(&self) -> Option<String>;

    /// Get the optional cloud that exists under `Channel`.
    fn cloud(&self) -> Option<Cloud>;

    /// Get the optional ttl that exists under `Channel`.
    fn ttl(&self) -> Option<String>;

    /// Get the optional image that exists under `Channel`.
    fn image(&self) -> Option<Image>;

    /// Get the optional text input that exists under `Channel`.
    fn text_input(&self) -> Option<TextInput>;

    /// Get the optional rating that exists under `Channel`.
    fn rating(&self) -> Option<String>;

    /// Get the skip hours that exists under `Channel`.
    fn skip_hours(&self) -> Vec<String>;

    /// Get the skip days that exists under `Channel`.
    fn skip_days(&self) -> Vec<String>;

    /// Get the items that exists under `Channel`.
    fn items(&self) -> Vec<Item>;

    /// Get the optional `ITunesChannelExtension` under `Channel`.
    fn itunes_ext(&self) -> Option<ITunesChannelExtension>;
}


/// This `ChannelBuilder` struct creates the `Channel`.
#[derive(Clone, Default)]
pub struct ChannelBuilder
{
    title: String,
    link: String,
    description: String,
    language: Option<String>,
    copyright: Option<String>,
    managing_editor: Option<String>,
    webmaster: Option<String>,
    pub_date: Option<String>,
    last_build_date: Option<String>,
    categories: Vec<Category>,
    generator: Option<String>,
    docs: Option<String>,
    cloud: Option<Cloud>,
    ttl: Option<i64>,
    image: Option<Image>,
    rating: Option<String>,
    text_input: Option<TextInput>,
    skip_hours: Vec<i64>,
    skip_days: Vec<String>,
    items: Vec<Item>,
    itunes_ext: Option<ITunesChannelExtension>,
}


/// The Getter functions for `Cloud`
pub trait CloudGetters
{
    /// Get the domain that exists under `Cloud`.
    fn domain(&self) -> String;

    /// Get the port that exists under `Cloud`.
    fn port(&self) -> String;

    /// Get the path that exists under `Cloud`.
    fn path(&self) -> String;

    /// Get the register procedure that exists under `Cloud`.
    fn register_procedure(&self) -> String;

    /// Get the protocol that exists under `Cloud`.
    fn protocol(&self) -> String;
}


/// This `CloudBuilder` struct creates the `Cloud`.
#[derive(Clone, Default)]
pub struct CloudBuilder
{
    domain: String,
    port: i64,
    path: String,
    register_procedure: String,
    protocol: String,
}


/// The Getter functions for `Enclosure`
pub trait EnclosureGetters
{
    /// Get the url that exists under `Enclosure`.
    fn url(&self) -> String;

    /// Get the length that exists under `Enclosure`.
    fn length(&self) -> String;

    /// Get the enclosure type that exists under `Enclosure`.
    fn mime_type(&self) -> String;
}


/// This `EnclosureBuilder` struct creates the `Enclosure`.
#[derive(Clone, Default)]
pub struct EnclosureBuilder
{
    url: String,
    length: i64,
    mime_type: String,
}


/// The Getter functions for `Guid`
pub trait GuidGetters
{
    /// Get the permalink that exists under `Guid`.
    fn is_permalink(&self) -> bool;

    /// Get the guid that exists under `Guid`.
    fn value(&self) -> String;
}


/// This `GuidBuilder` struct creates the `Guid`.
#[derive(Clone, Default)]
pub struct GuidBuilder
{
    is_permalink: Option<bool>,
    value: String,
}


/// The Getter functions for `Image`
pub trait ImageGetters
{
    /// Get the url that exists under `Image`.
    fn url(&self) -> String;

    /// Get the title that exists under `Image`.
    fn title(&self) -> String;

    /// Get the link that exists under `Image`.
    fn link(&self) -> String;

    /// Get the width that exists under `Image`.
    fn width(&self) -> Option<String>;

    /// Get the height that exists under `Image`.
    fn height(&self) -> Option<String>;

    /// Get the description that exists under `Image`.
    fn description(&self) -> Option<String>;
}


/// This `ImageBuilder` struct creates the `Image`.
#[derive(Clone, Default)]
pub struct ImageBuilder
{
    url: String,
    title: String,
    link: String,
    width: Option<i64>,
    height: Option<i64>,
    description: Option<String>,
}


/// The Getter functions for `Item`
pub trait ItemGetters
{
    /// Get the optional title that exists under `Item`.
    fn title(&self) -> Option<String>;

    /// Get the optional link that exists under `Item`.
    fn link(&self) -> Option<String>;

    /// Get the optional description that exists under `Item`.
    fn description(&self) -> Option<String>;

    /// Get the optional author that exists under `Item`.
    fn author(&self) -> Option<String>;

    /// Get the categories that exists under `Item`.
    fn categories(&self) -> Vec<Category>;

    /// Get the optional comments that exists under `Item`.
    fn comments(&self) -> Option<String>;

    /// Get the optional enclosure that exists under `Item`.
    fn enclosure(&self) -> Option<Enclosure>;

    /// Get the optional guid that exists under `Item`.
    fn guid(&self) -> Option<Guid>;

    /// Get the optional pub date that exists under `Item`.
    fn pub_date(&self) -> Option<String>;

    /// Get the optional source that exists under `Item`.
    fn source(&self) -> Option<Source>;

    /// Get the optional `ITunesItemExtension` under `Item`.
    fn itunes_ext(&self) -> Option<ITunesItemExtension>;
}


/// This `ItemBuilder` struct creates the `Item`.
#[derive(Clone, Default)]
pub struct ItemBuilder
{
    title: Option<String>,
    link: Option<String>,
    description: Option<String>,
    author: Option<String>,
    categories: Vec<Category>,
    comments: Option<String>,
    enclosure: Option<Enclosure>,
    guid: Option<Guid>,
    pub_date: Option<String>,
    source: Option<Source>,
    itunes_ext: Option<ITunesItemExtension>,
}


/// The Getter functions for `Source`
pub trait SourceGetters
{
    /// Get the url that exists under `Source`.
    fn url(&self) -> String;

    /// Get the source that exists under `Source`.
    fn title(&self) -> Option<String>;
}


/// This `SourceBuilder` struct creates the `Source`.
#[derive(Clone, Default)]
pub struct SourceBuilder
{
    url: String,
    title: Option<String>,
}


/// The Getter functions for `TextInput`
pub trait TextInputGetters
{
    /// Get the title that exists under `TextInput`.
    fn title(&self) -> String;

    /// Get the description that exists under `TextInput`.
    fn description(&self) -> String;

    /// Get the name that exists under `TextInput`.
    fn name(&self) -> String;

    /// Get the link that exists under `TextInput`.
    fn link(&self) -> String;
}


/// This `TextInputBuilder` struct creates the `TextInput`.
#[derive(Clone, Default)]
pub struct TextInputBuilder
{
    title: String,
    description: String,
    name: String,
    link: String,
}