This repository has been archived by the owner on Dec 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
/
keys_get_query_builder.go
92 lines (76 loc) · 2.14 KB
/
keys_get_query_builder.go
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
package t38c
import (
"context"
"strconv"
)
type KeysGetQueryBuilder struct {
client tile38Client
key, objectID string
withFields bool
}
func newKeysGetQueryBuilder(client tile38Client, key, objectID string) KeysGetQueryBuilder {
return KeysGetQueryBuilder{
client: client,
key: key,
objectID: objectID,
}
}
func (q KeysGetQueryBuilder) WithFields() KeysGetQueryBuilder {
q.withFields = true
return q
}
type GetObjectResponse struct {
Object Object `json:"object"`
Fields map[string]float64 `json:"fields"`
}
func (q KeysGetQueryBuilder) Object(ctx context.Context) (*GetObjectResponse, error) {
resp := new(GetObjectResponse)
args := []string{q.key, q.objectID}
if q.withFields {
args = append(args, "WITHFIELDS")
}
err := q.client.jExecute(ctx, resp, "GET", args...)
return resp, err
}
type GetPointResponse struct {
Point Point `json:"point"`
Fields map[string]float64 `json:"fields"`
}
func (q KeysGetQueryBuilder) Point(ctx context.Context) (*GetPointResponse, error) {
resp := new(GetPointResponse)
args := []string{q.key, q.objectID}
if q.withFields {
args = append(args, "WITHFIELDS")
}
args = append(args, "POINT")
err := q.client.jExecute(ctx, resp, "GET", args...)
return resp, err
}
type GetBoundsResponse struct {
Bounds Bounds `json:"bounds"`
Fields map[string]float64 `json:"fields"`
}
func (q KeysGetQueryBuilder) Bounds(ctx context.Context) (*GetBoundsResponse, error) {
resp := new(GetBoundsResponse)
args := []string{q.key, q.objectID}
if q.withFields {
args = append(args, "WITHFIELDS")
}
args = append(args, "BOUNDS")
err := q.client.jExecute(ctx, resp, "GET", args...)
return resp, err
}
type GetHashResponse struct {
Hash string `json:"hash"`
Fields map[string]float64 `json:"fields"`
}
func (q KeysGetQueryBuilder) Hash(ctx context.Context, precision int) (*GetHashResponse, error) {
resp := new(GetHashResponse)
args := []string{q.key, q.objectID}
if q.withFields {
args = append(args, "WITHFIELDS")
}
args = append(args, "HASH", strconv.Itoa(precision))
err := q.client.jExecute(ctx, resp, "GET", args...)
return resp, err
}