|
4 | 4 | // (See accompanying file LICENSE_1_0.txt or copy at
|
5 | 5 | // http://www.boost.org/LICENSE_1_0.txt)
|
6 | 6 |
|
7 |
| - |
8 | 7 | #include "atom.hpp"
|
9 | 8 | #include "../rapidxml/rapidxml.hpp"
|
10 | 9 | #include <stdexcept>
|
11 | 10 | #include <cassert>
|
12 | 11 |
|
13 | 12 | namespace network {
|
14 | 13 | namespace atom {
|
15 |
| -feed::feed(const http::client::response &response) { |
16 |
| - std::string response_body = body(response); |
17 |
| - rapidxml::xml_document<> doc; |
18 |
| - doc.parse<0>(const_cast<char *>(response_body.c_str())); |
19 |
| - |
20 |
| - rapidxml::xml_node<> *feed = doc.first_node("feed"); |
21 |
| - if (!feed) { |
22 |
| - throw std::runtime_error("Invalid atom feed."); |
| 14 | +feed::feed(const http::client::response& response) { |
| 15 | + std::string response_body = body(response); |
| 16 | + rapidxml::xml_document<> doc; |
| 17 | + doc.parse<0>(const_cast<char*>(response_body.c_str())); |
| 18 | + |
| 19 | + rapidxml::xml_node<>* feed = doc.first_node("feed"); |
| 20 | + if (!feed) { |
| 21 | + throw std::runtime_error("Invalid atom feed."); |
| 22 | + } |
| 23 | + |
| 24 | + rapidxml::xml_node<>* title = feed->first_node("title"); |
| 25 | + if (title) { |
| 26 | + title_ = title->first_node()->value(); |
| 27 | + } |
| 28 | + |
| 29 | + rapidxml::xml_node<>* subtitle = feed->first_node("subtitle"); |
| 30 | + if (subtitle) { |
| 31 | + subtitle_ = subtitle->first_node()->value(); |
| 32 | + } |
| 33 | + |
| 34 | + rapidxml::xml_node<>* id = feed->first_node("id"); |
| 35 | + if (id) { |
| 36 | + id_ = id->first_node()->value(); |
| 37 | + } |
| 38 | + |
| 39 | + rapidxml::xml_node<>* updated = feed->first_node("updated"); |
| 40 | + if (updated) { |
| 41 | + updated_ = updated->first_node()->value(); |
| 42 | + } |
| 43 | + |
| 44 | + rapidxml::xml_node<>* author = feed->first_node("author"); |
| 45 | + if (author) { |
| 46 | + rapidxml::xml_node<>* name = author->first_node("name"); |
| 47 | + rapidxml::xml_node<>* email = author->first_node("email"); |
| 48 | + if (name && email) { |
| 49 | + author_ = atom::author(name->first_node()->value(), |
| 50 | + email->first_node()->value()); |
| 51 | + } else if (name) { |
| 52 | + author_ = atom::author(name->first_node()->value()); |
23 | 53 | }
|
| 54 | + } |
| 55 | + |
| 56 | + rapidxml::xml_node<>* entry = feed->first_node("entry"); |
| 57 | + while (entry) { |
| 58 | + entries_.push_back(atom::entry()); |
24 | 59 |
|
25 |
| - rapidxml::xml_node<> *title = feed->first_node("title"); |
| 60 | + rapidxml::xml_node<>* title = entry->first_node("title"); |
26 | 61 | if (title) {
|
27 |
| - title_ = title->first_node()->value(); |
| 62 | + entries_.back().set_title(title->first_node()->value()); |
28 | 63 | }
|
29 | 64 |
|
30 |
| - rapidxml::xml_node<> *subtitle = feed->first_node("subtitle"); |
31 |
| - if (subtitle) { |
32 |
| - subtitle_ = subtitle->first_node()->value(); |
| 65 | + rapidxml::xml_node<>* id = entry->first_node("id"); |
| 66 | + if (id) { |
| 67 | + entries_.back().set_id(id->first_node()->value()); |
33 | 68 | }
|
34 | 69 |
|
35 |
| - rapidxml::xml_node<> *id = feed->first_node("id"); |
36 |
| - if (id) { |
37 |
| - id_ = id->first_node()->value(); |
| 70 | + rapidxml::xml_node<>* published = entry->first_node("published"); |
| 71 | + if (published) { |
| 72 | + entries_.back().set_published(published->first_node()->value()); |
38 | 73 | }
|
39 | 74 |
|
40 |
| - rapidxml::xml_node<> *updated = feed->first_node("updated"); |
| 75 | + rapidxml::xml_node<>* updated = entry->first_node("updated"); |
41 | 76 | if (updated) {
|
42 |
| - updated_ = updated->first_node()->value(); |
| 77 | + entries_.back().set_updated(updated->first_node()->value()); |
43 | 78 | }
|
44 | 79 |
|
45 |
| - rapidxml::xml_node<> *author = feed->first_node("author"); |
46 |
| - if (author) { |
47 |
| - rapidxml::xml_node<> *name = author->first_node("name"); |
48 |
| - rapidxml::xml_node<> *email = author->first_node("email"); |
49 |
| - if (name && email) { |
50 |
| - author_ = atom::author(name->first_node()->value(), email->first_node()->value()); |
51 |
| - } |
52 |
| - else if (name) { |
53 |
| - author_ = atom::author(name->first_node()->value()); |
54 |
| - } |
| 80 | + rapidxml::xml_node<>* summary = entry->first_node("summary"); |
| 81 | + if (summary) { |
| 82 | + entries_.back().set_summary(summary->first_node()->value()); |
55 | 83 | }
|
56 | 84 |
|
57 |
| - rapidxml::xml_node<> *entry = feed->first_node("entry"); |
58 |
| - while (entry) { |
59 |
| - entries_.push_back(atom::entry()); |
60 |
| - |
61 |
| - rapidxml::xml_node<> *title = entry->first_node("title"); |
62 |
| - if (title) { |
63 |
| - entries_.back().set_title(title->first_node()->value()); |
64 |
| - } |
65 |
| - |
66 |
| - rapidxml::xml_node<> *id = entry->first_node("id"); |
67 |
| - if (id) { |
68 |
| - entries_.back().set_id(id->first_node()->value()); |
69 |
| - } |
70 |
| - |
71 |
| - rapidxml::xml_node<> *published = entry->first_node("published"); |
72 |
| - if (published) { |
73 |
| - entries_.back().set_published(published->first_node()->value()); |
74 |
| - } |
75 |
| - |
76 |
| - rapidxml::xml_node<> *updated = entry->first_node("updated"); |
77 |
| - if (updated) { |
78 |
| - entries_.back().set_updated(updated->first_node()->value()); |
79 |
| - } |
80 |
| - |
81 |
| - rapidxml::xml_node<> *summary = entry->first_node("summary"); |
82 |
| - if (summary) { |
83 |
| - entries_.back().set_summary(summary->first_node()->value()); |
84 |
| - } |
85 |
| - |
86 |
| - rapidxml::xml_node<> *content = entry->first_node("content"); |
87 |
| - if (content) { |
88 |
| - entries_.back().set_content(content->first_node()->value()); |
89 |
| - } |
90 |
| - |
91 |
| - entry = entry->next_sibling(); |
| 85 | + rapidxml::xml_node<>* content = entry->first_node("content"); |
| 86 | + if (content) { |
| 87 | + entries_.back().set_content(content->first_node()->value()); |
92 | 88 | }
|
| 89 | + |
| 90 | + entry = entry->next_sibling(); |
| 91 | + } |
93 | 92 | }
|
94 |
| -} // namespace atom |
95 |
| -} // namespace network |
| 93 | +} // namespace atom |
| 94 | +} // namespace network |
0 commit comments