RAPP Platform API
 All Classes Namespaces Files Functions Variables Typedefs
weather_report.hpp
Go to the documentation of this file.
1 #ifndef RAPP_CLOUD_WEATHER_REPORT
2 #define RAPP_CLOUD_WEATHER_REPORT
3 #include "includes.ihh"
4 namespace rapp {
5 namespace cloud {
6 
14 {
15 public:
24  const std::string city,
25  const std::string weather_reporter,
26  const unsigned int metric,
27  const std::string token,
28  std::function<void(std::string)> callback
29  )
30  : asio_service_http(token), delegate_(callback)
31  {
32  boost::property_tree::ptree tree;
33  tree.put("city", city);
34  tree.put("weather_reporter", weather_reporter);
35  tree.put("metric", boost::lexical_cast<std::string>(metric));
36  std::stringstream ss;
37  boost::property_tree::write_json(ss, tree, false);
38  post_ = ss.str();
39  header_ = "POST /hop/weather_report_current HTTP/1.1\r\n"
40  + "Content-Type: application/x-www-form-urlencoded\r\n";
41  callback_ = std::bind(&weather_report_current::handle_reply, this, std::placeholders::_1);
42  }
43 private:
47  void handle_reply(std::string json)
48  {
49  std::stringstream ss(json);
50  delegate_(std::move(json));
51  }
53  std::function<void(std::string)> delegate_;
54 };
55 
63 {
64 public:
73  const std::string city,
74  const std::string weather_reporter,
75  const unsigned int metric,
76  const std::string token,
77  std::function<void(std::string)> callback
78  )
79  : asio_service_http(token), delegate_(callback)
80  {
81  boost::property_tree::ptree tree;
82  tree.put("city", city);
83  tree.put("weather_reporter", weather_reporter);
84  tree.put("metric", boost::lexical_cast<std::string>(metric));
85  std::stringstream ss;
86  boost::property_tree::write_json(ss, tree, false);
87  post_ = ss.str();
88  header_ = "POST /hop/weather_report_forecast HTTP/1.1\r\n"
89  + "Content-Type: application/x-www-form-urlencoded\r\n";
90  callback_ = std::bind(&weather_report_forecast::handle_reply, this, std::placeholders::_1);
91  }
92 private:
96  void handle_reply(std::string json)
97  {
98  std::stringstream ss(json);
99  delegate_(std::move(json));
100  }
102  std::function<void(std::string)> delegate_;
103 };
104 }
105 }
106 #endif
std::string header_
Header that will be used.
get current weather report
weather_report_current(const std::string city, const std::string weather_reporter, const unsigned int metric, const std::string token, std::function< void(std::string)> callback)
std::function< void(std::string)> delegate_
void handle_reply(std::string json)
handle platform's JSON reply
std::string post_
Actual post Data.
std::function< void(std::string)> delegate_
weather_report_forecast(const std::string city, const std::string weather_reporter, const unsigned int metric, const std::string token, std::function< void(std::string)> callback)
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
base class for asynchronous http websockets used for connecting to cloud services ...