/
beacons.clj
517 lines (442 loc) · 17 KB
/
beacons.clj
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
(ns happygapi.proximitybeacon.beacons
"Proximity Beacon API: beacons.
Registers, manages, indexes, and searches beacons.
See: https://developers.google.com/beacons/proximity/api/reference/rest/v1beta1/beacons"
(:require [cheshire.core :as json]
[clj-http.client :as http]
[happy.util :as util]))
(defn delete$
"https://developers.google.com/beacons/proximity/api/reference/rest/v1beta1/beacons/delete
Required parameters: beaconName
Optional parameters: projectId
Deletes the specified beacon including all diagnostics data for the beacon
as well as any attachments on the beacon (including those belonging to
other projects). This operation cannot be undone.
Authenticate using an [OAuth access
token](https://developers.google.com/identity/protocols/OAuth2) from a
signed-in user with **Is owner** or **Can edit** permissions in the Google
Developers Console project."
{:scopes ["https://www.googleapis.com/auth/userlocation.beacon.registry"]}
[auth parameters]
{:pre [(util/has-keys? parameters #{:beaconName})]}
(util/get-response
(http/delete
(util/get-url
"https://proximitybeacon.googleapis.com/"
"v1beta1/{+beaconName}"
#{:beaconName}
parameters)
(merge-with
merge
{:throw-exceptions false,
:query-params parameters,
:accept :json,
:as :json}
auth))))
(defn deactivate$
"https://developers.google.com/beacons/proximity/api/reference/rest/v1beta1/beacons/deactivate
Required parameters: beaconName
Optional parameters: projectId
Deactivates a beacon. Once deactivated, the API will not return
information nor attachment data for the beacon when queried via
`beaconinfo.getforobserved`. Calling this method on an already inactive
beacon will do nothing (but will return a successful response code).
Authenticate using an [OAuth access
token](https://developers.google.com/identity/protocols/OAuth2) from a
signed-in user with **Is owner** or **Can edit** permissions in the Google
Developers Console project."
{:scopes ["https://www.googleapis.com/auth/userlocation.beacon.registry"]}
[auth parameters]
{:pre [(util/has-keys? parameters #{:beaconName})]}
(util/get-response
(http/post
(util/get-url
"https://proximitybeacon.googleapis.com/"
"v1beta1/{+beaconName}:deactivate"
#{:beaconName}
parameters)
(merge-with
merge
{:throw-exceptions false,
:query-params parameters,
:accept :json,
:as :json}
auth))))
(defn list$
"https://developers.google.com/beacons/proximity/api/reference/rest/v1beta1/beacons/list
Required parameters: none
Optional parameters: pageToken, q, pageSize, projectId
Searches the beacon registry for beacons that match the given search
criteria. Only those beacons that the client has permission to list
will be returned.
Authenticate using an [OAuth access
token](https://developers.google.com/identity/protocols/OAuth2) from a
signed-in user with **viewer**, **Is owner** or **Can edit** permissions in
the Google Developers Console project."
{:scopes ["https://www.googleapis.com/auth/userlocation.beacon.registry"]}
[auth parameters]
{:pre [(util/has-keys? parameters #{})]}
(util/get-response
(http/get
(util/get-url
"https://proximitybeacon.googleapis.com/"
"v1beta1/beacons"
#{}
parameters)
(merge-with
merge
{:throw-exceptions false,
:query-params parameters,
:accept :json,
:as :json}
auth))))
(defn register$
"https://developers.google.com/beacons/proximity/api/reference/rest/v1beta1/beacons/register
Required parameters: none
Optional parameters: projectId
Body:
{:description string,
:properties {},
:beaconName string,
:indoorLevel {:name string},
:provisioningKey string,
:status string,
:advertisedId {:type string, :id string},
:latLng {:latitude number, :longitude number},
:ephemeralIdRegistration {:rotationPeriodExponent integer,
:serviceEcdhPublicKey string,
:beaconIdentityKey string,
:initialEid string,
:beaconEcdhPublicKey string,
:initialClockValue string},
:expectedStability string,
:placeId string}
Registers a previously unregistered beacon given its `advertisedId`.
These IDs are unique within the system. An ID can be registered only once.
Authenticate using an [OAuth access
token](https://developers.google.com/identity/protocols/OAuth2) from a
signed-in user with **Is owner** or **Can edit** permissions in the Google
Developers Console project."
{:scopes ["https://www.googleapis.com/auth/userlocation.beacon.registry"]}
[auth parameters body]
{:pre [(util/has-keys? parameters #{})]}
(util/get-response
(http/post
(util/get-url
"https://proximitybeacon.googleapis.com/"
"v1beta1/beacons:register"
#{}
parameters)
(merge-with
merge
{:content-type :json,
:body (json/generate-string body),
:throw-exceptions false,
:query-params parameters,
:accept :json,
:as :json}
auth))))
(defn activate$
"https://developers.google.com/beacons/proximity/api/reference/rest/v1beta1/beacons/activate
Required parameters: beaconName
Optional parameters: projectId
Activates a beacon. A beacon that is active will return information
and attachment data when queried via `beaconinfo.getforobserved`.
Calling this method on an already active beacon will do nothing (but
will return a successful response code).
Authenticate using an [OAuth access
token](https://developers.google.com/identity/protocols/OAuth2) from a
signed-in user with **Is owner** or **Can edit** permissions in the Google
Developers Console project."
{:scopes ["https://www.googleapis.com/auth/userlocation.beacon.registry"]}
[auth parameters]
{:pre [(util/has-keys? parameters #{:beaconName})]}
(util/get-response
(http/post
(util/get-url
"https://proximitybeacon.googleapis.com/"
"v1beta1/{+beaconName}:activate"
#{:beaconName}
parameters)
(merge-with
merge
{:throw-exceptions false,
:query-params parameters,
:accept :json,
:as :json}
auth))))
(defn get$
"https://developers.google.com/beacons/proximity/api/reference/rest/v1beta1/beacons/get
Required parameters: beaconName
Optional parameters: projectId
Returns detailed information about the specified beacon.
Authenticate using an [OAuth access
token](https://developers.google.com/identity/protocols/OAuth2) from a
signed-in user with **viewer**, **Is owner** or **Can edit** permissions in
the Google Developers Console project.
Requests may supply an Eddystone-EID beacon name in the form:
`beacons/4!beaconId` where the `beaconId` is the base16 ephemeral ID
broadcast by the beacon. The returned `Beacon` object will contain the
beacon's stable Eddystone-UID. Clients not authorized to resolve the
beacon's ephemeral Eddystone-EID broadcast will receive an error."
{:scopes ["https://www.googleapis.com/auth/userlocation.beacon.registry"]}
[auth parameters]
{:pre [(util/has-keys? parameters #{:beaconName})]}
(util/get-response
(http/get
(util/get-url
"https://proximitybeacon.googleapis.com/"
"v1beta1/{+beaconName}"
#{:beaconName}
parameters)
(merge-with
merge
{:throw-exceptions false,
:query-params parameters,
:accept :json,
:as :json}
auth))))
(defn update$
"https://developers.google.com/beacons/proximity/api/reference/rest/v1beta1/beacons/update
Required parameters: beaconName
Optional parameters: projectId
Body:
{:description string,
:properties {},
:beaconName string,
:indoorLevel {:name string},
:provisioningKey string,
:status string,
:advertisedId {:type string, :id string},
:latLng {:latitude number, :longitude number},
:ephemeralIdRegistration {:rotationPeriodExponent integer,
:serviceEcdhPublicKey string,
:beaconIdentityKey string,
:initialEid string,
:beaconEcdhPublicKey string,
:initialClockValue string},
:expectedStability string,
:placeId string}
Updates the information about the specified beacon. **Any field that you do
not populate in the submitted beacon will be permanently erased**, so you
should follow the \"read, modify, write\" pattern to avoid inadvertently
destroying data.
Changes to the beacon status via this method will be silently ignored.
To update beacon status, use the separate methods on this API for
activation, deactivation, and decommissioning.
Authenticate using an [OAuth access
token](https://developers.google.com/identity/protocols/OAuth2) from a
signed-in user with **Is owner** or **Can edit** permissions in the Google
Developers Console project."
{:scopes ["https://www.googleapis.com/auth/userlocation.beacon.registry"]}
[auth parameters body]
{:pre [(util/has-keys? parameters #{:beaconName})]}
(util/get-response
(http/put
(util/get-url
"https://proximitybeacon.googleapis.com/"
"v1beta1/{+beaconName}"
#{:beaconName}
parameters)
(merge-with
merge
{:content-type :json,
:body (json/generate-string body),
:throw-exceptions false,
:query-params parameters,
:accept :json,
:as :json}
auth))))
(defn decommission$
"https://developers.google.com/beacons/proximity/api/reference/rest/v1beta1/beacons/decommission
Required parameters: beaconName
Optional parameters: projectId
Decommissions the specified beacon in the service. This beacon will no
longer be returned from `beaconinfo.getforobserved`. This operation is
permanent -- you will not be able to re-register a beacon with this ID
again.
Authenticate using an [OAuth access
token](https://developers.google.com/identity/protocols/OAuth2) from a
signed-in user with **Is owner** or **Can edit** permissions in the Google
Developers Console project."
{:scopes ["https://www.googleapis.com/auth/userlocation.beacon.registry"]}
[auth parameters]
{:pre [(util/has-keys? parameters #{:beaconName})]}
(util/get-response
(http/post
(util/get-url
"https://proximitybeacon.googleapis.com/"
"v1beta1/{+beaconName}:decommission"
#{:beaconName}
parameters)
(merge-with
merge
{:throw-exceptions false,
:query-params parameters,
:accept :json,
:as :json}
auth))))
(defn attachments-delete$
"https://developers.google.com/beacons/proximity/api/reference/rest/v1beta1/beacons/attachments/delete
Required parameters: attachmentName
Optional parameters: projectId
Deletes the specified attachment for the given beacon. Each attachment has
a unique attachment name (`attachmentName`) which is returned when you
fetch the attachment data via this API. You specify this with the delete
request to control which attachment is removed. This operation cannot be
undone.
Authenticate using an [OAuth access
token](https://developers.google.com/identity/protocols/OAuth2) from a
signed-in user with **Is owner** or **Can edit** permissions in the Google
Developers Console project."
{:scopes ["https://www.googleapis.com/auth/userlocation.beacon.registry"]}
[auth parameters]
{:pre [(util/has-keys? parameters #{:attachmentName})]}
(util/get-response
(http/delete
(util/get-url
"https://proximitybeacon.googleapis.com/"
"v1beta1/{+attachmentName}"
#{:attachmentName}
parameters)
(merge-with
merge
{:throw-exceptions false,
:query-params parameters,
:accept :json,
:as :json}
auth))))
(defn attachments-list$
"https://developers.google.com/beacons/proximity/api/reference/rest/v1beta1/beacons/attachments/list
Required parameters: beaconName
Optional parameters: namespacedType, projectId
Returns the attachments for the specified beacon that match the specified
namespaced-type pattern.
To control which namespaced types are returned, you add the
`namespacedType` query parameter to the request. You must either use
`*/*`, to return all attachments, or the namespace must be one of
the ones returned from the `namespaces` endpoint.
Authenticate using an [OAuth access
token](https://developers.google.com/identity/protocols/OAuth2) from a
signed-in user with **viewer**, **Is owner** or **Can edit** permissions in
the Google Developers Console project."
{:scopes ["https://www.googleapis.com/auth/userlocation.beacon.registry"]}
[auth parameters]
{:pre [(util/has-keys? parameters #{:beaconName})]}
(util/get-response
(http/get
(util/get-url
"https://proximitybeacon.googleapis.com/"
"v1beta1/{+beaconName}/attachments"
#{:beaconName}
parameters)
(merge-with
merge
{:throw-exceptions false,
:query-params parameters,
:accept :json,
:as :json}
auth))))
(defn attachments-create$
"https://developers.google.com/beacons/proximity/api/reference/rest/v1beta1/beacons/attachments/create
Required parameters: beaconName
Optional parameters: projectId
Body:
{:creationTimeMs string,
:maxDistanceMeters number,
:attachmentName string,
:namespacedType string,
:data string}
Associates the given data with the specified beacon. Attachment data must
contain two parts:
<ul>
<li>A namespaced type.</li>
<li>The actual attachment data itself.</li>
</ul>
The namespaced type consists of two parts, the namespace and the type.
The namespace must be one of the values returned by the `namespaces`
endpoint, while the type can be a string of any characters except for the
forward slash (`/`) up to 100 characters in length.
Attachment data can be up to 1024 bytes long.
Authenticate using an [OAuth access
token](https://developers.google.com/identity/protocols/OAuth2) from a
signed-in user with **Is owner** or **Can edit** permissions in the Google
Developers Console project."
{:scopes ["https://www.googleapis.com/auth/userlocation.beacon.registry"]}
[auth parameters body]
{:pre [(util/has-keys? parameters #{:beaconName})]}
(util/get-response
(http/post
(util/get-url
"https://proximitybeacon.googleapis.com/"
"v1beta1/{+beaconName}/attachments"
#{:beaconName}
parameters)
(merge-with
merge
{:content-type :json,
:body (json/generate-string body),
:throw-exceptions false,
:query-params parameters,
:accept :json,
:as :json}
auth))))
(defn attachments-batchDelete$
"https://developers.google.com/beacons/proximity/api/reference/rest/v1beta1/beacons/attachments/batchDelete
Required parameters: beaconName
Optional parameters: namespacedType, projectId
Deletes multiple attachments on a given beacon. This operation is
permanent and cannot be undone.
You can optionally specify `namespacedType` to choose which attachments
should be deleted. If you do not specify `namespacedType`, all your
attachments on the given beacon will be deleted. You also may explicitly
specify `*/*` to delete all.
Authenticate using an [OAuth access
token](https://developers.google.com/identity/protocols/OAuth2) from a
signed-in user with **Is owner** or **Can edit** permissions in the Google
Developers Console project."
{:scopes ["https://www.googleapis.com/auth/userlocation.beacon.registry"]}
[auth parameters]
{:pre [(util/has-keys? parameters #{:beaconName})]}
(util/get-response
(http/post
(util/get-url
"https://proximitybeacon.googleapis.com/"
"v1beta1/{+beaconName}/attachments:batchDelete"
#{:beaconName}
parameters)
(merge-with
merge
{:throw-exceptions false,
:query-params parameters,
:accept :json,
:as :json}
auth))))
(defn diagnostics-list$
"https://developers.google.com/beacons/proximity/api/reference/rest/v1beta1/beacons/diagnostics/list
Required parameters: beaconName
Optional parameters: pageToken, pageSize, alertFilter, projectId
List the diagnostics for a single beacon. You can also list diagnostics for
all the beacons owned by your Google Developers Console project by using
the beacon name `beacons/-`.
Authenticate using an [OAuth access
token](https://developers.google.com/identity/protocols/OAuth2) from a
signed-in user with **viewer**, **Is owner** or **Can edit** permissions in
the Google Developers Console project."
{:scopes ["https://www.googleapis.com/auth/userlocation.beacon.registry"]}
[auth parameters]
{:pre [(util/has-keys? parameters #{:beaconName})]}
(util/get-response
(http/get
(util/get-url
"https://proximitybeacon.googleapis.com/"
"v1beta1/{+beaconName}/diagnostics"
#{:beaconName}
parameters)
(merge-with
merge
{:throw-exceptions false,
:query-params parameters,
:accept :json,
:as :json}
auth))))