mastodon-cpp  0.110.0
easy.hpp
1 /* This file is part of mastodon-cpp.
2  * Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Affero General Public License as published by
6  * the Free Software Foundation, version 3.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Affero General Public License for more details.
12  *
13  * You should have received a copy of the GNU Affero General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #ifndef MASTODON_EASY_CPP_HPP
18 #define MASTODON_EASY_CPP_HPP
19 
20 #include <string>
21 #include <cstdint>
22 #include <vector>
23 #include <functional>
24 #include <ostream>
25 #include <jsoncpp/json/json.h>
26 
27 #include "../mastodon-cpp.hpp"
28 #include "return_types_easy.hpp"
29 #include "types_easy.hpp"
30 #include "entities/notification.hpp"
31 #include "entities/status.hpp"
32 
33 using std::string;
34 using std::vector;
35 using std::uint64_t;
36 using std::uint16_t;
37 
38 namespace Mastodon
39 {
44 namespace Easy
45 {
53  // TODO: Convert to struct?
54  class Link
55  {
56  public:
62  explicit Link(const string &link_header);
63 
69  const string next() const;
70 
76  const string max_id() const;
77 
83  const string prev() const;
84 
90  const string since_id() const;
91 
92  private:
93  string _next;
94  string _prev;
95  };
96 
106  const vector<string> json_array_to_vector(const string &json);
107 
117  const vector<stream_event_type> parse_stream(const std::string &streamdata);
118 
124  const Easy::time_type string_to_time(const string &strtime);
125 
131  class API : public Mastodon::API
132  {
133  public:
145  explicit API(const string &instance, const string &access_token);
146 
152  const Link get_link() const;
153 
163  const return_entity<Easy::Status> send_post(const Status &status);
164 
170  const return_entity<Easy::Status> send_toot(const Status &status);
171 
184  const uint16_t limit = 20, const string since_id = "",
185  const string max_id = "");
186  };
187 }
188 }
189 
190 #endif // MASTODON_EASY_CPP_HPP
Interface to the Mastodon API.
Definition: mastodon-cpp.hpp:69
const Easy::time_type string_to_time(const string &strtime)
Convert ISO 8601 time string to Easy::time.
Definition: easy.cpp:85
const vector< stream_event_type > parse_stream(const std::string &streamdata)
Split stream into a vector of events.
Definition: easy.cpp:52
const return_entity< Easy::Status > send_post(const Status &status)
Sends a post.
Definition: simple_calls.cpp:31
Type for time. Converts to time_point and string.
Definition: types_easy.hpp:150
const Link get_link() const
Gets the links from the last answer.
Definition: easy.cpp:95
const return_entity_vector< Easy::Notification > get_notifications(const uint16_t limit=20, const string since_id="", const string max_id="")
Gets notifications.
Definition: simple_calls.cpp:135
const vector< string > json_array_to_vector(const string &json)
Turns a JSON array into a vector of strings.
Definition: easy.cpp:31
Return types for calls that return multiple Easy::Entitys.
Definition: return_types_easy.hpp:111
Class to hold statuses.
Definition: status.hpp:46
API(const string &instance, const string &access_token)
Constructs a new Easy object.
Definition: easy.cpp:27
Collection of things to interface with server software that implements the Mastodon API.
Definition: mastodon-cpp.hpp:47
const return_entity< Easy::Status > send_toot(const Status &status)
Alias for send_post()
Definition: simple_calls.cpp:26
Return types for calls that return a single Easy::Entity.
Definition: return_types_easy.hpp:40
Child of Mastodon::API with abstract methods.
Definition: easy.hpp:131