Browse Source

switched confuig file format from cfg to json

tags/0.4.0
tastytea 2 years ago
parent
commit
b361753f51
Signed by: tastytea <tastytea@tastytea.de> GPG Key ID: 59346E0EA35C67E5
4 changed files with 46 additions and 13 deletions
  1. +1
    -1
      CMakeLists.txt
  2. +8
    -3
      README.md
  3. +5
    -0
      src/expandurl-mastodon.hpp
  4. +32
    -9
      src/masto.cpp

+ 1
- 1
CMakeLists.txt View File

@@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.7)
project (expandurl-mastodon
VERSION 0.3.3
VERSION 0.4.0
LANGUAGES CXX
)



+ 8
- 3
README.md View File

@@ -21,6 +21,7 @@ or to [@tastytea@soc.ialis.me](https://soc.ialis.me/@tastytea).
* [cmake](https://cmake.org/) (tested: 3.9.6)
* [curlpp](http://www.curlpp.org/) (tested: 0.8.1)
* [mastodon-cpp](https://github.com/tastytea/mastodon-cpp) (at least: 0.13.1)
* [jsoncpp](https://github.com/open-source-parsers/jsoncpp) (tested: 1.8.4)

## Get sourcecode

@@ -39,12 +40,16 @@ Install with `make install`.

# Usage

**The config file has changed from cfg to JSON in 0.4.0.**

You will need to generate an access token yourself at the moment. Create a
config file with your account and access token in
`${HOME}/.config/expandurl-mastodon.cfg`:
`${HOME}/.config/expandurl-mastodon.json`:

expandurl@example.social
abc123
{
"account": "expandurl@example.social",
"access_tocken": "abc123"
}

Now start expandurl-mastodon without parameters.



+ 5
- 0
src/expandurl-mastodon.hpp View File

@@ -24,6 +24,7 @@
#include <cstdint>
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/all.hpp>
#include <jsoncpp/json/json.h>

using std::string;
using Mastodon::API;
@@ -75,6 +76,7 @@ public:
const void stop();

std::vector<Easy::Notification> get_new_messages();
const std::vector<Easy::Notification> catchup();
Easy::Status get_status(const std::uint_fast64_t &id);
const bool send_reply(const Easy::Status &to_status, const string &message);
const std::uint_fast64_t get_parent_id(Easy::Notification &notif);
@@ -89,6 +91,9 @@ private:
std::unique_ptr<API::http> _ptr;
std::thread _thread;
bool _running;
Json::Value _config;

const bool read_config();
};

#endif // EXPANDURL_MASTODON_HPP

+ 32
- 9
src/masto.cpp View File

@@ -18,6 +18,7 @@
#include <cstdlib> // getenv()
#include <iostream>
#include <mutex>
#include <sstream>
#include "version.hpp"
#include "expandurl-mastodon.hpp"

@@ -31,27 +32,44 @@ Listener::Listener()
, _stream("")
, _ptr(nullptr)
, _running(false)
{

if (read_config())
{
_masto = std::make_unique<Easy>(_instance, _access_token);
_masto->set_useragent(static_cast<const string>("expandurl-mastodon/") +
global::version);
}
else
{
exit(1);
}
}

const bool Listener::read_config()
{
const string filepath = static_cast<const string>(getenv("HOME")) +
"/.config/expandurl-mastodon.cfg";
"/.config/expandurl-mastodon.json";
std::ifstream file(filepath);

if (file.is_open())
{
std::getline(file, _instance);
_instance = _instance.substr(_instance.find('@') + 1);
std::getline(file, _access_token);
std::stringstream json;
json << file.rdbuf();
file.close();
json >> _config;

_masto = std::make_unique<Easy>(_instance, _access_token);
_masto->set_useragent(static_cast<const string>("expandurl-mastodon/") +
global::version);
_instance = _config["account"].asString();
_instance = _instance.substr(_instance.find('@') + 1);
_access_token = _config["access_token"].asString();
}
else
{
cerr << "ERROR: Could not open " << filepath << '\n';
exit(1);
cerr << "ERROR: Could not open " << filepath << ".\n";
return false;
}

return true;
}

const void Listener::start()
@@ -126,6 +144,11 @@ std::vector<Easy::Notification> Listener::get_new_messages()
return v;
}

const std::vector<Easy::Notification> Listener::catchup()
{
//
}

Mastodon::Easy::Status Listener::get_status(const std::uint_fast64_t &id)
{
std::uint_fast16_t ret;


Loading…
Cancel
Save