summaryrefslogtreecommitdiff
path: root/src/apiuseraccount.h
blob: 8a238d71452c92a5195808ba228bddefb8c202ea (plain)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#ifndef APIUSERACCOUNT_H
#define APIUSERACCOUNT_H

#include <QString>

/**
* represents user account types on a mod provider website such as nexus
*/
enum class APIUserAccountTypes
{
  // not logged in
  None = 0,

  // regular account
  Regular,

  // premium account
  Premium
};


/**
* current limits imposed on the user account
**/
struct APILimits
{
  // maximum number of requests per day
  int maxDailyRequests = 0;

  // remaining number of requests today
  int remainingDailyRequests = 0;

  // maximum number of requests per hour
  int maxHourlyRequests = 0;

  // remaining number of requests this hour
  int remainingHourlyRequests = 0;
};


/**
* API statistics
*/
struct APIStats
{
  // number of API requests currently queued
  int requestsQueued = 0;
};


/**
* represents a user account on the mod provier website
*/
class APIUserAccount
{
public:
  // when the number of remanining requests is under this number, further
  // requests will be throttled by avoiding non-critical ones
  static const int ThrottleThreshold = 200;

  APIUserAccount();

  /**
  * user id
  */
  const QString& id() const;

  /**
  * user name
  */
  const QString& name() const;

  /**
  * account type
  */
  APIUserAccountTypes type() const;

  /**
  * current API limits
  */
  const APILimits& limits() const;


  /**
  * sets the user id
  */
  APIUserAccount& id(const QString& id);

  /**
  * sets the user name
  **/
  APIUserAccount& name(const QString& name);

  /**
  * sets the acount type
  */
  APIUserAccount& type(APIUserAccountTypes type);

  /**
  * sets the current limits
  */
  APIUserAccount& limits(const APILimits& limits);


  /**
  * returns the number of remaining requests
  */
  int remainingRequests() const;

  /**
  * whether the number of remaining requests is low enough that further
  * requests should be throttled
  */
  bool shouldThrottle() const;

  /**
  * true if all the remaining requests have been used and the API will refuse
  * further requests
  */
  bool exhausted() const;

private:
  QString m_id, m_name;
  APIUserAccountTypes m_type;
  APILimits m_limits;
  APIStats m_stats;
};

#endif // APIUSERACCOUNT_H