Compare commits

...

417 Commits

Author SHA1 Message Date
tastytea 4b7215036b
Recommend switching to mastodonpp.
continuous-integration/drone/push Build is passing Details
2020-01-16 23:47:25 +01:00
tastytea e65fadfba6
Add low-maintenance note.
continuous-integration/drone/push Build is passing Details
2020-01-03 06:20:38 +01:00
tastytea fd407094a2
Add package for Ubuntu bionic. 2019-12-26 03:19:32 +01:00
tastytea 76e12d7093
Drone: Install lsb-release.
continuous-integration/drone/push Build is passing Details
2019-12-25 21:16:47 +01:00
tastytea 2a9219ce7e
Drone: Don't fail if file to delete doesn't exist. 2019-12-25 21:06:57 +01:00
tastytea cacc2c3a5b
Build packages for Debian stretch and buster. 2019-12-25 20:53:14 +01:00
tastytea ceda771700
Version bump 0.111.3.
continuous-integration/drone/push Build is passing Details
2019-12-19 15:16:24 +01:00
tastytea c6ad04e6ee
Typo in CMake config.
continuous-integration/drone/push Build was killed Details
2019-12-19 15:15:21 +01:00
tastytea 9671407556
Different indentation for CMake files. 2019-12-19 15:14:59 +01:00
tastytea c35dab8350
Merge branch 'develop'
continuous-integration/drone/push Build is passing Details
2019-10-14 12:06:43 +02:00
tastytea c772d7b60e
Improved introduction.
continuous-integration/drone/push Build is passing Details
2019-10-14 00:01:13 +02:00
tastytea e1b61b5041
Deprecated return_entity(_vector) and some high-level abstractions.
send_post(), send_toot() and get_notifications().
I don't have the energy to implement and maintain an useful set of high-level
abstractions.
2019-10-13 23:56:39 +02:00
tastytea db95855ab6
Merge branch 'develop'
continuous-integration/drone/push Build is passing Details
2019-10-13 21:05:34 +02:00
tastytea 5dce94a4a3
Add Emoji example.
continuous-integration/drone/push Build is passing Details
2019-10-13 17:39:49 +02:00
tastytea 7adad67dd9
Install examples into the correct directory. 2019-10-13 16:34:42 +02:00
tastytea 5275ab73ac
Version bump 0.111.2.
continuous-integration/drone/push Build is passing Details
2019-10-07 23:07:32 +02:00
tastytea a50d28e9a2
Merge branch 'develop' 2019-10-07 23:07:16 +02:00
tastytea 57238020a3
Do not return lowercased header, but the original one. 2019-10-07 23:06:15 +02:00
tastytea d37e720a11
Version bump 0.111.1.
continuous-integration/drone/push Build is passing Details
2019-10-06 17:20:44 +02:00
tastytea ad0773d5a7
Install documentation into ${CMAKE_INSTALL_DOCDIR}/${PROJECT_NAME}/. 2019-10-06 17:20:07 +02:00
tastytea bfe77f1b18
Don't install HTML documentation with autogenerated packages. 2019-10-06 17:19:07 +02:00
tastytea 10947148a1
Don't support versions pre 0.100.0.
continuous-integration/drone/push Build is passing Details
2019-10-06 16:43:13 +02:00
tastytea ec49399d39
Version bump 0.111.0 2019-10-06 16:40:22 +02:00
tastytea b4d6e37c96
Merge branch 'develop' 2019-10-06 16:39:38 +02:00
tastytea 719f8a7664
Actually delete parameters in delete_params(). 2019-10-06 16:39:06 +02:00
tastytea c3a5df62e5
Add Link::min_id() and allow for alphanumeric IDs. 2019-10-06 16:39:06 +02:00
tastytea 8b197134ab
Added favourites-example. 2019-10-06 16:39:06 +02:00
tastytea d43b1c72db
Match headers case-insensitively. 2019-10-06 14:58:04 +02:00
tastytea 2fa3bff89c
Re-add support for getting headers. 2019-10-06 14:35:06 +02:00
tastytea fe526f8e94
Merge branch 'develop'
continuous-integration/drone/push Build is passing Details
2019-09-27 03:54:53 +02:00
tastytea 28919cdaa8
Include contribution guidelines in readme.
continuous-integration/drone/push Build is failing Details
2019-09-27 03:52:58 +02:00
tastytea ff846a63cb
Make more use of variables in contribution guidelines. 2019-09-27 03:52:38 +02:00
tastytea 7857b17b8b
Fix contact-variable in COC. 2019-09-27 03:52:22 +02:00
tastytea f65cc6bac6
Add “patch via email”-paragraph to contributing guidelines.
continuous-integration/drone/push Build is passing Details
2019-09-23 19:27:26 +02:00
tastytea 453d8fc272
Fix path to CONTRIBUTING.adoc.
continuous-integration/drone/push Build is passing Details
2019-09-22 03:48:06 +02:00
tastytea a99fdc0742
Merge branch 'develop'
continuous-integration/drone/push Build was killed Details
2019-09-22 03:45:55 +02:00
tastytea 22754226f2
Replaced “mastodon-cpp” with variable “{project}” in readme.
continuous-integration/drone/push Build was killed Details
2019-09-22 03:45:18 +02:00
tastytea 66d41fec46
Add contributing guidelines, a COC and EditorConfig. 2019-09-22 03:38:14 +02:00
tastytea ff43aea4ab
Add CentOS 7 workaround.
continuous-integration/drone/push Build is passing Details
2019-09-20 03:55:13 +02:00
tastytea 83819c5f33
CI: Add openssl-devel to rpm dependencies. 2019-09-20 03:40:59 +02:00
tastytea 9b13db149b
Add package description workaround for CMake < 3.9. 2019-09-20 03:30:54 +02:00
tastytea 795bf14e51
Corrected version in documentation from 0.107.0 to 0.110.0.
continuous-integration/drone/push Build is passing Details
2019-09-20 02:58:58 +02:00
tastytea 47adbe0281
Merge branch 'develop' 2019-09-20 02:55:32 +02:00
tastytea 14d2e53cfc
Add support for the streaming event “filters_changed”. 2019-09-20 02:52:56 +02:00
tastytea f8ed45dcc4
Deleted report from return types and added Poll and Conversations.
continuous-integration/drone/push Build is passing Details
2019-09-20 02:41:27 +02:00
tastytea d100d1a2b6
Add support for GET /api/v1/streaming/direct. 2019-09-20 02:38:56 +02:00
tastytea ff649fd2eb
Add support for /api/v1/streaming/hashtag/local. 2019-09-20 02:37:33 +02:00
tastytea 7f80bff4e1
Add support for /api/v1/streaming/health. 2019-09-20 02:36:16 +02:00
tastytea 3446bbf5d6
Deleted Easy::Report and GET /api/v1/reports.
continuous-integration/drone/push Build is failing Details
They are no longer documented by Mastodon.
2019-09-20 02:29:45 +02:00
tastytea 14a1d92442
Added /api/v1/conversations. 2019-09-20 02:26:47 +02:00
tastytea c3e00e2e31
Added Easy::Conversation. 2019-09-20 02:26:07 +02:00
tastytea 1b514df555
Added /api/v1/polls/:id and /api/v1/polls/:id/votes.
continuous-integration/drone/push Build is passing Details
2019-09-20 00:40:22 +02:00
tastytea 416675a667
Added Entity Easy::Poll. 2019-09-20 00:07:17 +02:00
tastytea 4d5b331a0f
Removed /api/v1/search.
Because it is not documented by tootsuite anymore.
2019-09-19 23:21:58 +02:00
tastytea 2b265a5831
Merge branch 'develop'
continuous-integration/drone/push Build is passing Details
Switched from curlpp to POCO, modernized cmake recipes.
2019-08-30 08:20:48 +02:00
tastytea 08ae30835c
Confirmed that proxies work, added debug message with proxy info.
continuous-integration/drone/push Build is passing Details
2019-08-30 08:06:48 +02:00
tastytea 707771c7bf
Bugfix: Do not try to set proxy in parent class.
continuous-integration/drone/push Build is passing Details
2019-08-25 05:27:00 +02:00
tastytea 6b070dec98
Percent-decode proxy username and password. 2019-08-25 05:08:37 +02:00
tastytea d2a4d835de
Moved set_proxy() to API::http().
continuous-integration/drone/push Build is failing Details
API::set_proxy() calls API::http::set_proxy(). Deleted API::get_proxy().
2019-08-25 04:50:08 +02:00
tastytea acbcb6224e
Mastodon::http inherits proxy config from parent.
continuous-integration/drone/push Build is passing Details
Ff set_proxy() is called, _http.inherit_proxy() is called.
2019-08-21 11:06:41 +02:00
tastytea 188033a0c1
Simplify get_proxy(). 2019-08-21 10:52:06 +02:00
tastytea 41a580b32b
Rewrite parsing of http_proxy environment variable.
The regex matches host, port, username and password.
2019-08-21 10:42:59 +02:00
tastytea 915c85e9e9
Changed error codes and introduced error constants.
continuous-integration/drone/push Build is passing Details
2019-08-21 08:00:46 +02:00
tastytea 5ddea09924
Repair domain-change detection on HTTP redirect.
Also added debug statements.
2019-08-21 07:28:28 +02:00
tastytea c48c1a66f2
Removed and replaced last bits of curlpp.
continuous-integration/drone/push Build is passing Details
2019-08-21 04:54:17 +02:00
tastytea ed989935ac
Test with clang7. 2019-08-21 04:37:13 +02:00
tastytea a6f70263b8
Remove curlpp from drone recipe. 2019-08-21 04:36:04 +02:00
tastytea d0bac6779f
Replace curlpp with POCO in README. 2019-08-21 04:31:18 +02:00
tastytea 565317115c
Replace curlpp with POCO in RPM dependencies. 2019-08-21 04:27:24 +02:00
tastytea 9da01c0398
Add POCO to drone recipe.
continuous-integration/drone/push Build is failing Details
2019-08-21 04:25:20 +02:00
tastytea 62d28c523a
Updated TODOs and FIXMEs. 2019-08-21 04:20:25 +02:00
tastytea d16454e169
Merge branch 'develop' of schlomp.space:tastytea/mastodon-cpp into develop
continuous-integration/drone/push Build is failing Details
2019-08-21 04:10:37 +02:00
tastytea 12c0b896db
Use references for HTMLForm, where possible.
HTMLForm can't be copied, so I'm returning using unique_ptr in maptoformdata()
and references everywhere else.
2019-08-21 03:53:51 +02:00
tastytea ecb49c7e00
Actually send forms. 2019-08-21 03:36:25 +02:00
tastytea bc58a977f0
Add more debug statements around forms. 2019-08-21 03:35:44 +02:00
tastytea f97608ecfa
[WIP] Switch from curlpp to POCO.
Compilable, but untested and unfinished.
2019-08-20 18:13:51 +02:00
tastytea bd07dc6f9c
Change license in package generation recipe. 2019-08-16 02:09:12 +02:00
tastytea 1273518a5c
Add pkg-config recipe. 2019-08-16 02:08:14 +02:00
tastytea 5f73020056
Modernized CMake recipes. 2019-08-16 02:08:14 +02:00
tastytea ac3538aed2
Change license in readme.
continuous-integration/drone/push Build is passing Details
2019-08-16 02:07:45 +02:00
tastytea 231663b07e
Changed license to AGPL3.
continuous-integration/drone/push Build is passing Details
2019-08-15 22:53:38 +02:00
tastytea 72efbb515d
Add pkg-config recipe.
continuous-integration/drone/push Build is failing Details
2019-08-14 00:19:12 +02:00
tastytea 740890e402
Modernized CMake recipes. 2019-08-14 00:15:04 +02:00
tastytea 22d1232240
Only build tests once in CI.
continuous-integration/drone/push Build is passing Details
2019-08-13 14:27:03 +02:00
tastytea 0998ee5ef9
Do tests only one time in CI.
continuous-integration/drone/push Build is passing Details
2019-08-12 23:39:41 +02:00
tastytea e4937c954f
Set CXX for rpm build in CI. 2019-08-12 23:27:56 +02:00
tastytea f7af97ad73
Version bump 0.106.0.
continuous-integration/drone/push Build is passing Details
2019-08-12 23:06:29 +02:00
tastytea c49518981b
Added tests for Easy::Tag.
continuous-integration/drone/push Build is passing Details
2019-08-12 05:49:56 +02:00
tastytea f159f0c391
Get numbers in Easy::Tag::History::accounts() and ::use().
We were trying to get strings before.
2019-08-12 05:48:26 +02:00
tastytea 2a7d02fba8
Marked members of Easy::Tag::History const. 2019-08-12 05:47:49 +02:00
tastytea a5e7f12fd1
Fixed test description for Easy::Results. 2019-08-12 05:27:56 +02:00
tastytea dc09d3db5b
Fixed tests for Easy::Status.
The data was invalid JSON.
2019-08-12 05:27:49 +02:00
tastytea 4922fc79fe
Added tests for Easy::Status.
continuous-integration/drone/push Build is failing Details
2019-08-12 04:55:32 +02:00
tastytea 39af18fe35
Removed nonsensical ifdefs. 2019-08-12 04:55:31 +02:00
tastytea 61a2d4aeef
Added tests for Easy::Results. 2019-08-12 04:54:48 +02:00
tastytea 338274e368
Removed old TODOs. 2019-08-12 03:29:55 +02:00
tastytea 919f67b123
marked operators bool and uint8_t of return_base const.
continuous-integration/drone/push Build is passing Details
2019-07-22 22:09:50 +02:00
tastytea 581e4a96bb
Added tests for Easy::Relationship.
continuous-integration/drone/push Build is passing Details
2019-07-21 02:55:57 +02:00
tastytea 7874ca7830
Updated Easy::Relationship. 2019-07-21 02:48:48 +02:00
tastytea d9fa878136
Added tests for Easy::PushSubscription. 2019-07-21 02:36:03 +02:00
tastytea b1afd2533d
Fixed validity-check for push subscriptions. 2019-07-21 02:33:28 +02:00
tastytea b2b58990df
Clarified reasons for blocked instances.
continuous-integration/drone/push Build is passing Details
2019-07-18 17:48:32 +02:00
tastytea dbce486c9b
Blocked Kiwi Farms, added explanation in README.
continuous-integration/drone/push Build is passing Details
2019-07-14 18:01:10 +02:00
tastytea 9b0c68f2bf
Prevent usage with Gab domains.
continuous-integration/drone/push Build is passing Details
2019-06-26 02:35:35 +02:00
tastytea f293d54a63
Added tests for Easy::Notification. 2019-06-26 02:14:52 +02:00
tastytea 449bb65303
Fixed tests with catch 1.x.
continuous-integration/drone/push Build is passing Details
2019-06-10 18:33:44 +02:00
tastytea 4922f79bf2
Moved cmake config for tests to tests/.
continuous-integration/drone/push Build is failing Details
2019-06-10 17:40:00 +02:00
tastytea bbac2b7c51
Added tests for Easy::Mention. 2019-06-10 17:28:22 +02:00
tastytea d4e1f68235
Added tests for Easy::List. 2019-06-10 17:28:22 +02:00
tastytea 9090515a99
CI: Only test g++ 6/9. 2019-05-26 22:18:53 +02:00
tastytea 86ebbf90a2
Fixed drone-notification. 2019-05-18 06:17:20 +02:00
tastytea 57bf54ed32
Fixed regex in unescape_html(). 2019-05-18 06:16:54 +02:00
tastytea a79d0157fc
Added tests for Easy::Instance.
continuous-integration/drone/push Build is passing Details
2019-05-13 23:09:12 +02:00
tastytea 3a36744d72
Fixed Instance::stats(). 2019-05-13 23:08:04 +02:00
tastytea 5cebe53c3f
Corrected error in test-description. 2019-05-13 22:01:45 +02:00
tastytea 8f5d40ff7f
Updated Easy::Instance.
Added urls() and stats() and removed streaming_api().
2019-05-13 21:52:28 +02:00
tastytea 8a6bef8c2c
Made type names more consistent. 2019-05-13 21:31:38 +02:00
tastytea 51c9180128
Added tests for Easy::Filter.
continuous-integration/drone/push Build is passing Details
2019-05-12 17:59:10 +02:00
tastytea 69109ffc91
Updated Easy::Filter. Only cosmetic changes. 2019-05-12 17:34:34 +02:00
tastytea ae7ffc2908
Better and more consistent wording. 2019-05-11 02:19:34 +02:00
tastytea d614696260
Added tests for Easy::Emoji.
continuous-integration/drone/push Build is passing Details
2019-05-10 22:43:14 +02:00
tastytea 6ca1b9b7dc
Cosmetic change in Easy::Context test. 2019-05-10 22:31:08 +02:00
tastytea 26f43a1682
Updated Easy::Emoji.
Added visible_in_picker().
2019-05-10 22:21:08 +02:00
tastytea 920421edf1
Added tests for Easy::Context.
continuous-integration/drone/push Build is passing Details
2019-05-10 21:01:40 +02:00
tastytea fb689bcac0
Updated Easy::Context. Removed superfluous debug messages. 2019-05-10 20:23:34 +02:00
tastytea 81d2f923b1
Added tests for Easy::Card.
continuous-integration/drone/push Build is passing Details
2019-05-05 14:20:07 +02:00
tastytea 622c4c1baf
Updated Easy::Card.
Deleted excess debug statement, added undocumented attribute
embed_url.
2019-05-05 14:18:57 +02:00
tastytea f69dcc9e98
Added tests for Easy::Attachment.
continuous-integration/drone/push Build is passing Details
2019-05-01 20:17:06 +02:00
tastytea 8fe607d43e
Updated Easy::Attachment.
Moved Metadata into Attachment::meta.
2019-05-01 19:51:50 +02:00
tastytea 6ae56a05b4
Moved tests for Easy::Application into entities/. 2019-05-01 19:10:50 +02:00
tastytea 385245f421
Deprecated was on the wrong line. 2019-05-01 13:02:23 +02:00
tastytea 909b4edc86
Added tests for Easy::Application.
continuous-integration/drone/push Build is passing Details
2019-05-01 13:01:00 +02:00
tastytea f7ccda7004
Added tests for Easy::Account. 2019-05-01 12:50:33 +02:00
tastytea 0b72c80d94
Fixed Account::privacy() and Account::Source::privacy(). 2019-05-01 12:43:02 +02:00
tastytea 14593ccf17
Changed wording a bit. 2019-05-01 01:28:46 +02:00
tastytea 8448d8e720
Updated Easy::Account.
continuous-integration/drone/push Build is passing Details
Removed all setters, changed the type for account fields, added new
attributes.
2019-05-01 00:57:00 +02:00
tastytea ea0c3c5250
Fixed Easy::string_to_time() definition. 2019-05-01 00:10:19 +02:00
tastytea 42b263897b
Split up checklists in calls and entities. 2019-04-30 23:50:19 +02:00
tastytea a98351905b
Added Easy::account_field_type and Easy::account_fields. 2019-04-30 23:49:55 +02:00
tastytea de78019cb3
Added Easy::string_to_time(). 2019-04-30 23:29:05 +02:00
tastytea 6543ea4b51
CI: Renamed pipelines.
continuous-integration/drone/push Build is passing Details
2019-04-29 20:43:56 +02:00
tastytea 570aa32edf
CI: ARM pipeline.
continuous-integration/drone/push Build was killed Details
2019-04-29 19:31:30 +02:00
tastytea 2d56af7d5e
CI: Renamed notification pipeline. 2019-04-29 18:38:21 +02:00
tastytea d9a1872d1e
Fixed tests for (un)muting statuses. 2019-04-29 18:35:20 +02:00
tastytea 667150d18a
Added tests for API::v1::statuses_id_unmute.
continuous-integration/drone/push Build is passing Details
2019-04-29 18:26:03 +02:00
tastytea 95b9dd868d
Added tests for API::v1::statuses_id_mute. 2019-04-29 18:25:43 +02:00
tastytea 5714d29d95
Added tests for API::v1::accounts_id_unmute. 2019-04-29 18:19:04 +02:00
tastytea b17d09490f
Added tests for API::v1::accounts_id_mute. 2019-04-29 18:17:04 +02:00
tastytea c626462c0b
Added tests for API::v1::mutes. 2019-04-29 18:09:07 +02:00
tastytea e8eab3b947
Moved API tests to tests/api. 2019-04-29 17:59:34 +02:00
tastytea 761246c03b
Don't test API in CI. 2019-04-29 17:58:50 +02:00
tastytea 77b86bd8c0
Typo & typo % typo.
continuous-integration/drone/push Build is failing Details
2019-04-29 11:18:11 +02:00
tastytea 9c278db9b3
Added list of Pleroma API endpoints.
continuous-integration/drone/push Build is passing Details
2019-04-29 02:03:23 +02:00
tastytea ca9e0a71e1
Drone: Notify on success *and* failure.
continuous-integration/drone/push Build is passing Details
2019-04-29 00:48:44 +02:00
tastytea 9d1726acd5
Replaced README.md in build files.
continuous-integration/drone/push Build is passing Details
2019-04-29 00:38:10 +02:00
tastytea 41dfc410f1
Replaced README.md with README.adoc.
continuous-integration/drone/push Build is failing Details
2019-04-29 00:29:30 +02:00
tastytea c857e7d379
pull: true -> pull: always. 2019-04-28 18:23:40 +02:00
tastytea c341b8936e
Converted drone config to new format.
continuous-integration/drone/push Build is passing Details
2019-04-28 14:29:50 +02:00
tastytea d8739e14ae
Fixed test arguments.
the build was successful Details
2019-04-27 23:13:30 +02:00
tastytea f24fae28e9
Added the tag [auth] for tests that need authentication.
the build is pending Details
continuous-integration/drone/push Build was killed Details
2019-04-27 22:44:41 +02:00
tastytea 3705ae8d78
Added tests for API::v1::media_id.
the build is pending Details
continuous-integration/drone/push Build was killed Details
2019-04-27 22:33:01 +02:00
tastytea 3f09180b85
Added tests for API::v1::media. 2019-04-27 22:03:16 +02:00
tastytea 892a05e9fb
Removed mentions of base64. 2019-04-27 21:48:15 +02:00
tastytea a766ff001c
Check if files exists. 2019-04-27 21:38:01 +02:00
tastytea 8b3eaf1e73
Added tests for PUT and DELETE to API::v1::lists_id.
the build was successful Details
2019-04-25 17:25:39 +02:00
tastytea 9301586082
Added POST and DELETE to API::v1::lists_id_accounts. 2019-04-25 17:10:27 +02:00
tastytea 4302093684
Added tests for POST API::v1::lists.
the build was successful Details
2019-04-25 16:24:02 +02:00
tastytea b806dbfeb8
Added tests for API::v1::lists_id. 2019-04-25 15:45:03 +02:00
tastytea e9ac12efe3
Added tests for API::v1::lists_id_accounts. 2019-04-25 15:39:50 +02:00
tastytea 91ef34faa4
Added tests for API::v1::accounts_id_lists. 2019-04-25 15:27:54 +02:00
tastytea 5e6bf432a8
Harmonize calls to Entity::check_valid(). 2019-04-25 14:55:45 +02:00
tastytea a2aa33cf27
Added tests for API::v1::lists.
the build was successful Details
2019-04-25 14:26:14 +02:00
tastytea c3cdf6233a
Improved description of types.
the build was successful Details
2019-04-23 20:08:30 +02:00
tastytea 318eda9101
Confirmed that Account::moved() works
and changed my mind about writable Status::Attachment.
2019-04-22 05:15:03 +02:00
tastytea 5ddc0f20fe
Added dependency-install examples for Debian Stretch and CentOS 7.
the build was successful Details
2019-04-22 04:01:18 +02:00
tastytea 2287a4753c
Fixed operator << warnings.
the build was successful Details
2019-04-21 13:59:31 +02:00
tastytea d3d9f0f4e4
Fixed operator << for Easy::return_entity. 2019-04-21 13:17:39 +02:00
tastytea 7558c73648
Reformatted switch. 2019-04-21 06:15:37 +02:00
tastytea c94a2ccb4a
Added example for EXTRA_TEST_ARGS.
the build was successful Details
2019-04-20 01:30:05 +02:00
tastytea 1e58709b5c
Added tests for API::v1::suggestions_accountid.
the build failed Details
2019-04-20 00:50:28 +02:00
tastytea 0ca593b9b0
Added tests for API::v1::suggestions. 2019-04-20 00:43:37 +02:00
tastytea 14d0263606
Added support for /api/v1/suggestions,
and /api/v1/suggestions/:account_id.
2019-04-20 00:39:52 +02:00
tastytea 8094603c0f
Added tests for API::v1::follow_requests_id_reject. 2019-04-20 00:19:31 +02:00
tastytea 35778de6e0
Added tests for API::v1::follow_requests_id_authorize. 2019-04-20 00:17:27 +02:00
tastytea 9cfc245db6
Added tests for API::v1::follow_requests. 2019-04-20 00:12:43 +02:00
tastytea eaaa63a20c
Fixed definition of newly moved functions, changed calls to them.
the build was successful Details
2019-04-19 10:42:30 +02:00
tastytea fb27e79b3d
Deprecated API::urlencode, API::urldecode, API::unescape_html.
the build failed Details
Replaced by Mastodon::urlencode, Mastodon::urldecode,
Mastodon::unescape_html.
2019-04-19 09:11:37 +02:00
tastytea e9aa714ecf
Added Easy::context_type to list of types.
the build was successful Details
2019-04-19 06:12:01 +02:00
tastytea 53b2a4bbc6
Added tests for API::v1::filters_id.
the build was successful Details
2019-04-19 05:48:41 +02:00
tastytea 90a6873a38
Added tests for API::v1::filter. 2019-04-19 05:35:08 +02:00
tastytea 2527e9523e
Added support for /api/v1/filters and /api/v1/filters/:id. 2019-04-19 05:20:48 +02:00
tastytea cab52b53a0
Added tests for API::v1::statuses_id_unfavourite.
the build was successful Details
2019-04-19 02:00:49 +02:00
tastytea 887b77d334
Added tests for API::v1::statuses_id_favourite. 2019-04-19 01:58:57 +02:00
tastytea 5e721af0a1
Added tests for API::v1::favourites. 2019-04-19 01:40:36 +02:00
tastytea 9b1ae88b9b
Corrected expected HTTP error codes in follow/unfollow tests. 2019-04-19 01:39:30 +02:00
tastytea 7f46be68d1
Added daylight savings time detection to Easy::Entity::get_time(). 2019-04-18 04:46:55 +02:00
tastytea 5dee115f8f
Fixed RSS link.
the build was successful Details
2019-04-17 20:10:42 +02:00
tastytea 12bcb7e59b
Check if display_name really changed. 2019-04-17 08:09:43 +02:00
tastytea e48c289c23
Added RSS link.
the build was successful Details
2019-04-17 05:37:28 +02:00
tastytea 8db6d59c7a
Added tests for API::v1::endorsements, API::v1::accounts_id_{,un}pin 2019-04-16 23:28:04 +02:00
tastytea 2e99a0c155
Mention the HTTP method in tests.
the build was successful Details
2019-04-16 21:38:08 +02:00
tastytea 02d538333e
Added tests for API::v1::domain_blocks. 2019-04-16 21:32:15 +02:00
tastytea 53059684ac
Added test for API::v1::custom_emojis. 2019-04-16 19:52:26 +02:00
tastytea 275504a079
Added "visible_in_picker" to required fields in Easy::emoji. 2019-04-16 19:51:34 +02:00
tastytea 4a3432e339
Added support for /api/v1/accounts.
the build was successful Details
2019-04-16 19:26:09 +02:00
tastytea b54d54666a
Added the variable EXTRA_TEST_ARGS to cmake. 2019-04-16 18:40:35 +02:00
tastytea 346154c062
Added Easy::Token. 2019-04-16 17:56:45 +02:00
tastytea 8db37998fc
Fixed include path. 2019-04-16 17:55:49 +02:00
tastytea a86cd8eaa0
Added support for clang++ 5/6.
the build was successful Details
2019-04-16 05:35:27 +02:00
tastytea 04b2513493
Added tests for /api/v1/accounts/:id/unblock.
the build was successful Details
2019-04-16 04:00:32 +02:00
tastytea 361f2eaf68
Get environment variables only one time. 2019-04-16 03:55:28 +02:00
tastytea 984f40a7a4
Added tests for API::v1::accounts_id_block. 2019-04-16 03:25:44 +02:00
tastytea 28e2470468
Added tests for API::v1::blocks. 2019-04-16 03:15:45 +02:00
tastytea 76073881fe
Added support for /api/v1/apps/verify_credentials.
the build was successful Details
2019-04-16 02:58:20 +02:00
tastytea a35688f595
Added tests for API::v1::apps. 2019-04-16 02:37:04 +02:00
tastytea 915e67f1af
Added tests for API::v1::accounts_search. 2019-04-15 23:55:33 +02:00
tastytea 5875adf5db
Simplyfied and reduced calls in tests greatly.
the build was successful Details
2019-04-15 07:14:54 +02:00
tastytea 2c6997827f
typo
the build was successful Details
2019-04-15 05:17:29 +02:00
tastytea 73b6462d93
Added tests for API::v1::accounts_relationships.
the build failed Details
2019-04-15 04:29:54 +02:00
tastytea 7539c460a0
Added tests for API::v1::accounts_id_unfollow.
the build was successful Details
2019-04-15 03:51:27 +02:00
tastytea 5408f6f235
Added test for malformed JSON. 2019-04-15 03:48:39 +02:00
tastytea f84a272f53
Added support for "errors" in addition to "error". #12
the build was successful Details
2019-04-15 03:07:04 +02:00
tastytea e86019f41f
Added tests for API::v1::accounts_id_follow. 2019-04-15 03:06:40 +02:00
tastytea 9d1bb4a6e3
Changed requirement for a valid Easy::Status.
Made it required that "replies_count" and "application" is present in
statuses.
2019-04-15 02:03:24 +02:00
tastytea fa3eefdb74
Print what() in tests if an exception is thrown.
the build was successful Details
2019-04-15 02:00:05 +02:00
tastytea 5b387a1c7b
Added tests for API::v1::accounts_id_statuses. 2019-04-15 01:59:41 +02:00
tastytea 9c5779fd04
Added tests for API::v1::accounts_id_following.
the build was successful Details
2019-04-15 01:39:28 +02:00
tastytea ae7ac65931
Allowed the user ID for tests to be changed.
With the environment variable MASTODON_CPP_USER_ID.
2019-04-15 01:19:26 +02:00
tastytea 09a234e82f
Added tests for API::v1::accounts_id_followers. 2019-04-15 01:02:03 +02:00
tastytea 0ffd41c851
Allowed the setting of the instance for testing.
the build was successful Details
Via the environment variable MASTODON_CPP_INSTANCE.
2019-04-14 23:08:44 +02:00
tastytea e00b99fb17
Added tests for API::v1::accounts_update_credentials. 2019-04-14 22:45:44 +02:00
tastytea 09793c5511
Added tests for API::v1::accounts_verify_credentials.
the build was successful Details
2019-04-14 22:30:37 +02:00
tastytea 0166cc7b53
Added test for API::v1::accounts_id.
the build was successful Details
2019-04-14 19:58:55 +02:00
tastytea 7d245e0df1
Fixed deletion of parameters. 2019-04-14 19:57:39 +02:00
tastytea 64d4c65668
Added "emojis" to required fields in Easy::Account. 2019-04-14 19:57:07 +02:00
tastytea 5bcbf55274
Added Easy-test with /api/v1/instance.
the build was successful Details
2019-04-14 18:11:48 +02:00
tastytea 7de4c8c0ba
Do not require contact_account in Easy::Instance.
It is not required to have one, according to
<https://docs.joinmastodon.org/api/entities/#instance>.
2019-04-14 18:09:25 +02:00
tastytea d4736308fd
Put http_error_code in return_base. 2019-04-14 17:58:33 +02:00
tastytea a65cb89d20
Removed obsolete parameters from documentation.
the build was successful Details
2019-04-14 06:44:11 +02:00
tastytea a96b2e0ab5
Updated readme.
the build was successful Details
2019-04-14 06:34:26 +02:00
tastytea d5e6dfc776
Version bump 0.101.1
the build was successful Details
2019-04-14 04:46:03 +02:00
tastytea a1083b5c18
Changed CMAKE_PROJECT_NAME to PROJECT_NAME.
the build was successful Details
2019-04-14 04:38:59 +02:00
tastytea 2f962d04eb
Added first tests.
the build was successful Details
2019-04-14 04:18:33 +02:00
tastytea ca60900a0c
Reformatted and splitted cmake recipe. 2019-04-14 04:11:17 +02:00
tastytea 1432839f48
Install rpm-build on CentOS.
the build was successful Details
2019-04-14 00:11:30 +02:00
tastytea 7b42101384
Use g++-6 on CentOS.
the build failed Details
2019-04-14 00:04:01 +02:00
tastytea 4c7074cff9
CI: Install curlpp from CentOS 6.
the build was successful Details
2019-04-13 23:48:37 +02:00
tastytea f797b54880
Install cmake3 on centos.
the build was successful Details
2019-04-13 23:00:34 +02:00
tastytea 179692da93
Replaced wget with curl in CI recipe.
the build was successful Details
2019-04-13 22:49:48 +02:00
tastytea 5e6b3d2e73
Install "file" for .deb-package generation.
the build was successful Details
2019-04-13 22:32:17 +02:00
tastytea e5c02f04d3
Version bump 0.101.0.
the build was successful Details
2019-04-13 22:24:40 +02:00
tastytea ee97700495
Added links to Pleroma and glitch-soc documentation.
the build was successful Details
2019-04-13 21:59:27 +02:00
tastytea 9a7b107b32
typos.
the build was successful Details
2019-04-13 21:55:03 +02:00
tastytea 4e8c44a4ba
Added list of types to readme.
the build was successful Details
2019-04-13 21:50:20 +02:00
tastytea 4614cfba0c
Documentation fixes. 2019-04-13 21:04:59 +02:00
tastytea 3fe21ccfc7
Small documetation fixes.
the build was successful Details
2019-04-13 02:54:46 +02:00
tastytea 4302814e17
Replaced Easy::alertmap with Easy::alerts. 2019-04-13 02:45:27 +02:00
tastytea bc82dac69b
Marked Easy::time operators const. 2019-04-13 02:27:45 +02:00
tastytea a3f2e94034
Bettered documentation. 2019-04-13 02:27:21 +02:00
tastytea a0d47d48fa
Replaced parametermap with own types.
the build was successful Details
2019-04-12 01:10:33 +02:00
tastytea c2eff2b09e
Print remaining content of the stream in debug mode.
the build was successful Details
2019-04-10 21:12:13 +02:00
tastytea 031c0c3e22
Catch path by value in request_stream().
the build was successful Details
2019-04-10 21:04:04 +02:00
tastytea 2c97d43ce2
Added comment to example02. 2019-04-10 20:55:23 +02:00
tastytea 09ecd8e5e4
Report errors with get_stream() in-stream.
the build was successful Details
2019-04-10 20:52:36 +02:00
tastytea a551516be2
Added short descriptions to the examples.
the build was successful Details
Also added example02 to doxygen-documentation.
2019-04-10 02:35:38 +02:00
tastytea bde8d11706
Revamped streams. 2019-04-10 02:25:55 +02:00
tastytea ccedfba4af
Added GET_STREAM to switch in http::request(). 2019-04-09 21:58:02 +02:00
tastytea 438a3932e1
Build RPM packages on CentOS.
the build was successful Details
2019-04-08 21:24:08 +02:00
tastytea c9a826ebcb
Improved documentation a bit.
the build was successful Details
2019-04-05 14:41:18 +02:00
tastytea 6a01efc6aa
Moved API::http::method to http_method. 2019-04-05 14:40:54 +02:00
tastytea 88d69be298
Let Account::Source fall back to Easy::Entity. 2019-04-05 14:39:35 +02:00
tastytea 8d4dcb9984
Added doxygen to drone recipe.
the build was successful Details
2019-04-04 20:44:57 +02:00
tastytea 55529136c2
Changed default for WITH_EXAMPLES to NO.
the build failed Details
2019-04-04 12:58:49 +02:00
tastytea d7bec891dd
Set default values for all custom cmake-variables.
And changed WITHOUT_EASY to WITH_EASY.
2019-04-04 12:47:40 +02:00
tastytea beb6910085
Install all necessary headers. 2019-04-04 12:35:43 +02:00
tastytea 9d72c992a2
Updated readme.
the build was successful Details
2019-04-02 11:28:53 +02:00
tastytea a63f63bd4f
Fixed include guard. 2019-04-02 11:20:35 +02:00
tastytea b49e8600ac
Moved types to types.hpp and reformatted mastodon-cpp.hpp.
Also renamed easy/types.hpp to easy/types_easy.hpp.
2019-04-02 11:16:52 +02:00
tastytea 38e8809b92
Moved return_base and return_call to their own header. 2019-04-02 10:37:27 +02:00
tastytea c35b7f56fa
Moved easy types to easy/types.hpp.
the build was successful Details
2019-03-31 22:24:14 +02:00
tastytea 86dccaf2d7
Removed inclusion of easy.hpp from entities.
Also added override to valid().
2019-03-31 21:43:57 +02:00
tastytea 6f11116b1c
strtime: Explicitly cast char array to const string.
the build was successful Details
2019-03-31 00:08:11 +01:00
tastytea 6690d2bd0b
Changed for-loop to std::transform. 2019-03-31 00:02:02 +01:00
tastytea 94651f8dba
Changed for-loop to std::transform. 2019-03-30 23:59:27 +01:00
tastytea 07c39ab4bf
Changed for-loop to std::transform. 2019-03-30 23:57:25 +01:00
tastytea 3328821bca
Changed for-loop to std::transform. 2019-03-30 23:55:40 +01:00
tastytea c7f7123ba6
Fixed some capture clauses. 2019-03-30 23:49:08 +01:00
tastytea f5b05893cd
Changed for-loop to std::transform. 2019-03-30 23:42:06 +01:00
tastytea d84a18a0e7
Changed for-loop to std::transform. 2019-03-30 23:15:22 +01:00
tastytea 7ac5b2545a
Cleaned up whitespace. 2019-03-30 23:10:30 +01:00
tastytea 5cf3b18008
Updated .gitignore, deleted build.sh. 2019-03-30 22:35:15 +01:00
tastytea 7633bb0220
Updated fediverse address.
the build was successful Details
2019-03-30 22:32:24 +01:00
tastytea ff0bd7b906
Replaced for-loop with std::transform.
the build was successful Details
2019-03-30 22:24:15 +01:00
tastytea 57ec1fd23a
Cleaned up whitespace. 2019-03-30 22:14:58 +01:00
tastytea 43fd2aae6e
Changed debug.hpp to respect 80 char rule. 2019-03-30 20:53:53 +01:00
tastytea baf417ce69
Added documentation to return_entity{,_vector}.
the build was successful Details
2019-03-30 13:18:42 +01:00
tastytea c854230f95
Added documentation for return_base and return_call. 2019-03-30 13:06:57 +01:00
tastytea da1ee09640
Added explicit instantiations for return_entity{,_vector}. 2019-03-30 12:12:59 +01:00
tastytea 54a1fb0d3e
Added Easy::time as time type.
the build was successful Details
2019-03-29 14:44:39 +01:00
tastytea dff3b11c00
Cleaned up, fixed formatting and so on.
the build was successful Details
2019-03-28 21:23:24 +01:00
tastytea 76dc6a623c
Put Easy return types in own header. 2019-03-28 15:35:23 +01:00
tastytea ce5f9510a6
Put Entity in own header. 2019-03-28 15:35:00 +01:00
tastytea 4aad1425eb
Turned Easy into namespace, renamed class Easy::API.
Don't look, I'm not done yet! :-)
2019-03-28 15:30:56 +01:00
tastytea 354f7e1b90
Removed unnecessary type qualifiers. 2019-03-28 13:45:30 +01:00
tastytea 12d986ed06
Templated return_entity and return_entity_vector.
the build failed Details
2019-03-28 13:33:28 +01:00
tastytea 552c92a1ef
Set default for WITH_EXAMPLES to YES, disabled tests. 2019-03-28 13:29:21 +01:00
tastytea 0b35fa0828
Uodated copyright years. 2019-03-20 06:15:43 +01:00
tastytea c4fae35100
Reformatted for 80 char rule.
the build was successful Details
2019-03-14 18:34:34 +01:00
tastytea c43436d970
misc
the build was successful Details
2019-03-11 21:13:58 +01:00
tastytea d85190b113
Use std::transform instead of for loop in json_array_to_vector. 2019-03-11 21:13:34 +01:00
tastytea e07dc45184
Inherit constructors from Entity. 2019-03-11 20:48:54 +01:00
tastytea 1f36568b20
Added contructor with Json::Value and operator Json::Value() to Entity 2019-03-11 20:41:52 +01:00
tastytea cc43f133a4
Removed -DWITH_STATIC.
the build was successful Details
2019-03-03 12:28:14 +01:00
tastytea f227b25e85
Revert "Added const to overloaded operators."
the build was successful Details
This reverts commit 2103eb4ac2.
2019-03-03 12:24:09 +01:00
tastytea 2103eb4ac2
Added const to overloaded operators.
the build failed Details
2019-03-03 12:14:11 +01:00
tastytea 6d4199047f
Remove support for g++-5.
the build was successful Details
2019-03-03 11:42:54 +01:00
tastytea c244b2bb94
Updated README-examples.
the build failed Details
2019-03-03 11:22:11 +01:00
tastytea f28fac5579
Fixed << overloading. 2019-03-03 11:16:23 +01:00
tastytea d31c83f1d9
Did API inventory.
the build was successful Details
Added missing calls to readme, reordered calls, marked deprecated
calls.
2019-03-03 10:41:10 +01:00
tastytea 3820394099
Fixed example01.
the build was successful Details
2019-03-02 20:25:31 +01:00
tastytea 5fa7887fb1
Added operator overloads to return_entity and return_entity_vector 2019-03-02 20:21:31 +01:00
tastytea e1b32d13c8
Added example.
the build was successful Details
2019-03-02 13:52:35 +01:00
tastytea ebd40ba4d5
Changed default values for strings from 0 to "". 2019-03-02 12:47:15 +01:00
tastytea 4d3ffb5516
Typo 2019-03-02 12:21:40 +01:00
tastytea 9f21c5811a
Changed error codes for curlpp errors. 2019-03-02 11:53:02 +01:00
tastytea 4fb13d1876
Removed constexpr for g++-5.
the build was successful Details
2019-02-25 14:55:01 +01:00
tastytea 25628e1d5d
Added virtual destructors to API and Easy::Entity.
the build failed Details
2019-02-25 14:36:49 +01:00
tastytea 7bdeaeb236
Changed return types for simple calls.
the build failed Details
Also added return_entity, return_entity_vector and GenericEntity().
2019-02-25 13:55:24 +01:00
tastytea ada8f45415
Changed return tyoe for register_app[12]. 2019-02-25 12:32:19 +01:00
tastytea cbb1e18b0c
Replaced return types for get_stream, patch, post, put, del
the build failed Details
2019-02-22 12:36:03 +01:00
tastytea ade55f8f19
Updated error descriptions. 2019-02-22 12:14:15 +01:00
tastytea e034dbc299
Replaced return codes in API::http. 2019-02-22 12:03:28 +01:00
tastytea c8baf41582
Renamed macros.hpp to debug.hpp. 2019-02-22 11:35:06 +01:00
tastytea 514ae8dc63
Added new return types, replaced return types for API::get(). 2019-02-22 11:33:36 +01:00
tastytea 5c4ca94d4b
Added more warnings to debug build. 2019-02-22 10:10:44 +01:00
tastytea af5e658eb2
Added warning regarding the master branch.
the build was successful Details
2019-02-22 08:34:37 +01:00
tastytea 357b04dac2
Removed tests. 2019-02-22 08:31:03 +01:00
tastytea 8c97e8f516
Removed examples 2019-02-22 08:30:38 +01:00
tastytea 318221a2e6
Changed uint_fast16_t to uint16_t and uint_fast64_t to uint64_t. 2019-02-22 08:29:54 +01:00
tastytea 24687cba07
Removed deprecated code. 2019-02-22 08:23:26 +01:00
tastytea e41fd98ec1
Announce breaking API changes
the build was successful Details
2019-02-22 08:07:55 +01:00
tastytea 115726edf8
Escaped @ in doxygen documentation.
the build was successful Details
2019-02-19 04:41:24 +01:00
tastytea ffaf4a551a
Bugfix: Do not assume client_id, client_secret and token are hexadecimal.
the build was successful Details
2019-02-04 19:14:54 +01:00
tastytea 0cbfb415b5
Correted error in documentation. 2019-01-29 07:11:48 +01:00
tastytea 28734ee8cf
Add warning about int->string change.
the build was successful Details
2019-01-27 04:23:49 +01:00
tastytea a6b4a09dc8
Changed ids from uint_fast64_t to const string in examples.
the build was successful Details
2019-01-27 04:18:40 +01:00
tastytea b601369bfd
Forgot an int->string conversion. 2019-01-27 04:15:52 +01:00
tastytea 5a6b541de2
Changed ids from uint_fast64_t to const string in all relevant places. 2019-01-27 03:50:28 +01:00
tastytea 0b47e0ec8d
Changed ids from uint_fast64_t to const string in all Entities. 2019-01-27 03:44:08 +01:00
tastytea e2614c045e
Fixed documentation for get_notifications().
the build was successful Details
2019-01-26 07:08:20 +01:00
tastytea 462085470e
Added get_notifications().
the build was successful Details
Closes #3
2019-01-26 06:54:47 +01:00
tastytea 03f6b944d8
Updated the link to the Mastodon documentation.
the build was successful Details
2018-12-04 12:30:16 +01:00
tastytea ee82d35357
Removed const where it has no effect.
the build was successful Details
2018-12-04 11:26:28 +01:00
tastytea 8a0f709a6e
Added support vor bookmarks (Glitch-Soc)
the build was successful Details
2018-12-04 10:34:51 +01:00
tastytea 64f4e378ef
Added status of Glitch-Soc support to readme 2018-12-04 10:04:54 +01:00
tastytea cfb21e3e2b
Tell the compiler to be more pedantic for debug builds. 2018-12-04 09:49:57 +01:00
tastytea 1f5e356b2a
Added Instance::max_toot_chars() 2018-12-04 09:44:32 +01:00
tastytea 1875284670
CI: Updated drone recipe
the build was successful Details
2018-11-17 21:12:06 +01:00
tastytea ebaee939eb
Incorporated changes from Mastodon 2.4 to 2.6 2018-11-17 21:07:51 +01:00
tastytea 22c217d3da
Added GET /api/v1/endorsements, POST /api/v1/accounts/:id/pin, POST /api/v1/accounts/:id/unpin 2018-11-17 20:54:23 +01:00
tastytea ad7ac09ae1
Added Relationship::endorsed() and Relationship::showing_notifications() 2018-11-17 20:47:38 +01:00
tastytea c492158f64
Enhanced description for language(const string &language) 2018-11-17 20:41:06 +01:00
tastytea 121cf0f32b
Added Status::card() 2018-11-17 20:38:09 +01:00
tastytea a8e27d7f5d
Added Status::replies_count() 2018-11-17 20:32:36 +01:00
tastytea d79fbc212b
Bugfix: Link error with inline function
the build was successful Details
2018-11-13 14:50:42 +01:00
tastytea 18935da2d1
Added ABI instability warning
the build was successful Details
2018-10-09 23:43:44 +02:00
tastytea 688fa9f346
CI: Changed g++ packages from bionic to xenial
the build was successful Details
2018-10-09 02:04:53 +02:00
tastytea d4b42ac316
updated dependencies 2018-10-08 22:43:13 +02:00
tastytea 2d3d7e3bdd
CI: replace gcc image with debian image
the build was successful Details
2018-10-08 22:17:36 +02:00
tastytea 6385d405d9
fixed package build script
the build was successful Details
2018-10-08 19:07:28 +02:00
tastytea 497cab1122
CI: Dropped g++-6, was based on jessie, didn't work with libcurlpp-dev from sid
the build failed Details
2018-10-08 18:53:48 +02:00
tastytea 38390274ae
Removed ebuilds from CI recipe
the build failed Details
2018-10-08 18:36:13 +02:00
tastytea be39e04b05
Changed dependencies: libcurlpp-dev is not in buster anymore, but in sid
the build failed Details
2018-10-08 18:26:22 +02:00
tastytea dd306268c4
Deleted ebuilds.
the build failed Details
They are still in the overlay "tastytea".
2018-10-08 18:20:05 +02:00
tastytea e3c765ea5b
deleted useless debug statements 2018-10-08 01:45:46 +02:00
tastytea e372614068
Added error 16: Timeout 2018-10-08 01:33:09 +02:00
tastytea f1755d8de3
Bugfix: Error codes from send_post and send_toot were not reported back.
Because the variable was not a reference.
2018-10-08 01:22:55 +02:00
tastytea f64984f331
Updated Easy::Account for Mastodon 2.4.0+ 2018-09-16 02:45:24 +02:00
tastytea 54493cd42e
Fixed package generation issues 2018-09-16 01:28:38 +02:00
tastytea 21ba221779
drone: deactivated gcc 5
the build was successful Details
2018-08-26 20:36:16 +02:00
tastytea 7882429cef
drone: replaced stretch-dependencies with jessie-backports 2018-08-26 20:28:13 +02:00
tastytea fc281a698b
drone: reversed compiler list, generate generic binary package
the build was successful Details
2018-08-26 19:46:36 +02:00
tastytea 0ede902e0b
Enabled the possibility to generate source packages 2018-08-26 13:43:16 +02:00
tastytea 7c2dfa65e2
fixed drone file
the build was successful Details
2018-08-15 07:43:19 +02:00
tastytea b96ac7c19d
Updated readme
the build failed Details
2018-08-15 07:36:49 +02:00
tastytea fa4f6388a9
Fixed release-portion of CI-script 2018-08-14 17:42:01 +02:00
tastytea cdb538fa45
Updated dependencies, version bump
the build was successful Details
2018-08-14 17:26:34 +02:00
tastytea e885bd5ae6
Enhanced CI
the build was successful Details
2018-08-14 16:58:59 +02:00
tastytea fb0a7c0f7f
Added option to compile to static library
the build was successful Details
2018-07-19 12:23:27 +02:00
tastytea 63fd9f581c
bugfix: some examples didn't compile with -DWITHOUT_EASY 2018-07-19 11:17:46 +02:00
tastytea e18c9b1c35
drone: changed working dir for gitea-release
the build was successful Details
Because the checksum-files had build/foo in it
2018-07-14 12:53:11 +02:00
tastytea 70b7f1b673
fixed drone recipe
the build was successful Details
2018-07-14 12:32:48 +02:00
tastytea 14a60e1e82
fixed drone recipe
the build failed Details
2018-07-14 12:05:07 +02:00
tastytea b74381ceed
Enhanced Entity::valid
the build was successful Details
It now checks if all non-nullable attributes are set. fixes #10
2018-07-14 11:54:13 +02:00
tastytea 2565ff8d15
Renamed send_toot to send_post, made send_toot an alias for send_post 2018-07-14 10:36:34 +02:00
tastytea 81efd8bc1c
re-enabled automatic release to gitea
the build was successful Details
It was disabled because it was not compatible with gitea < 1.5.0.
2018-07-14 08:14:54 +02:00
tastytea 5df220913b
Added API::urldecode()
the build was successful Details
2018-06-28 14:19:43 +02:00
tastytea dd379bb573
fixed ebuilds
the build was successful Details
2018-06-21 22:28:09 +02:00
tastytea c29a8e908e
Updated DEB/RPM-package metainfo 2018-06-21 18:28:39 +02:00
tastytea 259ffad483
updated ebuilds
the build was successful Details
2018-06-21 18:11:47 +02:00
tastytea a5c1ce642d
removed .travis.yml
the build was successful Details
2018-06-21 17:25:34 +02:00
tastytea 917b98945a
drone: disabled gitea_release temporarily
the build was successful Details
2018-06-21 16:51:55 +02:00
tastytea 9eba5bd5d3
Updated dependencies
the build was successful Details
2018-06-21 14:06:04 +02:00
tastytea d44c69aaa3
downgraded drone from buster to stretch, fixed travis
the build was successful Details
2018-06-21 13:58:52 +02:00
tastytea f9c32f38d3
Removed redundant debug messages
the build was successful Details
2018-06-21 12:42:38 +02:00
tastytea 5c7dab4b78
Updated Gentoo install instructions
the build was successful Details
2018-06-20 11:05:49 +02:00
tastytea dc763ef41d
drone: always pull new images 2018-06-19 09:34:07 +02:00
tastytea ae9df6706d
reduced issue template
the build was successful Details
2018-06-14 11:52:56 +02:00
tastytea 7bd17a0ef0
Added a lot more version tags to the documentation
the build was successful Details
That was tedious! 😓
2018-06-14 11:17:26 +02:00
tastytea 43504f6ef7
Added Easy::send_toot (Closes #1)
the build failed Details
2018-06-14 04:11:28 +02:00
tastytea eaff505f15
bugfix: Made sure that arrays are send as arrays when they only have 1 entry
This applies to account_ids, exclude_types, and media_ids
2018-06-14 04:10:08 +02:00
tastytea 8f30451ec1
Made Easy::Attachment writable (#1)
the build was successful Details
2018-06-14 03:19:23 +02:00
tastytea 929e815c73
added @since-tags 2018-06-14 01:52:05 +02:00
tastytea a56f6f0340
Made Easy::Status writable (#1)
the build was successful Details
2018-06-13 23:55:19 +02:00
tastytea bb697639ef
updated dependencies
the build was successful Details
2018-06-13 05:28:17 +02:00
tastytea 20ba5212b4
drone: Added email notification
the build was successful Details
2018-06-13 05:14:29 +02:00
tastytea de07809a9d
Removed travis status, microchanged drone config
the build was successful Details
2018-06-13 00:27:45 +02:00
179 changed files with 12688 additions and 5101 deletions

View File

@ -1,33 +1,269 @@
pipeline:
build:
image: debian:buster-slim
pull: true
commands:
- apt-get update
- apt-get install -y build-essential cmake pkg-config
- apt-get install -y libcurl4-openssl-dev libcurlpp-dev libjsoncpp-dev
- apt-get install -y rpm file
- mkdir -p build && cd build
- cmake -DWITH_EXAMPLES=ON -DWITH_TESTS=ON ..
- make VERBOSE=1
- make install DESTDIR=install
- ctest ..
- cp -v ../packages/gentoo/mastodon-cpp-0.0.0.ebuild mastodon-cpp-${DRONE_TAG}.ebuild
- cmake -DWITH_DEB=ON ..
- make package
- cmake -DWITH_DEB=OFF -DWITH_RPM=ON ..
- make package
kind: pipeline
name: x86_64
pipeline:
gitea_release:
when:
event: tag
image: plugins/gitea-release
platform:
os: linux
arch: amd64
volumes:
- name: debian-package-cache
host:
path: /var/cache/debian-package-cache
trigger:
event:
exclude:
- tag
steps:
- name: gcc6
image: debian:stretch-slim
pull: true
environment:
CXX: g++-6
CXXFLAGS: -pipe -O2
MASTODON_CPP_ACCESS_TOKEN:
from_secret: mastodon_cpp_access_token
commands:
- rm -f /etc/apt/apt.conf.d/docker-clean
- rm -f /var/cache/apt/archives/lock
- apt-get update -q
- apt-get install -qy build-essential cmake
- apt-get install -qy libpoco-dev libjsoncpp-dev doxygen catch
- rm -rf build && mkdir -p build && cd build
- cmake -DWITH_EXAMPLES=YES -DWITH_TESTS=YES -DEXTRA_TEST_ARGS="~[api]" ..
- make VERBOSE=1
- make install DESTDIR=install
- cd tests && ctest
volumes:
- name: debian-package-cache
path: /var/cache/apt/archives
- name: gcc9
image: debian:stretch-slim
pull: true
environment:
CXX: g++-9
CXXFLAGS: -pipe -O2
MASTODON_CPP_ACCESS_TOKEN:
from_secret: mastodon_cpp_access_token
commands:
- rm -f /etc/apt/apt.conf.d/docker-clean
- rm -f /var/cache/apt/archives/lock
- apt-get update -q
- echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release
- echo "deb http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu xenial main" >> /etc/apt/sources.list.d/ubuntu-toolchain-r.list
- apt-get install -qy gnupg
- gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 0x60c317803a41ba51845e371a1e9377a2ba9ef27f
- gpg --armor --export 0x60c317803a41ba51845e371a1e9377a2ba9ef27f | apt-key add -
- apt-get update -q
- apt-get install -qy build-essential cmake
- apt-get install -qy -t xenial g++-9
- apt-get install -qy libpoco-dev libjsoncpp-dev doxygen catch
- rm -rf build && mkdir -p build && cd build
- cmake -DWITH_EXAMPLES=YES ..
- make VERBOSE=1
- make install DESTDIR=install
volumes:
- name: debian-package-cache
path: /var/cache/apt/archives
- name: clang5
image: debian:stretch-slim
pull: true
environment:
CXX: clang++-5.0
CXXFLAGS: -pipe -O2
MASTODON_CPP_ACCESS_TOKEN:
from_secret: mastodon_cpp_access_token
commands:
- rm -f /etc/apt/apt.conf.d/docker-clean
- rm -f /var/cache/apt/archives/lock
- apt-get update -q
- echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release
- echo "deb http://deb.debian.org/debian stretch-backports main" >> /etc/apt/sources.list.d/stretch.list
- apt-get update -q
- apt-get install -qy build-essential cmake
- apt-get install -qy -t stretch-backports clang-5.0
- apt-get install -qy libpoco-dev libjsoncpp-dev doxygen catch
- rm -rf build && mkdir -p build && cd build
- cmake -DWITH_EXAMPLES=YES ..
- make VERBOSE=1
- make install DESTDIR=install
volumes:
- name: debian-package-cache
path: /var/cache/apt/archives
- name: clang7
image: debian:buster-slim
pull: true
environment:
LANG: C.utf8
CXX: clang++
CXXFLAGS: -pipe -O2
MASTODON_CPP_ACCESS_TOKEN:
from_secret: mastodon_cpp_access_token
commands:
- rm -f /etc/apt/apt.conf.d/docker-clean
- rm -f /var/cache/apt/archives/lock
- apt-get update -q
- apt-get update -q
- apt-get install -qy build-essential cmake clang
- apt-get install -qy libpoco-dev libjsoncpp-dev doxygen catch
- rm -rf build && mkdir -p build && cd build
- cmake -DWITH_EXAMPLES=YES ..
- make VERBOSE=1
- make install DESTDIR=install
volumes:
- name: debian-package-cache
path: /var/cache/apt/archives
- name: notification
image: drillster/drone-email
pull: always
settings:
host: cryptoparty-celle.de
from: drone@tzend.de
username:
from_secret: email_username
password:
from_secret: email_password
when:
status: [ changed, failure ]
---
kind: pipeline
name: packages x86_64
platform:
os: linux
arch: amd64
volumes:
- name: debian-package-cache
host:
path: /var/cache/debian-package-cache
- name: centos-package-cache
host:
path: /var/cache/centos-package-cache
trigger:
event:
- tag
steps:
- name: Debian stretch
image: debian:stretch-slim
pull: always
environment:
CXXFLAGS: -pipe -O2
LANG: C.utf8
commands:
- rm -f /etc/apt/apt.conf.d/docker-clean
- rm -f /var/cache/apt/archives/lock
- apt-get update -q
- apt-get install -qy build-essential cmake lsb-release
- apt-get install -qy libpoco-dev libjsoncpp-dev file
- rm -rf build && mkdir -p build && cd build
- cmake -DWITH_DEB=YES -DWITH_DOC=NO ..
- make package
- cp -v libmastodon-cpp_${DRONE_TAG}-0_stretch_amd64.deb ..
volumes:
- name: debian-package-cache
path: /var/cache/apt/archives
- name: Debian buster
image: debian:buster-slim
pull: always
environment:
CXXFLAGS: -pipe -O2
LANG: C.utf8
commands:
- rm -f /etc/apt/apt.conf.d/docker-clean
- rm -f /var/cache/apt/archives/lock
- apt-get update -q
- apt-get install -qy build-essential cmake lsb-release
- apt-get install -qy libpoco-dev libjsoncpp-dev file
- rm -rf build && mkdir -p build && cd build
- cmake -DWITH_DEB=YES -DWITH_DOC=NO ..
- make package
- cp -v libmastodon-cpp_${DRONE_TAG}-0_buster_amd64.deb ..
volumes:
- name: debian-package-cache
path: /var/cache/apt/archives
- name: Ubuntu bionic
image: ubuntu:bionic
pull: always
environment:
CXXFLAGS: -pipe -O2
LANG: C.utf8
commands:
- rm -f /etc/apt/apt.conf.d/docker-clean
- rm -f /var/cache/apt/archives/lock
- apt-get update -q
- apt-get install -qy build-essential cmake lsb-release
- apt-get install -qy libpoco-dev libjsoncpp-dev file
- rm -rf build && mkdir -p build && cd build
- cmake -DWITH_DEB=YES -DWITH_DOC=NO ..
- make package
- cp -v libmastodon-cpp_${DRONE_TAG}-0_bionic_amd64.deb ..
volumes:
- name: debian-package-cache
path: /var/cache/apt/archives
- name: CentOS 7
image: centos:7
pull: always
environment:
CXX: /opt/rh/devtoolset-6/root/usr/bin/g++
CXXFLAGS: -pipe -O2
LANG: C.utf8
commands:
- sed -i 's/keepcache=0/keepcache=1/' /etc/yum.conf
- curl -s -o /var/cache/yum/epel-release-latest-7.noarch.rpm http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
- rpm -i /var/cache/yum/epel-release-latest-7.noarch.rpm
- yum install -qy centos-release-scl
- yum install -qy devtoolset-6
- scl enable devtoolset-6 bash
- yum install -qy poco-devel openssl-devel doxygen rpm-build
- yum --enablerepo=epel install -qy cmake3 jsoncpp-devel
- rm -rf build && mkdir -p build && cd build
- cmake3 -DWITH_RPM=YES -DWITH_DOC=NO ..
- make package
- cp -v libmastodon-cpp-${DRONE_TAG}-0.x86_64.rpm ..
volumes:
- name: centos-package-cache
path: /var/cache/yum
- name: gitea_release
image: plugins/gitea-release
pull: always
settings:
base_url: https://schlomp.space
secrets: [ gitea_token ]
api_key:
from_secret: gitea_token
title: ${DRONE_TAG}
prerelease: true
files:
- "mastodon-cpp-${DRONE_TAG}.ebuild"
- "libmastodon-cpp_${DRONE_TAG}-0_amd64.deb"
- "libmastodon-cpp-${DRONE_TAG}-0.x86_64.rpm"
- libmastodon-cpp_${DRONE_TAG}-0_stretch_amd64.deb
- libmastodon-cpp_${DRONE_TAG}-0_buster_amd64.deb
- libmastodon-cpp_${DRONE_TAG}-0_bionic_amd64.deb
- libmastodon-cpp-${DRONE_TAG}-0.x86_64.rpm
checksum:
- sha256
- sha512
- name: notification
image: drillster/drone-email
pull: always
settings:
host: cryptoparty-celle.de
from: drone@tzend.de
username:
from_secret: email_username
password:
from_secret: email_password
when:
status: [ changed, failure ]

20
.editorconfig Normal file
View File

@ -0,0 +1,20 @@
# Configuration file for EditorConfig.
# More information is available under <https://editorconfig.org/>.
root = true
[*]
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 80
[*.?pp]
indent_size = 4
tab_width = 4
[{CMakeLists.txt,*.cmake}]
indent_size = 2
tab_width = 2

1
.gitignore vendored
View File

@ -1,5 +1,4 @@
/build/
/doc/
/update_gh-pages.sh
/update_doc.sh
/examples/example99*

View File

@ -1,45 +0,0 @@
language: cpp
compiler:
- gcc
- clang
dist: trusty
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- sourceline: 'ppa:cspensky/sda'
packages:
- g++-5
- libcurlpp-dev
- libjsoncpp-dev
before_install:
- sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 60
script:
- mkdir -p build && cd build
- cmake -DWITH_EXAMPLES=ON -DWITH_TESTS=ON ..
- make VERBOSE=1
- make install DESTDIR=install
- ctest ..
- cd ..
before_deploy:
- sudo apt-get install rpm
- cd build
- cp -v ../packages/gentoo/mastodon-cpp-0.0.0.ebuild mastodon-cpp-${TRAVIS_TAG}.ebuild
- cmake -DWITH_DEB=ON ..
- make package
- cmake -DWITH_DEB=OFF -DWITH_RPM=ON ..
- make package
deploy:
provider: releases
api_key:
secure: "rdEd2cytMZb6oS5DBuGKjaQoccspMWlrlr/fKpdJkhfLgFOXI6lWSEvtWSB8Gmej9J++0dZPGbQ6fhRuSRwMa7LM3c2yM7kqhfeKcQiFgol33UbMBPZU/OkohJJl49Bp32qwLUQpfeL7B6ukVkxv7XPetE0ks+29vGsEWLowjLj3jEvHTzucgvxblwCdshekYnMUH+4lkLoSqTenCjjTcRbKI7yLLlGSa92PudzrfeAsz0lV4GiXiMIffTPP9dOfi4ceRB4qkKxb35CZbZUjxlZoppghh1uFvi9GYsGseIQl/iGvOtzoUj6c5AoTEZeDa96pD1x/QpjVk2lPYqtmzfIgzIueQW/BUddwaUbzw/8dVTXMsgy3ocTICqPic8LxNWjMGbt/v2E7wiY+TitNWqoNlgoZQjrlrYQ/21yoilvGfpnqRllzr4ofiHq4CI94kgxtuhd3De4O/aJvbrxj8liToqHSwX/taJHwV5rQ2Afl9vhTFgPWzyAbYXFNuulmG2ew6Q1ywyf+GXCPBk22w0IvLom5lqtFD/WSS0LFTzstDiDQEg/fnOo7bGzcQYQR5jq8hfj9EDaIZYek5BpNLeRmkqIbvtu6vwy4ufx3MIDR+69H1Xn5BlpXdhII7r4ZRKlUiw4mqHm76LPwoxLoWL36a+mySOgBxjAgJQdifYU="
file:
- "mastodon-cpp-${TRAVIS_TAG}.ebuild"
- "libmastodon-cpp_${TRAVIS_TAG}-0_amd64.deb"
- "libmastodon-cpp-${TRAVIS_TAG}-0.x86_64.rpm"
skip_cleanup: true
prerelease: true
on:
tags: true
condition: $CC = gcc

View File

@ -1,155 +1,86 @@
cmake_minimum_required (VERSION 3.7)
project (mastodon-cpp
VERSION 0.16.1
LANGUAGES CXX
)
# Support version 3.6 and above, but use policy settings up to 3.14.
# 3.6 is needed because of IMPORTED_TARGET in pkg_check_modules().
cmake_minimum_required(VERSION 3.6...3.14)
# Ranges are supported from 3.12, set policy to current for < 3.12.
if(${CMAKE_VERSION} VERSION_LESS 3.12)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
endif()
include(GNUInstallDirs)
find_package(PkgConfig REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(CURLPP REQUIRED curlpp)
pkg_check_modules(JSONCPP REQUIRED jsoncpp)
project (mastodon-cpp
VERSION 0.111.5
LANGUAGES CXX)
# DESCRIPTION was introduced in version 3.9.
if(NOT (${CMAKE_VERSION} VERSION_LESS 3.9))
set(PROJECT_DESCRIPTION
"C++ wrapper for the Mastodon API.")
endif()
option(WITH_EASY "Compile Easy interface." YES)
option(WITH_EXAMPLES "Compile examples." NO)
option(WITH_TESTS "Compile tests." NO)
option(WITH_DOC "Generate HTML documentation." YES)
option(WITH_DEB "Prepare for the building of .deb packages." NO)
option(WITH_RPM "Prepare for the building of .rpm packages." NO)
option(BUILD_SHARED_LIBS "Build shared libraries." YES)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type, Release or Debug.")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall")
# Do not complain about compatibility-wrapper
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
set(DEBUG_CXXFLAGS
"-Wall"
"-Wextra"
"-Wpedantic"
"-ftrapv"
"-fsanitize=undefined"
"-g"
"-Og"
"-fno-omit-frame-pointer"
"-Wno-deprecated-declarations")
set(DEBUG_LDFLAGS
"-fsanitize=undefined")
add_compile_options("$<$<CONFIG:Debug>:${DEBUG_CXXFLAGS}>")
# add_link_options was introduced in version 3.13.
if(${CMAKE_VERSION} VERSION_LESS 3.13)
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${DEBUG_LDFLAGS}")
else()
add_link_options("$<$<CONFIG:Debug>:${DEBUG_LDFLAGS}>")
endif()
include_directories(${PROJECT_SOURCE_DIR}/src)
include_directories(${PROJECT_BINARY_DIR})
include_directories(${CURL_INCLUDE_DIRS})
include_directories(${CURLPP_INCLUDE_DIRS})
include_directories(${JSONCPP_INCLUDE_DIRS})
link_directories(${CURL_LIBRARY_DIRS})
link_directories(${CURLPP_LIBRARY_DIRS})
link_directories(${JSONCPP_LIBRARY_DIRS})
# Write version in header
configure_file (
"${PROJECT_SOURCE_DIR}/src/version.hpp.in"
"${PROJECT_BINARY_DIR}/version.hpp"
)
# Announce that we are compiling mastodon-cpp (used to figure out where the
# headers are)
add_definitions(-DMASTODON_CPP=1)
# Turn on debug output.
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-DDEBUG=1)
add_definitions("-DDEBUG=1")
endif()
if(WITHOUT_EASY)
add_definitions(-DWITHOUT_EASY=1)
if(NOT WITH_EASY)
add_definitions("-DWITHOUT_EASY=1")
endif()
# Compile library
if(WITHOUT_EASY)
file(GLOB sources src/*.cpp src/api/*.cpp)
else()
file(GLOB sources src/*.cpp src/api/*.cpp
src/easy/*.cpp src/easy/entities/*.cpp)
endif()
add_library(mastodon-cpp SHARED ${sources})
set_target_properties(mastodon-cpp PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${mastodon-cpp_VERSION_MAJOR}
)
if(WITHOUT_EASY)
target_link_libraries(mastodon-cpp ${CURLPP_LIBRARIES})
else()
target_link_libraries(mastodon-cpp ${CURLPP_LIBRARIES} ${JSONCPP_LIBRARIES})
endif()
add_subdirectory("src")
# Compile examples
if(WITH_EXAMPLES)
file(GLOB sources_examples examples/*.cpp)
foreach(src ${sources_examples})
get_filename_component(bin ${src} NAME_WE)
add_executable(${bin} ${src})
target_link_libraries(${bin} pthread ${JSONCPP_LIBRARIES} mastodon-cpp)
endforeach()
add_subdirectory("examples")
endif()
# Compile tests
if(WITH_TESTS)
include(CTest)
file(GLOB sources_tests tests/test_*.cpp)
foreach(src ${sources_tests})
get_filename_component(bin ${src} NAME_WE)
add_executable(${bin} ${src})
target_link_libraries(${bin} mastodon-cpp)
add_test(${bin} ${bin})
endforeach()
add_subdirectory("tests")
endif()
# Install library and header files
install(TARGETS mastodon-cpp LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES src/mastodon-cpp.hpp
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mastodon-cpp)
if(NOT WITHOUT_EASY)
file(GLOB easy_header src/easy/*.hpp)
install(FILES ${easy_header}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mastodon-cpp/easy)
file(GLOB easy_entities_header src/easy/entities/*.hpp)
install(FILES ${easy_entities_header}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mastodon-cpp/easy/entities)
endif()
# Compile & install documentation
if(WITH_DOC)
execute_process(COMMAND ./build_doc.sh
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
install(DIRECTORY ${PROJECT_SOURCE_DIR}/doc/html
DESTINATION ${CMAKE_INSTALL_DOCDIR}/mastodon-cpp-${PROJECT_VERSION})
file(GLOB examples examples/example*.cpp)
install(FILES ${examples}
DESTINATION ${CMAKE_INSTALL_DOCDIR}/mastodon-cpp-${PROJECT_VERSION}/examples)
add_custom_command(OUTPUT ${PROJECT_SOURCE_DIR}/doc/html
COMMAND "./build_doc.sh" WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
add_custom_target(doc DEPENDS doc/html)
add_dependencies(${PROJECT_NAME} doc)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/doc/html
DESTINATION "${CMAKE_INSTALL_DOCDIR}/${PROJECT_NAME}")
endif()
# Packages
set(CPACK_PACKAGE_NAME ${CMAKE_PROJECT_NAME})
set(CPACK_PACKAGE_VERSION_MAJOR ${mastodon-cpp_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${mastodon-cpp_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${mastodon-cpp_VERSION_PATCH})
set(CPACK_PACKAGE_VERSION ${mastodon-cpp_VERSION})
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "C++ wrapper for the Mastodon API")
set(CPACK_PACKAGE_CONTACT "tastytea <tastytea@tastytea.de>")
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${PROJECT_SOURCE_DIR}/README.md")
set(CPACK_SOURCE_PACKAGE_FILE_NAME, "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
set(CPACK_SOURCE_IGNORE_FILES, "/\\\\.git/;/build/;/doc/;.\\\\.sublime-")
set(CPACK_GENERATOR "TGZ")
add_subdirectory("cmake")
add_subdirectory("pkg-config")
if (WITH_DEB)
set(CPACK_GENERATOR "DEB")
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/tastytea/mastodon-cpp")
#set(CPACK_DEBIAN_PACKAGE_DEPENDS "libcurlpp0 (>= 0.7.3)")
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
execute_process(COMMAND dpkg --print-architecture
OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(CPACK_PACKAGE_FILE_NAME
"lib${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}-0_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
endif()
if (WITH_RPM)
set(CPACK_GENERATOR "RPM")
set(CPACK_RPM_PACKAGE_LICENSE "GPL-3")
set(CPACK_RPM_PACKAGE_URL "https://github.com/tastytea/mastodon-cpp")
set(CPACK_RPM_PACKAGE_REQUIRES "curlpp >= 0.7.3")
execute_process(COMMAND uname -m
OUTPUT_VARIABLE CPACK_RPM_PACKAGE_ARCHITECTURE
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(CPACK_PACKAGE_FILE_NAME
"lib${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-0.${CPACK_RPM_PACKAGE_ARCHITECTURE}")
endif()
include(CPack)
include("cmake/packages.cmake")

49
CODE_OF_CONDUCT.adoc Normal file
View File

@ -0,0 +1,49 @@
:contact-coc: tastytea@tastytea.de
== Code of Conduct
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, education, ethnicity, gender identity and expression, level of
experience, nationality, personal appearance, race, religion, sex
characteristics, sexual identity and orientation or socio-economic status.
=== Examples
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language.
* Being respectful of differing viewpoints and experiences.
* Gracefully accepting constructive criticism.
* Focusing on what is best for the community.
* Showing empathy towards other community members.
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances.
* Trolling, insulting/derogatory comments, and personal attacks.
* Public or private harassment.
* Publishing others private information, such as a physical or electronic
address, without explicit permission.
=== Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at {contact-coc}.
All complaints will be reviewed and investigated and will result in a response
that is deemed necessary and appropriate to the circumstances. The project team
is obligated to maintain confidentiality with regard to the reporter of an
incident.
=== Attribution
This Code of Conduct is adapted from the Contributor Covenant, version 1.4,
available at
https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq

29
CONTRIBUTING.adoc Normal file
View File

@ -0,0 +1,29 @@
:project: mastodon-cpp
:uri-base: https://schlomp.space/tastytea/{project}
:uri-coc: {uri-base}/src/branch/master/CODE_OF_CONDUCT.adoc
:contact-email: tastytea@tastytea.de
:contact-xmpp: {contact-email}
:contact-fediverse: https://likeable.space/users/tastytea
== How to contribute
Read the link:{uri-coc}[Code of Conduct].
=== Reporting bugs or suggesting enhancements
Before reporting a bug, please
https://schlomp.space/tastytea/{project}/issues[perform a search] to see if the
problem has already been reported. If it has, add a comment to the existing
issue instead of opening a new one. Same for enhancements.
You can also contact me via mailto:{contact-email}[E-Mail],
link:xmpp:{contact-xmpp}[XMPP] or the {contact-fediverse}[Fediverse] if you
don't want to open an account.
=== Pull requests
Please use similar coding conventions as the rest of the project. The basic rule
to remember is to write code in the same style as the existing/surrounding code.
You can also send me your patches via mailto:{contact-email}[E-Mail], ideally
using `git format-patch` or `git send-email`.

View File

@ -1,16 +0,0 @@
# How to contribute
## Reporting bugs or suggesting enhancements
Before reporting a bug , please
[perform a search](https://schlomp.space/tastytea/mastodon-cpp/issues)
to see if the problem has already been reported. If it has, add a comment to the
existing issue instead of opening a new one. Same for enhancements.
You can also contact me via the Fediverse if you don't want to open an account.
My account is [@tastytea@soc.ialis.me](https://soc.ialis.me/@tastytea).
## Pull requests
Please use similar coding conventions as the rest of the project. The basic rule
to remember is to write code in the same style as the existing/surrounding code.

View File

@ -1,8 +1,7 @@
DOXYFILE_ENCODING = UTF-8
PROJECT_NAME = "mastodon-cpp"
PROJECT_NUMBER = 0.0.0
INPUT = README.md src/ src/api/ src/easy/ src/easy/entities/
USE_MDFILE_AS_MAINPAGE = README.md
INPUT = src/ src/api/ src/easy/ src/easy/entities/
CREATE_SUBDIRS = NO
ALLOW_UNICODE_NAMES = YES
OUTPUT_LANGUAGE = English

View File

@ -1,10 +1 @@
### Version
* [ ] Latest release
* [ ] Latest prerelease
* [ ] Latest commit of master-branch
### Expected behaviour
### Actual behaviour
### Steps to reproduce
Version or commit:

147
LICENSE
View File

@ -1,23 +1,21 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
GNU AFFERO GENERAL PUBLIC LICENSE
Version 3, 19 November 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The GNU Affero General Public License is a free, copyleft license for
software and other kinds of works, specifically designed to ensure
cooperation with the community in the case of network server software.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
our General Public Licenses are intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
software for all its users.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
@ -26,44 +24,34 @@ them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
Developers that use our General Public Licenses protect your rights
with two steps: (1) assert copyright on the software, and (2) offer
you this License which gives you legal permission to copy, distribute
and/or modify the software.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
A secondary benefit of defending all users' freedom is that
improvements made in alternate versions of the program, if they
receive widespread use, become available for other developers to
incorporate. Many developers of free software are heartened and
encouraged by the resulting cooperation. However, in the case of
software used on network servers, this result may fail to come about.
The GNU General Public License permits making a modified version and
letting the public access it on a server without ever releasing its
source code to the public.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
The GNU Affero General Public License is designed specifically to
ensure that, in such cases, the modified source code becomes available
to the community. It requires the operator of a network server to
provide the source code of the modified version running there to the
users of that server. Therefore, public use of a modified version, on
a publicly accessible server, gives the public access to the source
code of the modified version.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
An older license, called the Affero General Public License and
published by Affero, was designed to accomplish similar goals. This is
a different license, not a version of the Affero GPL, but Affero has
released a new version of the Affero GPL which permits relicensing under
this license.
The precise terms and conditions for copying, distribution and
modification follow.
@ -72,7 +60,7 @@ modification follow.
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"This License" refers to version 3 of the GNU Affero General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
@ -549,35 +537,45 @@ to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
13. Remote Network Interaction; Use with the GNU General Public License.
Notwithstanding any other provision of this License, if you modify the
Program, your modified version must prominently offer all users
interacting with it remotely through a computer network (if your version
supports such interaction) an opportunity to receive the Corresponding
Source of your version by providing access to the Corresponding Source
from a network server at no charge, through some standard or customary
means of facilitating copying of software. This Corresponding Source
shall include the Corresponding Source for any work covered by version 3
of the GNU General Public License that is incorporated pursuant to the
following paragraph.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
under version 3 of the GNU General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
but the work with which it is combined will remain governed by version
3 of the GNU General Public License.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
the GNU Affero General Public License from time to time. Such new versions
will be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Program specifies that a certain numbered version of the GNU Affero General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
GNU Affero General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
versions of the GNU Affero General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
@ -635,40 +633,29 @@ the "copyright" line and a pointer to where the full notice is found.
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
GNU Affero General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
If your software can interact with users remotely through a computer
network, you should also make sure that it provides a way for users to
get its source. For example, if your program is a web application, its
interface could display a "Source" link that leads users to an archive
of the code. There are many ways you could offer source, and different
solutions will be better for different programs; see section 13 for the
specific requirements.
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
For more information on this, and how to apply and follow the GNU AGPL, see
<https://www.gnu.org/licenses/>.

494
README.adoc Normal file
View File

@ -0,0 +1,494 @@
= mastodon-cpp
:toc: preamble
:project: mastodon-cpp
:uri-base: https://schlomp.space/tastytea/{project}
:uri-branch-main: {uri-base}/src/branch/master
:uri-mastodonpp: https://schlomp.space/tastytea/mastodonpp
[IMPORTANT]
This project has become too complicated to maintain by myself and I can't find
the energy to add features. **You can find a complete rewrite, with cleaner and
much easier to understand code at link:{uri-mastodonpp}[mastodonpp].** I
recommend switching to it. You can still report bugs here and I will respond,
but I won't put too much work in it. If you want to take over maintainership,
get in touch.
*{project}* is a C++ wrapper for the Mastodon API. You submit an API call
and get the raw JSON that you can then transform into easy to use abstractions.
== Usage
The HTML reference can be generated with `build_doc.sh`, if doxygen is
installed. It is also available at
https://doc.schlomp.space/{project}/annotated.html[doc.schlomp.space/{project}/].
There are more {uri-branch-main}/examples[examples] in `examples/`.
=== Examples
.Print own account as JSON to stdout.
====
[source,c++]
----
#include <iostream>
#include <mastodon-cpp/mastodon-cpp.hpp>
int main()
{
Mastodon::API masto("social.example.com", "auth_token");
std::cout << masto.get(Mastodon::API::v1::accounts_verify_credentials);
std::cout << std::endl;
}
----
====
.Use the `Easy` interface to get the last posts from the federated timeline.
====
[source,c++]
----
#include <iostream>
#include <string>
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/all.hpp>
using Mastodon;
int main()
{
Easy::API masto("social.example", "");
return_call ret = masto.get(API::v1::timelines_public);
for (const std::string &str : Easy::json_array_to_vector(ret.answer))
{
Easy::Status status(str);
std::cout << " " << status.account().acct() << " wrote:\n";
std::cout << status.content() << '\n';
}
}
----
====
=== Compiling your project
A project consisting of one file can be compiled as follows:
[source,shell]
----
g++ --std=c++14 -lmastodon-cpp example.cpp
----
=== List of types
Learn more at <https://doc.schlomp.space/mastodon-cpp/namespaceMastodon.html>
and <https://doc.schlomp.space/mastodon-cpp/namespaceMastodon_1_1Easy.html>.
Not included in this list are entities.
==== Return types
* `Mastodon::return_call`: Contains the response from `Mastodon::API` calls.
==== Other types
* `Mastodon::parameters`: Vector of `Mastodon::param` with custom `find()`, for
specifying parameters to an `Mastodon::API` call.
* `Mastodon::http_method`: HTTP method of an `Mastodon::API` call.
* `Mastodon::Easy::event_type`: Event types returned in streams.
* `Mastodon::Easy::visibility_type`: Describes the visibility of a post.
* `Mastodon::Easy::attachment_type`: Describes the type of attachment.
* `Mastodon::Easy::card_type`: Describes the type of card.
* `Mastodon::Easy::notification_type`: The type of the notification.
* `Mastodon::Easy::context_type`: Describes the context of a filter.
* `Mastodon::Easy::stream_event_type`: Type and data of an events returned in
streams.
* `Mastodon::Easy::alert_type`, used for push subscriptions.
* `Mastodon::Easy::time_type`: Type for time, can be converted to `time_point`
and `string`.
* `Mastodon::Easy::account_field_type`: Type for fields in accounts.
* `Mastodon::Easy::urls_type`: Type for URLs returned by `Instance::urls()`.
* `Mastodon::Easy::stats_type`: Type for statistics returned by
`Instance::stats()`.
* `Mastodon::Easy::poll_options_type`: Type for poll options returned by
`Poll::options()`.
=== Error codes
[options="header",cols=">,<"]
|===================================================
| Code | Explanation
| 0 | No error
| 1 | Invalid argument
| 10 | URL changed (HTTP 301 or 308)
| 11 | Connection timed out
| 12 | Connection refused (check http_error_code)
| 13 | No route to host / Could not resolve host
| 14 | Encryption error
| 127 | Unknown error
|===================================================
If you use a debug build, you get more verbose error messages.
=== Useful links
* https://docs.joinmastodon.org/[Mastodon documentation]
* https://git.pleroma.social/pleroma/pleroma/tree/develop/docs/api[Pleroma documentation]
* https://glitch-soc.github.io/docs/#whats-different[glitch-soc documentation]
== Install
=== Upgrading from versions below 0.100.0
Starting with version `0.100.0`, large parts of the library have been rewritten.
Upgrading from previous versions will require extensive code changes.
=== Packages
Every https://schlomp.space/tastytea/{project}/releases[release] includes
packages for Debian and Centos. Gentoo packages are available in my overlay.
==== Gentoo
Add my https://schlomp.space/tastytea/overlay[repository] and
install it from there.
[source,shell]
----
eselect repository enable tastytea
echo 'dev-cpp/mastodon-cpp ~amd64' >> /etc/portage/package.accept_keywords/mastodon-cpp
emaint sync -r tastytea
emerge -a dev-cpp/mastodon-cpp
----
==== DEB and RPM
Prebuilt DEB and RPM packages for x86_64(amd64) are provided with each release.
`.deb` packages are built on Debian stretch and `.rpm` packages are built on
CentOS 7. These packages are automatically built and not tested.
=== From source
==== Dependencies
* Tested OS: Linux
* C++ compiler (tested: https://gcc.gnu.org/[gcc] 6/8/9,
https://llvm.org/[clang] 5/7)
* https://cmake.org/[cmake] (at least: 3.6)
* https://pocoproject.org/[POCO] (tested: 1.9 / 1.7)
* Optional
** Easy interface & Examples:
https://github.com/open-source-parsers/jsoncpp[jsoncpp] (tested: 1.8 / 1.7)
** Documentation: https://www.stack.nl/~dimitri/doxygen/[doxygen] (tested: 1.8)
** DEB package: https://packages.qa.debian.org/dpkg[dpkg] (tested: 1.18)
** RPM package: http://www.rpm.org[rpm-build] (tested: 4.11)
** Tests: https://github.com/catchorg/Catch2[catch] (tested: 2.5 / 1.2)
.Install dependencies in Debian stretch.
====
[source,shell]
----
apt-get install build-essential cmake libpoco-dev libjsoncpp-dev doxygen
----
====
==== Get sourcecode
===== Release
Download the current release at
https://schlomp.space/tastytea/{project}/releases[schlomp.space].
===== Development version
[source,shell]
----
git clone https://schlomp.space/tastytea/mastodon-cpp.git
----
==== Compile
[source,shell]
----
mkdir build
cd build/
cmake ..
cmake --build . -- -j$(nproc --ignore=1)
----
.cmake options:
* `-DCMAKE_BUILD_TYPE=Debug` for a debug build.
* `-DWITH_EASY=NO` to not build the Easy abstractions and to get rid of the
jsoncpp-dependency (not recommended).
* `-DWITH_EXAMPLES=YES` if you want to compile the examples.
* `-DWITH_TESTS=YES` if you want to compile the tests.
* `-DEXTRA_TEST_ARGS` to run only some tests
(https://github.com/catchorg/Catch2/blob/master/docs/command-line.md#specifying-which-tests-to-run[format]).
** Possible tags: `[api]`, `[auth]`, `[mastodon]`, `[glitch-soc]`,
`[pleroma]`, `[upload]`, `[entity]`.
* `-DWITH_DOC=NO` if you don't want to compile the HTML reference.
* One of:
** `-DWITH_DEB=YES` if you want to be able to generate a deb-package.
** `-DWITH_RPM=YES` if you want to be able to generate an rpm-package.
.Run only tests for glitch-soc features that don't upload any files.
====
[source,shell]
----
cmake -DWITH_TESTS=YES -DEXTRA_TEST_ARGS=[glitch-soc]~[upload] ..
----
====
==== Tests
You can run the tests with `ctest` inside the build directory. You need to set
the environment variable `MASTODON_CPP_ACCESS_TOKEN` to an access token with the
scopes _read_, _write_ and _follow_ for tests tagged with `[auth]`.
You can select the instance to use with `MASTODON_CPP_INSTANCE`, the default is
_likeable.space_. You can select the user ID with `MASTODON_CPP_USER_ID`, the
default is _9hnrrVPriLiLVAhfVo_. You can select the status ID with
`MASTODON_CPP_STATUS_ID`, the default is _9hwnuJMq3eTdO4s1PU_. You can select
the filter ID with `MASTODON_CPP_FILTER_ID`. You can select the list ID with
`MASTODON_CPP_LIST_ID`, the default is _2_. You can select the media ID with
`MASTODON_CPP_MEDIA_ID`, the default is _2127742613_.
.Requirements for the test-user:
* Have at least 1 follower.
* Follow at least 1 account.
* Have at least 1 account endorsed.
* Have at least 1 public or unlisted status.
* Have at least 1 post favourited.
* Have no follow requests.
* Have at least 1 list with at least one account in it.
* have at least 1 account muted.
include::{uri-base}/raw/branch/master/CONTRIBUTING.adoc[]
== Status of implementation
You can still use unsupported calls by using `API::get` and the others with
strings and you can use unsupported fields in an `Entity` by converting it to
`Json::Value`.
=== Mastodon API
==== Calls
* Accounts
** [x] GET /api/v1/accounts/:id
** [x] POST /api/v1/accounts
** [x] GET /api/v1/accounts/verify_credentials
** [x] PATCH /api/v1/accounts/update_credentials
** [x] GET /api/v1/accounts/:id/followers
** [x] GET /api/v1/accounts/:id/following
** [x] GET /api/v1/accounts/:id/statuses
** [x] POST /api/v1/accounts/:id/follow
** [x] POST /api/v1/accounts/:id/unfollow
** [x] GET /api/v1/accounts/relationships
** [x] GET /api/v1/accounts/search
* Apps
** [x] POST /api/v1/apps
** [x] GET /api/v1/apps/verify_credentials
* Blocks
** [x] GET /api/v1/blocks
** [x] POST /api/v1/accounts/:id/block
** [x] POST /api/v1/accounts/:id/unblock
* Custom emoji
** [x] GET /api/v1/custom_emojis
* Domain blocks
** [x] GET /api/v1/domain_blocks
** [x] POST /api/v1/domain_blocks
** [x] DELETE /api/v1/domain_blocks
* Endorsements
** [x] GET /api/v1/endorsements
** [x] POST /api/v1/accounts/:id/pin
** [x] POST /api/v1/accounts/:id/unpin
* Favourites
** [x] GET /api/v1/favourites
** [x] POST /api/v1/statuses/:id/favourite
** [x] POST /api/v1/statuses/:id/unfavourite
* Filters
** [x] GET /api/v1/filters
** [x] POST /api/v1/filters
** [x] GET /api/v1/filters/:id
** [x] PUT /api/v1/filters/:id
** [x] DELETE /api/v1/filters/:id
* Follow requests
** [x] GET /api/v1/follow_requests
** [x] POST /api/v1/follow_requests/:id/authorize
** [x] POST /api/v1/follow_requests/:id/reject
* Follow suggestions
** [x] GET /api/v1/suggestions
** [x] DELETE /api/v1/suggestions/:account_id
* Instances
** [x] GET /api/v1/instance
* Lists
** [x] GET /api/v1/lists
** [x] GET /api/v1/accounts/:id/lists
** [x] GET /api/v1/lists/:id/accounts
** [x] GET /api/v1/lists/:id
** [x] POST /api/v1/lists
** [x] PUT /api/v1/lists/:id
** [x] DELETE /api/v1/lists/:id
** [x] POST /api/v1/lists/:id/accounts
** [x] DELETE /api/v1/lists/:id/accounts
* Media attachments
** [x] POST /api/v1/media
** [x] PUT /api/v1/media/:id
* Mutes
** [x] GET /api/v1/mutes
** [x] POST /api/v1/accounts/:id/mute
** [x] POST /api/v1/accounts/:id/unmute
** [x] POST /api/v1/statuses/:id/mute
** [x] POST /api/v1/statuses/:id/unmute
* Notifications
** [x] GET /api/v1/notifications
** [x] GET /api/v1/notifications/:id
** [x] POST /api/v1/notifications/clear
** [x] POST /api/v1/notifications/dismiss
** [x] POST /api/v1/push/subscription
** [x] GET /api/v1/push/subscription
** [x] PUT /api/v1/push/subscription
** [x] DELETE /api/v1/push/subscription
* Polls
** [x] GET /api/v1/polls/:id
** [x] POST /api/v1/polls/:id/votes
* Reports
** [x] POST /api/v1/reports
* Scheduled Statuses
** [ ] GET /api/v1/scheduled_statuses
** [ ] GET /api/v1/scheduled_statuses/:id
** [ ] PUT /api/v1/scheduled_statuses/:id
** [ ] DELETE /api/v1/scheduled_statuses/:id
* Search
** [x] GET /api/v2/search
* Statuses
** [x] GET /api/v1/statuses/:id
** [x] GET /api/v1/statuses/:id/context
** [x] GET /api/v1/statuses/:id/card
** [x] GET /api/v1/statuses/:id/reblogged_by
** [x] GET /api/v1/statuses/:id/favourited_by
** [x] POST /api/v1/statuses
** [x] DELETE /api/v1/statuses/:id
** [x] POST /api/v1/statuses/:id/reblog
** [x] POST /api/v1/statuses/:id/unreblog
** [x] POST /api/v1/statuses/:id/pin
** [x] POST /api/v1/statuses/:id/unpin
* Timelines
** [x] GET /api/v1/timelines/home
** [x] GET /api/v1/conversations
** [x] GET /api/v1/timelines/public
** [x] GET /api/v1/timelines/tag/:hashtag
** [x] GET /api/v1/timelines/list/:list_id
* Streaming API
** [x] GET /api/v1/streaming/health
** [x] GET /api/v1/streaming/user
** [x] GET /api/v1/streaming/public
** [x] GET /api/v1/streaming/public/local
** [x] GET /api/v1/streaming/hashtag
** [x] GET /api/v1/streaming/hashtag/local
** [x] GET /api/v1/streaming/list
** [x] GET /api/v1/streaming/direct
==== Entities
* [x] Account
* [x] Application
* [x] Attachment
* [x] Card
* [x] Context
* [x] Conversation
* [x] Emoji
* [x] Filter
* [x] Instance
* [x] List
* [x] Mention
* [x] Notification
* [x] Poll
* [x] PushSubscription
* [x] Relationship
* [x] Results
* [x] Status
* [ ] ScheduledStatus
* [x] Tag
* [ ] Token
=== glitch-soc API
==== Calls
* [x] GET /api/v1/bookmarks
* [x] POST /api/v1/statuses/:id/bookmark
* [x] POST /api/v1/statuses/:id/unbookmark
==== Entities
* [x] `max_toot_chars` in Instance
=== Pleroma API
==== Calls
* [ ] `preview` and `content_type` in POST /api/v1/statuses
* [ ] `no_rich_text`, `hide_followers`, `hide_follows`, `hide_favorites` and
`show_role` in /api/v1/update_credentials
* [ ] GET /api/pleroma/emoji
* [ ] POST /api/pleroma/follow_import
* [ ] GET /api/pleroma/captcha
* [ ] POST /api/pleroma/delete_account
* [ ] POST /api/account/register
* [ ] POST /api/v1/pleroma/flavour/:flavour
* [ ] GET /api/v1/pleroma/flavour
* [ ] POST /api/pleroma/notifications/read
* [ ] POST /api/v1/pleroma/accounts/:id/subscribe
* [ ] POST /api/v1/pleroma/accounts/:id/unsubscribe
* [ ] GET /api/v1/pleroma/accounts/:id/favourites
* [ ] PUT /api/pleroma/notification_settings
* [ ] GET /api/pleroma/healthcheck
* Admin API
** [ ] GET /api/pleroma/admin/users
** [ ] DELETE /api/pleroma/admin/user
** [ ] POST /api/pleroma/admin/user
** [ ] POST /api/pleroma/admin/user/follow
** [ ] POST /api/pleroma/admin/user/unfollow
** [ ] PATCH /api/pleroma/admin/users/:nickname/toggle_activation
** [ ] PUT /api/pleroma/admin/users/tag
** [ ] DELETE /api/pleroma/admin/users/tag
** [ ] GET /api/pleroma/admin/permission_group/:nickname
** [ ] GET /api/pleroma/admin/permission_group/:nickname/:permission_group
** [ ] POST /api/pleroma/admin/permission_group/:nickname/:permission_group
** [ ] DELETE /api/pleroma/admin/permission_group/:nickname/:permission_group
** [ ] PUT /api/pleroma/admin/activation_status/:nickname
** [ ] GET /api/pleroma/admin/users/:nickname
** [ ] POST /api/pleroma/admin/relay
** [ ] DELETE /api/pleroma/admin/relay
** [ ] GET /api/pleroma/admin/invite_token
** [ ] GET /api/pleroma/admin/invites
** [ ] POST /api/pleroma/admin/revoke_invite
** [ ] POST /api/pleroma/admin/email_invite
** [ ] GET /api/pleroma/admin/password_reset
==== Entities
* `pleroma` object in:
** [ ] Status
** [ ] Attachment
** [ ] Account
** [ ] Source
** [ ] Notification
== Blocked instances
Instances that are frequently used to hurt marginalized people are blocked from
using this library.
.List of blocked instances:
* https://en.wikipedia.org/wiki/Gab_(social_network)[Gab]
* https://en.wikipedia.org/wiki/Kiwi_Farms[Kiwi Farms]
== Copyright
[source,text]
----
Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>.
License AGPLv3: <https://www.gnu.org/licenses/agpl-3.0.html>.
This program comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
----

289
README.md
View File

@ -1,289 +0,0 @@
**mastodon-cpp** is a C++ wrapper for the Mastodon API.
The library takes care of the network stuff. You submit a query and get the raw
JSON. You can then put that JSON into easy to use classes.
[TODO-list](https://schlomp.space/tastytea/mastodon-cpp/milestones)
# Usage
The HTML reference can be generated with `build_doc.sh`, if doxygen is installed. It is also available at
[doc.schlomp.space/mastodon-cpp/](https://doc.schlomp.space/mastodon-cpp/annotated.html).
There are [examples](https://schlomp.space/tastytea/mastodon-cpp/src/branch/master/examples) in `examples/`.
## Upgrading from below 0.13.0
* You have to recompile all applications linking against this library.
* We use a mutex now to guard the string that is being written to. You can get a reference to it with `Mastodon::API::http::get_mutex()` (see examples 9 and 13 for more info). This is only relevant for streams.
## Upgrading from below 0.10.0
`Mastodon::API::get`, `::get_stream`, `::post`, `::put` and `::del` don't take
`std::string` as parameter to API-calls anymore, only `parametermap`s. The old behaviour is
still supported but is deprecated and will be removed in version 1.0.0.
## Upgrading from below 0.7.0
Your projects will break, sorry. Here are the important changes:
* The header location has changed. They are now in `mastodon-cpp/`.
* Specific network error messages have been replaced by 15, "Network error".
You can get the exceptions from curlpp with `Mastodon::API::exceptions(true)`.
## Most basic example
```C++
#include <iostream>
#include <string>
#include <mastodon-cpp/mastodon-cpp.hpp>
int main()
{
Mastodon::API masto("social.example.com", "auth_token");
std::string answer;
masto.get(Mastodon::API::v1::accounts_verify_credentials, answer);
std::cout << answer << '\n';
}
```
## Another simple example
Using the `Easy`-class.
```C++
#include <iostream>
#include <string>
#include <vector>
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/all.hpp>
using Mastodon::Easy;
int main()
{
Easy masto("social.example", "");
std::string answer;
masto.get(Mastodon::API::v1::timelines_public, answer);
for (const std::string &str : Easy::json_array_to_vector(answer))
{
Easy::Status status(str);
std::cout << " " << status.account().acct() << " wrote:\n";
std::cout << status.content() << '\n';
}
}
```
## Compiling your project
A project consisting of one file can be compiled as follows:
```SH
g++ -std=c++14 -lmastodon-cpp example.cpp
```
## Error codes
mastodon-cpp will never use error codes below 11, except 0.
| Code | Explanation |
| --------: |:---------------------------------|
| 0 | No error |
| 11 | Invalid call |
| 12 | Not implemented |
| 13 | URL changed (HTTP 301 or 308) |
| 14 | Aborted by user |
| 15 | Network error (curlpp exception) |
| 100 - 999 | HTTP status codes |
| 65535 | Unknown error |
If you use a debug build, you get more verbose error messages. Errors 20-25 are no longer in use (since 0.8.9).
## Useful links
* [Mastodon API reference](https://github.com/tootsuite/documentation/blob/master/Using-the-API/API.md)
* [Mastodon streaming API reference](https://github.com/tootsuite/documentation/blob/master/Using-the-API/Streaming-API.md)
# Install
## Packages
Every [release](https://schlomp.space/tastytea/mastodon-cpp/releases) includes
packages for the package managers of Gentoo, Debian and Red Hat.
### Gentoo
Put the ebuild into your [local overlay](https://wiki.gentoo.org/wiki/Custom_repository) and run `ebuild <ebuild path> manifest`.
Install with `emerge mastodon-cpp`.
Or [add my repository](https://wiki.gentoo.org/wiki/Eselect/Repository) and
install it from there.
```SH
eselect repository add tastytea git https://schlomp.space/tastytea/overlay.git
echo 'dev-cpp/mastodon-cpp ~amd64' >> /etc/portage/package.keywords/mastodon-cpp
emaint sync -r tastytea
emerge -a dev-cpp/mastodon-cpp
```
### DEB and RPM
Prebuilt DEB and RPM packages for x86_64(amd64) are provided with each release.
These packages are automatically built and not tested.
Install with `dpkg -i` or `rpm -i`, respectively.
To use the DEB package on stretch, you will need [libcurlpp0](https://packages.debian.org/libcurlpp0) from buster or jessie.
## From source
### Dependencies
* Tested OS: Linux
* C++ compiler (tested: gcc 6.4 / 5.4, clang 5.0)
* [cmake](https://cmake.org/) (tested: 3.9.6)
* [pkgconfig](https://pkgconfig.freedesktop.org/wiki/) (tested: 0.29.2)
* [libcurl](https://curl.haxx.se/) (tested: 7.58.0 / 7.35.0)
* [curlpp](http://www.curlpp.org/) (tested: 0.8.1 / 0.7.3)
* Optional
* Easy interface & Examples: [jsoncpp](https://github.com/open-source-parsers/jsoncpp) (tested: 1.8.1 / 1.7.2)
* Documentation: [doxygen](https://www.stack.nl/~dimitri/doxygen/) (tested: 1.8.13)
* DEB package: [dpkg](https://packages.qa.debian.org/dpkg) (tested: 1.19.0.5)
* RPM package: [rpm](http://www.rpm.org) (tested: 4.11.0.1)
### Get sourcecode
#### Release
Download the current release at [schlomp.space](https://schlomp.space/tastytea/mastodon-cpp/releases).
#### Development version
[![Build Status](https://travis-ci.org/tastytea/mastodon-cpp.svg?branch=master)](https://travis-ci.org/tastytea/mastodon-cpp)
```SH
git clone https://schlomp.space/tastytea/mastodon-cpp.git
```
### Compile
```SH
mkdir build
cd build/
cmake ..
make
```
cmake options:
* `-DCMAKE_BUILD_TYPE=Debug` for a debug build
* `-DWITHOUT_EASY=ON` to not build the Easy abstractions and to get rid of the jsoncpp-dependency (not recommended)
* `-DWITH_EXAMPLES=ON` if you want to compile the examples
* `-DWITH_TESTS=ON` if you want to compile the tests
* `-DWITH_DOC=ON` if you want to compile the HTML reference
* `-DWITH_DEB=ON` if you want to be able to generate a deb-package
* `-DWITH_RPM=ON` if you want to be able to generate an rpm-package
You can run the tests with `ctest ..` inside the build directory.
To install, run `make install`.
### Packages
#### Gentoo
Put the ebuild from `packages/gentoo` into your [local overlay](https://wiki.gentoo.org/wiki/Custom_repository) and rename it to match the desired version or use the live-ebuild (`mastodon-cpp-9999.ebuild`) to install the development version.
#### DEB and RPM
Compile with `-DWITH_DEB=ON` or `-DWITH_RPM=ON`.
Run `make package` from the build directory to generate a DEB/RPM package.
#### Other
Run `make package` from the build directory to generate a tar.gz archive.
# Status of implementation
Feature complete as of Mastodon 2.4.1
* [x] GET /api/v1/accounts/:id
* [x] GET /api/v1/accounts/verify_credentials
* [x] PATCH /api/v1/accounts/update_credentials
* [x] GET /api/v1/accounts/:id/followers
* [x] GET /api/v1/accounts/:id/following
* [x] GET /api/v1/accounts/:id/statuses
* [x] POST /api/v1/accounts/:id/follow
* [x] POST /api/v1/accounts/:id/unfollow
* [x] POST /api/v1/accounts/:id/block
* [x] POST /api/v1/accounts/:id/unblock
* [x] POST /api/v1/accounts/:id/mute
* [x] POST /api/v1/accounts/:id/unmute
* [x] GET /api/v1/accounts/relationships
* [x] GET /api/v1/accounts/search
* [x] POST /api/v1/apps
* [x] GET /api/v1/blocks
* [x] GET /api/v1/domain_blocks
* [x] POST /api/v1/domain_blocks
* [x] DELETE /api/v1/domain_blocks
* [x] GET /api/v1/favourites
* [x] GET /api/v1/follow_requests
* [x] POST /api/v1/follow_requests/:id/authorize
* [x] POST /api/v1/follow_requests/:id/reject
* [x] POST /api/v1/follows
* [x] GET /api/v1/instance
* [x] GET /api/v1/custom_emojis
* [x] GET /api/v1/lists
* [x] GET /api/v1/accounts/:id/lists
* [x] GET /api/v1/lists/:id/accounts
* [x] GET /api/v1/lists/:id
* [x] POST /api/v1/lists
* [x] PUT /api/v1/lists/:id
* [x] DELETE /api/v1/lists/:id
* [x] POST /api/v1/lists/:id/accounts
* [x] DELETE /api/v1/lists/:id/accounts
* [x] POST /api/v1/media
* [x] PUT /api/v1/media/:id
* [x] GET /api/v1/mutes
* [x] GET /api/v1/notifications
* [x] GET /api/v1/notifications/:id
* [x] POST /api/v1/notifications/clear
* [x] POST /api/v1/notifications/dismiss
* [x] GET /api/v1/reports
* [x] POST /api/v1/reports
* [x] GET /api/v1/search
* [x] GET /api/v1/statuses/:id
* [x] GET /api/v1/statuses/:id/context
* [x] GET /api/v1/statuses/:id/card
* [x] GET /api/v1/statuses/:id/reblogged_by
* [x] GET /api/v1/statuses/:id/favourited_by
* [x] POST /api/v1/statuses
* [x] DELETE /api/v1/statuses/:id
* [x] POST /api/v1/statuses/:id/reblog
* [x] POST /api/v1/statuses/:id/unreblog
* [x] POST /api/v1/statuses/:id/favourite
* [x] POST /api/v1/statuses/:id/unfavourite
* [x] POST /api/v1/statuses/:id/pin
* [x] POST /api/v1/statuses/:id/unpin
* [x] POST /api/v1/statuses/:id/mute
* [x] POST /api/v1/statuses/:id/unmute
* [x] GET /api/v1/timelines/home
* [x] GET /api/v1/timelines/public
* [x] GET /api/v1/timelines/tag/:hashtag
* [x] GET /api/v1/timelines/list/:list_id
* [x] GET /api/v1/streaming/user
* [x] GET /api/v1/streaming/public
* [x] GET /api/v1/streaming/public/local
* [x] GET /api/v1/streaming/hashtag
* [x] GET /api/v1/streaming/list
* [x] POST /api/v1/push/subscription
* [x] GET /api/v1/push/subscription
* [x] PUT /api/v1/push/subscription
* [x] DELETE /api/v1/push/subscription
* [x] GET /api/v2/search
# Copyright
```PLAIN
Copyright © 2018 tastytea <tastytea@tastytea.de>.
License GPLv3: GNU GPL version 3 <https://www.gnu.org/licenses/gpl-3.0.html>.
This program comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
```

View File

@ -1,10 +0,0 @@
#!/bin/sh
mkdir -p build && \
cd build/ && \
cmake .. && \
make
if [ "$(basename ${PWD})" == "build" ]; then
cd ..
fi

19
cmake/CMakeLists.txt Normal file
View File

@ -0,0 +1,19 @@
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
write_basic_package_version_file("${PROJECT_NAME}ConfigVersion.cmake"
VERSION ${PACKAGE_VERSION}
COMPATIBILITY ExactVersion) # TODO: Set to SameMajorVersion when stable.
install(EXPORT ${PROJECT_NAME}Targets
FILE "${PROJECT_NAME}Targets.cmake"
NAMESPACE "${PROJECT_NAME}::"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
configure_file("${PROJECT_NAME}Config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" @ONLY)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")

View File

@ -0,0 +1,7 @@
include(CMakeFindDependencyMacro)
include(GNUInstallDirs)
find_dependency(jsoncpp CONFIG REQUIRED)
find_package(Poco COMPONENTS Foundation Net NetSSL CONFIG REQUIRED)
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")

46
cmake/packages.cmake Normal file
View File

@ -0,0 +1,46 @@
set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
set(CPACK_PACKAGE_VERSION_MAJOR ${${PROJECT_NAME}_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${${PROJECT_NAME}_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${${PROJECT_NAME}_VERSION_PATCH})
set(CPACK_PACKAGE_VERSION ${mastodon-cpp_VERSION})
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PROJECT_DESCRIPTION}")
if(CPACK_PACKAGE_DESCRIPTION_SUMMARY STREQUAL "") # CMake < 3.9
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "C++ wrapper for the Mastodon API.")
endif()
set(CPACK_PACKAGE_CONTACT "tastytea <tastytea@tastytea.de>")
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${PROJECT_SOURCE_DIR}/README.adoc")
execute_process(COMMAND uname -m
OUTPUT_VARIABLE CPACK_PACKAGE_ARCHITECTURE OUTPUT_STRIP_TRAILING_WHITESPACE)
set(CPACK_PACKAGE_FILE_NAME
"${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}_${CPACK_PACKAGE_ARCHITECTURE}")
set(CPACK_GENERATOR "TGZ")
if (WITH_DEB)
set(CPACK_PACKAGE_NAME "lib${PROJECT_NAME}")
set(CPACK_GENERATOR "DEB")
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE
"https://schlomp.space/tastytea/${PROJECT_NAME}")
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
execute_process(COMMAND dpkg --print-architecture
OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND lsb_release --codename --short
OUTPUT_VARIABLE DEBIAN_CODENAME
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(CPACK_PACKAGE_FILE_NAME
"${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}-0_${DEBIAN_CODENAME}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
endif()
if (WITH_RPM)
set(CPACK_PACKAGE_NAME "lib${PROJECT_NAME}")
set(CPACK_GENERATOR "RPM")
set(CPACK_RPM_PACKAGE_LICENSE "AGPL-3")
set(CPACK_RPM_PACKAGE_URL "https://schlomp.space/tastytea/${PROJECT_NAME}")
set(CPACK_RPM_PACKAGE_REQUIRES "poco-netssl >= 1.6, jsoncpp >= 1.7.4")
set(CPACK_PACKAGE_FILE_NAME
"${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-0.${CPACK_PACKAGE_ARCHITECTURE}")
endif()
include(CPack)

11
examples/CMakeLists.txt Normal file
View File

@ -0,0 +1,11 @@
file(GLOB sources_examples *.cpp)
foreach(src ${sources_examples})
get_filename_component(bin ${src} NAME_WE)
add_executable(${bin} ${src})
target_link_libraries(${bin} PRIVATE ${PROJECT_NAME})
endforeach()
if(WITH_DOC)
install(FILES ${sources_examples}
DESTINATION "${CMAKE_INSTALL_DOCDIR}/${PROJECT_NAME}/examples")
endif()

View File

@ -1,89 +0,0 @@
/* This file is part of mastodon-cpp.
* This example dumps the raw JSON of your last toot with media attached
* and your last 2 followers.
*/
#include <iostream>
#include <vector>
#include <string>
#include <cstdint>
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#endif
using Mastodon::API;
int main(int argc, char *argv[])
{
if (argc < 3)
{
std::cerr << "usage: " << argv[0] << " <instance> <access token>\n";
return 1;
}
Mastodon::API masto(argv[1], argv[2]);
masto.set_useragent("mastodon-cpp-example/1.3.3.7");
std::string answer;
std::uint16_t ret;
ret = masto.get(API::v1::accounts_verify_credentials, answer);
if (ret == 0)
{
std::cout << "Your last toot with media attached:\n";
std::string uid = answer.substr(7, answer.find("\"", 7) - 7);
API::parametermap parameters =
{
{ "id", { uid } },
{ "limit", { "1" } },
{ "only_media", { "1" } }
};
ret = masto.get(API::v1::accounts_id_statuses, parameters, answer);
if (ret == 0)
{
std::cout << answer << '\n';
}
else
{
std::cerr << "Error code: " << ret << '\n';
return ret;
}
std::cout << "\nYour last 2 followers:\n";
parameters =
{
{
"limit", { "2" }
},
{
"exclude_types", { "favourite", "reblog", "mention" }
}
};
ret = masto.get(API::v1::notifications, parameters, answer);
if (ret == 0)
{
std::cout << answer << '\n';
return 0;
}
else
{
std::cerr << "Error code: " << ret << '\n';
return ret;
}
}
else if (ret == 13)
{
std::cerr << "The URL has permanently changed.\n" <<
"New URL: " << answer << '\n';
return ret;
}
else
{
std::cerr << "Error code: " << ret << '\n';
return ret;
}
return 0;
}

View File

@ -0,0 +1,78 @@
// This file is part of mastodon-cpp.
// Get the last 4 local posts from the public timeline and display them.
// Don't compile this if the Easy-interface is turned off
#ifndef WITHOUT_EASY
#include <iostream>
#include <string>
#include <cstdint>
#include <regex>
#include "mastodon-cpp.hpp"
#include "easy/all.hpp"
using std::cout;
using std::cerr;
using std::endl;
using std::string;
using std::uint16_t;
using namespace Mastodon;
int main(int argc, char *argv[])
{
if (argc < 2)
{
std::cerr << "usage: " << argv[0] << " <instance>\n";
return 1;
}
// Construct a Mastodon::Easy object without authorization token.
Easy::API masto(argv[1], "");
// Retrieve the last 4 local statuses.
return_call ret = masto.get(API::v1::timelines_public,
{
{ "local", { "true" }},
{ "limit", { "4" }}
});
// If no error was returned.
if (ret)
{
// Convert answer to vector of strings, loop through vector.
for (const string &strstatus : Easy::json_array_to_vector(ret.answer))
{
// Construct mastodon::Easy::Status from string.
Easy::Status status(strstatus);
string content = status.content();
std::regex re_html("<[^>]+>");
// Remove HTML tags from status content.
content = std::regex_replace(content, re_html, "");
// Print account and content.
cout << " " << status.account().acct() << " wrote:\n";
cout << content << endl << endl;
}
}
else
{
// Print error message.
cerr << ret.error_message << endl;
// Print HTTP status code, if there is one.
if (ret.http_error_code != 0)
{
cerr << "HTTP status code: "
<< std::to_string(ret.http_error_code) << endl;
}
return ret.error_code;
}
return 0;
}
#else
#include <cstdio>
int main()
{
std::printf("mastodon-cpp was compiled without Easy support.\n");
return 255;
}
#endif // WITHOUT_EASY

View File

@ -1,75 +0,0 @@
/* This file is part of mastodon-cpp.
* This example parses your account data and prints it out in a readable way.
*/
#include <iostream>
#include <vector>
#include <string>
#include <cstdint>
#include <sstream>
#include <jsoncpp/json/json.h>
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#endif
using Mastodon::API;
using std::cout;
int main(int argc, char *argv[])
{
if (argc < 3)
{
std::cerr << "usage: " << argv[0] << " <instance> <access token>\n";
return 1;
}
Mastodon::API masto(argv[1], argv[2]);
std::string answer;
std::stringstream ss;
std::uint16_t ret;
ret = masto.get(API::v1::accounts_verify_credentials, answer);
if (ret == 0)
{
ss.str(answer);
Json::Value json;
ss >> json;
std::string uid = json["id"].asString();
cout << "Your ID is: " << uid << '\n';
cout << "Your whole acount tree:\n";
for (auto it = json.begin(); it != json.end(); ++it)
{
if (it.name().compare("source") == 0)
{
cout << it.name() << '\n';
for (auto it_s = (*it).begin(); it_s != (*it).end(); ++it_s)
{
cout << '\t' << it_s.name() << ": ";
cout << *it_s << '\n';
}
}
else
{
cout << it.name() << ": ";
cout << *it << '\n';
}
}
}
else if (ret == 13)
{
std::cerr << "The URL has permanently changed.\n" <<
"New URL: " << answer << '\n';
return ret;
}
else
{
std::cerr << "Error code: " << ret << '\n';
return ret;
}
return 0;
}

View File

@ -0,0 +1,109 @@
// This file is part of mastodon-cpp.
// Listen to /api/v1/streaming/public and display the events.
// Don't compile this if the Easy-interface is turned off
#ifndef WITHOUT_EASY
#include <iostream>
#include <string>
#include <cstdint>
#include <mutex>
#include <chrono>
#include <vector>
#include "mastodon-cpp.hpp"
#include "easy/all.hpp"
using std::cout;
using std::cerr;
using std::endl;
using std::string;
using std::uint8_t;
using namespace Mastodon;
int main(int argc, char *argv[])
{
if (argc < 2)
{
std::cerr << "usage: " << argv[0] << " <instance>\n";
return 1;
}
// Construct a Mastodon::Easy object without authorization token.
Easy::API masto(argv[1], "");
// Prepare a pointer to the http object, to cancel the stream later.
std::unique_ptr<API::http> ptr;
// This variable is filled with the stream data.
string stream;
// Get the public timeline. The pointer is set here.
masto.get_stream(API::v1::streaming_public, ptr, stream);
// Listen to the stream for 120 seconds.
for (uint8_t counter = 0; counter < 120; ++counter)
{
std::this_thread::sleep_for(std::chrono::seconds(1));
// Acquire lock for the stream variable to avoid simultaneous access.
std::lock_guard<std::mutex> lock(ptr->get_mutex());
// Parse event stream into a vector.
std::vector<Easy::stream_event_type> events
= Easy::parse_stream(stream);
// Clear the stream buffer.
stream.clear();
for (const Easy::stream_event_type &event : events)
{
// Print out some information about the events.
switch (event.type)
{
case Easy::event_type::Update:
{
Easy::Status status(event.data);
cout << "[" << status.created_at().strtime("%T") << "] ";
cout << "Status from: " << status.account().acct()
<< " (" << status.url() << ")\n";
break;
}
case Easy::event_type::Notification:
{
Easy::Notification notification(event.data);
cout << "Notification involving: "
<< notification.account().acct()
<< " (" << notification.id() << ")\n";
break;
}
case Easy::event_type::Delete:
{
cout << "Deleted: " << event.data << endl;
break;
}
case Easy::event_type::Error:
{
// Errors are reported in-stream. Print error and exit.
cerr << "Error: " << event.data << endl;
ptr->cancel_stream();
return 1;
}
default:
{
cout << "Something undefined happened. 😱\n";
cout << event.data << endl;
}
}
}
}
// Close connection.
ptr->cancel_stream();
return 0;
}
#else
#include <cstdio>
int main()
{
std::printf("mastodon-cpp was compiled without Easy support.\n");
return 255;
}
#endif // WITHOUT_EASY

View File

@ -0,0 +1,91 @@
// This file is part of mastodon-cpp.
// Get 2 pages of 5 favourites each.
// Don't compile this if the Easy-interface is turned off
#ifndef WITHOUT_EASY
#include <iostream>
#include <string>
#include <vector>
#include "mastodon-cpp.hpp"
#include "easy/all.hpp"
using std::cout;
using std::cerr;
using std::endl;
using std::string;
using std::vector;
using namespace Mastodon;
void print_favs(Easy::API &masto, const string &max_id = "")
{
// Set up parameters.
Mastodon::parameters params =
{
{ "limit", { "5" } },
{ "exclude_types", { "follow", "reblog", "mention" } }
};
// Set max_id if given.
if (!max_id.empty())
{
params.push_back({ "max_id", { max_id } });
}
// Retrieve the last 5 favourites.
return_call ret = masto.get(API::v1::notifications, params);
// If no error was returned.
if (ret)
{
// Convert answer to vector of strings, loop through vector.
for (const string &str : Easy::json_array_to_vector(ret.answer))
{
// Construct Mastodon::Easy::Notification from string.
const Easy::Notification notif(str);
cout << notif.created_at().strtime("%F %T: ");
cout << notif.account().display_name() << " favourited a status.\n";
}
}
else
{
// Print error message.
cerr << ret.error_message << endl;
// Print HTTP status code, if there is one.
if (ret.http_error_code != 0)
{
cerr << "HTTP status code: "
<< std::to_string(ret.http_error_code) << endl;
}
}
}
int main(int argc, char *argv[])
{
const vector<string> args(argv, argv + argc);
if (args.size() < 3)
{
std::cerr << "usage: " << args[0] << " <instance> <auth token>\n";
return 1;
}
// Construct a Mastodon::Easy object.
Easy::API masto(args[1], args[2]);
print_favs(masto);
cout << "\nLink header is: " << masto.get_header("link") << "\n\n";
// Get the max_id for pagination.
// See <https://docs.joinmastodon.org/api/rest/notifications/#pagination>
print_favs(masto, masto.get_link().max_id());
// The same: print_favs(masto, masto.get_link().next());
return 0;
}
#else
#include <iostream>
int main()
{
std::cout << "mastodon-cpp was compiled without Easy support.\n";
return 255;
}
#endif // WITHOUT_EASY

View File

@ -1,134 +0,0 @@
/* This file is part of mastodon-cpp.
* Prints the new toots under a hashtag, designed to be used in cronjobs
*/
#include <iostream>
#include <vector>
#include <string>
#include <cstdint>
#include <regex>
#include <cstdlib>
#include <fstream>
#include <sstream>
#include <jsoncpp/json/json.h>
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#endif
using Mastodon::API;
using std::cout;
using std::string;
int main(int argc, char *argv[])
{
string limit = "20";
if (argc < 3)
{
std::cerr << "usage: " << argv[0] << " <instance> <hashtag> [limit]\n";
std::cerr << " Default limit is 20, max limit is 40.\n";
return 1;
}
else if (argc == 4)
{
limit = argv[3];
}
Mastodon::API masto(argv[1], "");
string hashtag = argv[2];
string answer;
std::stringstream ss;
std::uint16_t ret;
Json::Value config;
string lastid = "0";
string filename = string(getenv("HOME")) + "/.config/mastocron.json";
// Read config file, get last seen toot-id
try {
std::ifstream file(filename, std::ifstream::binary);
file >> config;
lastid = config.get(hashtag, "0").asString();
}
catch (std::exception &e)
{
// most likely no config file found, ignore
}
// Only get toots we haven't seen yet
API::parametermap params =
{
{ "hashtag", { hashtag } },
{ "limit", { limit } },
{ "since_id", { lastid } }
};
ret = masto.get(API::v1::timelines_tag_hashtag, params, answer);
if (ret == 0)
{
// If answer is empty, there are no new toots,
// if answer is "[]" there are none at all
if (answer != "" && answer != "[]")
{
string ornament = " +++++";
for (std::uint8_t i = hashtag.size(); i > 0; --i)
{
ornament += "+";
}
cout << ornament << '\n';
cout << " + " << hashtag << ": +\n";
cout << ornament << '\n';
Json::Value tree;
ss.str(answer);
ss >> tree;
for (const auto &toot : tree)
{
string content = toot["content"].asString();
std::regex reparagraph("</p><p>");
std::regex restrip("<[^>]*>");
cout << "++++++++\n";
content = std::regex_replace(content, reparagraph, "\n\n");
cout << std::regex_replace(content, restrip, "") << '\n';
cout << " ";
cout << toot["account"]["display_name"].asString()
<< " (" << toot["account"]["acct"] << ") at "
<< toot["created_at"].asString() << "\n";
cout << " " << toot["url"].asString() << '\n';
for (const auto &media : toot["media_attachments"])
{
cout << "Attachment: <" << media["url"].asString() << ">\n";
}
cout << "++++++++\n";
}
// Write the id of the newest toot in the config file
lastid = tree[0]["id"].asString();
config[hashtag] = lastid;
Json::StreamWriterBuilder wbuilder;
const string output = Json::writeString(wbuilder, config);
std::ofstream outfile(filename);
if (outfile.is_open())
{
outfile.write(output.c_str(), output.length());
outfile.close();
}
}
}
else if (ret == 13)
{
std::cerr << "The URL has permanently changed.\n" <<
"New URL: " << answer << '\n';
return ret;
}
else
{
std::cerr << "Error code: " << ret << '\n';
return ret;
}
return 0;
}

View File

@ -0,0 +1,48 @@
// This file is part of mastodon-cpp.
// Prints shortcode + URL for each custom emoji.
// Don't compile this if the Easy-interface is turned off
#ifndef WITHOUT_EASY
#include <iostream>
#include <string>
#include <vector>
#include "mastodon-cpp.hpp"
#include "easy/all.hpp"
using std::string;
using std::vector;
using namespace Mastodon;
int main(int argc, char *argv[])
{
const vector<string> args(argv, argv + argc);
if (args.size() < 2)
{
std::cerr << "usage: " << args[0] << " <instance>\n";
return 1;
}
// Construct a Mastodon::Easy object.
Easy::API masto(args[1], "");
const return_call ret = masto.get(API::v1::custom_emojis);
// Convert JSON array into vector of strings.
for (const string &str : Easy::json_array_to_vector(ret))
{
// Construct Emoji object from string.
const Easy::Emoji emoji(str);
std::cout << ':' << emoji.shortcode() << ": <" << emoji.url() << ">\n";
}
return 0;
}
#else
#include <iostream>
int main()
{
std::cout << "mastodon-cpp was compiled without Easy support.\n";
return 255;
}
#endif // WITHOUT_EASY

View File

@ -1,83 +0,0 @@
/* This file is part of mastodon-cpp.
* Updates your name, description and avatar.
*/
#include <iostream>
#include <vector>
#include <string>
#include <cstdint>
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#endif
using Mastodon::API;
int main(int argc, char *argv[])
{
if (argc < 3)
{
std::cerr << "usage: " << argv[0] << " <instance> <access token>\n";
return 1;
}
Mastodon::API masto(argv[1], argv[2]);
masto.set_useragent("mastodon-cpp-example/1.3.3.7");
std::string answer;
std::uint16_t ret;
// This is the Gimp icon, 24x24px, GPL-3
const std::string avatar =
"data:image/png;base64,"
"iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz"
"AAAN1wAADdcBQiibeAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAAMdEVY"
"dFRpdGxlAEZvbGRlcuNZL58AAAAUdEVYdEF1dGhvcgBKYWt1YiBTdGVpbmVy5vv3LwAAACF0RVh0"
"U291cmNlAGh0dHA6Ly9qaW1tYWMubXVzaWNoYWxsLmN6aWbjXgAAAFJ0RVh0Q29weXJpZ2h0AEND"
"IEF0dHJpYnV0aW9uLVNoYXJlQWxpa2UgaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbGljZW5z"
"ZXMvYnktc2EvMy4wL16DWrwAAARFSURBVEiJtZXNbxtFGMafGe+ud9eO7bXbNBsSNx9GSaW2aQgK"
"UDiQUmQJiQsHJETFhVNBKuLAhQviT0Aq6g0heqjUS4UQqhYJhCrxoUZKQakIJTFuTGzXjmN7d+31"
"endnhwNNiEIKRWpeaTSjmdHzm/cZzbwkn8/jIIMeqDoA4VGIVCqVZ0DxUuAFn2Wz2dXda/tmUC6X"
"z21sbGQfRrxarb4Mig8BvEkpHdy7vi+AUvokpfSNUqmk/8fJXyeEvD8xNvpcTFUzlNLI3j37W0Rx"
"WKDC/OnTT72gaRoAIJ4YuJ3OaLpl2ZptWtRnjOsjQ1m3a49kUgmp1TJ5FyAPBwCk+bmZ6ZHRUWly"
"YjISi8WkWv3erOd78tkzL0paSiPVaoX//NMiGvUaOrZJ/qG8F2AYBs3n8yEApBKpiBKLq6dmTglj"
"Y+OQJJEoSjSZyRzG1NQxqKoKXdeJqkRx8+Z36PU6D7Rx5w6i0ehkvdH4qLRR/mpk9LFnj5+YEaem"
"j/Hx8Qly7drnxHF6GDoyBMYYlpaWcPHix2i1TRD85QslhP9rBkktee6t8+df5cDg2todDA8PE0VW"
"cOnSJVy5cgXvXHgbAOA4Dq5evYobN24gNzkBgIA80KBdAOazCcZYYkjX6fXrX3JVpFAVOTI39wRU"
"VUIyNYDVtV+RSKaxcGYBs7OzqNc2sFEqwrYsBCFzGWHhAwEAbl++fHkhlTmk3C3+TkK3jaDfhqYl"
"Ydk9tBoVCIIAKSpDllWwkGHxx+9BwdFxfe55QYsxFhqGIQAIt+9zB0AixFwv3Q3anS7cfh89x0Fz"
"8x563SZ6bgh1IA3f9yH1qoj5W2i4IhyzBzWlo+/58INADdxgAEAMQN8wDD+fz7MdAGf8iyAIT7S3"
"Gq9FBKoFYQjXC8A40Gya8Co1MMZAmYsMNbFwpIn+oQgKbhc9VyYkCFYty4oDyAAwAXQNwwgjuVwO"
"ALC8vNyhsnwnoShxRVGyw/qgeiiTJqIoggAIfB+EAJwIECQZHQ/QxD5mkm2kFBHlXkxumu6iZdtV"
"AP79FuwACoUC6TtOJx6PFwWBmv2ADRNCU4TSiBAREFNVpFIaUuk0lHgagXIEdTtEyQz5b20Z82df"
"ERgRp5LJ5POapvXDMCw6jtPdAeRyORQKBViW1REEsciBdcZ4xbS6TttywqbVxWbTJvWtNq1utru1"
"hrleavSKf1j4utzsf2K7XG+1WpOU0izn/HFZlr/Z3Nys7P0qQgBurVYrO45z3XXcHyRJ0kRRHGCM"
"xQMeKAAID7jnc26HnucxxqxOp7Nle7/cSiQGLoii9HQYhkc9zxsEECH7VTTDMHYe6P2eAJABSAA4"
"gOC+x9uvlwPg09PTR2VZfo9zftyyrA+KxeK3+wL2C8MwKP7+Wvguceyaw8mTJ8cIIe96nvfpysrK"
"rYcG/J+oVqvjAOq6rncfScncG7quF7fHB170DxzwJ8uH9gSkOVdYAAAAAElFTkSuQmCC";
API::parametermap params =
{
{ "display_name", { "Botty McBotface" } },
{ "note", { "Beep Bop." } },
{ "avatar", { avatar } }
};
ret = masto.patch(API::v1::accounts_update_credentials, params, answer);
if (ret == 0)
{
std::cout << answer << '\n';
}
else if (ret == 13)
{
std::cerr << "The URL has permanently changed.\n" <<
"New URL: " << answer << '\n';
return ret;
}
else
{
std::cerr << "Error code: " << ret << '\n';
return ret;
}
return 0;
}

View File

@ -1,102 +0,0 @@
/* This file is part of mastodon-cpp.
* Follow someone, then unfollow.
*/
#include <iostream>
#include <vector>
#include <string>
#include <cstdint>
#include <chrono>
#include <thread>
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#endif
using Mastodon::API;
int main(int argc, char *argv[])
{
if (argc < 3)
{
std::cerr << "usage: " << argv[0] << " <instance> <access token>\n";
return 1;
}
Mastodon::API masto(argv[1], argv[2]);
masto.set_useragent("mastodon-cpp-example/1.3.3.7");
std::string answer;
std::uint16_t ret;
std::string id;
std::cout << "Follow [ID or username@domain]: ";
std::cin >> id;
// If no @ is found, it is presumably an ID
if (id.find('@') == std::string::npos)
{
ret = masto.post(API::v1::accounts_id_follow, {{"id", {id}}}, answer);
if (ret == 0)
{
// std::cout << answer << '\n';
}
else if (ret == 13)
{
std::cerr << "The URL has permanently changed.\n" <<
"New URL: " << answer << '\n';
return ret;
}
else
{
std::cerr << "Error code: " << ret << '\n';
return ret;
}
std::cout << "Unfollowing in 30 seconds...\n";
std::this_thread::sleep_for(std::chrono::seconds(30));
ret = masto.post(API::v1::accounts_id_unfollow, {{"id", {id}}}, answer);
if (ret == 0)
{
// std::cout << answer << '\n';
}
else
{
std::cerr << "Error code: " << ret << '\n';
return ret;
}
}
else
{
API::parametermap params =
{
{ "uri", { id } }
};
ret = masto.post(API::v1::follows, params, answer);
if (ret == 0)
{
// std::cout << answer << '\n';
id = answer.substr(7, answer.find("\"", 7) - 7);
}
else
{
std::cerr << "Error code: " << ret << '\n';
return ret;
}
std::cout << "Unfollowing " << id << " in 30 seconds...\n";
std::this_thread::sleep_for(std::chrono::seconds(30));
ret = masto.post(API::v1::accounts_id_unfollow, {{"id", {id}}}, answer);
if (ret == 0)
{
// std::cout << answer << '\n';
}
else
{
std::cerr << "Error code: " << ret << '\n';
return ret;
}
}
return 0;
}

View File

@ -1,74 +0,0 @@
/* This file is part of mastodon-cpp.
* Post a status, then delete it.
*/
#include <iostream>
#include <vector>
#include <string>
#include <cstdint>
#include <chrono>
#include <thread>
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#endif
using Mastodon::API;
int main(int argc, char *argv[])
{
if (argc < 3)
{
std::cerr << "usage: " << argv[0] << " <instance> <access token>\n";
return 1;
}
Mastodon::API masto(argv[1], argv[2]);
masto.set_useragent("mastodon-cpp-example/1.3.3.7");
std::string answer;
std::uint16_t ret;
std::string toot;
std::string id;
std::cout << "Toot: ";
std::cin >> toot;
API::parametermap parameters =
{
{ "status", { toot } },
{ "visibility", { "unlisted" } },
{ "spoiler_text", { "test" } }
};
ret = masto.post(API::v1::statuses, parameters, answer);
if (ret == 0)
{
id = answer.substr(7, answer.find("\"", 7) - 7);
std::cout << "Deleting in 30 seconds...\n";
std::this_thread::sleep_for(std::chrono::seconds(30));
ret = masto.del(API::v1::statuses_id, {{"id", {id}}});
if (ret == 0)
{
std::cout << "Status " << id << " deleted.\n";
}
else
{
std::cerr << "Error code: " << ret << '\n';
return ret;
}
}
else if (ret == 13)
{
std::cerr << "The URL has permanently changed.\n" <<
"New URL: " << answer << '\n';
return ret;
}
else
{
std::cerr << "Error code: " << ret << '\n';
return ret;
}
return 0;
}

View File

@ -1,88 +0,0 @@
/* This file is part of mastodon-cpp.
* Register as an application.
*/
#include <iostream>
#include <vector>
#include <string>
#include <cstdint>
#include <sstream>
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#endif
using Mastodon::API;
int main(int argc, char *argv[])
{
if (argc < 2)
{
std::cerr << "usage: " << argv[0] << " <instance>\n";
return 1;
}
Mastodon::API masto(argv[1], "");
masto.set_useragent("mastodon-cpp-example/1.3.3.7");
std::string answer;
std::uint16_t ret;
std::string client_id, client_secret, url;
ret = masto.register_app1("test123",
"urn:ietf:wg:oauth:2.0:oob",
"read follow",
"",
client_id,
client_secret,
url);
if (ret == 0)
{
std::cout << "Visit " << url << " to get the code.\n";
std::string code;
std::cout << "Insert code: ";
std::cin >> code;
std::string access_token;
ret = masto.register_app2(client_id,
client_secret,
"urn:ietf:wg:oauth:2.0:oob",
code,
access_token);
if (ret == 0)
{
std::cout << "Success!\nAccess-token: " << access_token << '\n';
std::cout << "Testing access token...\n";
ret = masto.get(API::v1::accounts_verify_credentials, answer);
if (ret == 0)
{
std::cout << answer;
}
else
{
std::cerr << "Error code: " << ret << '\n';
return ret;
}
}
else
{
std::cerr << "Error code: " << ret << '\n';
return ret;
}
}
else if (ret == 13)
{
std::cerr << "The URL has permanently changed.\n" <<
"New URL: " << url << '\n';
return ret;
}
else
{
std::cerr << "Error code: " << ret << '\n';
return ret;
}
return 0;
}

View File

@ -1,57 +0,0 @@
/* This file is part of mastodon-cpp.
* In this example we look at HTTP headers to determine how many calls we are
* allowed to make.
*/
#include <iostream>
#include <vector>
#include <string>
#include <cstdint>
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#endif
using Mastodon::API;
int main(int argc, char *argv[])
{
if (argc < 3)
{
std::cerr << "usage: " << argv[0] << " <instance> <access token>\n";
return 1;
}
Mastodon::API masto(argv[1], argv[2]);
masto.set_useragent("mastodon-cpp-example/1.3.3.7");
std::string answer;
std::uint16_t ret;
ret = masto.get(API::v1::accounts_verify_credentials, answer);
if (ret == 0)
{
std::string remaining = masto.get_header("X-RateLimit-Remaining");
std::string reset = masto.get_header("X-RateLimit-Reset");
std::cout << "You are allowed to make " << remaining
<< " calls until the counter is reset at " << reset << '\n';
if (std::stoi(remaining) <= 1)
{
std::cout << "🔥 Please let the server cool off a bit! 🔥\n";
}
}
else if (ret == 13)
{
std::cerr << "The URL has permanently changed.\n" <<
"New URL: " << answer << '\n';
return ret;
}
else
{
std::cerr << "Error code: " << ret << '\n';
return ret;
}
return 0;
}

View File

@ -1,77 +0,0 @@
/* This file is part of mastodon-cpp.
* Streaming API example
*/
#include <iostream>
#include <string>
#include <cstdint>
#include <thread>
#include <chrono>
#include <memory>
#include <mutex>
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#endif
using Mastodon::API;
int main(int argc, char *argv[])
{
if (argc < 3)
{
std::cerr << "usage: " << argv[0] << " <instance> <access_token>\n";
return 1;
}
static std::string answer;
static std::unique_ptr<Mastodon::API::http> ptr;
std::cout << "Dumping public timeline...\n";
std::thread pub([=]
{
Mastodon::API masto(argv[1], argv[2]);
masto.set_useragent("mastodon-cpp-example/1.3.3.7");
masto.get_stream(API::v1::streaming_public, answer, ptr);
});
std::uint8_t counter = 0;
while (true)
{
std::this_thread::sleep_for(std::chrono::seconds(2));
if (ptr != nullptr)
{
std::lock_guard<std::mutex> lock(ptr->get_mutex());
++counter;
std::cout << answer;
answer.clear();
if (counter == 10)
{
std::cerr << "Cancelling...\n";
ptr->cancel_stream();
break;
}
}
}
pub.join();
std::cout << '\n';
std::cout << "Dumping the #np tag...\n";
answer = "";
std::thread tag([=]
{
Mastodon::API masto(argv[1], argv[2]);
masto.set_useragent("mastodon-cpp-example/1.3.3.7");
masto.get_stream(API::v1::streaming_hashtag, {{ "hashtag", {"np"} }},
answer, ptr);
});
std::this_thread::sleep_for(std::chrono::seconds(20));
ptr->cancel_stream();
std::cout << answer;
std::cout << '\n';
tag.join();
return 0;
}

View File

@ -1,56 +0,0 @@
/* This file is part of mastodon-cpp.
* Simplify the interface
*/
#include <iostream>
#include <string>
#include <cstdint>
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#endif
using Mastodon::API;
class EasyToot : public Mastodon::API
{
public:
explicit EasyToot(const std::string &instance, const std::string &access_token)
: API(instance, access_token)
{}
std::uint16_t toot(const std::string &text, const std::string &cw = "")
{
std::string answer;
API::parametermap parameters;
parameters.insert({ "status", { text } } );
if (!cw.empty())
{
parameters.insert({ "spoiler_text", { cw } } );
}
return post(API::v1::statuses, parameters, answer);
}
};
int main(int argc, char *argv[])
{
if (argc < 3)
{
std::cerr << "usage: " << argv[0] << " <instance> <access_token>\n";
return 1;
}
std::uint16_t ret = 0;
EasyToot masto(argv[1], argv[2]);
ret = masto.toot("Test");
if (ret != 0)
{
std::cerr << "Error: " << ret << '\n';
}
return ret;
}

View File

@ -1,82 +0,0 @@
/* This file is part of mastodon-cpp.
* Post the same media 2 times, with URLs
*/
#include <iostream>
#include <vector>
#include <string>
#include <cstdint>
#include <sstream>
#include <jsoncpp/json/json.h>
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#endif
using Mastodon::API;
int main(int argc, char *argv[])
{
if (argc < 3)
{
std::cerr << "usage: " << argv[0] << " <instance> <access token>\n";
return 1;
}
Mastodon::API masto(argv[1], argv[2]);
std::string answer;
std::stringstream ss;
Json::Value json;
std::uint16_t ret;
std::string filepath;
std::cout << "Absolute filename: ";
std::cin >> filepath;
API::parametermap parameters =
{
{ "file", { filepath } }
};
ret = masto.post(API::v1::media, parameters, answer);
if (ret == 0)
{
ss.str(answer);
ss >> json;
std::string image1_id = json["id"].asString();
std::string image1_url = json["url"].asString();
parameters =
{
{ "file", { filepath } }
};
ret = masto.post(API::v1::media, parameters, answer);
if (ret == 0)
{
ss.str(answer);
ss >> json;
std::string image2_id = json["id"].asString();
std::string image2_url = json["url"].asString();
parameters =
{
{ "status", { image1_url + " \n" + image2_url } },
{ "media_ids", { image1_id, image2_id } },
{ "visibility", { "direct" } }
};
ret = masto.post(API::v1::statuses, parameters, answer);
if (ret == 0)
{
return 0;
}
}
}
else if (ret == 13)
{
std::cerr << "The URL has permanently changed.\n" <<
"New URL: " << answer << '\n';
return ret;
}
std::cout << answer << '\n';
std::cerr << "Error code: " << ret << '\n';
return ret;
}

View File

@ -1,128 +0,0 @@
/* This file is part of mastodon-cpp.
* Prints some information about your last status.
*/
// Don't compile this if the Easy-interface is turned off
#ifndef WITHOUT_EASY
#include <iostream>
#include <string>
#include <cstdint>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy/all.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
// Include all headers in mastodon-cpp/easy/
#include <mastodon-cpp/easy/all.hpp>
#endif
using Mastodon::API;
using Mastodon::Easy;
using std::cout;
int main(int argc, char *argv[])
{
if (argc < 3)
{
std::cerr << "usage: " << argv[0] << " <instance> <access token>\n";
return 1;
}
Easy masto(argv[1], argv[2]);
std::string answer;
std::uint16_t ret;
// Get own account in order to obtain account ID
ret = masto.get(API::v1::accounts_verify_credentials, answer);
if (ret == 0)
{
// Construct an Account object using the JSON string from the server
Easy::Account acc(answer);
// Get last status
ret = masto.get(API::v1::accounts_id_statuses,
{
{ "id", { std::to_string(acc.id()) } },
{ "limit", { "1" } }
},
answer);
if (ret == 0)
{
// answer contains an array with a single object. This works because
// Easy::Status will turn that into an object, but an array with
// more than 1 object will not work.
Easy::Status status(answer);
// An Entitiy is valid if the JSON was not empty and contained no
// "error":-key
if (status.valid())
{
if (!status.language().empty())
cout << "Language: " << status.language() << '\n';
if (!status.content().empty())
cout << "Content: "
<< status.content().substr(0, 200) << "\n";
if (!status.application().name().empty())
cout << "Application used: "
<< status.application().name() << '\n';
cout << "ID: " << status.id() << '\n';
string acct;
string url;
std::vector<Easy::Attachment> attachments;
std::vector<Easy::Tag> tags;
// If the status is a reblog, print the original author
if (status.reblog().valid())
{
// status.reblog() is an Easy::Status
// status.reblog().account() is an Easy::Account
cout << "Original ID: " << status.reblog().id() << '\n';
acct = status.reblog().account().acct();
url = status.reblog().account().url();
attachments = status.reblog().media_attachments();
tags = status.reblog().tags();
}
else
{
acct = status.account().acct();
url = status.account().url();
attachments = status.media_attachments();
tags = status.tags();
}
cout << "From: " << acct << " ";
cout << "(" << url << ")\n";
// List attachments, if any
for (const Easy::Attachment &attachment : attachments)
{
cout << "Attachment: " << attachment.text_url()
<< " (" << attachment.size() << ")\n";
}
// List hashtags, if any
for (const Easy::Tag &tag : tags)
{
cout << "Hashtag: #" << tag.name()
<< " (" << tag.url() << ")\n";
}
}
return 0;
}
}
std::cout << answer << '\n';
std::cerr << "Error code: " << ret << '\n';
return ret;
}
#else
int main()
{
printf("mastodon-cpp was compiled without Easy support.\n");
return 255;
}
#endif // WITHOUT_EASY

View File

@ -1,110 +0,0 @@
/* This file is part of mastodon-cpp.
* Prints some information from the public timeline.
*/
// Don't compile this if the Easy-interface is turned off
#ifndef WITHOUT_EASY
#include <iostream>
#include <string>
#include <thread>
#include <memory>
#include <vector>
#include <chrono>
#include <mutex>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy/all.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
// Include all headers in mastodon-cpp/easy/
#include <mastodon-cpp/easy/all.hpp>
#endif
using Mastodon::API;
using Mastodon::Easy;
using std::cout;
using std::chrono::system_clock;
int main(int argc, char *argv[])
{
if (argc < 3)
{
std::cerr << "usage: " << argv[0] << " <instance> <access token>\n";
return 1;
}
cout << "I'll show you the public timeline. Press CTRL-C to cancel\n";
// These have to be static in order to use them in- and outside the thread
static std::string stream;
// You can cancel the stream with this pointer (ptr->cancel_stream())
static std::unique_ptr<Mastodon::API::http> ptr;
// Start a new thread for the stream
std::thread pub_tl([=]
{
Easy masto(argv[1], argv[2]);
masto.get_stream(Mastodon::API::v1::streaming_public, stream, ptr);
});
while (true)
{
std::this_thread::sleep_for(std::chrono::seconds(1));
// Skip iteration if ptr points not to the Mastodon::API::http object
if (ptr == nullptr)
{
continue;
}
// Acquire lock for the stream variable
std::lock_guard<std::mutex> lock(ptr->get_mutex());
// Parse event stream and clear it afterwards
std::vector<Easy::stream_event> events = Easy::parse_stream(stream);
stream.clear();
// The contents of the stream are now in a vector of pairs
// { Easy::event_type, std::string }
for (const Easy::stream_event &event : events)
{
Easy::Status status;
Easy::Notification notification;
// Print out some information about the events
switch (event.first)
{
case Easy::event_type::Update:
status.from_string(event.second);
cout << "[" <<
Easy::strtime_local(status.created_at(), "%T") << "] ";
cout << "Status from: " << status.account().acct()
<< " (" << status.url() << ")\n";
break;
case Easy::event_type::Notification:
notification.from_string(event.second);
cout << "Notification involving: "
<< notification.account().acct()
<< " (" << notification.id() << ")\n";
break;
case Easy::event_type::Delete:
cout << "Deleted: " << event.second << '\n';
break;
default:
cout << "Something undefined happened. 😱\n";
}
}
}
pub_tl.join();
}
#else
int main()
{
printf("mastodon-cpp was compiled without Easy support.\n");
return 255;
}
#endif // WITHOUT_EASY

View File

@ -1,129 +0,0 @@
/* This file is part of mastodon-cpp.
* Prints a Mastodon-conversation in a tree.
* Argument has to be in the form: https://<domain>/<user>/<status id>
*
* This example uses a rather wasteful approach in order to use less code and
* therefore be more clear. Please don't use it on long conversations.
*/
// Don't compile this if the Easy-interface is turned off
#ifndef WITHOUT_EASY
#include <iostream>
#include <string>
#include <thread>
#include <chrono>
#include <ctime>
#include <regex>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy/all.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
// Include all headers in mastodon-cpp/easy/
#include <mastodon-cpp/easy/all.hpp>
#endif
using Mastodon::API;
using Mastodon::Easy;
using std::cout;
using std::chrono::system_clock;
// Print a status to stdout, nicely formatted
void format_status(const Easy::Status &status, const std::uint8_t &level)
{
std::string space(level, ' ');
// Remove HTML-tags
std::regex restrip("<[^>]*>");
std::string content = std::regex_replace(status.content(), restrip, "");
cout << space << "+-----------------------------------------\n";
cout << space << "| " << status.account().acct() << ": \n";
while (!content.empty())
{
cout << space << "| " << content.substr(0, 40) << '\n';
if (content.length() > 40)
{
content = content.substr(40);
}
else
{
content.clear();
}
}
cout << space << "| "
<< Easy::strtime_local(status.created_at(), "%T") << '\n';
cout << space << "+-----------------------------------------" << std::endl;
}
// Fetch status and its descendants, output them
std::uint16_t print_status(Easy &masto, const std::string &id,
const std::uint8_t level)
{
std::uint16_t ret;
std::string answer;
API::parametermap parameters =
{
{ "id", { id }}
};
ret = masto.get(Mastodon::API::v1::statuses_id, parameters, answer);
if (ret == 0)
{
format_status(Easy::Status(answer), level);
ret = masto.get(Mastodon::API::v1::statuses_id_context,
parameters, answer);
if (ret == 0)
{
Easy::Context context(answer);
for (const Easy::Status &s : context.descendants())
{
// Only print descendant if it is a direct reply
// NOTE: This is a wasteful approach, I use it only in the
// interest of more clarity. Don't do this at home. :-)
if (s.in_reply_to_id() == std::stoull(id))
{
print_status(masto, std::to_string(s.id()), level + 4);
}
}
}
}
return ret;
}
int main(int argc, char *argv[])
{
if (argc < 2)
{
std::cerr << "usage: " << argv[0] << " <url>\n";
return 1;
}
// Extract domain name
std::string instance = std::string(argv[1]);
std::size_t pos = instance.find('/') + 2;
instance = instance.substr(pos, instance.find('/', pos) - pos);
// Extract status ID
std::string id = std::string(argv[1]);
id = id.substr(id.rfind('/') + 1);
cout << " Instance: " << instance << "\nStatus ID: " << id << "\n\n";
Easy masto(instance, "");
return print_status(masto, id, 0);
}
#else
int main()
{
printf("mastodon-cpp was compiled without Easy support.\n");
return 255;
}
#endif // WITHOUT_EASY

View File

@ -1,40 +0,0 @@
/* This file is part of mastodon-cpp.
* This example shows how to use a proxy.
*/
#include <iostream>
#include <vector>
#include <string>
#include <cstdint>
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#endif
using std::cout;
using Mastodon::API;
int main(int argc, char *argv[])
{
if (argc < 3)
{
std::cerr << "usage: " << argv[0] << " <instance> <access token>\n";
return 1;
}
Mastodon::API masto(argv[1], argv[2]);
// SOCKS5 Proxy. Proxy resolves URL hostname.
masto.set_proxy("socks5h://[fd12::1a]:1080/");
// HTTPS proxy with username and password
masto.set_proxy("https://localhost:3128", "user5:supersecurepassword");
std::string answer;
std::uint16_t ret;
ret = masto.get(API::v1::accounts_verify_credentials, answer);
cout << "Return code: " << ret << '\n';
std::cout << answer << '\n';
return 0;
}

View File

@ -1,45 +0,0 @@
/* This file is part of mastodon-cpp.
* Get fields from own account.
*/
#include <iostream>
#include <vector>
#include <string>
#include <cstdint>
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy/all.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/all.hpp>
#endif
using std::cout;
using Mastodon::API;
using Mastodon::Easy;
int main(int argc, char *argv[])
{
if (argc < 3)
{
std::cerr << "usage: " << argv[0] << " <instance> <access token>\n";
return 1;
}
Easy masto(argv[1], argv[2]);
std::string answer;
std::uint16_t ret;
ret = masto.get(API::v1::accounts_verify_credentials, answer);
cout << "Return code: " << ret << '\n';
Easy::Account account(answer);
std::vector<Easy::Account::fields_pair> fields(account.fields());
for (const auto &field : fields)
{
cout << "Name: " << field.first << "\nValue: " << field.second << "\n\n";
}
return 0;
}

View File

@ -1,58 +0,0 @@
EAPI=6
inherit cmake-utils
DESCRIPTION="mastodon-cpp is a C++ wrapper for the Mastodon API."
HOMEPAGE="https://git.schlomp.space/tastytea/mastodon-cpp"
SRC_URI="https://git.schlomp.space/tastytea/mastodon-cpp/archive/${PV}.tar.gz -> ${P}.tar.gz"
LICENSE="GPL-3"
SLOT="0"
KEYWORDS="~amd64"
IUSE="doc debug examples"
RDEPEND=">=dev-cpp/curlpp-0.7.3
>=dev-libs/jsoncpp-1.8.1"
DEPEND=">=dev-util/cmake-3.9.6
doc? ( >=app-doc/doxygen-1.8.13-r1 )
${RDEPEND}"
src_unpack() {
default_src_unpack
mv ${PN} ${P}
}
src_configure() {
local mycmakeargs=(
-DWITH_DOC=NO
-DWITH_EXAMPLES=NO
-DWITH_TESTS=NO
)
if use debug; then
mycmakeargs+=(-DCMAKE_BUILD_TYPE=Debug)
else
mycmakeargs+=(-DCMAKE_BUILD_TYPE=Release)
fi
cmake-utils_src_configure
}
# We won't let cmake handle the documentation, because it would install the
# examples, no matter if we want them.
src_compile() {
if use doc; then
./build_doc.sh
fi
cmake-utils_src_compile
}
src_install() {
if use doc; then
HTML_DOCS="doc/html/*"
fi
if use examples; then
docinto examples
for file in examples/*.cpp; do
dodoc ${file}
done
fi
cmake-utils_src_install
}

View File

@ -1,61 +0,0 @@
# Copyright 1999-2017 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$
EAPI=6
inherit git-r3 cmake-utils
DESCRIPTION="mastodon-cpp is a C++ wrapper for the Mastodon API."
HOMEPAGE="https://git.schlomp.space/tastytea/mastodon-cpp"
EGIT_REPO_URI="https://git.schlomp.space/tastytea/mastodon-cpp.git"
LICENSE="GPL-3"
SLOT="0"
KEYWORDS=""
IUSE="doc debug examples"
RDEPEND=">=dev-cpp/curlpp-0.8.1
>=dev-libs/jsoncpp-1.8.1"
DEPEND=">=dev-util/cmake-3.9.6
doc? ( >=app-doc/doxygen-1.8.13-r1 )
${RDEPEND}"
src_unpack() {
git-r3_src_unpack
}
src_configure() {
local mycmakeargs=(
-DWITH_DOC=NO
-DWITH_EXAMPLES=NO
-DWITH_TESTS=NO
)
if use debug; then
mycmakeargs+=(-DCMAKE_BUILD_TYPE=Debug)
else
mycmakeargs+=(-DCMAKE_BUILD_TYPE=Release)
fi
cmake-utils_src_configure
}
# We can not let cmake handle the documentation, because it would end up in
# doc/mastodon-cpp-${PROJECT_VERSION} instead of -9999
src_compile() {
if use doc; then
./build_doc.sh
fi
cmake-utils_src_compile
}
src_install() {
if use doc; then
HTML_DOCS="doc/html/*"
fi
if use examples; then
docinto examples
for file in examples/*.cpp; do
dodoc ${file}
done
fi
cmake-utils_src_install
}

View File

@ -0,0 +1,7 @@
include(GNUInstallDirs)
configure_file("${PROJECT_NAME}.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")

View File

@ -0,0 +1,12 @@
name=@PROJECT_NAME@
prefix=@CMAKE_INSTALL_PREFIX@
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
Name: ${name}
Description: @PROJECT_DESCRIPTION@
Version: @PROJECT_VERSION@
Cflags: -I${includedir}
Libs: -L${libdir} -l${name} -lpthread -lPocoNet
Requires: jsoncpp
Libs.private: -lPocoFoundation -lPocoNetSSL

71
src/CMakeLists.txt Normal file
View File

@ -0,0 +1,71 @@
include(GNUInstallDirs)
if(WITH_EASY)
find_package(jsoncpp CONFIG REQUIRED)
endif()
# Some distributions do not contain Poco*Config.cmake recipes.
find_package(Poco COMPONENTS Foundation Net NetSSL CONFIG)
if(WITH_EASY)
file(GLOB_RECURSE sources *.cpp *.hpp)
else()
file(GLOB sources *.cpp api/*.cpp *.hpp api/*.hpp)
endif()
# Write version in header
configure_file ("version.hpp.in"
"${CMAKE_CURRENT_BINARY_DIR}/version.hpp")
add_library(${PROJECT_NAME} ${sources})
set_target_properties(${PROJECT_NAME} PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${${PROJECT_NAME}_VERSION_MAJOR})
target_include_directories(${PROJECT_NAME}
PRIVATE
"$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
PUBLIC
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
if(WITH_EASY)
target_link_libraries(${PROJECT_NAME}
PUBLIC pthread jsoncpp_lib)
endif()
# If no Poco*Config.cmake recipes are found, look for headers in standard dirs.
if(PocoNetSSL_FOUND)
target_link_libraries(${PROJECT_NAME}
PRIVATE Poco::Foundation Poco::Net Poco::NetSSL)
else()
find_file(Poco_h NAMES "Poco/Poco.h"
PATHS "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}")
if("${Poco_h}" STREQUAL "Poco_h-NOTFOUND")
message(FATAL_ERROR "Could not find POCO.")
else()
message(WARNING
"Your distribution of POCO doesn't contain the *Config.cmake recipes, "
"but the files seem to be in the standard directories. "
"Let's hope this works.")
target_link_libraries(${PROJECT_NAME}
PRIVATE PocoFoundation PocoNet PocoNetSSL)
endif()
endif()
install(TARGETS ${PROJECT_NAME}
EXPORT "${PROJECT_NAME}Targets"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}")
install(FILES mastodon-cpp.hpp return_types.hpp types.hpp
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME})
if(WITH_EASY)
file(GLOB easy_header easy/*.hpp)
install(FILES ${easy_header}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/easy)
file(GLOB easy_entities_header easy/entities/*.hpp)
install(FILES ${easy_entities_header}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/easy/entities)
endif()

View File

@ -1,91 +1,92 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include "macros.hpp"
#include "debug.hpp"
#include "mastodon-cpp.hpp"
using namespace Mastodon;
const uint_fast16_t API::del(const Mastodon::API::v1 &call,
const parametermap &parameters)
return_call API::del(const Mastodon::API::v1 &call,
const parameters &params)
{
string strcall = "";
string strid = "";
// The ID is part of the path
const auto &it = parameters.find("id");
if (it != parameters.end())
const parameters::const_iterator &it_id = params.find("id");
const parameters::const_iterator &it_aid = params.find("accountid");
if (it_id != params.end())
{
strid = it->second[0];
strid = it_id->values[0];
}
else if (it_aid != params.end())
{
strid = it_aid->values[0];
}
switch (call)
{
case v1::domain_blocks:
strcall = "/api/v1/domain_blocks";
break;
case v1::lists_id:
strcall = "/api/v1/lists/" + strid;
break;
case v1::lists_id_accounts:
strcall = "/api/v1/lists/" + strid + "/accounts";
break;
case v1::statuses_id:
strcall = "/api/v1/statuses/" + strid;
break;
case v1::push_subscription:
strcall = "/api/v1/push/subscription";
break;
default:
ttdebug << "ERROR: Invalid call.\n";
return 11;
break;
case v1::domain_blocks:
{
strcall = "/api/v1/domain_blocks";
break;
}
case v1::lists_id:
{
strcall = "/api/v1/lists/" + strid;
break;
}
case v1::lists_id_accounts:
{
strcall = "/api/v1/lists/" + strid + "/accounts";
break;
}
case v1::statuses_id:
{
strcall = "/api/v1/statuses/" + strid;
break;
}
case v1::push_subscription:
{
strcall = "/api/v1/push/subscription";
break;
}
case v1::filters_id:
{
strcall = "/api/v1/filters/" + strid;
break;
}
case v1::suggestions_accountid:
{
strcall = "/api/v1/suggestions/" + strid;
break;
}
default:
{
ttdebug << "ERROR: Invalid argument.\n";
return { error::INVALID_ARGUMENT, "Invalid argument", 0, "" };
}
}
string answer;
return del(strcall, parameters, answer);
return del(strcall, params);
}
const uint_fast16_t API::del(const std::string &call,
const parametermap &parameters, string &answer)
return_call API::del(const std::string &call, const parameters &params)
{
return _http.request(http::method::DELETE, call,
maptoformdata(parameters), answer);
}
// ↓↓ DEPRECATED ↓↓
const uint_fast16_t API::del(const Mastodon::API::v1 &call,
const string &argument)
{
const parametermap p = {};
return del(call, argument, p);
}
const uint_fast16_t API::del(const Mastodon::API::v1 &call,
const string &argument,
const parametermap &parameters)
{
parametermap newparameters = parameters;
// Emulate old behaviour
newparameters["id"] = { argument };
return del(call, parameters);
return _http.request(http_method::DELETE, call, *maptoformdata(params));
}

View File

@ -1,245 +1,306 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include "macros.hpp"
#include <algorithm>
#include "debug.hpp"
#include "mastodon-cpp.hpp"
using namespace Mastodon;
using std::cerr;
const uint_fast16_t API::get(const Mastodon::API::v1 &call,
const parametermap &parameters, string &answer)
const return_call API::get(const Mastodon::API::v1 &call,
const parameters &params)
{
string strcall = "";
string strid = "";
// The ID is part of the path
const auto &it = parameters.find("id");
if (it != parameters.end())
const auto &it_id = params.find("id");
if (it_id != params.end())
{
strid = it->second[0];
strid = it_id->values[0];
}
switch (call)
{
case v1::accounts_verify_credentials:
strcall = "/api/v1/accounts/verify_credentials";
break;
case v1::blocks:
strcall = "/api/v1/blocks";
break;
case v1::domain_blocks:
strcall = "/api/v1/domain_blocks";
break;
case v1::favourites:
strcall = "/api/v1/favourites";
break;
case v1::follow_requests:
strcall = "/api/v1/follow_requests";
break;
case v1::instance:
strcall = "/api/v1/instance";
break;
case v1::custom_emojis:
strcall = "/api/v1/custom_emojis";
break;
case v1::lists:
strcall = "/api/v1/lists";
break;
case v1::mutes:
strcall = "/api/v1/mutes";
break;
case v1::notifications:
strcall = "/api/v1/notifications";
break;
case v1::reports:
strcall = "/api/v1/reports";
break;
case v1::timelines_home:
strcall = "/api/v1/timelines/home";
break;
case v1::timelines_public:
strcall = "/api/v1/timelines/public";
break;
case v1::accounts_relationships:
strcall = "/api/v1/accounts/relationships";
break;
case v1::accounts_id:
strcall = "/api/v1/accounts/" + strid;
break;
case v1::accounts_id_followers:
strcall = "/api/v1/accounts/" + strid + "/followers";
break;
case v1::accounts_id_following:
strcall = "/api/v1/accounts/" + strid + "/following";
break;
case v1::accounts_id_statuses:
strcall = "/api/v1/accounts/" + strid + "/statuses";
break;
case v1::accounts_search:
strcall = "/api/v1/accounts/search";
break;
case v1::accounts_id_lists:
strcall = "/api/v1/accounts/" + strid + "/lists";
break;
case v1::lists_id_accounts:
strcall = "/api/v1/lists/" + strid + "/accounts";
break;
case v1::lists_id:
strcall = "/api/v1/lists/" + strid;
break;
case v1::notifications_id:
strcall = "/api/v1/notifications/" + strid;
break;
case v1::search:
strcall = "/api/v1/search";
break;
case v1::statuses_id:
strcall = "/api/v1/statuses/" + strid;
break;
case v1::statuses_id_context:
strcall = "/api/v1/statuses/" + strid + "/context";
break;
case v1::statuses_id_card:
strcall = "/api/v1/statuses/" + strid + "/card";
break;
case v1::statuses_id_reblogged_by:
strcall = "/api/v1/statuses/" + strid + "/reblogged_by";
break;
case v1::statuses_id_favourited_by:
strcall = "/api/v1/statuses/" + strid + "/favourited_by";
break;
case v1::timelines_tag_hashtag:
{
// The hashtag is part of the path
const auto &it = parameters.find("hashtag");
if (it != parameters.end())
{
strcall = "/api/v1/timelines/tag/" + urlencode(it->second[0]);
}
else
{
ttdebug << "ERROR: Invalid call.\n";
return 11;
}
}
break;
case v1::timelines_list_list_id:
strcall = "/api/v1/timelines/list/" + strid;
break;
case v1::push_subscription:
strcall = "/api/v1/push/subscription";
break;
default:
ttdebug << "ERROR: Invalid call.\n";
return 11;
break;
case v1::accounts_verify_credentials:
{
strcall = "/api/v1/accounts/verify_credentials";
break;
}
case v1::blocks:
{
strcall = "/api/v1/blocks";
break;
}
case v1::domain_blocks:
{
strcall = "/api/v1/domain_blocks";
break;
}
case v1::favourites:
{
strcall = "/api/v1/favourites";
break;
}
case v1::follow_requests:
{
strcall = "/api/v1/follow_requests";
break;
}
case v1::instance:
{
strcall = "/api/v1/instance";
break;
}
case v1::custom_emojis:
{
strcall = "/api/v1/custom_emojis";
break;
}
case v1::lists:
{
strcall = "/api/v1/lists";
break;
}
case v1::mutes:
{
strcall = "/api/v1/mutes";
break;
}
case v1::notifications:
{
strcall = "/api/v1/notifications";
break;
}
case v1::timelines_home:
{
strcall = "/api/v1/timelines/home";
break;
}
case v1::timelines_public:
{
strcall = "/api/v1/timelines/public";
break;
}
case v1::accounts_relationships:
{
strcall = "/api/v1/accounts/relationships";
break;
}
case v1::accounts_id:
{
strcall = "/api/v1/accounts/" + strid;
break;
}
case v1::accounts_id_followers:
{
strcall = "/api/v1/accounts/" + strid + "/followers";
break;
}
case v1::accounts_id_following:
{
strcall = "/api/v1/accounts/" + strid + "/following";
break;
}
case v1::accounts_id_statuses:
{
strcall = "/api/v1/accounts/" + strid + "/statuses";
break;
}
case v1::accounts_search:
{
strcall = "/api/v1/accounts/search";
break;
}
case v1::accounts_id_lists:
{
strcall = "/api/v1/accounts/" + strid + "/lists";
break;
}
case v1::lists_id_accounts:
{
strcall = "/api/v1/lists/" + strid + "/accounts";
break;
}
case v1::lists_id:
{
strcall = "/api/v1/lists/" + strid;
break;
}
case v1::notifications_id:
{
strcall = "/api/v1/notifications/" + strid;
break;
}
case v1::statuses_id:
{
strcall = "/api/v1/statuses/" + strid;
break;
}
case v1::statuses_id_context:
{
strcall = "/api/v1/statuses/" + strid + "/context";
break;
}
case v1::statuses_id_card:
{
strcall = "/api/v1/statuses/" + strid + "/card";
break;
}
case v1::statuses_id_reblogged_by:
{
strcall = "/api/v1/statuses/" + strid + "/reblogged_by";
break;
}
case v1::statuses_id_favourited_by:
{
strcall = "/api/v1/statuses/" + strid + "/favourited_by";
break;
}
case v1::timelines_tag_hashtag:
{
// The tag is part of the path
const auto &it = params.find("tag");
if (it != params.end())
{
strcall = "/api/v1/timelines/tag/" + ::urlencode(it->values[0]);
}
else
{
ttdebug << "ERROR: Invalid argument.\n";
return { error::INVALID_ARGUMENT, "Invalid argument", 0, "" };
}
break;
}
case v1::timelines_list_list_id:
{
strcall = "/api/v1/timelines/list/" + strid;
break;
}
case v1::push_subscription:
{
strcall = "/api/v1/push/subscription";
break;
}
case v1::endorsements:
{
strcall = "/api/v1/endorsements";
break;
}
case v1::bookmarks:
{
strcall = "/api/v1/bookmarks";
break;
}
case v1::apps_verify_credentials:
{
strcall = "/api/v1/apps/verify_credentials";
break;
}
case v1::filters:
{
strcall = "/api/v1/filters";
break;
}
case v1::filters_id:
{
strcall = "/api/v1/filters/" + strid;
break;
}
case v1::suggestions:
{
strcall = "/api/v1/suggestions";
break;
}
case v1::polls_id:
{
strcall = "/api/v1/polls/" + strid;
break;
}
case v1::conversations:
{
strcall = "/api/v1/conversations";
break;
}
case v1::streaming_health:
{
strcall = "/api/v1/streaming/health";
break;
}
default:
{
ttdebug << "ERROR: Invalid argument.\n";
return { error::INVALID_ARGUMENT, "Invalid argument", 0, "" };
}
}
if (parameters.size() > 0)
if (params.size() > 0)
{
// Delete the parameters that are already in strcall
parametermap newparameters = parameters;
newparameters.erase("id");
newparameters.erase("hashtag");
strcall += maptostr(newparameters);
const parameters newparams = delete_params(params, { "id", "tag" });
strcall += maptostr(newparams);
}
return get(strcall, answer);
return get(strcall);
}
const uint_fast16_t API::get(const Mastodon::API::v2 &call,
const parametermap &parameters, string &answer)
const return_call API::get(const Mastodon::API::v2 &call,
const parameters &params)
{
string strcall = "";
string strid = "";
// The ID is part of the path
const auto &it = parameters.find("id");
if (it != parameters.end())
const auto &it = params.find("id");
if (it != params.end())
{
strid = it->second[0];
strid = it->values[0];
}
switch (call)
{
case v2::search:
{
strcall = "/api/v2/search";
break;
}
default:
ttdebug << "ERROR: Invalid call.\n";
return 11;
break;
{
ttdebug << "ERROR: Invalid argument.\n";
return { error::INVALID_ARGUMENT, "Invalid argument", 0, "" };
}
}
if (parameters.size() > 0)
if (params.size() > 0)
{
// Delete the parameters that are already in strcall
parametermap newparameters = parameters;
newparameters.erase("id");
newparameters.erase("hashtag");
strcall += maptostr(newparameters);
// Delete the parameterss that are already in strcall
const parameters newparams = delete_params(params, { "id", "tag" });
strcall += maptostr(newparams);
}
return get(strcall, answer);
return get(strcall);
}
const uint_fast16_t API::get(const Mastodon::API::v1 &call, string &answer)
const return_call API::get(const Mastodon::API::v1 &call)
{
const parametermap p;
return get(call, p, answer);
return get(call, {});
}
const uint_fast16_t API::get(const std::string &call, string &answer)
const return_call API::get(const std::string &call)
{
return _http.request(http::method::GET, call, answer);
}
// ↓↓ DEPRECATED ↓↓
const uint_fast16_t API::get(const Mastodon::API::v1 &call,
const string &argument,
const parametermap &parameters, string &answer)
{
parametermap newparameters = parameters;
// Emulate old behaviour
switch (call)
{
case v1::search:
case v1::accounts_search:
newparameters["q"] = { argument };
break;
case v1::timelines_tag_hashtag:
newparameters["hashtag"] = { argument };
break;
default:
newparameters["id"] = { argument };
break;
}
return get(call, newparameters, answer);
}
const uint_fast16_t API::get(const Mastodon::API::v1 &call,
const string &argument, string &answer)
{
const parametermap p;
return get(call, argument, p, answer);
return _http.request(http_method::GET, call);
}

View File

@ -1,103 +1,99 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include "macros.hpp"
#include "debug.hpp"
#include "mastodon-cpp.hpp"
using namespace Mastodon;
using std::cerr;
using std::to_string;
const uint_fast16_t API::get_stream(const Mastodon::API::v1 &call,
const parametermap &parameters,
string &answer,
std::unique_ptr<Mastodon::API::http> &ptr)
void API::get_stream(const Mastodon::API::v1 &call,
const parameters &params,
std::unique_ptr<Mastodon::API::http> &ptr,
string &stream)
{
string strcall = "";
switch (call)
{
case v1::streaming_user:
strcall = "/api/v1/streaming/user";
break;
case v1::streaming_public:
strcall = "/api/v1/streaming/public";
break;
case v1::streaming_public_local:
strcall = "/api/v1/streaming/public/local";
break;
case v1::streaming_hashtag:
strcall = "/api/v1/streaming/hashtag";
break;
case v1::streaming_list:
strcall = "/api/v1/streaming/list";
break;
default:
ttdebug << "ERROR: Invalid call.\n";
return 11;
break;
}
if (parameters.size() > 0)
case Mastodon::API::v1::streaming_user:
{
strcall += maptostr(parameters);
strcall = "/api/v1/streaming/user";
break;
}
case v1::streaming_public:
{
strcall = "/api/v1/streaming/public";
break;
}
case v1::streaming_public_local:
{
strcall = "/api/v1/streaming/public/local";
break;
}
case v1::streaming_hashtag:
{
strcall = "/api/v1/streaming/hashtag";
break;
}
case v1::streaming_hashtag_local:
{
strcall = "/api/v1/streaming/hashtag/local";
break;
}
case v1::streaming_list:
{
strcall = "/api/v1/streaming/list";
break;
}
case v1::streaming_direct:
{
strcall = "/api/v1/streaming/direct";
break;
}
default:
{
const uint8_t err = static_cast<uint8_t>(error::INVALID_ARGUMENT);
ttdebug << "ERROR: Invalid call.\n";
stream = "event: ERROR\ndata: "
"{\"error_code\":" + to_string(err) + "}\n";
return;
}
}
return get_stream(strcall, answer, ptr);
if (params.size() > 0)
{
strcall += maptostr(params);
}
return get_stream(strcall, ptr, stream);
}
const uint_fast16_t API::get_stream(const Mastodon::API::v1 &call,
string &answer,
std::unique_ptr<Mastodon::API::http> &ptr)
void API::get_stream(const Mastodon::API::v1 &call,
std::unique_ptr<Mastodon::API::http> &ptr,
string &stream)
{
parametermap p = {};
return get_stream(call, p, answer, ptr);
return get_stream(call, {}, ptr, stream);
}
const uint_fast16_t API::get_stream(const std::string &call, string &answer,
std::unique_ptr<http> &ptr)
void API::get_stream(const std::string &call, std::unique_ptr<http> &ptr,
string &stream)
{
ptr = std::make_unique<http>(*this, _instance, _access_token);
return ptr->request(http::method::GET_STREAM, call, answer);
}
// ↓↓ DEPRECATED ↓↓
const uint_fast16_t API::get_stream(const Mastodon::API::v1 &call,
const string &argument,
string &answer,
std::unique_ptr<Mastodon::API::http> &ptr)
{
parametermap parameters;
// Emulate old behaviour
switch (call)
{
case v1::streaming_hashtag:
parameters["tag"] = { argument };
break;
case v1::streaming_list:
parameters["list"] = { argument };
break;
default:
ttdebug << "ERROR: Invalid call.\n";
return 11;
break;
}
return get_stream(call, parameters, answer, ptr);
return ptr->request_stream(call, stream);
}

View File

@ -1,29 +1,28 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include "macros.hpp"
#include "debug.hpp"
#include "mastodon-cpp.hpp"
using namespace Mastodon;
using std::cerr;
const uint_fast16_t API::patch(const Mastodon::API::v1 &call,
const parametermap &parameters,
string &answer)
return_call API::patch(const Mastodon::API::v1 &call,
const parameters &params)
{
string strcall = "";
switch (call)
@ -32,11 +31,10 @@ const uint_fast16_t API::patch(const Mastodon::API::v1 &call,
strcall = "/api/v1/accounts/update_credentials";
break;
default:
ttdebug << "ERROR: Invalid call.\n";
return 11;
ttdebug << "ERROR: Invalid argument.\n";
return { error::INVALID_ARGUMENT, "Invalid argument", 0, "" };
break;
}
return _http.request(API::http::method::PATCH,
strcall, maptoformdata(parameters), answer);
return _http.request(http_method::PATCH, strcall, *maptoformdata(params));
}

View File

@ -1,162 +1,223 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include "macros.hpp"
#include "debug.hpp"
#include "mastodon-cpp.hpp"
using namespace Mastodon;
const uint_fast16_t API::post(const Mastodon::API::v1 &call,
const parametermap &parameters, string &answer)
return_call API::post(const Mastodon::API::v1 &call,
const parameters &params)
{
string strcall = "";
string strid = "";
// The ID is part of the path
const auto &it = parameters.find("id");
if (it != parameters.end())
const auto &it = params.find("id");
if (it != params.end())
{
strid = it->second[0];
strid = it->values[0];
}
switch (call)
{
case v1::apps:
strcall = "/api/v1/apps";
break;
case v1::domain_blocks:
strcall = "/api/v1/domain_blocks";
break;
case v1::follows:
strcall = "/api/v1/follows";
break;
case v1::lists:
strcall = "/api/v1/lists";
break;
case v1::media:
strcall = "/api/v1/media";
break;
case v1::notifications_clear:
strcall = "/api/v1/notifications/clear";
break;
case v1::notifications_dismiss:
strcall = "/api/v1/notifications/dismiss";
break;
case v1::reports:
strcall = "/api/v1/reports";
break;
case v1::statuses:
strcall = "/api/v1/statuses";
break;
case v1::accounts_id_follow:
strcall = "/api/v1/accounts/" + strid + "/follow";
break;
case v1::accounts_id_unfollow:
strcall = "/api/v1/accounts/" + strid + "/unfollow";
break;
case v1::accounts_id_block:
strcall = "/api/v1/accounts/" + strid + "/block";
break;
case v1::accounts_id_unblock:
strcall = "/api/v1/accounts/" + strid + "/unblock";
break;
case v1::accounts_id_mute:
strcall = "/api/v1/accounts/" + strid + "/mute";
break;
case v1::accounts_id_unmute:
strcall = "/api/v1/accounts/" + strid + "/unmute";
break;
case v1::follow_requests_id_authorize:
strcall = "/api/v1/folow_requests/" + strid + "/authorize";
break;
case v1::follow_requests_id_reject:
strcall = "/api/v1/folow_requests/" + strid + "/reject";
break;
case v1::lists_id_accounts:
strcall = "/api/v1/lists/" + strid + "/accounts";
break;
case v1::statuses_id_reblog:
strcall = "/api/v1/statuses/" + strid + "/reblog";
break;
case v1::statuses_id_unreblog:
strcall = "/api/v1/statuses/" + strid + "/unreblog";
break;
case v1::statuses_id_favourite:
strcall = "/api/v1/statuses/" + strid + "/favourite";
break;
case v1::statuses_id_unfavourite:
strcall = "/api/v1/statuses/" + strid + "/unfavourite";
break;
case v1::statuses_id_pin:
strcall = "/api/v1/statuses/" + strid + "/pin";
break;
case v1::statuses_id_unpin:
strcall = "/api/v1/statuses/" + strid + "/unpin";
break;
case v1::statuses_id_mute:
strcall = "/api/v1/statuses/" + strid + "/mute";
break;
case v1::statuses_id_unmute:
strcall = "/api/v1/statuses/" + strid + "/unmute";
break;
case v1::push_subscription:
strcall = "/api/v1/push/subscription";
break;
default:
ttdebug << "ERROR: Invalid call.\n";
return 11;
break;
case v1::apps:
{
strcall = "/api/v1/apps";
break;
}
case v1::domain_blocks:
{
strcall = "/api/v1/domain_blocks";
break;
}
case v1::lists:
{
strcall = "/api/v1/lists";
break;
}
case v1::media:
{
strcall = "/api/v1/media";
break;
}
case v1::notifications_clear:
{
strcall = "/api/v1/notifications/clear";
break;
}
case v1::notifications_dismiss:
{
strcall = "/api/v1/notifications/dismiss";
break;
}
case v1::reports:
{
strcall = "/api/v1/reports";
break;
}
case v1::statuses:
{
strcall = "/api/v1/statuses";
break;
}
case v1::accounts:
{
strcall = "/api/v1/accounts";
break;
}
case v1::accounts_id_follow:
{
strcall = "/api/v1/accounts/" + strid + "/follow";
break;
}
case v1::accounts_id_unfollow:
{
strcall = "/api/v1/accounts/" + strid + "/unfollow";
break;
}
case v1::accounts_id_block:
{
strcall = "/api/v1/accounts/" + strid + "/block";
break;
}
case v1::accounts_id_unblock:
{
strcall = "/api/v1/accounts/" + strid + "/unblock";
break;
}
case v1::accounts_id_mute:
{
strcall = "/api/v1/accounts/" + strid + "/mute";
break;
}
case v1::accounts_id_unmute:
{
strcall = "/api/v1/accounts/" + strid + "/unmute";
break;
}
case v1::follow_requests_id_authorize:
{
strcall = "/api/v1/folow_requests/" + strid + "/authorize";
break;
}
case v1::follow_requests_id_reject:
{
strcall = "/api/v1/folow_requests/" + strid + "/reject";
break;
}
case v1::lists_id_accounts:
{
strcall = "/api/v1/lists/" + strid + "/accounts";
break;
}
case v1::statuses_id_reblog:
{
strcall = "/api/v1/statuses/" + strid + "/reblog";
break;
}
case v1::statuses_id_unreblog:
{
strcall = "/api/v1/statuses/" + strid + "/unreblog";
break;
}
case v1::statuses_id_favourite:
{
strcall = "/api/v1/statuses/" + strid + "/favourite";
break;
}
case v1::statuses_id_unfavourite:
{
strcall = "/api/v1/statuses/" + strid + "/unfavourite";
break;
}
case v1::statuses_id_pin:
{
strcall = "/api/v1/statuses/" + strid + "/pin";
break;
}
case v1::statuses_id_unpin:
{
strcall = "/api/v1/statuses/" + strid + "/unpin";
break;
}
case v1::statuses_id_mute:
{
strcall = "/api/v1/statuses/" + strid + "/mute";
break;
}
case v1::statuses_id_unmute:
{
strcall = "/api/v1/statuses/" + strid + "/unmute";
break;
}
case v1::push_subscription:
{
strcall = "/api/v1/push/subscription";
break;
}
case v1::accounts_id_pin:
{
strcall = "/api/v1/accounts/" + strid + "/pin";
break;
}
case v1::accounts_id_unpin:
{
strcall = "/api/v1/accounts/" + strid + "/unpin";
break;
}
case v1::statuses_id_bookmark:
{
strcall = "/api/v1/statuses/" + strid + "/bookmark";
break;
}
case v1::statuses_id_unbookmark:
{
strcall = "/api/v1/statuses/" + strid + "/unbookmark";
break;
}
case v1::filters:
{
strcall = "/api/v1/filters";
break;
}
case v1::polls_id_votes:
{
strcall = "/api/v1/polls/" + strid + "/votes";
break;
}
default:
{
ttdebug << "ERROR: Invalid argument.\n";
return { error::INVALID_ARGUMENT, "Invalid argument", 0, ""};
}
}
return post(strcall, parameters, answer);
return post(strcall, params);
}
const uint_fast16_t API::post(const Mastodon::API::v1 &call, string &answer)
return_call API::post(const Mastodon::API::v1 &call)
{
const parametermap p;
return post(call, p, answer);
const parameters p;
return post(call, p);
}
const uint_fast16_t API::post(const string &call,
const parametermap &parameters, string &answer)
return_call API::post(const string &call, const parameters &params)
{
return _http.request(http::method::POST, call,
maptoformdata(parameters), answer);
}
// ↓↓ DEPRECATED ↓↓
const uint_fast16_t API::post(const Mastodon::API::v1 &call,
const string &argument,
const parametermap &parameters, string &answer)
{
parametermap newparameters = parameters;
// Emulate old behaviour
newparameters["id"] = { argument };
return post(call, newparameters, answer);
}
const uint_fast16_t API::post(const Mastodon::API::v1 &call,
const string &argument, string &answer)
{
const parametermap p;
return post(call, argument, p, answer);
return _http.request(http_method::POST, call, *maptoformdata(params));
}

View File

@ -1,76 +1,72 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include "macros.hpp"
#include "debug.hpp"
#include "mastodon-cpp.hpp"
using namespace Mastodon;
const uint_fast16_t API::put(const Mastodon::API::v1 &call,
const parametermap &parameters, string &answer)
return_call API::put(const Mastodon::API::v1 &call,
const parameters &params)
{
string strcall = "";
string strid = "";
// The ID is part of the path
const auto &it = parameters.find("id");
if (it != parameters.end())
const auto &it = params.find("id");
if (it != params.end())
{
strid = it->second[0];
strid = it->values[0];
}
switch (call)
{
case v1::lists_id:
strcall = "/api/v1/lists/" + strid;
break;
case v1::media_id:
strcall = "/api/v1/media/" + strid;
break;
case v1::push_subscription:
strcall = "/api/v1/push/subscription";
break;
default:
ttdebug << "ERROR: Invalid call.\n";
return 11;
break;
case v1::lists_id:
{
strcall = "/api/v1/lists/" + strid;
break;
}
case v1::media_id:
{
strcall = "/api/v1/media/" + strid;
break;
}
case v1::push_subscription:
{
strcall = "/api/v1/push/subscription";
break;
}
case v1::filters_id:
{
strcall = "/api/v1/filters/" + strid;
break;
}
default:
{
ttdebug << "ERROR: Invalid argument.\n";
return { error::INVALID_ARGUMENT, "Invalid argument", 0, "" };
}
}
return put(strcall, parameters, answer);
return put(strcall, params);
}
const uint_fast16_t API::put(const string &call,
const parametermap &parameters, string &answer)
return_call API::put(const string &call, const parameters &params)
{
return _http.request(http::method::PUT, call,
maptoformdata(parameters), answer);
}
// ↓↓ DEPRECATED ↓↓
const uint_fast16_t API::put(const Mastodon::API::v1 &call,
const string &argument,
const parametermap &parameters, string &answer)
{
parametermap newparameters = parameters;
// Emulate old behaviour
newparameters["id"] = { argument };
return put(call, newparameters, answer);
return _http.request(http_method::PUT, call, *maptoformdata(params));
}

View File

@ -1,16 +1,16 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@ -20,7 +20,8 @@
#include <iostream>
#ifdef DEBUG
#define ttdebug std::cerr << "[" << __FILE__ << ":" << __LINE__ << "] DEBUG: "
#define ttdebug \
std::cerr << "[" << __FILE__ << ":" << __LINE__ << "] DEBUG: "
#else
#define ttdebug false && std::cerr
#endif

View File

@ -1,59 +1,41 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MASTODON_CPP_EASY_ALL_HPP
#define MASTODON_CPP_EASY_ALL_HPP
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "easy/easy.hpp"
#include "easy/entities/account.hpp"
#include "easy/entities/application.hpp"
#include "easy/entities/attachment.hpp"
#include "easy/entities/card.hpp"
#include "easy/entities/context.hpp"
#include "easy/entities/emoji.hpp"
#include "easy/entities/instance.hpp"
#include "easy/entities/list.hpp"
#include "easy/entities/mention.hpp"
#include "easy/entities/notification.hpp"
#include "easy/entities/relationship.hpp"
#include "easy/entities/report.hpp"
#include "easy/entities/results.hpp"
#include "easy/entities/status.hpp"
#include "easy/entities/tag.hpp"
#include "easy/entities/pushsubscription.hpp"
#else
#include <mastodon-cpp/easy/easy.hpp>
#include <mastodon-cpp/easy/entities/account.hpp>
#include <mastodon-cpp/easy/entities/application.hpp>
#include <mastodon-cpp/easy/entities/attachment.hpp>
#include <mastodon-cpp/easy/entities/card.hpp>
#include <mastodon-cpp/easy/entities/context.hpp>
#include <mastodon-cpp/easy/entities/emoji.hpp>
#include <mastodon-cpp/easy/entities/instance.hpp>
#include <mastodon-cpp/easy/entities/list.hpp>
#include <mastodon-cpp/easy/entities/mention.hpp>
#include <mastodon-cpp/easy/entities/notification.hpp>
#include <mastodon-cpp/easy/entities/relationship.hpp>
#include <mastodon-cpp/easy/entities/report.hpp>
#include <mastodon-cpp/easy/entities/results.hpp>
#include <mastodon-cpp/easy/entities/status.hpp>
#include <mastodon-cpp/easy/entities/tag.hpp>
#include <mastodon-cpp/easy/entities/pushsubscription.hpp>
#endif
#include "easy.hpp"
#include "entities/account.hpp"
#include "entities/application.hpp"
#include "entities/attachment.hpp"
#include "entities/card.hpp"
#include "entities/context.hpp"
#include "entities/emoji.hpp"
#include "entities/instance.hpp"
#include "entities/list.hpp"
#include "entities/mention.hpp"
#include "entities/notification.hpp"
#include "entities/relationship.hpp"
#include "entities/results.hpp"
#include "entities/status.hpp"
#include "entities/tag.hpp"
#include "entities/token.hpp"
#include "entities/pushsubscription.hpp"
#include "entities/filter.hpp"
#include "entities/poll.hpp"
#include "entities/conversation.hpp"
#endif // MASTODON_CPP_EASY_ALL_HPP

View File

@ -1,16 +1,16 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@ -18,14 +18,14 @@
#include <iomanip> // get_time
#include <sstream>
#include <regex>
#include <algorithm>
#include "easy.hpp"
#include "macros.hpp"
#include "debug.hpp"
using namespace Mastodon;
using std::string;
Easy::Easy(const string &instance, const string &access_token)
: API(instance, access_token)
Easy::API::API(const string &instance, const string &access_token)
: Mastodon::API(instance, access_token)
{}
const std::vector<string> Easy::json_array_to_vector(const string &json)
@ -36,11 +36,11 @@ const std::vector<string> Easy::json_array_to_vector(const string &json)
if (json_array.isArray())
{
std::vector<string> vec;
for (const Json::Value &value : json_array)
{
vec.push_back(value.toStyledString());
}
// Transform array of Json::Value to vector of string.
std::vector<string> vec(json_array.size());
std::transform(json_array.begin(), json_array.end(), vec.begin(),
[](const Json::Value &j)
{ return j.toStyledString(); });
return vec;
}
@ -49,13 +49,14 @@ const std::vector<string> Easy::json_array_to_vector(const string &json)
return {};
}
const std::vector<Easy::stream_event>
Easy::parse_stream(const std::string &streamdata)
const vector<Easy::stream_event_type> Easy::parse_stream(
const std::string &streamdata)
{
string stream = streamdata;
std::regex reevent("event: (update|notification|delete)\ndata: (.*)\n");
std::regex reevent("event: (update|notification|delete|filters_changed"
"|ERROR)\ndata: (.*)\n");
std::smatch match;
std::vector<stream_event> vec = {};
std::vector<stream_event_type> vec = {};
while (std::regex_search(stream, match, reevent))
{
@ -63,92 +64,78 @@ const std::vector<Easy::stream_event>
const string &data = match[2].str();
event_type type = event_type::Undefined;
if (event.compare("update") == 0)
if (event == "update")
type = event_type::Update;
else if (event.compare("notification") == 0)
else if (event == "notification")
type = event_type::Notification;
else if (event.compare("delete") == 0)
else if (event == "delete")
type = event_type::Delete;
else if (event == "ERROR")
type = event_type::Error;
else if (event == "filters_changed")
type = event_type::Filters_changed;
vec.push_back(stream_event(type, data));
vec.push_back({ type, data });
stream = match.suffix().str();
}
return vec;
}
const Easy::Link Easy::get_link() const
const Easy::time_type Easy::string_to_time(const string &strtime)
{
std::stringstream sstime(strtime);
struct std::tm tm = {};
tm.tm_isdst = -1; // Detect daylight saving time.
sstime >> std::get_time(&tm, "%Y-%m-%dT%T");
std::time_t time = timegm(&tm); // Assume time is UTC.
return { system_clock::from_time_t(time) };
}
const Easy::Link Easy::API::get_link() const
{
return Link(get_header("Link"));
}
const string Easy::strtime_utc(const system_clock::time_point &timepoint,
const string &format)
{
return strtime(timepoint, format, true);
}
const string Easy::strtime_local(const system_clock::time_point &timepoint,
const string &format)
{
return strtime(timepoint, format, false);
}
const string Easy::strtime(const system_clock::time_point &timepoint,
const string &format, const bool &utc)
{
constexpr std::uint_fast16_t bufsize = 1024;
std::time_t time = system_clock::to_time_t(timepoint);
std::tm *timeinfo;
if (utc)
{
timeinfo = std::gmtime(&time);
}
else
{
timeinfo = std::localtime(&time);
}
char buffer[bufsize];
std::strftime(buffer, bufsize, format.c_str(), timeinfo);
return buffer;
}
Easy::Link::Link(const string &link_header)
: _next(0)
, _prev(0)
: _next()
, _prev()
{
std::regex renext("max_id=([[:digit:]]*)");
std::regex reprev("since_id=([[:digit:]]*)");
std::regex renext("max_id=([[:alnum:]]*)");
std::regex reprev("(?:since|min)_id=([[:alnum:]]*)");
std::smatch match;
if (std::regex_search(link_header, match, renext))
{
_next = std::stoull(match[1].str());
_next = match[1].str();
}
if (std::regex_search(link_header, match, reprev))
{
_prev = std::stoull(match[1].str());
_prev = match[1].str();
}
}
const uint_fast64_t Easy::Link::next() const
const string Easy::Link::next() const
{
return _next;
}
const uint_fast64_t Easy::Link::max_id() const
const string Easy::Link::max_id() const
{
return _next;
}
const uint_fast64_t Easy::Link::prev() const
const string Easy::Link::prev() const
{
return _prev;
}
const uint_fast64_t Easy::Link::since_id() const
const string Easy::Link::since_id() const
{
return _prev;
}
const string Easy::Link::min_id() const
{
return _prev;
}

View File

@ -1,16 +1,16 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@ -19,359 +19,182 @@
#include <string>
#include <cstdint>
#include <chrono>
#include <vector>
#include <utility>
#include <functional>
#include <ostream>
#include <jsoncpp/json/json.h>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#endif
#include "../mastodon-cpp.hpp"
#include "return_types_easy.hpp"
#include "types_easy.hpp"
#include "entities/notification.hpp"
#include "entities/status.hpp"
using std::string;
using std::uint_fast64_t;
using std::chrono::system_clock;
using std::vector;
using std::uint64_t;
using std::uint16_t;
namespace Mastodon
{
/*!
* @brief Child of Mastodon::API with abstract methods.
* @brief Collection of things that make it easier to interface with server
* software that implements the Mastodon API.
*/
class Easy : public API
namespace Easy
{
public:
/*!
* @brief Describes the event type
*/
enum class event_type
{
Update,
Notification,
Delete,
Undefined
};
/*!
* @brief Describes visibility of toots.
*/
enum class visibility_type
{
Direct,
Private,
Unlisted,
Public,
Undefined
};
/*!
* @brief Describes the attachment type
*/
enum class attachment_type
{
Image,
Video,
Gifv,
Unknown,
Undefined
};
/*!
* @brief Describes the card type
*/
enum class card_type
{
Link,
Photo,
Video,
Rich,
Undefined
};
/*!
* @brief Describes the notification type
*/
enum class notification_type
{
Mention,
Reblog,
Favourite,
Follow,
Undefined
};
/*!
* @brief Used for stream events.
*/
typedef std::pair<event_type, string> stream_event;
/*!
* @brief Map of 'notification type' and 'push is requested or not'
*
* Used in PushSubscription::alerts().
*/
typedef std::map<Easy::notification_type, bool> alertmap;
/*!
* @brief Class to hold the `Link`-header.
*
*
* Extracts max_id and since_id from the `Link`-header
*
* @since before 0.11.0
*/
// TODO: Convert to struct?
class Link
{
public:
/*!
* @param link_header The content of the `Link` header
*
* @since before 0.11.0
*/
explicit Link(const string &link_header);
/*!
* @brief Returns max_id
*
* @since before 0.11.0
*/
const uint_fast64_t next() const;
const string next() const;
/*!
* @brief Returns max_id
*
* @since before 0.11.0
*/
const uint_fast64_t max_id() const;
const string max_id() const;
/*!
* @brief Returns since_id
*
* @since before 0.11.0
*/
const uint_fast64_t prev() const;
const string prev() const;
/*!
* @brief Returns since_id
*
* @since before 0.11.0
*/
const uint_fast64_t since_id() const;
const string since_id() const;
/*!
* @brief Returns min_id.
*
* @since 0.111.0
*/
const string min_id() const;
private:
uint_fast64_t _next;
uint_fast64_t _prev;
string _next;
string _prev;
};
/*!
* @brief Constructs a new Easy object.
*
* To register your application, leave access_token blank and call
* register_app1() and register_app2().
*
* @param instance The hostname of your instance
* @param access_token The access token
*/
explicit Easy(const string &instance, const string &access_token);
/*!
* @brief Turns a JSON array into a vector of strings
*
* @param json JSON string holding the array
*
* @return vector of strings or an empty vector on error
*
* @since before 0.11.0
*/
static const std::vector<string> json_array_to_vector(const string &json);
const vector<string> json_array_to_vector(const string &json);
/*!
* @brief Split stream into a vector of events
*
* @param streamdata Data from get_stream()
*
* @return vector of stream events
*/
static const std::vector<stream_event>
parse_stream(const std::string &streamdata);
/*!
* @brief Gets the links from the last answer
*/
const Link get_link() const;
/*!
* @brief Converts a time_point to a string
*
* The return value can not exceed 1023 chars.
* @return vector of Easy::stream_event
*
* @param timepoint The timepoint
* @param format The format of the string, same as with `strftime`.
*
* Example:
* @code
* auto timepoint = status.created_at();
* cout << Easy::strtime_utc(timepoint, "%F, %T") << '\n';
* @endcode
*
* @return The UTC time as string
*
* @since 0.11.0
* @since before 0.11.0
*/
static const string strtime_utc(const system_clock::time_point &timepoint,
const string &format);
const vector<stream_event_type> parse_stream(const std::string &streamdata);
/*!
* @brief See strtime_utc
* @brief Convert ISO 8601 time string to Easy::time.
*
* @return The local time as string
*
* @since 0.11.0
* @param strtime Time string as returned by Mastodon.
*/
static const string strtime_local(const system_clock::time_point &timepoint,
const string &format);
const Easy::time_type string_to_time(const string &strtime);
/*!
* @brief Base class for all entities.
* @brief Child of Mastodon::API with abstract methods.
*
* Provides convenient functions to deal with the responses you get.
*/
class Entity
class API : public Mastodon::API
{
public:
/*!
* @brief Constructs an Entity object from a JSON string.
* @brief Constructs a new Easy object.
*
* @param json JSON string
*/
explicit Entity(const string &json);
/*!
* @brief Constructs an empty Entity object.
*/
Entity();
/*!
* @brief Replaces the Entity with a new one from a JSON string.
* To register your application, leave access_token blank and
* call register_app1() and register_app2().
*
* @param json JSON string
*/
const void from_string(const string &json);
/*!
* @brief Returns the JSON object of the Entity
* @param instance The hostname of your instance
* @param access_token The access token
*
* @return JSON object
* @since 0.100.0
*/
const Json::Value to_object() const;
explicit API(const string &instance, const string &access_token);
/*!
* @brief Returns true if the Entity holds valid data
*/
const bool valid() const;
/*!
* @brief Returns error string sent by the server
*/
const string error() const;
/*!
* @brief Returns true if the last requested value was set, false if
* it was unset.
*
* Members of Easy::Entity-derived classes return a default
* value depending on its type when the requested value is not
* found in the JSON. "" for strings, false for bools and so
* on. Most of the time this is no problem, but sometimes you
* need to know for sure.
*
* Example:
* @code
* Easy::Account a(jsonstring);
* if (a.note().empty())
* {
* if (a.was_set())
* {
* cout << "Account has an empty description.\n";
* }
* else
* {
* cout << "Account has no description.\n";
* }
* }
* @endcode
*/
const bool was_set() const;
protected:
/*!
* @brief Returns the value of key as Json::Value
* @brief Gets the links from the last answer
*
* Returns an empty object if the value does not exist or is
* null.
* @since 0.100.0
*/
const Json::Value get(const string &key) const;
const Link get_link() const;
/*!
* @brief Returns the value of key as std::string
*
* returns "" if the value does not exist or is null.
* @brief Sends a post.
*
* @param status The status to send
*
* @return The new Easy::Status
*
* @since 0.100.0
*/
const string get_string(const string &key) const;
[[deprecated("Will go away in 1.0.0 with no replacement.")]]
const return_entity<Easy::Status> send_post(const Status &status);
/*!
* @brief Returns the value of key as std::uint_fast64_t
*
* Returns 0 if the value does not exist or is null.
* @brief Alias for send_post()
*
* @since 0.100.0
*/
const uint_fast64_t get_uint64(const string &key) const;
[[deprecated("Will go away in 1.0.0 with no replacement.")]]
const return_entity<Easy::Status> send_toot(const Status &status);
/*!
* @brief Returns the value of key as double
*
* Returns 0.0 if the value does not exist or is null.
* @brief Gets notifications.
*
* @param limit Maximum number of notifications
* @param since_id Return notifications newer than ID
* @param max_id Return notifications older than ID
*
* @return vector of Easy::Notification.
*
* @since 0.100.0
*/
const double get_double(const string &key) const;
// TODO: Maybe an enum would be better?
/*!
* @brief Returns the value of key as bool
*
* Returns false if the value does not exist or is null.
*/
const bool get_bool(const string &key) const;
/*!
* @brief Returns the value of key as time_point
*
* Returns clocks epoch if the value does not exist or is null.
*/
const system_clock::time_point get_time_point(const string &key) const;
/*!
* @brief Returns the value of key as vector
*
* Returns an empty vector if the value does not exist or is
* null.
*/
const std::vector<string> get_vector(const string &key) const;
const std::uint_fast64_t stouint64(const string &str) const;
private:
Json::Value _tree;
bool _valid;
mutable bool _was_set;
[[deprecated("Will go away in 1.0.0 with no replacement.")]]
const return_entity_vector<Easy::Notification> get_notifications(
const uint16_t limit = 20, const string since_id = "",
const string max_id = "");
};
class Account;
class Application;
class Attachment;
class Card;
class Context;
class Emoji;
class Instance;
class List;
class Mention;
class Notification;
class Relationship;
class Report;
class Results;
class Status;
class Tag;
class PushSubscription;
protected:
inline static const string strtime
(const system_clock::time_point &timepoint,
const string &format, const bool &utc);
};
}
}
#endif // MASTODON_EASY_CPP_HPP

View File

@ -1,32 +1,49 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <algorithm>
#include "account.hpp"
#include "macros.hpp"
#include "debug.hpp"
#include "easy/easy.hpp"
using namespace Mastodon;
using Account = Easy::Account;
Account::Account(const string &json)
: Entity(json)
{}
Account::Account()
: Entity()
{}
bool Account::valid() const
{
return Entity::check_valid(
{
"id",
"username",
"acct",
"display_name",
"locked",
"created_at",
"followers_count",
"following_count",
"statuses_count",
"note",
"url",
"avatar",
"avatar_static",
"header",
"header_static",
"emojis"
});
}
const string Account::acct() const
{
@ -43,14 +60,14 @@ const string Account::avatar_static() const
return get_string("avatar_static");
}
const bool Account::bot() const
bool Account::bot() const
{
return get_bool("bot");
}
const system_clock::time_point Account::created_at() const
const Easy::time_type Account::created_at() const
{
return get_time_point("created_at");
return get_time("created_at");
}
const string Account::display_name() const
@ -58,30 +75,54 @@ const string Account::display_name() const
return get_string("display_name");
}
const std::vector<Account::fields_pair> Account::fields() const
const std::vector<Easy::Emoji> Account::emojis()
{
const Json::Value &node = get("fields");
const Json::Value &node = get("emojis");
if (node.isArray())
{
std::vector<Account::fields_pair> vec;
for (const Json::Value &value : node)
{
vec.push_back(Account::fields_pair(value["name"].asString(),
value["value"].asString()));
}
std::vector<Easy::Emoji> vec;
std::transform(node.begin(), node.end(), std::back_inserter(vec),
[](const Json::Value &value)
{
return Easy::Emoji(value);
});
return vec;
}
return {};
}
const std::uint_fast64_t Account::followers_count() const
const vector<Easy::account_field_type> Account::fields() const
{
const Json::Value &node = get("fields");
if (node.isArray())
{
vector<Easy::account_field_type> vec;
std::transform(node.begin(), node.end(), std::back_inserter(vec),
[](const Json::Value &value)
{
return Easy::account_field_type(
{
value["name"].asString(),
value["value"].asString(),
Easy::string_to_time(
value["verified_at"].asString())
});
});
return vec;
}
return {};
}
std::uint64_t Account::followers_count() const
{
return get_uint64("followers_count");
}
const std::uint_fast64_t Account::following_count() const
std::uint64_t Account::following_count() const
{
return get_uint64("following_count");
}
@ -96,17 +137,17 @@ const string Account::header_static() const
return get_string("header_static");
}
const std::uint_fast64_t Account::id() const
const string Account::id() const
{
return stouint64(get_string("id"));
return get_string("id");
}
const bool Account::locked() const
bool Account::locked() const
{
return get_bool("locked");
}
const bool Account::has_moved() const
bool Account::has_moved() const
{
if (get("moved").isObject())
{
@ -120,8 +161,7 @@ const Account Account::moved() const
{
if (has_moved())
{
// TODO: Find an account with moved-node and test
return Account(get("moved").toStyledString());
return Account(get("moved"));
}
return Account();
@ -129,36 +169,35 @@ const Account Account::moved() const
const string Account::note() const
{
return get_string("source.note");
return get_string("note");
}
const string Account::note_plain() const
Easy::visibility_type Account::privacy() const
{
return get_string("source.note");
}
const Easy::visibility_type Account::privacy() const
{
const string strprivacy = get_string("source.privacy");
if (strprivacy.compare("public") == 0)
const string strprivacy = get_string("privacy");
if (strprivacy == "public")
return visibility_type::Public;
else if (strprivacy.compare("unlisted") == 0)
else if (strprivacy == "unlisted")
return visibility_type::Unlisted;
else if (strprivacy.compare("private") == 0)
else if (strprivacy == "private")
return visibility_type::Private;
else if (strprivacy.compare("direct") == 0)
else if (strprivacy == "direct")
return visibility_type::Direct;
ttdebug << "Could not get data: source.privacy\n";
return visibility_type::Undefined;
}
const bool Account::sensitive() const
bool Account::sensitive() const
{
return get_bool("source.sensitive");
}
const std::uint_fast64_t Account::statuses_count() const
const Account::Source Account::source() const
{
return Account::Source(get("source"));
}
std::uint64_t Account::statuses_count() const
{
return get_uint64("statuses_count");
}
@ -172,3 +211,66 @@ const string Account::username() const
{
return get_string("username");
}
bool Account::Source::valid() const
{
return Entity::check_valid(
{
"note",
"fields"
});
}
const vector<Easy::account_field_type> Account::Source::fields() const
{
const Json::Value &node = get("fields");
if (node.isArray())
{
vector<Easy::account_field_type> vec;
std::transform(node.begin(), node.end(), std::back_inserter(vec),
[](const Json::Value &value)
{
return Easy::account_field_type(
{
value["name"].asString(),
value["value"].asString(),
Easy::string_to_time(
value["verified_at"].asString())
});
});
return vec;
}
return {};
}
const string Account::Source::language() const
{
return get_string("language");
}
const string Account::Source::note() const
{
return get_string("note");
}
Easy::visibility_type Account::Source::privacy() const
{
const string strprivacy = get_string("privacy");
if (strprivacy == "public")
return visibility_type::Public;
else if (strprivacy == "unlisted")
return visibility_type::Unlisted;
else if (strprivacy == "private")
return visibility_type::Private;
else if (strprivacy == "direct")
return visibility_type::Direct;
return visibility_type::Undefined;
}
bool Account::Source::sensitive() const
{
return get_bool("sensitive");
}

View File

@ -1,16 +1,16 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@ -19,166 +19,247 @@
#include <string>
#include <cstdint>
#include <chrono>
#include <vector>
#include <utility>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy/easy.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/easy.hpp>
#endif
#include "../../mastodon-cpp.hpp"
#include "../entity.hpp"
#include "emoji.hpp"
using std::string;
using std::uint_fast64_t;
using std::chrono::system_clock;
using std::uint64_t;
using std::vector;
namespace Mastodon
{
namespace Easy
{
/*!
* @brief Class to hold accounts.
*
* @since before 0.11.0
*/
class Easy::Account : public Easy::Entity
class Account : public Entity
{
public:
/*!
* @brief Describes a field. Format: name, value
*
* @since 0.16.1
*/
using fields_pair = std::pair<const string, const string>;
using Entity::Entity;
/*!
* @brief Constructs an Account object from a JSON string.
*
* @param json JSON string
*/
explicit Account(const string &json);
/*!
* @brief Constructs an empty Account object.
*/
Account();
virtual bool valid() const override;
/*!
* @brief Returns username
*
* `username` for users on the same instance, `user@hostname`
* for users on other instances.
*
* @since before 0.11.0
*/
const string acct() const;
/*!
* @brief Returns URL of avatar
* @brief Returns URL of avatar.
*
* @since before 0.11.0
*/
const string avatar() const;
/*!
* @brief Returns URL of static avatar
* @brief Returns URL of static avatar.
*
* @since before 0.11.0
*/
const string avatar_static() const;
/*!
* @brief Returns true if the account performs automated actions
* @brief Returns true if the account performs automated actions.
*
* @since 0.16.0
*/
const bool bot() const;
bool bot() const;
/*!
* @brief Returns time of creation
* @brief Returns time of creation.
*
* @since before 0.11.0
*/
const system_clock::time_point created_at() const;
const Easy::time_type created_at() const;
/*!
* @brief Returns display name
* @brief Returns display name.
*
* @since before 0.11.0
*/
const string display_name() const;
/*!
* @brief Returns metadata fields
*
* @brief Returns emojis.
*
* @since 0.106.0
*/
const std::vector<Easy::Emoji> emojis();
/*!
* @brief Returns metadata fields.
*
* @since 0.16.1
*/
const std::vector<fields_pair> fields() const;
const vector<Easy::account_field_type> fields() const;
/*!
* @brief Returns number of followers
* @brief Returns number of followers.
*
* @since before 0.11.0
*/
const uint_fast64_t followers_count() const;
uint64_t followers_count() const;
/*!
* @brief Returns number of people this account follows
* @brief Returns number of people this account follows.
*
* @since before 0.11.0
*/
const uint_fast64_t following_count() const;
uint64_t following_count() const;
/*!
* @brief Returns URL of header image
* @brief Returns URL of header image.
*
* @since before 0.11.0
*/
const string header() const;
/*!
* @brief Returns URL of static header image
* @brief Returns URL of static header image.
*
* @since before 0.11.0
*/
const string header_static() const;
/*!
* @brief Returns account-ID
* @brief Returns account-ID.
*
* @since before 0.11.0
*/
const uint_fast64_t id() const;
const string id() const;
/*!
* @brief Returns true if the account is locked
* @brief Returns true if the account is locked.
*
* @since before 0.11.0
*/
const bool locked() const;
bool locked() const;
/*!
* @brief Returns true if the account has been moved
* @brief Returns true if the account has been moved. (Deprecated)
*
* @since before 0.11.0
*/
const bool has_moved() const;
bool has_moved() const;
/*!
* @brief If the owner decided to switch accounts, new account is in
* this attribute
* this attribute.
*
* @since before 0.11.0
*/
const Account moved() const;
/*!
* @brief Returns note
* @brief Returns account description, or biography.
*
* @since before 0.11.0
*/
const string note() const;
/*!
* @brief Returns plaintext version of note
* @brief Returns default privacy of new toots.
*
* @since before 0.11.0
*/
const string note_plain() const;
visibility_type privacy() const;
/*!
* @brief Returns default privacy of new toots
* @brief Returns if media is marked as sensitive by default.
*
* @since before 0.11.0
*/
const visibility_type privacy() const;
bool sensitive() const;
/*!
* @brief Returns if media is marked as sensitive by default
* @brief Class to hold source attribute.
*
* @since 0.18.5
*/
const bool sensitive() const;
class Source : public Entity
{
public:
using Entity::Entity;
virtual bool valid() const override;
/*!
* @brief Returns metadata fields.
*
* @since 0.18.5
*/
const vector<Easy::account_field_type> fields() const;
/*!
* @brief Returns the language as ISO 6391 string.
*
* @since 0.106.0
*/
const string language() const;
/*!
* @brief Returns account description in plain text.
*
* @since 0.18.5
*/
const string note() const;
/*!
* @brief Returns default privacy of new toots.
*
* @since 0.18.5
*/
visibility_type privacy() const;
/*!
* @brief Returns if media is marked as sensitive by default.
*
* @since 0.18.5
*/
bool sensitive() const;
};
/*!
* @brief Get source.
*
* @since before 0.100.0
*/
const Source source() const;
/*!
* @brief Returns number of statuses
*
* @since before 0.11.0
*/
const uint_fast64_t statuses_count() const;
uint64_t statuses_count() const;
/*!
* @brief Returns URL of the profile
*
* @since before 0.11.0
*/
const string url() const;
/*!
* @brief Returns username (without @hostname)
* @brief Returns username (without \@hostname)
*
* @since before 0.11.0
*/
const string username() const;
};
}
}
#endif // MASTODON_CPP_EASY_ACCOUNT_HPP

View File

@ -1,16 +1,16 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@ -19,13 +19,10 @@
using namespace Mastodon;
using Application = Easy::Application;
Application::Application(const string &json)
: Entity(json)
{}
Application::Application()
: Entity()
{}
bool Application::valid() const
{
return Entity::check_valid({"name"});
}
const string Application::name() const
{

View File

@ -1,16 +1,16 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@ -19,47 +19,42 @@
#include <string>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy/easy.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/easy.hpp>
#endif
#include "../../mastodon-cpp.hpp"
#include "../entity.hpp"
using std::string;
namespace Mastodon
{
namespace Easy
{
/*!
* @brief Class to hold applications.
*
* @since before 0.11.0
*/
class Easy::Application : public Easy::Entity
class Application : public Entity
{
public:
/*!
* @brief Constructs an Application object from a JSON string.
*
* @param json JSON string
*/
explicit Application(const string &json);
using Entity::Entity;
/*!
* @brief Constructs an empty Application object.
*/
Application();
virtual bool valid() const override;
/*!
* @brief Returns the name of the application
*
* @since before 0.11.0
*/
const string name() const;
/*!
* @brief Returns the website of the application
*
* @since before 0.11.0
*/
const string website() const;
};
}
}
#endif // MASTODON_CPP_EASY_APPLICATION_HPP

View File

@ -1,47 +1,35 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sstream>
#include "attachment.hpp"
#include "macros.hpp"
#include "debug.hpp"
using namespace Mastodon;
using Attachment = Easy::Attachment;
Attachment::Attachment(const string &json)
: Entity(json)
{}
Attachment::Attachment()
: Entity()
{}
const double Attachment::aspect() const
bool Attachment::valid() const
{
return get_double("meta.original.aspect");
}
const double Attachment::aspect_small() const
{
return get_double("meta.small.aspect");
}
const uint_fast64_t Attachment::bitrate() const
{
return get_uint64("meta.original.bitrate");
return Entity::check_valid(
{
"id",
"type",
"url",
"preview_url"
});
}
const string Attachment::description() const
@ -49,13 +37,24 @@ const string Attachment::description() const
return get_string("description");
}
const std::chrono::duration<double> Attachment::duration() const
Attachment Attachment::description(const string &description)
{
const double sec = get_double("meta.original.duration");
return std::chrono::duration<double>(sec);
set("description", Json::Value(description));
return *this;
}
const string Attachment::file() const
{
return get_string("file");
}
Attachment Attachment::file(const string &file)
{
set("file", Json::Value(file));
return *this;
}
const std::array<double, 2> Attachment::focus() const
{
const Json::Value x = get("meta.focus.x");
@ -72,38 +71,21 @@ const std::array<double, 2> Attachment::focus() const
return {};
}
const double Attachment::framerate() const
Attachment Attachment::focus(const std::array<double, 2> &focus)
{
string strframes = get_string("meta.original.frame_rate");
if (!strframes.empty())
{
std::size_t pos = strframes.find('/');
if (pos != std::string::npos)
{
std::uint_fast16_t frames = std::stoul(strframes.substr(0, pos));
std::uint_fast16_t divider = std::stoul(strframes.substr(pos + 1));
return frames / divider;
}
}
return 0.0;
set("meta.focus.x", Json::Value(focus[0]));
set("meta.focus.y", Json::Value(focus[1]));
return *this;
}
const uint_fast64_t Attachment::height() const
const string Attachment::id() const
{
return get_uint64("meta.original.height");
return get_string("id");
}
const uint_fast64_t Attachment::height_small() const
const Attachment::Meta Attachment::meta() const
{
return get_uint64("meta.small.height");
}
const std::uint_fast64_t Attachment::id() const
{
return stouint64(get_string("id"));
return Meta(get("meta"));
}
const string Attachment::preview_url() const
@ -116,22 +98,12 @@ const string Attachment::remote_url() const
return get_string("remote_url");
}
const string Attachment::size() const
{
return get_string("meta.original.size");
}
const string Attachment::size_small() const
{
return get_string("meta.small.size");
}
const string Attachment::text_url() const
{
return get_string("text_url");
}
const Easy::attachment_type Attachment::type() const
Easy::attachment_type Attachment::type() const
{
const string strtype = get_string("type");
if (strtype.compare("image") == 0)
@ -152,12 +124,78 @@ const string Attachment::url() const
return get_string("url");
}
const uint_fast64_t Attachment::width() const
bool Attachment::Meta::valid() const
{
return get_uint64("meta.original.width");
return true;
}
const uint_fast64_t Attachment::width_small() const
double Attachment::Meta::aspect() const
{
return get_uint64("meta.small.width");
return get_double("original.aspect");
}
double Attachment::Meta::aspect_small() const
{
return get_double("small.aspect");
}
uint64_t Attachment::Meta::bitrate() const
{
return get_uint64("original.bitrate");
}
const std::chrono::duration<double> Attachment::Meta::duration() const
{
const double sec = get_double("original.duration");
return std::chrono::duration<double>(sec);
}
double Attachment::Meta::frame_rate() const
{
string strframes = get_string("original.frame_rate");
if (!strframes.empty())
{
std::size_t pos = strframes.find('/');
if (pos != std::string::npos)
{
std::uint16_t frames = std::stoul(strframes.substr(0, pos));
std::uint16_t divider = std::stoul(strframes.substr(pos + 1));
return frames / divider;
}
}
return 0.0;
}
uint64_t Attachment::Meta::height() const
{
return get_uint64("original.height");
}
uint64_t Attachment::Meta::height_small() const
{
return get_uint64("small.height");
}
const string Attachment::Meta::size() const
{
return get_string("original.size");
}
const string Attachment::Meta::size_small() const
{
return get_string("small.size");
}
uint64_t Attachment::Meta::width() const
{
return get_uint64("original.width");
}
uint64_t Attachment::Meta::width_small() const
{
return get_uint64("small.width");
}

View File

@ -1,16 +1,16 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@ -22,136 +22,216 @@
#include <chrono>
#include <array>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy/easy.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/easy.hpp>
#endif
#include "../../mastodon-cpp.hpp"
#include "../entity.hpp"
using std::string;
using std::uint_fast64_t;
using std::uint64_t;
namespace Mastodon
{
namespace Easy
{
/*!
* @brief Class to hold attachments
*
* @since before 0.11.0
*/
class Easy::Attachment : public Easy::Entity
class Attachment : public Entity
{
public:
using Entity::Entity;
/*!
* @brief Constructs an Attachment object from a JSON string.
* @brief Metadata for attachments.
*
* @param json JSON string
* @since 0.106.0
*/
explicit Attachment(const string &json);
class Meta : public Entity
{
public:
using Entity::Entity;
/*!
* @brief Constructs an empty Attachment object.
*/
Attachment();
virtual bool valid() const override;
/*!
* @brief Aspect of original image
*/
const double aspect() const;
/*!
* @brief Aspect of original image.
*
* @since 0.106.0
*/
double aspect() const;
/*!
* @brief Aspect of preview image
*/
const double aspect_small() const;
/*!
* @brief Aspect of preview image.
*
* @since 0.106.0
*/
double aspect_small() const;
/*!
* @brief Returns the bitrate of a video.
*
* @since 0.106.0
*/
uint64_t bitrate() const;
/*!
* @brief Returns the duration of a video in seconds.
*
* @since 0.106.0
*/
const std::chrono::duration<double> duration() const;
/*!
* @brief Returns the framerate of a video in frames per second.
*
* @since 0.106.0
*/
double frame_rate() const;
/*!
* @brief Returns the height of the original image.
*
* @since 0.106.0
*/
uint64_t height() const;
/*!
* @brief Returns the height of the preview image.
*
* @since 0.106.0
*/
uint64_t height_small() const;
/*!
* @brief Returns the size of the original image.
*
* @since 0.106.0
*/
const string size() const;
/*!
* @brief Returns the size of the preview image.
*
* @since 0.106.0
*/
const string size_small() const;
/*!
* @brief Returns the width of the original image.
*
* @since 0.106.0
*/
uint64_t width() const;
/*!
* @brief Returns the width of the preview image
*
* @since 0.106.0
*/
uint64_t width_small() const;
};
virtual bool valid() const override;
/*!
* @brief Returns the bitrate of a video
*/
const uint_fast64_t bitrate() const;
/*!
* @brief Returns the image description
*
* @since before 0.11.0
*/
const string description() const;
/*!
* @brief Returns the duration of a video in seconds
* @brief Sets the image description
*
* @since 0.17.0
*/
const std::chrono::duration<double> duration() const;
Attachment description(const string &description);
/*!
* @brief Gets file to upload
*
* @since 0.17.0
*/
const string file() const;
/*!
* @brief Sets file to upload
*
* @since 0.17.0
*
* @param file Filename
*/
Attachment file(const string &file);
/*!
* @brief Returns the focus point (x, y)
*
*
* Values are between -1.0 and 1.0.
*
* @since before 0.11.0
*/
const std::array<double, 2> focus() const;
/*!
* @brief Returns the framerate of a video in frames per second
* @brief Sets the focus point (x, y)
*
* Values are between -1.0 and 1.0.
*
* @since 0.17.0
*/
const double framerate() const;
/*!
* @brief Returns the height of the original image
*/
const uint_fast64_t height() const;
/*!
* @brief Returns the height of the preview image
*/
const uint_fast64_t height_small() const;
Attachment focus(const std::array<double, 2> &focus);
/*!
* @brief Returns the ID of the attachment
*
* @since before 0.11.0
*/
const uint_fast64_t id() const;
const string id() const;
/*!
* @brief Returns metadata about the attachment.
*
* @since 0.106.0
*/
const Meta meta() const;
/*!
* @brief Returns the URL of the preview image
*
* @since before 0.11.0
*/
const string preview_url() const;
/*!
* @brief Returns the remote URL of the original image
*
* @since before 0.11.0
*/
const string remote_url() const;
/*!
* @brief Returns the size of the original image
*/
const string size() const;
/*!
* @brief Returns the size of the preview image
*/
const string size_small() const;
/*!
* @brief Returns shorter URL for the image
*
* @since before 0.11.0
*/
const string text_url() const;
/*!
* @brief Returns attachment type
*
* @since before 0.11.0
*/
const attachment_type type() const;
attachment_type type() const;
/*!
* @brief Returns URL of the locally hosted version of the image
*
* @since before 0.11.0
*/
const string url() const;
/*!
* @brief Returns the width of the original image
*/
const uint_fast64_t width() const;
/*!
* @brief Returns the width of the preview image
*/
const uint_fast64_t width_small() const;
};
}
}
#endif // MASTODON_CPP_EASY_ATTACHMENT_HPP

View File

@ -1,32 +1,35 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "card.hpp"
#include "macros.hpp"
#include "debug.hpp"
using namespace Mastodon;
using Card = Easy::Card;
Card::Card(const string &json)
: Entity(json)
{}
Card::Card()
: Entity()
{}
bool Card::valid() const
{
return Entity::check_valid(
{
"url",
"title",
"description",
"type"
});
}
const string Card::author_name() const
{
@ -43,7 +46,12 @@ const string Card::description() const
return get_string("description");
}
const uint_fast64_t Card::height() const
const string Card::embed_url() const
{
return get_string("embed_url");
}
uint64_t Card::height() const
{
return get_uint64("height");
}
@ -73,20 +81,19 @@ const string Card::title() const
return get_string("title");
}
const Easy::card_type Card::type() const
Easy::card_type Card::type() const
{
const string strtype = get_string("type");
if (strtype.compare("link") == 0)
if (strtype == "link")
return card_type::Link;
else if (strtype.compare("photo") == 0)
else if (strtype == "photo")
return card_type::Photo;
else if (strtype.compare("video") == 0)
else if (strtype == "video")
return card_type::Video;
else if (strtype.compare("rich") == 0)
else if (strtype == "rich")
return card_type::Rich;
ttdebug << "Could not get data: type\n";
return card_type::Undefined;
else
return card_type::Undefined;
}
const string Card::url() const
@ -94,7 +101,7 @@ const string Card::url() const
return get_string("url");
}
const uint_fast64_t Card::width() const
uint64_t Card::width() const
{
return get_uint64("width");
}

View File

@ -1,16 +1,16 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@ -20,98 +20,122 @@
#include <string>
#include <cstdint>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy/easy.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/easy.hpp>
#endif
#include "../../mastodon-cpp.hpp"
#include "../entity.hpp"
using std::string;
using std::uint_fast64_t;
using std::uint64_t;
namespace Mastodon
{
namespace Easy
{
/*!
* @brief Class to hold cards
*
* @since before 0.11.0
*/
class Easy::Card : public Easy::Entity
class Card : public Entity
{
public:
/*!
* @brief Constructs a Card object from a JSON string.
*
* @param json JSON string
*/
explicit Card(const string &json);
using Entity::Entity;
/*!
* @brief Constructs an empty Card object.
*/
Card();
virtual bool valid() const override;
/*!
* @brief Returns the name of the author
*
* @since before 0.11.0
*/
const string author_name() const;
/*!
* @brief Returns the URL of the author
*
* @since before 0.11.0
*/
const string author_url() const;
/*!
* @brief Returns the description
*
* @since before 0.11.0
*/
const string description() const;
/*!
* @brief Returns the height of the card
* @brief Returns the embed URL.
*
* This is an undocumented attribute and may vanish at any time.
*
* @since 0.106.0
*/
const uint_fast64_t height() const;
const string embed_url() const;
/*!
* @brief Returns the height of the card
*
* @since before 0.11.0
*/
uint64_t height() const;
/*!
* @brief Returns the HTML
*
* @since before 0.11.0
*/
const string html() const;
/*!
* @brief Returns the URL of the image associated with the card
*
* @since before 0.11.0
*/
const string image() const;
/*!
* @brief Returns the name of the provider
*
* @since before 0.11.0
*/
const string provider_name() const;
/*!
* @brief Returns the URL of the provider
*
* @since before 0.11.0
*/
const string provider_url() const;
/*!
* @brief Returns the title
*
* @since before 0.11.0
*/
const string title() const;
/*!
* @brief Returns the type of the card
*
* @since before 0.11.0
*/
const Easy::card_type type() const;
Easy::card_type type() const;
/*!
* @brief Returns the URL associated with the card
*
* @since before 0.11.0
*/
const string url() const;
/*!
* @brief Returns the width of the card
*
* @since before 0.11.0
*/
const uint_fast64_t width() const;
uint64_t width() const;
};
}
}
#endif // MASTODON_CPP_EASY_CARD_HPP

View File

@ -1,32 +1,34 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <algorithm>
#include "context.hpp"
#include "macros.hpp"
#include "debug.hpp"
using namespace Mastodon;
using Context = Easy::Context;
Context::Context(const string &json)
: Entity(json)
{}
Context::Context()
: Entity()
{}
bool Context::valid() const
{
return Entity::check_valid(
{
"ancestors",
"descendants"
});
}
const std::vector<Easy::Status> Context::ancestors() const
{
@ -34,14 +36,12 @@ const std::vector<Easy::Status> Context::ancestors() const
if (node.isArray())
{
std::vector<Easy::Status> vec;
for (const Json::Value &value : node)
{
vec.push_back(Easy::Status(value.toStyledString()));
}
std::transform(node.begin(), node.end(), std::back_inserter(vec),
[](const Json::Value &value)
{ return Easy::Status(value); });
return vec;
}
ttdebug << "Could not get data: ancestors\n";
return {};
}
@ -51,13 +51,11 @@ const std::vector<Easy::Status> Context::descendants() const
if (node.isArray())
{
std::vector<Easy::Status> vec;
for (const Json::Value &value : node)
{
vec.push_back(Easy::Status(value.toStyledString()));
}
std::transform(node.begin(), node.end(), std::back_inserter(vec),
[](const Json::Value &value)
{ return Easy::Status(value); });
return vec;
}
ttdebug << "Could not get data: descendants\n";
return {};
}

View File

@ -1,16 +1,16 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@ -20,49 +20,43 @@
#include <string>
#include <vector>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy/easy.hpp"
#include "easy/entities/status.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/easy.hpp>
#include <mastodon-cpp/easy/entities/status.hpp>
#endif
#include "../../mastodon-cpp.hpp"
#include "../entity.hpp"
#include "status.hpp"
using std::string;
namespace Mastodon
{
namespace Easy
{
/*!
* @brief Class to hold contexts
*
* @since before 0.11.0
*/
class Easy::Context : public Easy::Entity
class Context : public Entity
{
public:
/*!
* @brief Constructs a Context object from a JSON string.
*
* @param json JSON string
*/
explicit Context(const string &json);
using Entity::Entity;
/*!
* @brief Constructs an empty Context object.
*/
Context();
virtual bool valid() const override;
/*!
* @brief Returns the ancestors of the Status as vector of Statuses
*
* @since before 0.11.0
*/
const std::vector<Status> ancestors() const;
/*!
* @brief Returns the descendants of the Status as vector of Statuses
*
* @since before 0.11.0
*/
const std::vector<Status> descendants() const;
};
}
}
#endif // MASTODON_CPP_EASY_CONTEXT_HPP

View File

@ -0,0 +1,68 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <algorithm>
#include "conversation.hpp"
#include "debug.hpp"
using namespace Mastodon;
using Conversation = Easy::Conversation;
bool Conversation::valid() const
{
return Entity::check_valid(
{
"id",
"accounts",
"unread"
});
}
const string Conversation::id() const
{
return get_string("id");
}
const std::vector<Easy::Account> Conversation::accounts() const
{
const Json::Value node = get("accounts");
if (node.isArray())
{
std::vector<Easy::Account> vec;
std::transform(node.begin(), node.end(), std::back_inserter(vec),
[](const Json::Value &value)
{ return Easy::Account(value); });
return vec;
}
return {};
}
const Easy::Status Conversation::last_status() const
{
const Json::Value &node = get("last_status");
if (!node.isNull())
{
return Easy::Status(node);
}
return {};
}
bool Conversation::unread() const
{
return get_bool("unread");
}

View File

@ -0,0 +1,77 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MASTODON_CPP_EASY_CONVERSATION_HPP
#define MASTODON_CPP_EASY_CONVERSATION_HPP
#include <string>
#include <vector>
#include "../../mastodon-cpp.hpp"
#include "../entity.hpp"
#include "account.hpp"
#include "status.hpp"
using std::string;
namespace Mastodon
{
namespace Easy
{
/*!
* @brief Class to hold conversations.
*
* @since 0.110.0
*/
class Conversation : public Entity
{
public:
using Entity::Entity;
virtual bool valid() const override;
/*!
* @brief Returns the id of the conversation.
*
* @since 0.110.0
*/
const string id() const;
/*!
* @brief Returns the participating accounts.
*
* @since 0.110.0
*/
const std::vector<Account> accounts() const;
/*!
* @brief Returns the last status.
*
* @since 0.110.0
*/
const Status last_status() const;
/*!
* @brief Returns true if unread.
*
* @since 0.110.0
*/
bool unread() const;
};
}
}
#endif // MASTODON_CPP_EASY_CONVERSATION_HPP

View File

@ -1,32 +1,35 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "emoji.hpp"
#include "macros.hpp"
#include "debug.hpp"
using namespace Mastodon;
using Emoji = Easy::Emoji;
Emoji::Emoji(const string &json)
: Entity(json)
{}
Emoji::Emoji()
: Entity()
{}
bool Emoji::valid() const
{
return Entity::check_valid(
{
"shortcode",
"static_url",
"url",
"visible_in_picker"
});
}
const string Emoji::shortcode() const
{
@ -42,3 +45,8 @@ const string Emoji::url() const
{
return get_string("url");
}
bool Emoji::visible_in_picker() const
{
return get_bool("visible_in_picker");
}

View File

@ -1,16 +1,16 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@ -19,52 +19,56 @@
#include <string>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy/easy.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/easy.hpp>
#endif
#include "../../mastodon-cpp.hpp"
#include "../entity.hpp"
using std::string;
namespace Mastodon
{
namespace Easy
{
/*!
* @brief Class to hold emojis
* @brief Class to hold emojis.
*
* @since before 0.11.0
*/
class Easy::Emoji : public Easy::Entity
class Emoji : public Entity
{
public:
using Entity::Entity;
virtual bool valid() const override;
/*!
* @brief Constructs an Emoji object from a JSON string.
* @brief Returns the shortcode of the emoji.
*
* @param json JSON string
*/
explicit Emoji(const string &json);
/*!
* @brief Constructs an empty Emoji object.
*/
Emoji();
/*!
* @brief Returns the shortcode of the emoji
* @since before 0.11.0
*/
const string shortcode() const;
/*!
* @brief Returns the URL to the emoji static image
* @brief Returns the URL to the emoji static image.
*
* @since before 0.11.0
*/
const string static_url() const;
/*!
* @brief Returns the URL to the emoji image
* @brief Returns the URL to the emoji image.
*
* @since before 0.11.0
*/
const string url() const;
/*!
* @brief Returns if the emoji is visible in the picker.
*
* @since 0.106.0
*/
bool visible_in_picker() const;
};
}
}
#endif // MASTODON_CPP_EASY_EMOJI_HPP

View File

@ -0,0 +1,87 @@
/* This file is part of mastodon-cpp.
* Copyright © 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <vector>
#include <algorithm>
#include "filter.hpp"
using std::vector;
using namespace Mastodon;
using Filter = Easy::Filter;
bool Filter::valid() const
{
return Entity::check_valid(
{
"id",
"phrase",
"context",
"irreversible",
"whole_word"
});
}
const string Filter::id() const
{
return get_string("id");
}
const string Filter::phrase() const
{
return get_string("phrase");
}
const vector<Easy::context_type> Filter::context() const
{
const Json::Value node = get("context");
if (node.isArray())
{
vector<Easy::context_type> vec;
std::transform(node.begin(), node.end(), std::back_inserter(vec),
[](const Json::Value &value)
{
const string strtype = value.asString();
if (strtype == "home")
return Easy::context_type::Home;
else if (strtype == "notifications")
return Easy::context_type::Notifications;
else if (strtype == "public")
return Easy::context_type::Public;
else if (strtype == "thread")
return Easy::context_type::Thread;
else
return context_type::Undefined;
});
return vec;
}
return {};
}
const Easy::time_type Filter::expires_at() const
{
return get_time("expires_at");
}
bool Filter::irreversible() const
{
return get_bool("irreversible");
}
bool Filter::whole_word() const
{
return get_bool("whole_word");
}

View File

@ -0,0 +1,92 @@
/* This file is part of mastodon-cpp.
* Copyright © 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MASTODON_CPP_EASY_FILTER_HPP
#define MASTODON_CPP_EASY_FILTER_HPP
#include <string>
#include "../../mastodon-cpp.hpp"
#include "../entity.hpp"
using std::string;
namespace Mastodon
{
namespace Easy
{
/*!
* @brief Class to hold filters.
*
* @since 0.104.0
*/
class Filter : public Entity
{
public:
using Entity::Entity;
virtual bool valid() const override;
/*!
* @brief Returns the id of the filter
*
* @since 0.104.0
*/
const string id() const;
/*!
* @brief Returns the phrase to filter.
*
* @since 0.104.0
*/
const string phrase() const;
/*!
* @brief Returns the contexts in which to filter.
*
* @since 0.104.0
*/
const vector<Easy::context_type> context() const;
/*!
* @brief Returns the expiration time of the filter.
*
* @since 0.104.0
*/
const Easy::time_type expires_at() const;
/*!
* @brief Returns if the phrase should disappear irreversibly.
*
* If set to true, the filtered posts will be hidden even if filter is
* later removed.
*
* @since 0.104.0
*/
bool irreversible() const;
/*!
* @brief Returns if the filter should only be applied if it matches
* the whole word.
*
* @since 0.104.0
*/
bool whole_word() const;
};
}
}
#endif // MASTODON_CPP_EASY_FILTER_HPP

View File

@ -1,44 +1,50 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <jsoncpp/json/json.h>
#include "instance.hpp"
#include "account.hpp"
#include "macros.hpp"
#include "debug.hpp"
using namespace Mastodon;
using Instance = Easy::Instance;
Instance::Instance(const string &json)
: Entity(json)
{}
Instance::Instance()
: Entity()
{}
bool Instance::valid() const
{
return Entity::check_valid(
{
"uri",
"title",
"description",
"email",
"version",
"urls",
"stats",
"languages"
});
}
const Easy::Account Instance::contact_account() const
{
const Json::Value node = get("contact_account");
if (node.isObject())
{
return Easy::Account(node.toStyledString());
return Easy::Account(node);
}
ttdebug << "Could not get data: contact_account\n";
return Easy::Account();
}
@ -57,6 +63,15 @@ const std::vector<string> Instance::languages() const
return get_vector("languages");
}
const Easy::stats_type Instance::stats() const
{
Easy::stats_type s;
s.user_count = get_uint64("stats.user_count");
s.status_count = get_uint64("stats.status_count");
s.domain_count = get_uint64("stats.domain_count");
return s;
}
const string Instance::title() const
{
return get_string("title");
@ -67,12 +82,30 @@ const string Instance::uri() const
return get_string("uri");
}
const Easy::urls_type Instance::urls() const
{
return { get_string("urls.streaming_api") };
}
const string Instance::version() const
{
return get_string("version");
}
const string Instance::streaming_api() const
const string Instance::thumbnail() const
{
return get_string("urls.streaming_api");
return get_string("thumbnail");
}
uint64_t Instance::max_toot_chars() const
{
const uint64_t max_chars = get_uint64("max_toot_chars");
if (was_set())
{
return max_chars;
}
else
{
return 500;
}
}

View File

@ -1,16 +1,16 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@ -20,81 +20,113 @@
#include <string>
#include <vector>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy/easy.hpp"
#include "easy/entities/account.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/easy.hpp>
#include <mastodon-cpp/easy/entities/account.hpp>
#endif
using std::uint64_t;
#include "../../mastodon-cpp.hpp"
#include "../entity.hpp"
#include "account.hpp"
using std::string;
namespace Mastodon
{
namespace Easy
{
/*!
* @brief Class to hold instances
* @brief Class to hold instances.
*
* @since before 0.11.0
*/
class Easy::Instance : public Easy::Entity
class Instance : public Entity
{
public:
using Entity::Entity;
virtual bool valid() const override;
/*!
* @brief Constructs an Instance object from a JSON string.
* @brief Returns the Account of the admin or another contact person.
*
* @param json JSON string
*/
explicit Instance(const string &json);
/*!
* @brief Constructs an empty Instance object.
*/
Instance();
/*!
* @brief Returns the Account of the admin or another contact person
* @since before 0.11.0
*/
const Account contact_account() const;
/*!
* @brief Returns the description of the instance
* @brief Returns the description of the instance.
*
* @since before 0.11.0
*/
const string description() const;
/*!
* @brief Returns the email address which can be used to contact the
* instance administrator
* instance administrator.
*
* @since before 0.11.0
*/
const string email() const;
/*!
* @brief Returns a vector of ISO 6391 language codes the instance has
* chosen to advertise
* chosen to advertise.
*
* @since before 0.11.0
*/
const std::vector<string> languages() const;
const vector<string> languages() const;
/*!
* @brief Returns the title of the instance
* @brief Returns the thumbnail of the instance.
*
* @since 0.106.0
*/
const string thumbnail() const;
/*!
* @brief Returns the title of the instance.
*
* @since before 0.11.0
*/
const string title() const;
/*!
* @brief Returns the URI of the instance
* @brief Returns the URI of the instance.
*
* @since before 0.11.0
*/
const string uri() const;
/*!
* @brief Returns the version used by the instance
* @brief Returns the URL for the streaming API and possibly others.
*
* @since 0.106.0
*/
const Easy::urls_type urls() const;
/*!
* @brief Returns statistics about the instance.
*
* @since 0.106.0
*/
const Easy::stats_type stats() const;
/*!
* @brief Returns the version used by the instance.
*
* @since before 0.11.0
*/
const string version() const;
/*!
* @brief Returns the URL for the streaming API
* @brief Returns the maximum chars a post can have
*
* This parameter is not supported by upstream Mastodon. If it
* is not found, 500 is returned.
*
* @since 0.20.0
*/
const string streaming_api() const;
uint64_t max_toot_chars() const;
};
}
}
#endif // MASTODON_CPP_EASY_INSTANCE_HPP

View File

@ -1,16 +1,16 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@ -19,19 +19,20 @@
using namespace Mastodon;
using List = Easy::List;
using std::string;
using std::uint_fast64_t;
using std::uint64_t;
List::List(const string &json)
: Entity(json)
{}
List::List()
: Entity()
{}
const uint_fast64_t List::id() const
bool List::valid() const
{
return stouint64(get_string("id"));
return Entity::check_valid(
{
"id",
"title"
});
}
const string List::id() const
{
return get_string("id");
}
const string List::title() const

View File

@ -1,16 +1,16 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@ -21,48 +21,43 @@
#include <vector>
#include <cstdint>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy/easy.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/easy.hpp>
#endif
#include "../../mastodon-cpp.hpp"
#include "../entity.hpp"
using std::string;
using std::uint_fast64_t;
using std::uint64_t;
namespace Mastodon
{
namespace Easy
{
/*!
* @brief Class to hold lists
*
* @since before 0.11.0
*/
class Easy::List : public Easy::Entity
class List : public Entity
{
public:
/*!
* @brief Constructs a List object from a JSON string.
*
* @param json JSON string
*/
explicit List(const string &json);
using Entity::Entity;
/*!
* @brief Constructs an empty List object.
*/
List();
virtual bool valid() const override;
/*!
* @brief Returns list-ID
*
* @since before 0.11.0
*/
const uint_fast64_t id() const;
const string id() const;
/*!
* @brief Returns title
*
* @since before 0.11.0
*/
const string title() const;
};
}
}
#endif // MASTODON_CPP_EASY_LIST_HPP

View File

@ -1,16 +1,16 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@ -19,22 +19,25 @@
using namespace Mastodon;
using Mention = Easy::Mention;
Mention::Mention(const string &json)
: Entity(json)
{}
Mention::Mention()
: Entity()
{}
bool Mention::valid() const
{
return Entity::check_valid(
{
"url",
"username",
"acct",
"id"
});
}
const string Mention::acct() const
{
return get_string("acct");
}
const uint_fast64_t Mention::id() const
const string Mention::id() const
{
return stouint64(get_string("id"));
return get_string("id");
}
const string Mention::url() const

View File

@ -1,16 +1,16 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@ -20,59 +20,58 @@
#include <string>
#include <cstdint>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy/easy.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/easy.hpp>
#endif
#include "../../mastodon-cpp.hpp"
#include "../entity.hpp"
using std::string;
using std::uint_fast64_t;
using std::uint64_t;
using std::chrono::system_clock;
namespace Mastodon
{
namespace Easy
{
/*!
* @brief Class to hold mentions
*
* before 0.11.0
*/
class Easy::Mention : public Easy::Entity
class Mention : public Entity
{
public:
/*!
* @brief Constructs a Mention object from a JSON string.
*
* @param json JSON string
*/
explicit Mention(const string &json);
using Entity::Entity;
/*!
* @brief Constructs an empty Mention object.
*/
Mention();
virtual bool valid() const override;
/*!
* @brief Returns acct
*
* @since before 0.11.0
*/
const string acct() const;
/*!
* @brief Returns account ID
*
* @since before 0.11.0
*/
const uint_fast64_t id() const;
const string id() const;
/*!
* @brief Returns the URL of user's profile
*
* @since before 0.11.0
*/
const string url() const;
/*!
* @brief Returns the username of the account
*
* @since before 0.11.0
*/
const string username() const;
};
}
}
#endif // MASTODON_CPP_EASY_MENTION_HPP

View File

@ -1,32 +1,35 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "notification.hpp"
#include "macros.hpp"
#include "debug.hpp"
using namespace Mastodon;
using Notification = Easy::Notification;
Notification::Notification(const string &json)
: Entity(json)
{}
Notification::Notification()
: Entity()
{}
bool Notification::valid() const
{
return Entity::check_valid(
{
"id",
"type",
"created_at",
"account"
});
}
const Easy::Account Notification::account() const
{
@ -40,14 +43,14 @@ const Easy::Account Notification::account() const
return Easy::Account();
}
const system_clock::time_point Notification::created_at() const
const Easy::time_type Notification::created_at() const
{
return get_time_point("created_at");
return get_time("created_at");
}
const uint_fast64_t Notification::id() const
const string Notification::id() const
{
return stouint64(get_string("id"));
return get_string("id");
}
const Easy::Status Notification::status() const
@ -62,7 +65,7 @@ const Easy::Status Notification::status() const
return Easy::Status();
}
const Easy::notification_type Notification::type() const
Easy::notification_type Notification::type() const
{
const string strtype = get_string("type");
if (strtype.compare("mention") == 0)

View File

@ -1,16 +1,16 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@ -19,71 +19,68 @@
#include <string>
#include <cstdint>
#include <chrono>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy/easy.hpp"
#include "easy/entities/account.hpp"
#include "easy/entities/status.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/easy.hpp>
#include <mastodon-cpp/easy/entities/account.hpp>
#include <mastodon-cpp/easy/entities/status.hpp>
#endif
#include "../../mastodon-cpp.hpp"
#include "../entity.hpp"
#include "account.hpp"
#include "status.hpp"
using std::string;
using std::uint_fast64_t;
using std::chrono::system_clock;
using std::uint64_t;
namespace Mastodon
{
namespace Easy
{
/*!
* @brief Class to hold notifications
*
* @since before 0.11.0
*/
class Easy::Notification : public Easy::Entity
class Notification : public Entity
{
public:
/*!
* @brief Constructs a Notification object from a JSON string.
*
* @param json JSON string
*/
explicit Notification(const string &json);
using Entity::Entity;
/*!
* @brief Constructs an empty Notification object.
*/
Notification();
virtual bool valid() const override;
/*!
* @brief Returns the Account sending the notification to the user
*
* @since before 0.11.0
*/
const Account account() const;
/*!
* @brief Returns time of creation
*
* @since before 0.11.0
*/
const system_clock::time_point created_at() const;
const Easy::time_type created_at() const;
/*!
* @brief Returns notification ID
*
* @since before 0.11.0
*/
const uint_fast64_t id() const;
const string id() const;
/*!
* @brief Returns the Status associated with the notification, if
* applicable
*
* @since before 0.11.0
*/
const Status status() const;
/*!
* @brief Returns notification type
*
* @since before 0.11.0
*/
const Easy::notification_type type() const;
Easy::notification_type type() const;
};
}
}
#endif // MASTODON_CPP_EASY_NOTIFICATION_HPP

View File

@ -0,0 +1,86 @@
/* This file is part of mastodon-cpp.
* Copyright © 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "poll.hpp"
#include "debug.hpp"
using namespace Mastodon;
using Poll = Easy::Poll;
bool Poll::valid() const
{
return Entity::check_valid(
{
"id",
"expired",
"expired",
"multiple",
"votes_count",
"options"
});
}
const string Poll::id() const
{
return get_string("id");
}
const Easy::time_type Poll::expires_at() const
{
return get_time("expires_at");
}
bool Poll::expired() const
{
return get_bool("expired");
}
bool Poll::multiple() const
{
return get_bool("multiple");
}
uint64_t Poll::votes_count() const
{
return get_uint64("votes_count");
}
const vector<Easy::poll_options_type> Poll::options() const
{
const Json::Value &node = get("options");
if (node.isArray())
{
vector<Easy::poll_options_type> vec_options;
std::transform(node.begin(), node.end(), std::back_inserter(vec_options),
[](const Json::Value &value)
{
return Easy::poll_options_type(
{
value["title"].asString(),
value["votes_count"].asUInt64()
});
});
return vec_options;
}
return {};
}
bool Poll::voted() const
{
return get_bool("voted");
}

View File

@ -0,0 +1,98 @@
/* This file is part of mastodon-cpp.
* Copyright © 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MASTODON_CPP_EASY_POLL_HPP
#define MASTODON_CPP_EASY_POLL_HPP
#include <string>
#include <cstdint>
#include <vector>
#include "../../mastodon-cpp.hpp"
#include "../entity.hpp"
using std::string;
using std::uint64_t;
namespace Mastodon
{
namespace Easy
{
/*!
* @brief Class to hold polls.
*
* @since 0.110.0
*/
class Poll : public Entity
{
public:
using Entity::Entity;
virtual bool valid() const override;
/*!
* @brief Returns poll ID.
*
* @since 0.110.0
*/
const string id() const;
/*!
* @brief Returns time when the poll expires.
*
* @since 0.110.0
*/
const Easy::time_type expires_at() const;
/*!
* @brief Returns true if poll has expired.
*
* @since 0.110.0
*/
bool expired() const;
/*!
* @brief Returns true or false.
*
* @since 0.110.0
*/
bool multiple() const;
/*!
* @brief Returns the number of votes.
*
* @since 0.110.0
*/
uint64_t votes_count() const;
/*!
* @brief Returns poll options and their votes count.
*
* @since 0.110.0
*/
const vector<poll_options_type> options() const;
/*!
* @brief Returns whether you voted or not.
*
* @since 0.110.0
*/
bool voted() const;
};
}
}
#endif // MASTODON_CPP_EASY_POLL_HPP

View File

@ -1,16 +1,16 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@ -19,18 +19,21 @@
using namespace Mastodon;
using PushSubscription = Easy::PushSubscription;
PushSubscription::PushSubscription(const string &json)
: Entity(json)
{}
const uint_fast64_t PushSubscription::id() const
const string PushSubscription::id() const
{
return stouint64(get_string("id"));
return get_string("id");
}
PushSubscription::PushSubscription()
: Entity()
{}
bool PushSubscription::valid() const
{
return Entity::check_valid(
{
"id",
"endpoint",
"server_key",
"alerts"
});
}
const string PushSubscription::endpoint() const
{
@ -42,9 +45,9 @@ const string PushSubscription::server_key() const
return get_string("server_key");
}
const Easy::alertmap PushSubscription::alerts() const
const vector<Easy::alert_type> PushSubscription::alerts() const
{
alertmap alerts;
vector<Easy::alert_type> alerts;
const Json::Value node = get("alerts");
for (auto it = node.begin(); it != node.end(); ++it)
{
@ -71,12 +74,12 @@ const Easy::alertmap PushSubscription::alerts() const
type = notification_type::Undefined;
}
alerts.insert({{ type, s_to_b(it->asString()) }});
alerts.push_back({ type, s_to_b(it->asString()) });
}
return alerts;
}
const bool PushSubscription::s_to_b(const string &str) const
bool PushSubscription::s_to_b(const string &str) const
{
if (str.compare("true") == 0)
{

View File

@ -1,16 +1,16 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@ -18,64 +18,59 @@
#define MASTODON_CPP_EASY_PUSHSUBSCRIPTION_HPP
#include <string>
#include <vector>
#include <cstdint>
#include <map>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy/easy.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/easy.hpp>
#endif
#include "../../mastodon-cpp.hpp"
#include "../entity.hpp"
using std::string;
using std::uint_fast64_t;
using std::vector;
namespace Mastodon
{
namespace Easy
{
/*!
* @brief Class to hold push subscriptions.
*
* @since 0.14.0
*/
class Easy::PushSubscription : public Easy::Entity
class PushSubscription : public Entity
{
public:
/*!
* @brief Constructs an PushSubscription object from a JSON string.
*
* @param json JSON string
*/
explicit PushSubscription(const string &json);
using Entity::Entity;
/*!
* @brief Constructs an empty PushSubscription object.
*/
PushSubscription();
virtual bool valid() const override;
/*!
* @brief Returns push subscription ID
*
* @since 0.14.0
*/
const uint_fast64_t id() const;
const string id() const;
/*!
* @brief Returns the endpoint URL
*
* @since 0.14.0
*/
const string endpoint() const;
/*!
* @brief Returns the server public key for signature verification
*
* @since 0.14.0
*/
const string server_key() const;
// TODO: Look up what the data looks like
/*!
* @brief Returns a map of 'notification event type' and
* 'push is requested or not'
* @brief Returns a vector of Easy::alert_type.
*
* @since 0.100.0
*/
const Easy::alertmap alerts() const;
const vector<Easy::alert_type> alerts() const;
protected:
/*!
@ -83,8 +78,9 @@ namespace Mastodon
*
* @return `true` if str is equal to "true", `false` otherwise
*/
const bool s_to_b(const string &str) const;
bool s_to_b(const string &str) const;
};
}
}
#endif // MASTODON_CPP_EASY_PUSHSUBSCRIPTION_HPP

View File

@ -1,16 +1,16 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@ -19,50 +19,74 @@
using namespace Mastodon;
using Relationship = Easy::Relationship;
Relationship::Relationship(const string &json)
: Entity(json)
{}
bool Relationship::valid() const
{
return Entity::check_valid(
{
"id",
"following",
"followed_by",
"blocking",
"muting",
"muting_notifications",
"requested",
"domain_blocking",
"showing_reblogs",
"endorsed"
});
}
Relationship::Relationship()
: Entity()
{}
const bool Relationship::blocking() const
bool Relationship::blocking() const
{
return get_bool("blocking");
}
const bool Relationship::domain_blocking() const
bool Relationship::domain_blocking() const
{
return get_bool("domain_blocking");
}
const bool Relationship::followed_by() const
bool Relationship::endorsed() const
{
return get_bool("endorsed");
}
bool Relationship::followed_by() const
{
return get_bool("followed_by");
}
const bool Relationship::following() const
bool Relationship::following() const
{
return get_bool("following");
}
const uint_fast64_t Relationship::id() const
const string Relationship::id() const
{
return stouint64(get_string("id"));
return get_string("id");
}
const bool Relationship::muting() const
bool Relationship::muting() const
{
return get_bool("muting");
}
const bool Relationship::muting_notifications() const
bool Relationship::muting_notifications() const
{
return get_bool("muting_notifications");
}
const bool Relationship::requested() const
bool Relationship::requested() const
{
return get_bool("requested");
}
bool Relationship::showing_notifications() const
{
return get_bool("showing_notifications");
}
bool Relationship::showing_reblogs() const
{
return get_bool("showing_reblogs");
}

View File

@ -1,16 +1,16 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@ -20,78 +20,106 @@
#include <string>
#include <cstdint>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy/easy.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/easy.hpp>
#endif
#include "../../mastodon-cpp.hpp"
#include "../entity.hpp"
using std::string;
using std::uint_fast64_t;
using std::uint64_t;
namespace Mastodon
{
namespace Easy
{
/*!
* @brief Class to hold relationships
*
* before 0.11.0
*/
class Easy::Relationship : public Easy::Entity
class Relationship : public Entity
{
public:
using Entity::Entity;
virtual bool valid() const override;
/*!
* @brief Constructs a Relationship object from a JSON string.
* @brief Returns true if the user is blocking the account.
*
* @param json JSON string
* @since before 0.11.0
*/
explicit Relationship(const string &json);
bool blocking() const;
/*!
* @brief Constructs an empty Relationship object.
* @brief Returns true if the user is blocking the account's domain.
*
* @since before 0.11.0
*/
Relationship();
bool domain_blocking() const;
/*!
* @brief Returns true if the user is blocking the account
* @brief Returns true if the account is endorsed by the user.
*
* @since 0.19.0
*/
const bool blocking() const;
bool endorsed() const;
/*!
* @brief Returns true if the user is blocking the account's domain
* @brief Returns true if the user is being followed by the account.
*
* @since before 0.11.0
*/
const bool domain_blocking() const;
bool followed_by() const;
/*!
* @brief Returns true if the user is being followed by the account
* @brief Returns true if the user is being following the account.
*
* @since before 0.11.0
*/
const bool followed_by() const;
bool following() const;
/*!
* @brief Returns true if the user is being following the account
* @brief Returns the target account ID.
*
* @since before 0.11.0
*/
const bool following() const;
const string id() const;
/*!
* @brief Returns the target account ID
* @brief Returns true if the user is muting the account.
*
* @since before 0.11.0
*/
const uint_fast64_t id() const;
bool muting() const;
/*!
* @brief Returns true if the user is muting the account
* @brief Returns true if the user is also muting notifications.
*
* @since before 0.11.0
*/
const bool muting() const;
bool muting_notifications() const;
/*!
* @brief Returns true if the user is also muting notifications
* @brief Returns true if the user has requested to follow the account.
*
* @since before 0.11.0
*/
const bool muting_notifications() const;
bool requested() const;
/*!
* @brief Returns true if the user has requested to follow the account
* @brief Returns true if the user is showing notifications.
*
* @since 0.19.0
*/
const bool requested() const;
bool showing_notifications() const;
/*!
* @brief Returns true if the user is showing reblogs.
*
* @since 0.106.0
*/
bool showing_reblogs() const;
};
}
}
#endif // MASTODON_CPP_EASY_RELATIONSHIP_HPP

View File

@ -1,39 +0,0 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "report.hpp"
using namespace Mastodon;
using Report = Easy::Report;
Report::Report(const string &json)
: Entity(json)
{}
Report::Report()
: Entity()
{}
const bool Report::action_taken() const
{
return get_bool("action_taken");
}
const uint_fast64_t Report::id() const
{
return stouint64(get_string("id"));
}

View File

@ -1,68 +0,0 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MASTODON_CPP_EASY_REPORT_HPP
#define MASTODON_CPP_EASY_REPORT_HPP
#include <string>
#include <cstdint>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy/easy.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/easy.hpp>
#endif
using std::string;
using std::uint_fast64_t;
namespace Mastodon
{
/*!
* @brief Class to hold reports
*/
class Easy::Report : public Easy::Entity
{
public:
/*!
* @brief Constructs a Report object from a JSON string.
*
* @param json JSON string
*/
explicit Report(const string &json);
/*!
* @brief Constructs an empty Report object.
*/
Report();
/*!
* @brief Returns true if an action was taken in response to the
* report
*/
const bool action_taken() const;
/*!
* @brief Returns the ID of the report
*/
const uint_fast64_t id() const;
};
}
#endif // MASTODON_CPP_EASY_REPORT_HPP

View File

@ -1,32 +1,35 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <algorithm>
#include <jsoncpp/json/json.h>
#include "results.hpp"
using namespace Mastodon;
using Results = Easy::Results;
Results::Results(const string &json)
: Entity(json)
{}
Results::Results()
: Entity()
{}
bool Results::valid() const
{
return Entity::check_valid(
{
"accounts",
"statuses",
"hashtags"
});
}
const std::vector<Easy::Account> Results::accounts() const
{
@ -34,10 +37,9 @@ const std::vector<Easy::Account> Results::accounts() const
if (node.isArray())
{
std::vector<Easy::Account> vec;
for (const Json::Value &value : node)
{
vec.push_back(Easy::Account(value.toStyledString()));
}
std::transform(node.begin(), node.end(), std::back_inserter(vec),
[](const Json::Value &value)
{ return Easy::Account(value); });
return vec;
}
@ -50,10 +52,9 @@ const std::vector<Easy::Status> Results::statuses() const
if (node.isArray())
{
std::vector<Easy::Status> vec;
for (const Json::Value &value : node)
{
vec.push_back(Easy::Status(value.toStyledString()));
}
std::transform(node.begin(), node.end(), std::back_inserter(vec),
[](const Json::Value &value)
{ return Easy::Status(value); });
return vec;
}
@ -71,17 +72,11 @@ const std::vector<Easy::Tag> Results::hashtags_v2() const
if (node.isArray())
{
std::vector<Easy::Tag> vec;
for (const Json::Value &value : node)
{
vec.push_back(Easy::Tag(value.toStyledString()));
}
std::transform(node.begin(), node.end(), std::back_inserter(vec),
[](const Json::Value &value)
{ return Easy::Tag(value); });
return vec;
}
return {};
}
const std::vector<string> Results::hashtags() const
{
return hashtags_v1();
}

View File

@ -1,16 +1,16 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@ -20,56 +20,47 @@
#include <string>
#include <vector>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy/easy.hpp"
#include "easy/entities/account.hpp"
#include "easy/entities/status.hpp"
#include "easy/entities/tag.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/easy.hpp>
#include <mastodon-cpp/easy/entities/account.hpp>
#include <mastodon-cpp/easy/entities/status.hpp>
#include <mastodon-cpp/easy/entities/tag.hpp>
#endif
#include "../../mastodon-cpp.hpp"
#include "../entity.hpp"
#include "account.hpp"
#include "status.hpp"
#include "tag.hpp"
using std::string;
namespace Mastodon
{
namespace Easy
{
/*!
* @brief Class to hold results
*
* @since before 0.11.0
*/
class Easy::Results : public Easy::Entity
class Results : public Entity
{
public:
/*!
* @brief Constructs a Results object from a JSON string.
*
* @param json JSON string
*/
explicit Results(const string &json);
using Entity::Entity;
/*!
* @brief Constructs an empty Results object.
*/
Results();
virtual bool valid() const override;
/*!
* @brief Returns an array of matched Accounts
*
* @since before 0.11.0
*/
const std::vector<Account> accounts() const;
/*!
* @brief Returns an array of matched Statuses
*
* @since before 0.11.0
*/
const std::vector<Status> statuses() const;
/*!
* @brief Returns an array of matched hashtags as string
*
*
* @since 0.16.0
*/
const std::vector<string> hashtags_v1() const;
@ -80,13 +71,8 @@ namespace Mastodon
* @since 0.16.0
*/
const std::vector<Tag> hashtags_v2() const;
/*!
* @brief Alias for hashtags_v1
*/
[[deprecated("Will vanish in 1.0.0, use hashtags_v1() instead")]]
const std::vector<string> hashtags() const;
};
}
}
#endif // MASTODON_CPP_EASY_RESULTS_HPP

View File

@ -1,33 +1,49 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include <algorithm>
#include <jsoncpp/json/json.h>
#include "status.hpp"
#include "macros.hpp"
using namespace Mastodon;
using Status = Easy::Status;
Status::Status(const string &json)
: Entity(json)
{}
Status::Status()
: Entity()
{}
bool Status::valid() const
{
return Entity::check_valid(
{
"id",
"uri",
"account",
"content",
"created_at",
"emojis",
"replies_count",
"reblogs_count",
"favourites_count",
"sensitive",
"spoiler_text",
"visibility",
"media_attachments",
"mentions",
"tags",
"application"
});
}
const Easy::Account Status::account() const
{
@ -37,7 +53,6 @@ const Easy::Account Status::account() const
return Easy::Account(node.toStyledString());
}
ttdebug << "Could not get data: account\n";
return Easy::Account();
}
@ -49,13 +64,23 @@ const Easy::Application Status::application() const
return Easy::Application(node.toStyledString());
}
ttdebug << "Could not get data: application\n";
return Easy::Application();
}
const system_clock::time_point Status::created_at() const
const Easy::Card Status::card() const
{
return get_time_point("created_at");
const Json::Value node = get("card");
if (node.isObject())
{
return Easy::Card(node.toStyledString());
}
return Easy::Card();
}
const Easy::time_type Status::created_at() const
{
return get_time("created_at");
}
const string Status::content() const
@ -63,46 +88,56 @@ const string Status::content() const
return get_string("content");
}
Status Status::content(const string &content)
{
set("content", Json::Value(content));
return *this;
}
const std::vector<Easy::Emoji> Status::emojis() const
{
const Json::Value node = get("emojis");
if (node.isArray())
{
std::vector<Easy::Emoji> vec;
for (const Json::Value &value : node)
{
vec.push_back(Easy::Emoji(value.toStyledString()));
}
std::transform(node.begin(), node.end(), std::back_inserter(vec),
[](const Json::Value &value)
{ return Easy::Emoji(value); });
return vec;
}
ttdebug << "Could not get data: emojis\n";
return {};
}
const bool Status::favourited() const
bool Status::favourited() const
{
return get_bool("favourited");
}
const uint_fast64_t Status::favourites_count() const
uint64_t Status::favourites_count() const
{
return get_uint64("favourites_count");
}
const uint_fast64_t Status::id() const
const string Status::id() const
{
return stouint64(get_string("id"));
return get_string("id");
}
const uint_fast64_t Status::in_reply_to_id() const
const string Status::in_reply_to_id() const
{
return stouint64(get_string("in_reply_to_id"));
return get_string("in_reply_to_id");
}
const uint_fast64_t Status::in_reply_to_account_id() const
Status Status::in_reply_to_id(const string &in_reply_to_id)
{
return stouint64(get_string("in_reply_to_account_id"));
set("in_reply_to_id", Json::Value(in_reply_to_id));
return *this;
}
const string Status::in_reply_to_account_id() const
{
return get_string("in_reply_to_account_id");
}
const string Status::language() const
@ -110,51 +145,66 @@ const string Status::language() const
return get_string("language");
}
Status Status::language(const string &language)
{
set("language", Json::Value(language));
return *this;
}
const std::vector<Easy::Attachment> Status::media_attachments() const
{
const Json::Value node = get("media_attachments");
if (node.isArray())
{
std::vector<Easy::Attachment> vec;
for (const Json::Value &value : node)
{
vec.push_back(Easy::Attachment(value.toStyledString()));
}
std::transform(node.begin(), node.end(), std::back_inserter(vec),
[](const Json::Value &value)
{ return Easy::Attachment(value); });
return vec;
}
ttdebug << "Could not get data: media_attachments\n";
return {};
}
Status Status::media_attachments
(const std::vector<Attachment> &media_attachments)
{
Json::Value jsonarray(Json::arrayValue);
for (const Attachment &att : media_attachments)
{
jsonarray.append(att.to_object());
}
set("media_attachments", jsonarray);
return *this;
}
const std::vector<Easy::Mention> Status::mentions() const
{
const Json::Value node = get("mentions");
if (node.isArray())
{
std::vector<Easy::Mention> vec;
for (const Json::Value &value : node)
{
vec.push_back(Easy::Mention(value.toStyledString()));
}
std::transform(node.begin(), node.end(), std::back_inserter(vec),
[](const Json::Value &value)
{ return Easy::Mention(value); });
return vec;
}
ttdebug << "Could not get data: mentions\n";
return {};
}
const bool Status::muted() const
bool Status::muted() const
{
return get_bool("muted");
}
const bool Status::pinned() const
bool Status::pinned() const
{
return get_bool("pinned");
}
const Easy::Status Status::reblog() const
const Status Status::reblog() const
{
const Json::Value node = get("reblog");
if (node.isObject())
@ -162,44 +212,58 @@ const Easy::Status Status::reblog() const
return Easy::Status(node.toStyledString());
}
ttdebug << "Could not get data: reblog\n";
return Easy::Status();
}
const bool Status::reblogged() const
bool Status::reblogged() const
{
return get_bool("reblogged");
}
const uint_fast64_t Status::reblogs_count() const
uint64_t Status::reblogs_count() const
{
return get_uint64("reblogs_count");
}
const bool Status::sensitive() const
uint64_t Status::replies_count() const
{
return get_uint64("replies_count");
}
bool Status::sensitive() const
{
return get_bool("sensitive");
}
Status Status::sensitive(const bool &sensitive)
{
set("sensitive", Json::Value(sensitive));
return *this;
}
const string Status::spoiler_text() const
{
return get_string("spoiler_text");
}
Status Status::spoiler_text(const string &spoiler_text)
{
set("spoiler_text", Json::Value(spoiler_text));
return *this;
}
const std::vector<Easy::Tag> Status::tags() const
{
const Json::Value node = get("tags");
if (node.isArray())
{
std::vector<Easy::Tag> vec;
for (const Json::Value &value : node)
{
vec.push_back(Easy::Tag(value.toStyledString()));
}
std::transform(node.begin(), node.end(), std::back_inserter(vec),
[](const Json::Value &value)
{ return Easy::Tag(value); });
return vec;
}
ttdebug << "Could not get data: tags\n";
return {};
}
@ -213,7 +277,7 @@ const string Status::url() const
return get_string("url");
}
const Easy::visibility_type Status::visibility() const
Easy::visibility_type Status::visibility() const
{
const string strvisibility = get_string("visibility");
if (strvisibility.compare("public") == 0)
@ -225,6 +289,29 @@ const Easy::visibility_type Status::visibility() const
else if (strvisibility.compare("direct") == 0)
return visibility_type::Direct;
ttdebug << "Could not get data: visibility\n";
return visibility_type::Undefined;
}
Status Status::visibility(const visibility_type &visibility)
{
switch (visibility)
{
case visibility_type::Direct:
set("visibility", "direct");
break;
case visibility_type::Private:
set("visibility", "private");
break;
case visibility_type::Unlisted:
set("visibility", "unlisted");
break;
case visibility_type::Public:
set("visibility", "public");
break;
default:
std::cerr << "WARNING: setting visibility to Undefined "
"has no effect.\n";
break;
};
return *this;
}

View File

@ -1,16 +1,16 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@ -19,179 +19,270 @@
#include <string>
#include <cstdint>
#include <chrono>
#include <vector>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy/easy.hpp"
#include "easy/entities/account.hpp"
#include "easy/entities/emoji.hpp"
#include "easy/entities/attachment.hpp"
#include "easy/entities/mention.hpp"
#include "easy/entities/tag.hpp"
#include "easy/entities/application.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/easy.hpp>
#include <mastodon-cpp/easy/entities/account.hpp>
#include <mastodon-cpp/easy/entities/emoji.hpp>
#include <mastodon-cpp/easy/entities/attachment.hpp>
#include <mastodon-cpp/easy/entities/mention.hpp>
#include <mastodon-cpp/easy/entities/tag.hpp>
#include <mastodon-cpp/easy/entities/application.hpp>
#endif
#include "../../mastodon-cpp.hpp"
#include "../entity.hpp"
#include "account.hpp"
#include "emoji.hpp"
#include "attachment.hpp"
#include "mention.hpp"
#include "tag.hpp"
#include "application.hpp"
#include "card.hpp"
using std::string;
using std::uint_fast64_t;
using std::chrono::system_clock;
using std::uint64_t;
namespace Mastodon
{
namespace Easy
{
/*!
* @brief Class to hold statuses
*
* @since before 0.11.0
*/
class Easy::Status : public Easy::Entity
class Status : public Entity
{
public:
using Entity::Entity;
virtual bool valid() const override;
/*!
* @brief Constructs a Status object from a JSON string.
* @brief Returns an array of matched accounts.
*
* @param json JSON string
*/
explicit Status(const string &json);
/*!
* @brief Constructs an empty Status object.
*/
Status();
/*!
* @brief Returns an array of matched accounts
* @since before 0.11.0
*/
const Account account() const;
/*!
* @brief Returns application from which the status was posted
* @brief Returns application from which the status was posted.
*
* @since before 0.11.0
*/
const Application application() const;
/*!
* @brief Returns time of creation
* @brief Returns card
*
* @since 0.19.0
*/
const system_clock::time_point created_at() const;
const Card card() const;
/*!
* @brief Returns time of creation
*
* @since before 0.11.0
*/
const Easy::time_type created_at() const;
/*!
* @brief Returns content of status
*
* @since before 0.11.0
*/
const string content() const;
/*!
* @brief Sets content of status
*
* @since 0.17.0
*/
Status content(const string &content);
/*!
* @brief Returns an array of emojis
*
* @since before 0.11.0
*/
const std::vector<Emoji> emojis() const;
/*!
* @brief Returns true if the user has favourited the status
*
* @since before 0.11.0
*/
const bool favourited() const;
bool favourited() const;
/*!
* @brief Returns the number of favourites
*
* @since before 0.11.0
*/
const uint_fast64_t favourites_count() const;
uint64_t favourites_count() const;
/*!
* @brief Returns the ID of the status
*
* @since before 0.11.0
*/
const uint_fast64_t id() const;
const string id() const;
/*!
* @brief Returns the ID of the status it replies to
*
* @since before 0.11.0
*/
const uint_fast64_t in_reply_to_id() const;
const string in_reply_to_id() const;
/*!
* @brief Sets the ID of the status it replies to
*
* @since 0.17.0
*/
Status in_reply_to_id(const string &in_reply_to_id);
/*!
* @brief Returns the ID of the account it replies to
*
* @since before 0.11.0
*/
const uint_fast64_t in_reply_to_account_id() const;
const string in_reply_to_account_id() const;
/*!
* @brief Returns the language of the status
*
* @since before 0.11.0
*/
const string language() const;
/*!
* @brief Overrides the language of the status (ISO 639-2)
*
* @since 0.17.0
*/
Status language(const string &language);
/*!
* @brief Returns the attachments
*
* @since before 0.11.0
*/
const std::vector<Attachment> media_attachments() const;
/*!
* @brief Sets the attachments
*
* @since 0.17.0
*/
Status media_attachments
(const std::vector<Attachment> &media_attachments);
/*!
* @brief Returns the mentions
*
* @since before 0.11.0
*/
const std::vector<Mention> mentions() const;
/*!
* @brief Returns true if the user muted the conversation
*
* @since before 0.11.0
*/
const bool muted() const;
bool muted() const;
/*!
* @brief Returns true if the status is pinned
*
* @since before 0.11.0
*/
const bool pinned() const;
bool pinned() const;
/*!
* @brief Returns the reblogged Status
*
* @since before 0.11.0
*/
const Status reblog() const;
/*!
* @brief Returns true if the user has reblogged the status
*
* @since before 0.11.0
*/
const bool reblogged() const;
bool reblogged() const;
/*!
* @brief Returns the number of reblogs for the status
*
* @since before 0.11.0
*/
const uint_fast64_t reblogs_count() const;
uint64_t reblogs_count() const;
/*!
* @brief Returns the number of replies for the status
*
* @since 0.19.0
*/
uint64_t replies_count() const;
/*!
* @brief Returns true if the attachments should be hidden by default
*
* @since before 0.11.0
*/
const bool sensitive() const;
bool sensitive() const;
/*!
* @brief Sets sensitive flag for attachments
*
* @since 0.17.0
*/
Status sensitive(const bool &sensitive);
/*!
* @brief Returns the spoiler text
*
* @since before 0.11.0
*/
const string spoiler_text() const;
/*!
* @brief Sets the spoiler text
*
* @since 0.17.0
*/
Status spoiler_text(const string &spoiler_text);
/*!
* @brief Returns the tags
*
* @since before 0.11.0
*/
const std::vector<Tag> tags() const;
/*!
* @brief Returns the Fediverse-unique resource ID
*
* @since before 0.11.0
*/
const string uri() const;
/*!
* @brief Returns the URL to the status page
*
* @since before 0.11.0
*/
const string url() const;
/*!
* @brief Returns the visibility of the status
*
* @since before 0.11.0
*/
const visibility_type visibility() const;
visibility_type visibility() const;
/*!
* @brief Returns the
* @brief Sets the visibility of the status
*
* @since 0.17.0
*/
Status visibility(const visibility_type &visibility);
};
}
}
#endif // MASTODON_CPP_EASY_STATUS_HPP

View File

@ -1,34 +1,36 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sstream>
#include <iomanip>
#include <algorithm>
#include "tag.hpp"
#include "macros.hpp"
#include "debug.hpp"
using namespace Mastodon;
using Tag = Easy::Tag;
Tag::Tag(const string &json)
: Entity(json)
{}
Tag::Tag()
: Entity()
{}
bool Tag::valid() const
{
return Entity::check_valid(
{
"name",
"url"
});
}
const string Tag::name() const
{
@ -46,10 +48,9 @@ const std::vector<Tag::History> Tag::history() const
if (node.isArray())
{
std::vector<Easy::Tag::History> vec;
for (const Json::Value &value : node)
{
vec.push_back(Easy::Tag::History(value.toStyledString()));
}
std::transform(node.begin(), node.end(), std::back_inserter(vec),
[](const Json::Value &value)
{ return Easy::Tag::History(value); });
return vec;
}
@ -57,35 +58,38 @@ const std::vector<Tag::History> Tag::history() const
return {};
}
Tag::History::History(const string &json)
: Entity(json)
{}
Tag::History::History()
: Entity()
{}
const uint_fast64_t Tag::History::accounts()
bool Tag::History::valid() const
{
return stouint64(get_string("accounts"));
const std::vector<string> attributes =
{{
"day",
"uses",
"accounts"
}};
return Entity::check_valid(attributes);
}
const system_clock::time_point Tag::History::day()
uint64_t Tag::History::accounts() const
{
return get_uint64("accounts");
}
const Easy::time_type Tag::History::day() const
{
const Json::Value node = get("day");
if (node.isString())
{
std::chrono::seconds seconds(stouint64(node.asString()));
return system_clock::time_point(seconds);
return {system_clock::time_point(seconds)};
}
ttdebug << "Could not get data: day\n";
return system_clock::time_point();
return Easy::time_type();
}
const uint_fast64_t Tag::History::uses()
uint64_t Tag::History::uses() const
{
return stouint64(get_string("uses"));
return get_uint64("uses");
}

View File

@ -1,16 +1,16 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@ -18,94 +18,86 @@
#define MASTODON_CPP_EASY_TAG_HPP
#include <string>
#include <chrono>
#include <cstdint>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy/easy.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/easy.hpp>
#endif
#include "../../mastodon-cpp.hpp"
#include "../entity.hpp"
using std::string;
using std::chrono::system_clock;
using std::uint_fast64_t;
using std::uint64_t;
namespace Mastodon
{
namespace Easy
{
/*!
* @brief Class to hold tags.
*
* @since before 0.11.0
*/
class Easy::Tag : public Easy::Entity
class Tag : public Entity
{
public:
/*!
* @brief Class to hold Tag history
*
*
* @since 0.16.0
*/
class History : public Easy::Entity
{
public:
/*!
* @brief Constructs an Tag::History object from a JSON string.
*
* @param json JSON string
*/
explicit History(const string &json);
/*!
* @brief Constructs an empty Tag::History object.
*/
History();
using Entity::Entity;
virtual bool valid() const override;
/*!
* @brief Returns the number of accounts using that hashtag.
*
* @since 0.16.0
*/
const uint_fast64_t accounts();
uint64_t accounts() const;
/*!
* @brief Returns the day.
*
* @since 0.16.0
*/
const system_clock::time_point day();
const Easy::time_type day() const;
/*!
* @brief Returns the number of accounts using that hashtag.
* @brief Returns the number of statuses with that hashtag.
*
* @since 0.16.0
*/
const uint_fast64_t uses();
uint64_t uses() const;
};
/*!
* @brief Constructs an Tag object from a JSON string.
*
* @param json JSON string
*/
explicit Tag(const string &json);
using Entity::Entity;
/*!
* @brief Constructs an empty Tag object.
*/
Tag();
virtual bool valid() const override;
/*!
* @brief Returns the name of the tag
*
* @since before 0.11.0
*/
const string name() const;
/*!
* @brief Returns the URL of the tag
*
* @since before 0.11.0
*/
const string url() const;
/*!
* @brief Returns the history of the tag
*
*
* @since 0.16.0
*/
const std::vector<History> history() const;
};
}
}
#endif // MASTODON_CPP_EASY_TAG_HPP

View File

@ -0,0 +1,51 @@
/* This file is part of mastodon-cpp.
* Copyright © 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "token.hpp"
using namespace Mastodon;
using Token = Easy::Token;
bool Token::valid() const
{
return Entity::check_valid(
{
"access_token",
"token_type",
"scope",
"created_at"
});
}
const string Token::access_token() const
{
return get_string("access_token");
}
const string Token::token_type() const
{
return get_string("token_type");
}
const string Token::scope() const
{
return get_string("scope");
}
const Easy::time_type Token::created_at() const
{
return get_time("created_at");
}

View File

@ -0,0 +1,74 @@
/* This file is part of mastodon-cpp.
* Copyright © 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MASTODON_CPP_EASY_TOKEN_HPP
#define MASTODON_CPP_EASY_TOKEN_HPP
#include <string>
#include "../../mastodon-cpp.hpp"
#include "../entity.hpp"
using std::string;
namespace Mastodon
{
namespace Easy
{
/*!
* @brief Class to hold applications.
*
* @since before 0.11.0
*/
class Token : public Entity
{
public:
using Entity::Entity;
virtual bool valid() const override;
/*!
* @brief Returns the access token.
*
* @since 0.103.0
*/
const string access_token() const;
/*!
* @brief Returns the token type.
*
* @since 0.103.0
*/
const string token_type() const;
/*!
* @brief Returns the scope of the token.
*
* @since 0.103.0
*/
const string scope() const;
/*!
* @brief Returns the date of creation.
*
* @since 0.103.0
*/
const Easy::time_type created_at() const;
};
}
}
#endif // MASTODON_CPP_EASY_TOKEN_HPP

View File

@ -1,26 +1,28 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <ctime>
#include <iomanip> // get_time
#include <sstream>
#include <chrono>
#include <ctime>
#include <regex>
#include "easy.hpp"
#include "macros.hpp"
#include <algorithm>
#include "easy/entity.hpp"
#include "easy/easy.hpp"
#include "debug.hpp"
using namespace Mastodon;
using std::string;
@ -28,16 +30,40 @@ using std::chrono::system_clock;
Easy::Entity::Entity(const string &json)
: _tree(Json::nullValue)
, _valid(false)
,_was_set(false)
{
from_string(json);
}
const void Easy::Entity::from_string(const string &json)
Easy::Entity::Entity(const Json::Value &object)
: _tree(object)
,_was_set(false)
{}
Easy::Entity::Entity()
: _tree(Json::nullValue)
, _was_set(false)
{}
Easy::Entity::~Entity()
{}
Easy::Entity::operator const Json::Value() const
{
std::stringstream ss(json);
ss >> _tree;
return to_object();
}
void Easy::Entity::from_string(const string &json)
{
if (json.find('{') != std::string::npos)
{
std::stringstream ss(json);
ss >> _tree;
}
else
{
_tree.clear();
}
// If the JSON is a single object encapsulated in an array,
// transform it into an object. If the JSON string is [], transform to null
@ -51,15 +77,21 @@ const void Easy::Entity::from_string(const string &json)
ttdebug << "ERROR: JSON string holds no object\n";
ttdebug << "String was: " << json << '\n';
}
else if (!_tree["error"].isNull())
else if (!_tree["error"].isNull() || !_tree["errors"].isNull())
{
ttdebug << "ERROR: Server returned an error\n";
ttdebug << "String was: " << json << '\n';
}
else
{
_valid = true;
}
}
const string Easy::Entity::to_string() const
{
return _tree.toStyledString();
}
void Easy::Entity::from_object(const Json::Value &object)
{
_tree = object;
}
const Json::Value Easy::Entity::to_object() const
@ -67,22 +99,33 @@ const Json::Value Easy::Entity::to_object() const
return _tree;
}
Easy::Entity::Entity()
: _valid(false)
, _was_set(false)
{}
const bool Easy::Entity::valid() const
bool Easy::Entity::check_valid(const std::vector<string> &attributes) const
{
return _valid;
for (const string &attribute : attributes)
{
get(attribute);
if (!was_set())
{
return false;
}
}
return true;
}
const string Easy::Entity::error() const
{
return get_string("error");
string error = get_string("error");
if (error.empty())
{
// Pleroma uses {"errors":{"detail":"[…]"}} sometimes.
const Json::Value node = get("errors.detail");
error = node.asString();
}
return error;
}
const bool Easy::Entity::was_set() const
bool Easy::Entity::was_set() const
{
return _was_set;
}
@ -142,7 +185,7 @@ const string Easy::Entity::get_string(const string &key) const
return "";
}
const uint_fast64_t Easy::Entity::get_uint64(const string &key) const
uint64_t Easy::Entity::get_uint64(const string &key) const
{
const Json::Value node = get(key);
@ -156,7 +199,7 @@ const uint_fast64_t Easy::Entity::get_uint64(const string &key) const
return 0;
}
const double Easy::Entity::get_double(const string &key) const
double Easy::Entity::get_double(const string &key) const
{
const Json::Value node = get(key);
@ -170,7 +213,7 @@ const double Easy::Entity::get_double(const string &key) const
return 0.0;
}
const bool Easy::Entity::get_bool(const string &key) const
bool Easy::Entity::get_bool(const string &key) const
{
const Json::Value node = get(key);
@ -184,24 +227,19 @@ const bool Easy::Entity::get_bool(const string &key) const
return false;
}
const system_clock::time_point
Easy::Entity::get_time_point(const string &key) const
const Easy::time_type Easy::Entity::get_time(const string &key) const
{
const Json::Value node = get(key);
if (node.isString())
{
std::stringstream sstime(node.asString());
struct std::tm tm = {0};
sstime >> std::get_time(&tm, "%Y-%m-%dT%T");
std::time_t time = timegm(&tm);
_was_set = true;
return system_clock::from_time_t(time);
return Easy::string_to_time(node.asString());
}
_was_set = false;
// Return clocks epoch
return system_clock::time_point();
return { system_clock::time_point() };
}
const std::vector<string> Easy::Entity::get_vector(const string &key) const
@ -211,10 +249,9 @@ const std::vector<string> Easy::Entity::get_vector(const string &key) const
if (node.isArray())
{
std::vector<string> vec;
for (const Json::Value &value : node)
{
vec.push_back(value.asString());
}
std::transform(node.begin(), node.end(), std::back_inserter(vec),
[](const Json::Value &value)
{ return value.asString(); });
_was_set = true;
return vec;
}
@ -223,7 +260,45 @@ const std::vector<string> Easy::Entity::get_vector(const string &key) const
return {};
}
const std::uint_fast64_t Easy::Entity::stouint64(const string &str) const
void Easy::Entity::set(const string &key, const Json::Value &value)
{
if (key.find('.') == std::string::npos)
{
_tree[key] = value;
return;
}
else
{
std::size_t pos = 0;
string current_key = key;
Json::Value *node = &_tree;
while ((pos = current_key.find('.')) != std::string::npos)
{
try
{
node = &(*node)[current_key.substr(0, pos)];
if (node->isNull())
{
*node = Json::Value(Json::objectValue);
}
current_key = current_key.substr(pos + 1);
}
catch (const Json::LogicError &e)
{
ttdebug << e.what() << '\n';
goto error;
}
}
(*node)[current_key] = value;
return;
}
error:
ttdebug << "Could not set data: " << key << '\n';
}
std::uint64_t Easy::Entity::stouint64(const string &str) const
{
if (str == "")
{

240
src/easy/entity.hpp Normal file
View File

@ -0,0 +1,240 @@
/* This file is part of mastodon-cpp.
* Copyright © 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MASTODON_CPP_EASY_ENTITY_HPP
#define MASTODON_CPP_EASY_ENTITY_HPP
#include <string>
#include <jsoncpp/json/json.h>
#include "types_easy.hpp"
using std::string;
namespace Mastodon
{
namespace Easy
{
/*!
* @brief Base class for all entities.
*
* @since before 0.11.0
*/
class Entity
{
public:
/*!
* @brief Constructs an Entity object from a JSON string.
*
* @param json JSON string
*
* @since before 0.11.0
*/
explicit Entity(const string &json);
/*!
* @brief Constructs an Entity object from a JSON object.
*
* @param object JSON object
*
* @since 0.100.0
*/
explicit Entity(const Json::Value &object);
/*!
* @brief Constructs an empty Entity object.
*
* @since before 0.11.0
*/
Entity();
/*!
* @brief Destroys the object.
*
* @since 0.100.0
*/
virtual ~Entity();
/*!
* Returns the JSON object of the Entity
*
* @since 0.100.0
*/
operator const Json::Value() const;
/*!
* @brief Replaces the Entity with a new one from a JSON string.
*
* @param json JSON string
*
* @since before 0.11.0
*/
void from_string(const string &json);
/*!
* @brief Returns the JSON of the Entity as formatted string.
*
* @return JSON string
*
* @since before 0.11.0
*/
const string to_string() const;
/*!
* @brief Replaces the Entity with a new one from a JSON object.
*
* @param object JSON object
*
* @since 0.100.0
*/
void from_object(const Json::Value &object);
/*!
* @brief Returns the JSON object of the Entity
*
* @return JSON object
*
* @since before 0.11.0
*/
const Json::Value to_object() const;
/*!
* @brief Returns true if the Entity holds valid data
*
* @since before 0.11.0 (virtual since 0.18.2)
*/
virtual bool valid() const = 0;
/*!
* @brief Returns error string sent by the server
*
* @since before 0.11.0
*/
const string error() const;
/*!
* @brief Returns true if the last requested value was set, false if
* it was unset.
*
* Members of Easy::Entity-derived classes return a default
* value depending on its type when the requested value is not
* found in the JSON. "" for strings, false for bools and so
* on. Most of the time this is no problem, but sometimes you
* need to know for sure.
*
* Example:
* @code
* Easy::Account a(jsonstring);
* if (a.note().empty())
* {
* if (a.was_set())
* {
* cout << "Account has an empty description.\n";
* }
* else
* {
* cout << "Account has no description.\n";
* }
* }
* @endcode
*
* @since before 0.11.0
*/
bool was_set() const;
protected:
/*!
* @brief Returns the value of key as Json::Value
*
* Returns an empty object if the value does not exist or is
* null.
*/
const Json::Value get(const string &key) const;
/*!
* @brief Returns the value of key as std::string
*
* returns "" if the value does not exist or is null.
*/
const string get_string(const string &key) const;
/*!
* @brief Returns the value of key as std::uint64_t
*
* Returns 0 if the value does not exist or is null.
*/
uint64_t get_uint64(const string &key) const;
/*!
* @brief Returns the value of key as double
*
* Returns 0.0 if the value does not exist or is null.
*/
double get_double(const string &key) const;
/*!
* @brief Returns the value of key as bool
*
* Returns false if the value does not exist or is null.
*/
bool get_bool(const string &key) const;
/*!
* @brief Returns the value of key as Easy::time.
*
* Returns clocks epoch if the value does not exist or is null.
*/
const Easy::time_type get_time(const string &key) const;
/*!
* @brief Returns the value of key as vector
*
* Returns an empty vector if the value does not exist or is
* null.
*/
const std::vector<string> get_vector(const string &key) const;
/*!
* @brief Sets the value of key
*
* @since 0.17.0
*/
void set(const string &key, const Json::Value &value);
/*!
* @brief Returns value of str as uint64_t.
*/
std::uint64_t stouint64(const string &str) const;
/*!
* @brief Checks if an Entity is valid
*
* @param attributes The attributes to check
*
* @return true if all attributes are set
*
* @since 0.18.2
*/
bool check_valid(const std::vector<string> &attributes) const;
private:
Json::Value _tree;
mutable bool _was_set;
};
}
}
#endif // MASTODON_CPP_EASY_ENTITY_HPP

View File

@ -0,0 +1,142 @@
/* This file is part of mastodon-cpp.
* Copyright © 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "return_types_easy.hpp"
#include "easy/entities/account.hpp"
#include "easy/entities/application.hpp"
#include "easy/entities/attachment.hpp"
#include "easy/entities/card.hpp"
#include "easy/entities/context.hpp"
#include "easy/entities/emoji.hpp"
#include "easy/entities/instance.hpp"
#include "easy/entities/list.hpp"
#include "easy/entities/mention.hpp"
#include "easy/entities/notification.hpp"
#include "easy/entities/relationship.hpp"
#include "easy/entities/results.hpp"
#include "easy/entities/status.hpp"
#include "easy/entities/tag.hpp"
#include "easy/entities/token.hpp"
#include "easy/entities/pushsubscription.hpp"
#include "easy/entities/filter.hpp"
#include "easy/entities/poll.hpp"
#include "easy/entities/conversation.hpp"
using namespace Mastodon;
template<typename T>
Easy::return_entity<T>::return_entity()
: entity()
{}
template<typename T>
Easy::return_entity<T>::return_entity(const uint8_t ec, const string &em,
const uint16_t hec, const T &ent)
: entity(ent)
{
error_code = ec;
error_message = em;
http_error_code = hec;
}
template<typename T>
Easy::return_entity<T>::return_entity(const error ec, const string &em,
const uint16_t hec, const T &ent)
: entity(ent)
{
error_code = static_cast<uint8_t>(ec);
error_message = em;
http_error_code = hec;
}
template<typename T>
Easy::return_entity<T>::return_entity::operator const T() const
{
return entity;
}
template<typename T>
Easy::return_entity<T>::return_entity::operator const string() const
{
return entity.to_string();
}
// Explicit instantiations, so it can be used from outside.
template struct Easy::return_entity<Easy::Account>;
template struct Easy::return_entity<Easy::Application>;
template struct Easy::return_entity<Easy::Attachment>;
template struct Easy::return_entity<Easy::Card>;
template struct Easy::return_entity<Easy::Context>;
template struct Easy::return_entity<Easy::Emoji>;
template struct Easy::return_entity<Easy::Instance>;
template struct Easy::return_entity<Easy::List>;
template struct Easy::return_entity<Easy::Mention>;
template struct Easy::return_entity<Easy::Notification>;
template struct Easy::return_entity<Easy::Relationship>;
template struct Easy::return_entity<Easy::Results>;
template struct Easy::return_entity<Easy::Status>;
template struct Easy::return_entity<Easy::Tag>;
template struct Easy::return_entity<Easy::Token>;
template struct Easy::return_entity<Easy::PushSubscription>;
template struct Easy::return_entity<Easy::Filter>;
template struct Easy::return_entity<Easy::Poll>;
template struct Easy::return_entity<Easy::Conversation>;
template<typename T>
Easy::return_entity_vector<T>::
return_entity_vector::return_entity_vector()
: entities()
{}
template<typename T>
Easy::return_entity_vector<T>::return_entity_vector::return_entity_vector(
const uint8_t ec, const string &em,
const uint16_t hec, const vector<T> &vec)
: entities(vec)
{
error_code = ec;
error_message = em;
http_error_code = hec;
}
template<typename T>
Easy::return_entity_vector<T>::return_entity_vector::operator const vector<T>()
const
{
return entities;
}
// Explicit instantiations, so it can be used from outside.
template struct Easy::return_entity_vector<Easy::Account>;
template struct Easy::return_entity_vector<Easy::Application>;
template struct Easy::return_entity_vector<Easy::Attachment>;
template struct Easy::return_entity_vector<Easy::Card>;
template struct Easy::return_entity_vector<Easy::Context>;
template struct Easy::return_entity_vector<Easy::Emoji>;
template struct Easy::return_entity_vector<Easy::Instance>;
template struct Easy::return_entity_vector<Easy::List>;
template struct Easy::return_entity_vector<Easy::Mention>;
template struct Easy::return_entity_vector<Easy::Notification>;
template struct Easy::return_entity_vector<Easy::Relationship>;
template struct Easy::return_entity_vector<Easy::Results>;
template struct Easy::return_entity_vector<Easy::Status>;
template struct Easy::return_entity_vector<Easy::Tag>;
template struct Easy::return_entity_vector<Easy::Token>;
template struct Easy::return_entity_vector<Easy::PushSubscription>;
template struct Easy::return_entity_vector<Easy::Filter>;
template struct Easy::return_entity_vector<Easy::Poll>;
template struct Easy::return_entity_vector<Easy::Conversation>;

View File

@ -0,0 +1,136 @@
/* This file is part of mastodon-cpp.
* Copyright © 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MASTODON_CPP_EASY_RETURN_TYPES_EASY_HPP
#define MASTODON_CPP_EASY_RETURN_TYPES_EASY_HPP
#include <string>
#include <vector>
#include <ostream>
#include <cstdint>
#include "../mastodon-cpp.hpp"
using std::string;
using std::vector;
using std::uint8_t;
namespace Mastodon
{
namespace Easy
{
/*!
* @brief Return types for calls that return a single `Easy::Entity`.
*
* @since 0.100.0
*/
template <typename T> struct
[[deprecated("Will go away in 1.0.0 with no replacement.")]]
return_entity : return_base
{
/*!
* @brief Mastodon::Easy::Entity
*
* @since 0.100.0
*/
T entity;
return_entity();
/*!
* @brief Return type for easy Mastodon::Easy::API.
*
* @param ec Error code
* @param em Error message
* @param hec HTTP error code
* @param ent Answer
*
* @since 0.100.0
*/
return_entity(const uint8_t ec, const string &em,
const uint16_t hec, const T &ent);
/*!
* @brief Return type for easy Mastodon::Easy::API.
*
* @param ec Error code
* @param em Error message
* @param hec HTTP error code
* @param ent Answer
*
* @since 0.110.0
*/
return_entity(const error ec, const string &em,
const uint16_t hec, const T &ent);
/*!
* @brief Same as return_entity::entity.
*
* @since 0.100.0
*/
operator const T() const;
/*!
* @brief Mastodon::Easy::Entity as formatted string.
*
* @since 0.100.0
*/
operator const string() const;
/*!
* @brief Mastodon::Easy::Entity as formatted string.
*
* @since 0.100.0
*/
friend std::ostream &operator <<(std::ostream &out,
const return_entity<T> &ret)
{
// Could only get it to work by implementing it here.
out << ret.entity.to_string();
return out;
}
};
/*!
* @brief Return types for calls that return multiple `Easy::Entity`s.
*
* @since 0.100.0
*/
template <typename T> struct
[[deprecated("Will go away in 1.0.0 with no replacement.")]]
return_entity_vector : return_base
{
/*!
* @brief std::vector of Mastodon::Easy::Entity.
*
* @since 0.100.0
*/
vector<T> entities;
return_entity_vector();
return_entity_vector(const uint8_t ec, const string &em,
const uint16_t hec, const vector<T> &vec);
/*!
* @brief Same es return_entity_vector::entities.
*
* @since 0.100.0
*/
operator const vector<T>() const;
};
}
}
#endif // MASTODON_CPP_EASY_RETURN_TYPES_EASY_HPP

171
src/easy/simple_calls.cpp Normal file
View File

@ -0,0 +1,171 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <algorithm>
#include "easy.hpp"
#include "debug.hpp"
#include "easy/entities/status.hpp"
#include "easy/entities/attachment.hpp"
#include "easy/entities/notification.hpp"
using namespace Mastodon::Easy;
const return_entity<Status> API::send_toot(const Status &status)
{
return send_post(status);
}
const return_entity<Status> API::send_post(const Status &status)
{
parameters params;
if (!status.content().empty())
{
params.push_back({ "status", { status.content() }});
}
else
{
ttdebug << "ERROR: Easy::Status::content can not be empty.\n";
return { error::INVALID_ARGUMENT,
"Easy::Status::content can not be empty", 0, Status() };
}
if (!status.in_reply_to_id().empty())
{
params.push_back({ "in_reply_to_id",
{ status.in_reply_to_id() }});
}
if (status.sensitive())
{
params.push_back({ "sensitive", { "true" }});
}
if (!status.spoiler_text().empty())
{
params.push_back({ "spoiler_text", { status.spoiler_text() }});
}
if (status.visibility() != visibility_type::Undefined)
{
string visibility;
switch (status.visibility())
{
case visibility_type::Direct:
visibility = "direct";
break;
case visibility_type::Private:
visibility = "private";
break;
case visibility_type::Unlisted:
visibility = "unlisted";
break;
case visibility_type::Public:
visibility = "public";
break;
default:
break;
};
params.push_back({ "visibility", { visibility }});
}
if (!status.language().empty())
{
params.push_back({ "language", { status.language() }});
}
if (!status.media_attachments().empty())
{
std::vector<string> media_ids;
for (const Attachment &att : status.media_attachments())
{
parameters param_att;
if (!att.file().empty())
{
param_att.push_back({ "file", { att.file() }});
}
else
{
ttdebug << "ERROR: Easy::Attachment::file can not be empty.\n";
return { error::INVALID_ARGUMENT,
"Easy::Attachment::file can not be empty", 0,
Status() };
}
if (!att.description().empty())
{
param_att.push_back({ "description", { att.description() }});
}
if (!att.focus().empty())
{
param_att.push_back({ "focus",
{ std::to_string(att.focus()[0]) + ',' +
std::to_string(att.focus()[1]) }});
}
return_call ret = post(API::v1::media, param_att);
if (ret.error_code == 0)
{
Attachment attachment(ret.answer);
media_ids.push_back(attachment.id());
}
else
{
ttdebug << "ERROR: Could not upload file.\n";
return { ret.error_code, ret.error_message,
ret.http_error_code, Status(ret.answer) };
}
}
params.push_back({ "media_ids", media_ids });
}
return_call ret = post(API::v1::statuses, params);
return { ret.error_code, ret.error_message, ret.http_error_code,
Status(ret.answer) };
}
const return_entity_vector<Notification> API::get_notifications(
const uint16_t limit, const string since_id, const string max_id)
{
parameters params;
params.push_back({ "limit", { std::to_string(limit) } });
if (!since_id.empty())
{
params.push_back({ "since_id", { since_id } });
}
if (!max_id.empty())
{
params.push_back({ "max_id", { max_id } });
}
return_call ret = API::get(API::v1::notifications, params);
if (ret.error_code == 0)
{
const vector<string> &answer_v = json_array_to_vector(ret.answer);
vector<Notification> notifications;
notifications.resize(answer_v.size());
// Transform vector of strings to vector of Notification.
std::transform(answer_v.begin(), answer_v.end(), notifications.begin(),
[](const string &s)
{ return Notification(s); });
return { ret.error_code, ret.error_message, ret.http_error_code,
notifications };
}
else
{
ttdebug << "ERROR: Could not get notifications.\n";
return { ret.error_code, ret.error_message, ret.http_error_code, {} };
}
}

61
src/easy/types_easy.cpp Normal file
View File

@ -0,0 +1,61 @@
/* This file is part of mastodon-cpp.
* Copyright © 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "types_easy.hpp"
namespace Mastodon
{
namespace Easy
{
time_type::operator const system_clock::time_point() const
{
return timepoint;
}
time_type::operator const string() const
{
return strtime("%FT%T%z", true);
}
const string time_type::strtime(const string &format, const bool &local) const
{
constexpr std::uint16_t bufsize = 1024;
std::time_t time = system_clock::to_time_t(timepoint);
std::tm *tm;
if (local)
{
tm = std::localtime(&time);
}
else
{
tm = std::gmtime(&time);
}
char buffer[bufsize];
std::strftime(buffer, bufsize, format.c_str(), tm);
return static_cast<const string>(buffer);
}
std::ostream &operator <<(std::ostream &out,
const time_type &t)
{
const string s = t; // Converts using operator const string().
out << s;
return out;
}
}
}

239
src/easy/types_easy.hpp Normal file
View File

@ -0,0 +1,239 @@
/* This file is part of mastodon-cpp.
* Copyright © 2019 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MASTODON_CPP_EASY_TYPES_EASY_HPP
#define MASTODON_CPP_EASY_TYPES_EASY_HPP
#include <string>
#include <utility>
#include <chrono>
#include <cstdint>
using std::string;
using std::chrono::system_clock;
using std::uint64_t;
namespace Mastodon
{
namespace Easy
{
/*!
* @brief Describes the event type returned in streams.
*
* @since before 0.11.0
*/
enum class event_type
{
Update,
Notification,
Delete,
Error,
Filters_changed,
Undefined
};
/*!
* @brief Describes visibility of posts.
*
* @since before 0.11.0
*/
// TODO: What about instance-only?
enum class visibility_type
{
Direct,
Private,
Unlisted,
Public,
Undefined
};
/*!
* @brief Describes the attachment type
*
* @since before 0.11.0
*/
// TODO: Look up what Pleroma returns.
enum class attachment_type
{
Image,
Video,
Gifv,
Unknown,
Undefined
};
/*!
* @brief Describes the card type
*
* @since before 0.11.0
*/
enum class card_type
{
Link,
Photo,
Video,
Rich,
Undefined
};
/*!
* @brief Describes the notification type
*
* @since before 0.11.0
*/
enum class notification_type
{
Mention,
Reblog,
Favourite,
Follow,
Undefined
};
/*!
* @brief Describes the context.
*
* @since 0.104.0
*/
enum class context_type
{
Home,
Notifications,
Public,
Thread,
Undefined
};
/*!
* @brief Used for stream events.
*
* @since 0.100.0
*/
typedef struct stream_event_type
{
event_type type = event_type::Undefined;
string data;
} stream_event_type;
[[deprecated("Replaced by Mastodon::Easy::stream_event_type")]]
typedef stream_event_type stream_event;
/*!
* @brief Type of notification and 'push is requested or not'.
*
* @since 0.100.0
*/
typedef struct alert_type
{
Easy::notification_type type = Easy::notification_type::Undefined;
bool pushreq = false;
} alert_type;
/*!
* @brief Type for time. Converts to time_point and string.
*
* @since 0.100.0
*/
struct time_type
{
system_clock::time_point timepoint = system_clock::time_point();
operator const system_clock::time_point() const;
/*!
* @brief Returns local time as string in ISO 8601 format (%FT%T%z).
*
* @since 0.100.0
*/
operator const string() const;
/*!
* @brief Returns local time as string in ISO 8601 format (%FT%T%z).
*
* @since 0.100.0
*/
friend std::ostream &operator <<(std::ostream &out,
const Easy::time_type &t);
/*!
* @brief Converts time to a string.
*
* The return value can not exceed 1023 chars.
*
* @param format The format of the string, same as with
* `strftime`.
* @param local Use local time (default) or UTC.
*
* Example:
* @code
* Mastodon::Easy::time timepoint = status.created_at();
* std::cout << timepoint.strtime("%F, %T UTC", false) << '\n';
* @endcode
*
* @return The time as string.
*
* @since 0.100.0
*/
const string strtime(const string &format,
const bool &local = true) const;
};
[[deprecated("Replaced by Mastodon::Easy::time_type")]]
typedef time_type time;
/*!
* @brief Describes an account-field.
*
* @since 0.106.0
*/
typedef struct account_field_type
{
const string name;
const string value;
Easy::time_type verified_at;
} account_field_type;
/*!
* @brief URLs returned by Instance::urls().
*
* @since 0.106.0
*/
typedef struct urls_type
{
string streaming_api;
} urls_type;
/*!
* @brief Statistics returned by Instance::stats().
*/
typedef struct stats_type
{
uint64_t user_count = 0;
uint64_t status_count = 0;
uint64_t domain_count = 0;
} stats_type;
/*!
* @brief Poll options returned by Poll::options().
*/
typedef struct poll_options_type
{
string title;
uint64_t votes_count = 0;
} poll_options_type;
}
}
#endif // MASTODON_CPP_EASY_TYPES_EASY_HPP

Some files were not shown because too many files have changed in this diff Show More