about summary refs log tree commit diff stats
path: root/src/tweet.cpp
blob: 5885b5101118c6b8c2ddebb22a3fb98bbe469993 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "tweet.h"
#include <json.hpp>
#include <cassert>

using nlohmann::json;

namespace twitter {
  
  tweet::tweet() : _valid(false)
  {
    
  }
  
  tweet::tweet(std::string data) : _valid(true)
  {
    auto _data = json::parse(data);
    _id = _data.at("id");
    _text = _data.at("text");
    _author = user(_data.at("user").dump());
    _retweeted = _data.at("retweeted");
  }
  
  tweet_id tweet::getID() const
  {
    assert(_valid);
    
    return _id;
  }
  
  std::string tweet::getText() const
  {
    assert(_valid);
    
    return _text;
  }
  
  const user& tweet::getAuthor() const
  {
    assert(_valid);
    
    return _author;
  }
  
  bool tweet::isRetweet() const
  {
    assert(_valid);
    
    return _retweeted;
  }
  
  tweet::operator bool() const
  {
    return _valid;
  }
  
};