forked from viewfinderco/viewfinder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
json_schema.py
2718 lines (2435 loc) · 79.1 KB
/
json_schema.py
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
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright 2012 Viewfinder Inc. All Rights Reserved.
"""JSON Schemas for request/response pairs used with Viewfinder ops.
All times are expressed in seconds (possibly subsecond floating-point
precision) since the epoch (January 1st, 1970) in UTC.
Every mutating request may be run synchronously by specifying
'synchronous' = True in the request header.
"""
__authors__ = ['[email protected] (Spencer Kimball)',
'[email protected] (Andy Kimball)']
from copy import deepcopy
from viewfinder.backend.db.follower import Follower
from viewfinder.backend.db.contact import Contact
from viewfinder.backend.db.settings import AccountSettings
from viewfinder.backend.db.viewpoint import Viewpoint
##
# HELPER METHODS
##
def _MakeOptional(property_dict, test_key):
"""Iterates through all key/value pairs in the property dictionary. If the "test_key" function
returns True for a particular property key, then makes that property optional. Returns the
updated property dict.
"""
for key, value in property_dict.items():
if test_key(key):
property_dict[key]['required'] = False
return property_dict
def _CopyProperties(target_dict, source_dict):
"""Deep copies properties in source_dict['properties'] to target_dict['properties']. Asserts
if a property of the same name already exists in source_dict['properties'], but has a
different value.
"""
for key, value in source_dict['properties'].items():
assert key not in target_dict['properties'] or target_dict['properties'][key] == value, (source_dict, target_dict)
target_dict['properties'][key] = deepcopy(value)
##
# COMMON DATA STRUCTURES
##
# Headers object that must be at the top-level of every request or response message.
HEADERS = {
'description': 'contains headers used for read-only methods',
'type': 'object',
'properties': {
'version': {
'description': 'version of the message format; this is not necessarily equal '
'to the max version supported by the sender; for example, the server will '
'respond in an older dialect to older clients',
'type': 'integer',
},
'min_required_version': {
'description': 'this field requires that the recipient be able to understand '
'messages of this version or greater; if not, the recipient may report an '
'error (server), or it may try again after upgrade to a later version (client)',
'type': 'integer',
'required': False,
},
'synchronous': {
'description': 'used in tests to wait until a requested operation completes',
'type': 'boolean',
'required': False,
},
},
}
OP_HEADERS = {
'description': 'contains headers used for mutable methods',
'type': 'object',
'properties': {
'op_id': {
'description': 'id of the requested operation; the id is a composite of '
'the device id and a unique operation id generated by that device; the '
'client may provide the op_id, or if it does not, the server will '
'generate one',
'type': 'string',
},
'op_timestamp': {
'description': 'timestamp of this requested operation; the client may '
'provide the op_timestamp, or if it does not, the server will generate one',
'type': 'number',
},
},
}
_CopyProperties(target_dict=OP_HEADERS, source_dict=HEADERS)
# Location in degrees of latitude and longitude and accuracy in meters.
LOCATION = {
'description': 'location in degrees of latitude & longitude and accuracy in meters',
'type': 'object',
'properties': {
'latitude': {'type': 'number'},
'longitude': {'type': 'number'},
'accuracy': {'type': 'number'},
},
}
OPTIONAL_LOCATION = deepcopy(LOCATION)
OPTIONAL_LOCATION['required'] = False
# Hierarchical place names from country to street level.
PLACEMARK = {
'description': 'placemark identifies a place by name from country to street level',
'type': 'object',
'properties': {
'iso_country_code': {'type': 'string', 'blank': True, 'required': False},
'country': {'type': 'string', 'blank': True, 'required': False},
'state': {'type': 'string', 'blank': True, 'required': False},
'locality': {'type': 'string', 'blank': True, 'required': False},
'sublocality': {'type': 'string', 'blank': True, 'required': False},
'thoroughfare': {'type': 'string', 'blank': True, 'required': False},
'subthoroughfare': {'type': 'string', 'blank': True, 'required': False},
},
}
OPTIONAL_PLACEMARK = deepcopy(PLACEMARK)
OPTIONAL_PLACEMARK['required'] = False
# Select a set of assets, with some control over the scope of projection.
VIEWPOINT_SELECTION = {
'description': 'select a set of viewpoints by id; if "get_attributes" is '
'True or not specified, then return all attributes on the viewpoints; '
'"get_followers", "get_activities", "get_episodes", and "get_comments" '
'specify whether to return the corresponding collections associated with '
'the viewpoint; "start_key" fields enable paging of the collections',
'type': 'array',
'items': {
'type': 'object',
'properties': {
'viewpoint_id': {'type': 'string'},
'get_attributes': {'type': 'boolean', 'required': False},
'get_followers': {'type': 'boolean', 'required': False},
'follower_start_key': {'type': 'string', 'required': False},
'get_activities': {'type': 'boolean', 'required': False},
'activity_start_key': {'type': 'string', 'required': False},
'get_episodes': {'type': 'boolean', 'required': False},
'episode_start_key': {'type': 'string', 'required': False},
'get_comments': {'type': 'boolean', 'required': False},
'comment_start_key': {'type': 'string', 'required': False},
},
},
}
EPISODE_SELECTION = {
'description': 'select a set of episodes by id; if "get_attributes" is '
'True or not specified, then return all attributes on the episodes; if '
'"get_photos" is True or not specified, return photos in the episode, '
'starting with "photo_start_key" if it is specified',
'type': 'array',
'items': {
'type': 'object',
'properties': {
'episode_id': {'type': 'string'},
'get_attributes': {'type': 'boolean', 'required': False},
'get_photos': {'type': 'boolean', 'required': False},
'photo_start_key': {'type': 'string', 'required': False},
},
},
}
USER_SELECTION = {
'description': 'select set of users by id',
'type': 'array',
'items': {'type': 'number'},
}
CONTACT_SELECTION = {
'description': 'select set of contacts that have a sort_key greater '
'than start_key',
'type': 'object',
'properties': {
'all': {
'description': 'invalidate all contacts, forcing complete client reload',
'type': 'boolean', 'required': False,
},
'start_key': {'type': 'string'},
},
}
# Cover photo metadata.
COVER_PHOTO_METADATA = {
'description': 'describes cover photo for a shared viewpoint',
'type': 'object',
'required': False,
'properties': {
'episode_id': {
'description': 'episode_id of episode that contains cover photo',
'type': 'string'
},
'photo_id': {
'description': 'photo_id of cover photo',
'type': 'string'
},
},
}
# Activity metadata.
CREATE_ACTIVITY_METADATA = {
'description': 'activity metadata for creation',
'type': 'object',
'properties': {
'activity_id': {'type': 'string'},
'timestamp': {
'description': 'time that activity was created on the client',
'type': 'number',
},
},
}
ACTIVITY_POST_ARRAY = {
'description': 'array of (episode, photo_id) tuples used by share '
'and unshare activities',
'type': 'array',
'items': {
'type': 'object',
'properties': {
'episode_id': {'type': 'string'},
'photo_ids': {
'type': 'array',
'items': {'type': 'string'},
},
},
},
}
ACTIVITY_METADATA = {
'description': 'full activity metadata (includes create metadata)',
'type': 'object',
'properties': {
'viewpoint_id': {'type': 'string'},
'user_id': {
'description': 'id of user that caused the activity to be created',
'type': 'number',
},
'update_seq': {
'description': 'set to the value of the viewpoint\'s update_seq '
'attribute after it is incremented during the creation of the '
'activity',
'type': 'number',
},
'add_followers': {
'description': 'new followers added to this viewpoint',
'required': False,
'type': 'object',
'properties': {
'follower_ids': {
'description': 'user ids of new viewpoint followers',
'type': 'array',
'items': {'type': 'number'},
},
},
},
'merge_accounts': {
'description': 'user accounts merged; target user added to this viewpoint',
'required': False,
'type': 'object',
'properties': {
'target_user_id': {
'description': 'user that receives the assets to be merged; this user remains after '
'the merge is completed',
'type': 'number',
},
'source_user_id': {
'description': 'user that provides the assets to be merged; the account of this user '
'is terminated after the merge is completed',
'type': 'number',
},
},
},
'post_comment': {
'description': 'comment posted to this viewpoint',
'required': False,
'type': 'object',
'properties': {
'comment_id': {'type': 'string'},
},
},
'remove_followers': {
'description': 'followers removed from this viewpoint',
'required': False,
'type': 'object',
'properties': {
'follower_ids': {
'description': 'user ids of removed viewpoint followers',
'type': 'array',
'items': {'type': 'number'},
},
},
},
'save_photos': {
'description': 'photos saved to default viewpoint',
'required': False,
'type': 'object',
'properties': {
'episodes': ACTIVITY_POST_ARRAY,
},
},
'share_existing': {
'description': 'photos shared to an already existing viewpoint',
'required': False,
'type': 'object',
'properties': {
'episodes': ACTIVITY_POST_ARRAY,
},
},
'share_new': {
'description': 'photos shared to a newly created viewpoint',
'required': False,
'type': 'object',
'properties': {
'episodes': ACTIVITY_POST_ARRAY,
'follower_ids': {
'description': 'user ids of new viewpoint followers; excludes '
'the creating user id',
'type': 'array',
'items': {'type': 'number'},
},
},
},
'unshare': {
'description': 'photos unshared from this viewpoint',
'required': False,
'type': 'object',
'properties': {
'episodes': ACTIVITY_POST_ARRAY,
},
},
'update_episode': {
'description': 'episode metadata updated in this viewpoint',
'required': False,
'type': 'object',
'properties': {
'episode_id': {'type': 'string'},
},
},
'update_viewpoint': {
'description': 'viewpoint metadata updated',
'required': False,
'type': 'object',
'properties': {
'viewpoint_id': {'type': 'string'},
'prev_title': {'type': 'string', 'required': False},
'prev_cover_photo': COVER_PHOTO_METADATA,
},
},
'upload_episode': {
'description': 'photos uploaded to an episode in this viewpoint',
'required': False,
'type': 'object',
'properties': {
'episode_id': {'type': 'string'},
'photo_ids': {
'type': 'array',
'items': {'type': 'string'},
},
},
},
},
}
_CopyProperties(target_dict=ACTIVITY_METADATA, source_dict=CREATE_ACTIVITY_METADATA)
# Photo metadata.
PHOTO_URL_METADATA = {
'description': 'metadata for signed S3 URLs that reference photo image data',
'type': 'object',
'properties': {
'tn_get_url': {
'description': 'url for thumbnail resolution image file; '
'URL expires in 24 hours--only returned with photo query responses',
'type': 'string', 'required': False,
},
'med_get_url': {
'description': 'url for medium-screen resolution image file (max 480 pixels); '
'URL expires in 24 hours--only returned with photo query responses',
'type': 'string', 'required': False,
},
'full_get_url': {
'description': 'url for full-screen resolution image file (max 960 pixels); '
'URL expires in 24 hours--only returned with photo query responses',
'type': 'string', 'required': False,
},
'orig_get_url': {
'description': 'url for full-screen resolution image file; '
'URL expires in 24 hours--only returned with photo query responses',
'type': 'string', 'required': False,
},
},
}
USER_PHOTO_METADATA = {
'description': 'per-user photo metadata',
'type': 'object',
'properties': {
'photo_id': {'type': 'string'},
'asset_keys': {
'description': 'identifiers for copies of this photo in the user\'s devices\' native '
'asset library. This field is per-user, and its format is client-specific',
'type': 'array',
'required': False,
'items': {'type': 'string'},
},
},
}
UPDATE_PHOTO_METADATA = {
'description': 'photo metadata for updates',
'type': 'object',
'properties': {
'location': OPTIONAL_LOCATION,
'placemark': OPTIONAL_PLACEMARK,
'caption': {'type': 'string', 'required': False},
'link': {'type': 'string', 'required': False},
},
}
_CopyProperties(target_dict=UPDATE_PHOTO_METADATA, source_dict=USER_PHOTO_METADATA)
UPLOAD_PHOTO_METADATA = {
'description': 'photo metadata for upload (includes update metadata)',
'type': 'object',
'properties': {
'timestamp': {
'description': 'time that photo was created on the client',
'type': 'number',
},
'aspect_ratio': {
'description': 'floating point value: width / height',
'type': 'number',
},
'tn_md5': {
'description': 'thumbnail resolution md5 csum',
'type': 'string',
},
'med_md5': {
'description': 'medium resolution md5 csum (max 480 pixels)',
'type': 'string',
},
'full_md5': {
'description': 'full-screen resolution md5 csum (max 960 pixels)',
'type': 'string',
},
'orig_md5': {
'description': 'original resolution md5 csum',
'type': 'string',
},
'tn_size': {
'description': 'thumbnail resolution size in bytes',
'type': 'integer', 'required': False,
},
'med_size': {
'description': 'medium resolution size in bytes (max 480 pixels)',
'type': 'integer', 'required': False,
},
'full_size': {
'description': 'full-screen resolution size in bytes (max 960 pixels)',
'type': 'integer', 'required': False,
},
'orig_size': {
'description': 'original resolution size in bytes',
'type': 'integer', 'required': False,
},
'content_type': {
'description': 'image file content type (e.g. image/jpeg)',
'type': 'string', 'required': False,
},
'parent_id': {
'description': 'if specified, this photo was derived from another',
'type': 'string', 'required': False,
},
},
}
_CopyProperties(target_dict=UPLOAD_PHOTO_METADATA, source_dict=UPDATE_PHOTO_METADATA)
PHOTO_METADATA = {
'description': 'full photo metadata (includes upload metadata)',
'type': 'object',
'properties': {
'user_id': {
'description': 'id of user that created the photo',
'type': 'number'
},
'episode_id': {
'description': 'episode in which the photo was originally uploaded',
'type': 'string', 'required': False,
},
'labels': {
'description': 'set of boolean modifiers affecting the photo (e.g. "removed")',
'type': 'array', 'required': False, 'items': {'type': 'string'},
},
'sharing_user_id': {
'description': 'user who shared this photo (if applicable)',
'type': 'number', 'required': False,
},
},
}
_CopyProperties(target_dict=PHOTO_METADATA, source_dict=UPLOAD_PHOTO_METADATA)
_CopyProperties(target_dict=PHOTO_METADATA, source_dict=PHOTO_URL_METADATA)
# Older photos may be missing one or more MD5 attributes.
PHOTO_METADATA['properties']['tn_md5']['required'] = False
PHOTO_METADATA['properties']['med_md5']['required'] = False
PHOTO_METADATA['properties']['full_md5']['required'] = False
PHOTO_METADATA['properties']['orig_md5']['required'] = False
POST_PHOTO_METADATA = deepcopy(PHOTO_METADATA)
# Episode metadata.
UPDATE_EPISODE_METADATA = {
'description': 'episode metadata for updates',
'type': 'object',
'properties': {
'episode_id': {'type': 'string'},
'title': {'type': 'string', 'required': False},
'description': {'type': 'string', 'required': False},
'location': OPTIONAL_LOCATION,
'placemark': OPTIONAL_PLACEMARK,
},
}
UPLOAD_EPISODE_METADATA = {
'description': 'episode metadata for upload (includes update metadata)',
'type': 'object',
'properties': {
'timestamp': {
'description': 'timestamp of the newest photo in the episode',
'type': 'number',
},
},
}
_CopyProperties(target_dict=UPLOAD_EPISODE_METADATA, source_dict=UPDATE_EPISODE_METADATA)
EPISODE_METADATA = {
'description': 'full episode metadata (includes upload metadata)',
'type': 'object',
'properties': {
'user_id': {
'description': 'id of user that created the episode',
'type': 'number'
},
'viewpoint_id': {
'description': 'viewpoint to which the episode belongs',
'type': 'string',
},
'publish_timestamp': {
'description': 'time at which the episode was uploaded',
'type': 'number',
},
'sharing_user_id': {
'description': 'user who shared this episode (if applicable)',
'type': 'number', 'required': False,
},
'parent_ep_id': {
'description': 'id of the parent episode, if one exists',
'type': 'string', 'required': False,
},
},
}
_CopyProperties(target_dict=EPISODE_METADATA, source_dict=UPLOAD_EPISODE_METADATA)
# Follower metadata.
UPDATE_FOLLOWER_METADATA = {
'description': 'follower metadata for updates',
'type': 'object',
'properties': {
'viewpoint_id': {'type': 'string'},
'labels': {
'description': 'set of boolean permissions and modifiers affecting '
'the viewpoint (e.g. "personal")',
'type': 'array', 'required': False, 'uniqueItems': True,
'items': {'type': 'string', 'enum': Follower.ALL_LABELS},
},
'viewed_seq': {
'description': 'sequence number of last viewpoint update that the '
'client has viewed on any device; the client and server will always '
'"ratchet up" this value; they will ignore any value that is smaller '
'than a value already received',
'type': 'number', 'required': False,
},
},
}
FRIEND_FOLLOWER_METADATA = {
'description': 'follower metadata that is returned to other followers of same viewpoint when '
'they invoke query_viewpoints',
'type': 'object',
'properties': {
'follower_id': {'type': 'number'},
'labels': {
'description': 'set of boolean permissions and modifiers affecting the follower\'s '
'relationship to the viewpoint',
'type': 'array', 'required': False, 'uniqueItems': True,
'items': {'type': 'string', 'enum': [Follower.REMOVED, Follower.UNREVIVABLE]},
},
'adding_user_id': {
'description': 'user who added this follower to the viewpoint; for older viewpoints, '
'this may not be present; it also is not present for the user that created the viewpoint',
'type': 'number', 'required': False,
},
'follower_timestamp': {
'description': 'timestamp at which follower was added to the viewpoint; if not present, '
'assume follower was added more than 7 days ago',
'type': 'number', 'required': False,
},
},
}
# Viewpoint metadata.
UPDATE_VIEWPOINT_METADATA = {
'description': 'viewpoint metadata for updates',
'type': 'object',
'properties': {
'viewpoint_id': {'type': 'string'},
'title': {'type': 'string', 'required': False},
'description': {'type': 'string', 'required': False},
'name': {'type': 'string', 'required': False},
'cover_photo': COVER_PHOTO_METADATA,
},
}
CREATE_VIEWPOINT_METADATA = {
'description': 'viewpoint metadata for create (includes update metadata)',
'type': 'object',
'properties': {
'type': {
'description': 'kind of viewpoint (only allow event viewpoint to be created by users)',
'type': 'string', 'enum': [Viewpoint.EVENT],
},
},
}
_CopyProperties(target_dict=CREATE_VIEWPOINT_METADATA, source_dict=UPDATE_VIEWPOINT_METADATA)
VIEWPOINT_METADATA = {
'description': 'full viewpoint metadata (includes create metadata)',
'type': 'object',
'properties': {
'follower_id': {
'description': 'id of the calling user who follows this viewpoint',
'type': 'number',
},
'user_id': {
'description': 'id of user that created the viewpoint',
'type': 'number'
},
'timestamp': {
'description': 'timestamp at which viewpoint was created',
'type': 'number',
},
'update_seq': {
'description': 'sequence number of the last add, remove, or update of '
'any assets or metadata within the viewpoint; only updates to shared '
'assets increment this value (i.e. not changes to user-specific '
'tables like Follower or UserPost)',
'type': 'number', 'required': False,
},
'adding_user_id': {
'description': 'user who added this follower to the viewpoint (if applicable)',
'type': 'number', 'required': False,
},
'last_updated': {
'description': 'timestamp of the activity that was last added to '
'the viewpoint',
'type': 'number', 'required': False,
},
},
}
_CopyProperties(target_dict=VIEWPOINT_METADATA, source_dict=CREATE_VIEWPOINT_METADATA)
_CopyProperties(target_dict=VIEWPOINT_METADATA, source_dict=UPDATE_FOLLOWER_METADATA)
_CopyProperties(target_dict=VIEWPOINT_METADATA['properties']['cover_photo'], source_dict=PHOTO_URL_METADATA)
VIEWPOINT_METADATA['properties']['type']['enum'] = Viewpoint.TYPES
# Copying episodes between viewpoints.
COPY_EPISODES_METADATA = {
'description': 'array of episode copy information; each item specifies the existing episode '
'id, the new episode id, and the photo ids to include in the copied episode',
'type': 'array',
'items': {
'type': 'object',
'properties': {
'existing_episode_id': {
'description': 'id of the episode from which the copy originates; '
'this will be the parent_ep_id of the new episode',
'type': 'string',
},
'new_episode_id': {
'description': 'id of the new episode to create',
'type': 'string',
},
'photo_ids': {
'description': 'ids of photos to copy from the existing episode',
'type': 'array',
'items': {'type': 'string'},
},
},
},
}
OPTIONAL_COPY_EPISODES_METADATA = deepcopy(COPY_EPISODES_METADATA)
OPTIONAL_COPY_EPISODES_METADATA['required'] = False
# Device metadata.
DEVICE_METADATA = {
'description': 'full device metadata properties',
'type': 'object',
'properties': {
'device_id': {
'description': 'unique identifier of the device. Generated on the server.',
'type': 'number',
},
'name': {
'description': 'name of device',
'type': 'string', 'blank': True, 'required': False,
},
'version': {
'description': 'version of the Viewfinder mobile application',
'type': 'string', 'blank': True, 'required': False,
},
'platform': {
'description': 'mobile platform (e.g. iPhone 4S, Samsung Galaxy S)',
'type': 'string', 'blank': True, 'required': False,
},
'os': {
'description': 'mobile os (e.g. iOS 5.0.1, Android 4.0)',
'type': 'string', 'blank': True, 'required': False,
},
'push_token': {
'description': 'opaque token for push notifications',
'type': 'string', 'blank': True, 'required': False,
},
'device_uuid': {
'description': 'per-install unique device id. Generated on the device.',
'type': 'string', 'blank': True, 'required': False,
},
'language': {
'description': 'device language code',
'type': 'string', 'blank': True, 'required': False,
},
'country': {
'description': 'device country code',
'type': 'string', 'blank': True, 'required': False,
},
'test_udid': {
'description': 'unique device ID. Only sent by DEV and ADHOC builds. ID matches that found on testflight.',
'type': 'string', 'blank': True, 'required': False,
},
},
}
# Device id is optional when registering a device.
REGISTER_DEVICE_METADATA = deepcopy(DEVICE_METADATA)
REGISTER_DEVICE_METADATA['required'] = False
REGISTER_DEVICE_METADATA['properties']['device_id']['required'] = False
# Information message sent as part of the ping response.
INFO_MESSAGE = {
'description': 'an informative message to the client',
'type': 'object',
'properties': {
'title': {'type': 'string'},
'body': {'type': 'string', 'required': False},
'link': {'type': 'string', 'required': False},
'identifier': {
'description': 'Unique identifier for this message. The client will not re-display a message with the '
'same identifier. However, a new identifier, then an old again will work (eg: A -> B -> A)',
'type': 'string',
},
'severity': {
'description': 'Severity level. One of "SILENT", "INFO", "ATTENTION", "DISABLE_NETWORK"',
'type': 'string',
},
},
}
PING_RESPONSE_MESSAGE = deepcopy(INFO_MESSAGE)
PING_RESPONSE_MESSAGE['required'] = False
# Comment metadata.
POST_COMMENT_METADATA = {
'description': 'comment metadata used when posting a comment',
'type': 'object',
'properties': {
'viewpoint_id': {'type': 'string'},
'comment_id': {'type': 'string'},
'asset_id': {
'description': 'id of the viewpoint asset to which this comment is '
'attached; this may be a photo, if the comment was about a photo; it '
'may be another comment, if this comment was a direct response to '
'that comment',
'type': 'string',
'required': False,
},
'timestamp': {
'description': 'timestamp of the new comment; this timestamp MUST '
'be the same across successive request attempts by the client in '
'order to guarantee idempotency',
'type': 'number',
},
'message': {
'description': 'text of the comment',
'type': 'string',
},
},
}
COMMENT_METADATA = {
'description': 'full comment metadata (includes post metadata)',
'type': 'object',
'properties': {
'user_id': {
'description': 'id of user that caused the comment to be created',
'type': 'number',
},
},
}
_CopyProperties(target_dict=COMMENT_METADATA, source_dict=POST_COMMENT_METADATA)
# Contact metadata.
UPLOAD_CONTACT_METADATA = {
'description': '(name, given_name, family_name, rank, contact_source, identities) tuple',
'type': 'object',
'properties': {
'contact_source': {
'description': 'Source of contacts: ip (iPhone), or m (Manual)',
'type': 'string',
'enum': Contact.UPLOAD_SOURCES
},
'identities': {
'description': 'Order of this list will be preserved by server for query_contacts responses',
'type': 'array',
'maxItems': 50,
'items': {
'type': 'object',
'properties': {
'identity': {'type': 'string', 'maxLength': 1000},
'description': {'type': 'string', 'maxLength': 1000, 'required': False},
},
},
},
'name': {'type': 'string', 'maxLength': 1000, 'required': False},
'given_name': {'type': 'string', 'maxLength': 1000, 'required': False},
'family_name': {'type': 'string', 'maxLength': 1000, 'required': False},
'rank': {'type': 'number', 'required': False},
},
}
QUERY_CONTACT_METADATA = {
'description': 'Metadata returned in query_contacts response',
'type': 'object',
'properties': {
'contact_id': {'type': 'string'},
'labels': {
'description': 'set of boolean modifiers affecting the contact (e.g. "removed")',
'type': 'array', 'required': False, 'items': {'type': 'string'},
},
},
}
_CopyProperties(target_dict=QUERY_CONTACT_METADATA, source_dict=UPLOAD_CONTACT_METADATA)
QUERY_CONTACT_METADATA['properties']['contact_source']['enum'] = Contact.ALL_SOURCES
QUERY_CONTACT_METADATA['properties']['identities']['items']['properties']['user_id'] = \
{'type': 'number', 'required': False}
QUERY_CONTACT_METADATA['properties']['identities']['required'] = False
FOLLOWER_CONTACTS_METADATA = {
'description': 'array of contacts to add as followers of a viewpoint',
'type': 'array',
'items': {
'description': 'contacts: identity key and name if available. '
'user_id is required if known.',
'type': 'object',
'properties': {
'user_id': {'type': 'number', 'required': False},
'identity': {'type': 'string', 'required': False},
'name': {'type': 'string', 'required': False},
},
},
}
# Invalidate structure.
INVALIDATE = {
'description': 'each notification can select parts of the asset tree to '
'invalidate if the operation that triggered the notification modified '
'the tree',
'type': 'object',
'properties': {
'all': {
'description': 'invalidate all assets, forcing complete client reload',
'type': 'boolean',
},
'viewpoints': VIEWPOINT_SELECTION,
'episodes': EPISODE_SELECTION,
'users': USER_SELECTION,
'contacts': CONTACT_SELECTION,
},
}
# Usage information for a given category.
USAGE_CATEGORY_METADATA = {
'description': 'usage information for a single category',
'type': 'object',
'required': False,
'properties': {
'num_photos': { 'type': 'number', 'required': False },
'tn_size': { 'type': 'number', 'required': False },
'med_size': { 'type': 'number', 'required': False },
'full_size': { 'type': 'number', 'required': False },
'orig_size': { 'type': 'number', 'required': False },
},
}
# Usage information for a single user.
USAGE_METADATA = {
'description': 'usage information by category',
'type': 'object',
'properties': {
'owned_by': deepcopy(USAGE_CATEGORY_METADATA),
'shared_by': deepcopy(USAGE_CATEGORY_METADATA),
'visible_to': deepcopy(USAGE_CATEGORY_METADATA),
},
}
# The optional variant is used in NOTIFICATION. Currently, the last notification in the response to
# QueryNotifications will have the usage information.
OPTIONAL_USAGE_METADATA = deepcopy(USAGE_METADATA)
OPTIONAL_USAGE_METADATA['required'] = False
# Notification structure.
NOTIFICATION = {
'description': 'a union of notifications delivered to client asynchronously',
'type': 'object',
'properties': {
'notification_id': {'type': 'number'},
'name': {'type': 'string'},
'sender_id': {'type': 'number'},
'op_id': {
'description': 'id of the operation that produced this notification; this attribute '
'will be missing if no operation was involved',
'type': 'string', 'required': False,
},
'timestamp': {'type': 'number'},
'invalidate': deepcopy(INVALIDATE),
'inline': {
'description': 'some common invalidations are in-lined in the notification '
'in order to avoid extra round-trips',
'type': 'object', 'required': False,
'properties': {
'activity': deepcopy(ACTIVITY_METADATA),
'viewpoint': {
'description': 'if this notification updates the value of the update_seq '
'and / or viewed_seq attributes, then in-line the changed value(s) in '
'order to reduce round-trips',
'type': 'object', 'required': False,
'properties': {
'viewpoint_id': {'type': 'string'},
'update_seq': {
'description': 'value of the viewpoint update_seq attribute after '
'it was incremented by the operation; the client will "ratchet up" '
'this value, discarding any that is smaller than a value already '
'received',
'type': 'number', 'required': False,
},