forked from adaburrows/C---QT-Geoloqi-Client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocationhistoryrequest.cpp
172 lines (154 loc) · 3.97 KB
/
locationhistoryrequest.cpp
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include "locationhistoryrequest.h"
LocationHistoryRequest::LocationHistoryRequest(QObject *parent) :
QObject(parent)
{
_base_url = QString("https://api.geoloqi.com/1/location/history");
_count = 0; // (default 10)
//_after(); // timestamp toString(Qt::ISODate)
//QDateTime _before; // timestamp toString(Qt::ISODate)
//_sort; // asc || desc
_accuracy = 0; // (default: 150)
_thinning = 0; // (default: 0)
//enum geometry_type _geometry; // circle || rectangle
//Coordinates *_center; // Required for geometry=circle
//long _radius; // Required for geometry=circle
//Coordinates *_sw; // Required for geometry=rectangle
//Coordinates *_ne; // Required for geometry=rectangle
//QString _base_url;
}
bool LocationHistoryRequest::isValid()
{
return true;
}
QUrl LocationHistoryRequest::url()
{
QUrl url(_base_url);
if(_count)
{
QString count;
count.setNum(_count);
url.addQueryItem(QString("count"),count);
}
if(_after.isValid())
{
QString afterString;
afterString.setNum(_after.toTime_t());
url.addQueryItem(QString("after"),afterString);
}
if(_before.isValid())
{
QString beforeString;
beforeString.setNum(_before.toTime_t());
url.addQueryItem(QString("before"),beforeString);
}
switch(_sort)
{
case no_sort:
break;
case asc:
url.addQueryItem(QString("sort"),QString("asc"));
break;
case desc:
url.addQueryItem(QString("sort"),QString("desc"));
break;
default:
break;
}
if(_accuracy)
{
QString accuracy;
accuracy.setNum(_count);
url.addQueryItem(QString("accuracy"),accuracy);
}
if(_thinning)
{
QString thinning;
thinning.setNum(_thinning);
url.addQueryItem(QString("thinning"),thinning);
}
switch(_geometry)
{
case no_geometry:
break;
case circle:
url.addQueryItem(QString("geometry"),QString("circle"));
break;
case rectangle:
url.addQueryItem(QString("geometry"),QString("rectangle"));
break;
default:
break;
}
if(_geometry == circle)
{
url.addQueryItem(QString("center"),_center->toString());
QString radius;
radius.setNum(_radius);
url.addQueryItem(QString("radius"),radius);
}else if (_geometry == rectangle) {
url.addQueryItem(QString("sw"),_sw->toString());
url.addQueryItem(QString("ne"),_ne->toString());
}
return url;
}
/* Setters */
LocationHistoryRequest * LocationHistoryRequest::setCount(long count)
{
_count = count;
return this;
}
LocationHistoryRequest * LocationHistoryRequest::setCount(QString countString)
{
_count = countString.toLong();
return this;
}
LocationHistoryRequest * LocationHistoryRequest::setAfter(QDateTime after)
{
_after = after;
return this;
}
LocationHistoryRequest * LocationHistoryRequest::setBefore(QDateTime before)
{
_before = before;
return this;
}
LocationHistoryRequest * LocationHistoryRequest::setSort(enum sort_direction sort)
{
_sort = sort;
return this;
}
LocationHistoryRequest * LocationHistoryRequest::setAccuracy(long accuracy)
{
_accuracy = accuracy;
return this;
}
LocationHistoryRequest * LocationHistoryRequest::setThinning(long thinning)
{
_thinning = thinning;
return this;
}
LocationHistoryRequest * LocationHistoryRequest::setGeometry(enum geometry_type geometry)
{
_geometry = geometry;
return this;
}
LocationHistoryRequest * LocationHistoryRequest::setCenter(Coordinates *center)
{
_center = center;
return this;
}
LocationHistoryRequest * LocationHistoryRequest::setRadius(long radius)
{
_radius = radius;
return this;
}
LocationHistoryRequest * LocationHistoryRequest::setSW(Coordinates *sw)
{
_sw = sw;
return this;
}
LocationHistoryRequest * LocationHistoryRequest::setNE(Coordinates *ne)
{
_ne = ne;
return this;
}