RAPP Platform API
 All Classes Namespaces Files Functions Variables Typedefs
news.hpp
Go to the documentation of this file.
1 #ifndef RAPP_CLOUD_NEWS
2 #define RAPP_CLOUD_NEWS
3 #include "includes.ihh"
4 namespace rapp {
5 namespace cloud {
13 {
14 public:
26  const std::string news_engine,
27  const std::vector<std::string> keywords,
28  const std::vector<std::string> exclude_titles,
29  const std::string region,
30  const std::string topic,
31  const unsigned int num_news,
32  const std::string token,
33  std::function<void(std::string)> callback
34  )
35  : asio_service_http(token), delegate_(callback)
36  {
37  boost::property_tree::ptree tree;
38  tree.put("news_engine", email);
39  tree.put("passwd", pwd);
40  boost::property_tree::ptree keyword_array;
41  for (const auto key : keywords) {
42  keyword_array.push_back(std::make_pair("", key));
43  }
44  tree.add_child("keywords", keyword_array);
45  boost::property_tree::ptree exclude_title_array;
46  for (const auto key : exclude_titles) {
47  exclude_title_array.push_back(std::make_pair("", key));
48  }
49  tree.add_child("exclude_titles", exclude_title_array);
50  tree.put("region", region);
51  tree.put("topic", topic);
52  tree.put("num_news", boost::lexical_cast<std::string>(num_news));
53  std::stringstream ss;
54  boost::property_tree::write_json(ss, tree, false);
55  post_ = ss.str();
56  header_ = "POST /hop/email_fetch HTTP/1.1\r\n"
57  + "Content-Type: application/x-www-form-urlencoded\r\n";
58  callback_ = std::bind(&email_fetch::handle_reply, this, std::placeholders::_1);
59  }
60 
61 private:
65  void handle_reply(std::string json)
66  {
67  std::stringstream ss(json);
68  delegate_(std::move(json));
69  }
71  std::function<void(std::string)> delegate_;
72 };
73 }
74 }
75 #endif
std::string header_
Header that will be used.
std::function< void(std::string)> delegate_
Definition: news.hpp:71
std::string post_
Actual post Data.
std::function< void(std::string)> callback_
Callback Handler - use with std::bind or boost variant.
void handle_reply(std::string json)
handle platform's JSON reply
Definition: email.hpp:63
base class for asynchronous http websockets used for connecting to cloud services ...
news_explore(const std::string news_engine, const std::vector< std::string > keywords, const std::vector< std::string > exclude_titles, const std::string region, const std::string topic, const unsigned int num_news, const std::string token, std::function< void(std::string)> callback)
Definition: news.hpp:25
void handle_reply(std::string json)
handle platform's JSON reply
Definition: news.hpp:65