diaspora_federation 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0143fd95b478d62bc2fb26b136df5103c0074fce
4
- data.tar.gz: 919d5d547e686a4994305c8a42514762072784be
3
+ metadata.gz: 5dbce3e434737107507881b68c2f8d51a0cf2d78
4
+ data.tar.gz: 6c974f67b87f2ffa988c1286d17b920ad49fe9ef
5
5
  SHA512:
6
- metadata.gz: 40f7824b9fa501dee9fe1683ec5ab33ee22e6da144d5a55d278252c4f365893ee9478ff97e9113ada59d9fb722ddb69fa35eaf63abdfc247200de63e05ba4418
7
- data.tar.gz: fb88dd79852c1bb5ff77260165bdaca7ae10745205cd1baa2719033b43b7f8cba97ede1136e323e7f9e3c30121d08a32ee6065f71495759549e7c872acf96457
6
+ metadata.gz: 9ac23b66e6c06e368f7dff5a190222e123a388653c2bb9983a28b80c08a9f6831fb584e86195ac627ad16f1d73fb9f185695d5b5c469efb19be70bddb2681f91
7
+ data.tar.gz: 248882b3d9a8c71a94894724719f63a04a4398eabb2f13b35fb7559cae0fdf017b0010a1940390ecab70664598fe01cf168efb2ac6f44f404fc6c82360b26c38
@@ -1,3 +1,13 @@
1
+ # 0.2.1
2
+
3
+ ## Features
4
+
5
+ Add `DiasporaFederation::Schemas` to access the JSON schema [#70](https://github.com/diaspora/diaspora_federation/pull/70)
6
+
7
+ ## Refactor
8
+
9
+ Don't add optional properties to generated XML and JSON when nil [#71](https://github.com/diaspora/diaspora_federation/pull/71)
10
+
1
11
  # 0.2.0
2
12
 
3
13
  ## Features
@@ -24,7 +24,7 @@ module DiasporaFederation
24
24
  # @!attribute [r] description
25
25
  # Description of the event
26
26
  # @return [String] event description
27
- property :description, :string, default: nil
27
+ property :description, :string, optional: true
28
28
 
29
29
  # @!attribute [r] start
30
30
  # The start time of the event
@@ -34,22 +34,22 @@ module DiasporaFederation
34
34
  # @!attribute [r] end
35
35
  # The end time of the event
36
36
  # @return [String] event end
37
- property :end, :timestamp, default: nil
37
+ property :end, :timestamp, optional: true
38
38
 
39
39
  # @!attribute [r] all_day
40
40
  # Points if the event is an all day event
41
41
  # @return [Boolean] is it an all day event
42
- property :all_day, :boolean, default: false
42
+ property :all_day, :boolean, optional: true, default: false
43
43
 
44
44
  # @!attribute [r] timezone
45
45
  # Timezone to which the event is fixed to
46
46
  # @return [String] timezone
47
- property :timezone, :string, default: nil
47
+ property :timezone, :string, optional: true
48
48
 
49
49
  # @!attribute [r] location
50
50
  # Location of the event
51
51
  # @return [Entities::Location] location
52
- entity :location, Entities::Location, default: nil
52
+ entity :location, Entities::Location, optional: true
53
53
  end
54
54
  end
55
55
  end
@@ -37,13 +37,13 @@ module DiasporaFederation
37
37
 
38
38
  # @!attribute [r] text
39
39
  # @return [String] text
40
- property :text, :string, default: nil
40
+ property :text, :string, optional: true
41
41
 
42
42
  # @!attribute [r] status_message_guid
43
43
  # Guid of a status message this photo belongs to
44
44
  # @see StatusMessage#guid
45
45
  # @return [String] guid
46
- property :status_message_guid, :string, default: nil
46
+ property :status_message_guid, :string, optional: true
47
47
 
48
48
  # @!attribute [r] height
49
49
  # Photo height
@@ -29,7 +29,7 @@ module DiasporaFederation
29
29
  property :author, :string, xml_name: :diaspora_handle
30
30
  property :guid, :string
31
31
  property :created_at, :timestamp, default: -> { Time.now.utc }
32
- property :provider_display_name, :string, default: nil
32
+ property :provider_display_name, :string, optional: true
33
33
  end
34
34
  end
35
35
  end
@@ -20,7 +20,7 @@ module DiasporaFederation
20
20
  # @see #full_name
21
21
  # @see Discovery::HCard#first_name
22
22
  # @return [String] first name
23
- property :first_name, :string, default: nil
23
+ property :first_name, :string, optional: true
24
24
 
25
25
  # @!attribute [r] last_name
26
26
  # @deprecated We decided to only use one name field, these should be removed
@@ -28,38 +28,38 @@ module DiasporaFederation
28
28
  # @see #full_name
29
29
  # @see Discovery::HCard#last_name
30
30
  # @return [String] last name
31
- property :last_name, :string, default: nil
31
+ property :last_name, :string, optional: true
32
32
 
33
33
  # @!attribute [r] image_url
34
34
  # @see Discovery::HCard#photo_large_url
35
35
  # @return [String] url to the big avatar (300x300)
36
- property :image_url, :string, default: nil
36
+ property :image_url, :string, optional: true
37
37
  # @!attribute [r] image_url_medium
38
38
  # @see Discovery::HCard#photo_medium_url
39
39
  # @return [String] url to the medium avatar (100x100)
40
- property :image_url_medium, :string, default: nil
40
+ property :image_url_medium, :string, optional: true
41
41
  # @!attribute [r] image_url_small
42
42
  # @see Discovery::HCard#photo_small_url
43
43
  # @return [String] url to the small avatar (50x50)
44
- property :image_url_small, :string, default: nil
44
+ property :image_url_small, :string, optional: true
45
45
 
46
- property :birthday, :string, default: nil
47
- property :gender, :string, default: nil
48
- property :bio, :string, default: nil
49
- property :location, :string, default: nil
46
+ property :birthday, :string, optional: true
47
+ property :gender, :string, optional: true
48
+ property :bio, :string, optional: true
49
+ property :location, :string, optional: true
50
50
 
51
51
  # @!attribute [r] searchable
52
52
  # @see Discovery::HCard#searchable
53
53
  # @return [Boolean] searchable flag
54
- property :searchable, :boolean, default: true
54
+ property :searchable, :boolean, optional: true, default: true
55
55
 
56
56
  # @!attribute [r] public
57
57
  # Shows whether the profile is visible to everyone or only to contacts
58
58
  # @return [Boolean] is it public
59
- property :public, :boolean, default: false
59
+ property :public, :boolean, optional: true, default: false
60
60
 
61
- property :nsfw, :boolean, default: false
62
- property :tag_string, :string, default: nil
61
+ property :nsfw, :boolean, optional: true, default: false
62
+ property :tag_string, :string, optional: true
63
63
 
64
64
  # @return [String] string representation of this object
65
65
  def to_s
@@ -100,7 +100,9 @@ module DiasporaFederation
100
100
  # The order for signing
101
101
  # @return [Array]
102
102
  def signature_order
103
- @signature_order || self.class.class_props.keys - %i[author_signature parent_author_signature parent]
103
+ @signature_order || self.class.class_props.keys.reject {|key|
104
+ self.class.optional_props.include?(key) && public_send(key).nil?
105
+ } - %i[author_signature parent_author_signature parent]
104
106
  end
105
107
 
106
108
  private
@@ -21,7 +21,7 @@ module DiasporaFederation
21
21
  # @!attribute [r] public
22
22
  # Has no meaning at the moment
23
23
  # @return [Boolean] public
24
- property :public, :boolean, default: true # always true? (we only reshare public posts)
24
+ property :public, :boolean, optional: true, default: true # always true? (we only reshare public posts)
25
25
 
26
26
  # @return [String] string representation of this object
27
27
  def to_s
@@ -14,22 +14,22 @@ module DiasporaFederation
14
14
  # @!attribute [r] photos
15
15
  # Optional photos attached to the status message
16
16
  # @return [[Entities::Photo]] photos
17
- entity :photos, [Entities::Photo], default: []
17
+ entity :photos, [Entities::Photo], optional: true, default: []
18
18
 
19
19
  # @!attribute [r] location
20
20
  # Optional location attached to the status message
21
21
  # @return [Entities::Location] location
22
- entity :location, Entities::Location, default: nil
22
+ entity :location, Entities::Location, optional: true
23
23
 
24
24
  # @!attribute [r] poll
25
25
  # Optional poll attached to the status message
26
26
  # @return [Entities::Poll] poll
27
- entity :poll, Entities::Poll, default: nil
27
+ entity :poll, Entities::Poll, optional: true
28
28
 
29
29
  # @!attribute [r] event
30
30
  # Optional event attached to the status message
31
31
  # @return [Entities::Event] event
32
- entity :event, Entities::Event, default: nil
32
+ entity :event, Entities::Event, optional: true
33
33
 
34
34
  # @!attribute [r] public
35
35
  # Shows whether the status message is visible to everyone or only to some aspects
@@ -270,6 +270,8 @@ module DiasporaFederation
270
270
  end
271
271
 
272
272
  def normalize_property(name, value)
273
+ return nil if optional_nil_value?(name, value)
274
+
273
275
  case self.class.class_props[name]
274
276
  when :string
275
277
  value.to_s
@@ -315,8 +317,9 @@ module DiasporaFederation
315
317
  def json_data
316
318
  enriched_properties.map {|key, value|
317
319
  type = self.class.class_props[key]
320
+ next if optional_nil_value?(key, value)
318
321
 
319
- if !value.nil? && type.instance_of?(Class) && value.respond_to?(:to_json)
322
+ if !value.nil? && type.instance_of?(Class)
320
323
  entity_data = value.to_json
321
324
  [key, entity_data] unless entity_data.nil?
322
325
  elsif type.instance_of?(Array)
@@ -328,6 +331,10 @@ module DiasporaFederation
328
331
  }.compact.to_h
329
332
  end
330
333
 
334
+ def optional_nil_value?(name, value)
335
+ value.nil? && self.class.optional_props.include?(name)
336
+ end
337
+
331
338
  # Raised, if entity is not valid
332
339
  class ValidationError < RuntimeError
333
340
  end
@@ -46,16 +46,20 @@ module DiasporaFederation
46
46
  # Return array of missing required property names
47
47
  # @return [Array<Symbol>] missing required property names
48
48
  def missing_props(args)
49
- class_props.keys - default_props.keys - args.keys
49
+ class_props.keys - default_props.keys - optional_props - args.keys
50
+ end
51
+
52
+ def optional_props
53
+ @optional_props ||= []
50
54
  end
51
55
 
52
56
  # Return a new hash of default values, with dynamic values
53
57
  # resolved on each call
54
58
  # @return [Hash] default values
55
59
  def default_values
56
- default_props.each_with_object({}) {|(name, prop), hash|
57
- hash[name] = prop.respond_to?(:call) ? prop.call : prop
58
- }
60
+ optional_props.map {|name| [name, nil] }.to_h.merge(default_props).map {|name, prop|
61
+ [name, prop.respond_to?(:call) ? prop.call : prop]
62
+ }.to_h
59
63
  end
60
64
 
61
65
  # @param [Hash] data entity data
@@ -111,6 +115,7 @@ module DiasporaFederation
111
115
  raise InvalidName unless name_valid?(name)
112
116
 
113
117
  class_props[name] = type
118
+ optional_props << name if opts[:optional]
114
119
  default_props[name] = opts[:default] if opts.has_key? :default
115
120
  xml_names[name] = determine_xml_name(name, type, opts)
116
121
 
@@ -1,4 +1,4 @@
1
1
  module DiasporaFederation
2
2
  # the gem version
3
- VERSION = "0.2.0".freeze
3
+ VERSION = "0.2.1".freeze
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diaspora_federation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Neff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-02 00:00:00.000000000 Z
11
+ date: 2017-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -59,7 +59,7 @@ dependencies:
59
59
  version: 0.10.0
60
60
  - - "<"
61
61
  - !ruby/object:Gem::Version
62
- version: 0.12.0
62
+ version: 0.13.0
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
@@ -69,7 +69,7 @@ dependencies:
69
69
  version: 0.10.0
70
70
  - - "<"
71
71
  - !ruby/object:Gem::Version
72
- version: 0.12.0
72
+ version: 0.13.0
73
73
  - !ruby/object:Gem::Dependency
74
74
  name: typhoeus
75
75
  requirement: !ruby/object:Gem::Requirement
@@ -174,7 +174,6 @@ files:
174
174
  - lib/diaspora_federation/salmon/magic_envelope.rb
175
175
  - lib/diaspora_federation/salmon/slap.rb
176
176
  - lib/diaspora_federation/salmon/xml_payload.rb
177
- - lib/diaspora_federation/schemas/federation_entities.json
178
177
  - lib/diaspora_federation/validators.rb
179
178
  - lib/diaspora_federation/validators/account_deletion_validator.rb
180
179
  - lib/diaspora_federation/validators/account_migration_validator.rb
@@ -1,379 +0,0 @@
1
- {
2
- "$schema": "http://json-schema.org/draft-04/schema#",
3
- "id": "https://diaspora.github.io/diaspora_federation/schemas/federation_entities.json",
4
- "oneOf": [
5
- {"$ref": "#/definitions/comment"},
6
- {"$ref": "#/definitions/like"},
7
- {"$ref": "#/definitions/participation"},
8
- {"$ref": "#/definitions/poll_participation"},
9
- {"$ref": "#/definitions/status_message"},
10
- {"$ref": "#/definitions/reshare"},
11
- {"$ref": "#/definitions/profile"},
12
- {"$ref": "#/definitions/location"},
13
- {"$ref": "#/definitions/photo"},
14
- {"$ref": "#/definitions/poll"},
15
- {"$ref": "#/definitions/poll_answer"}
16
- ],
17
-
18
- "definitions": {
19
- "signature": {
20
- "oneOf" : [
21
- {
22
- "type": "string",
23
- "minLength": 30
24
- },
25
- {
26
- "type": "string",
27
- "maxLength": 0,
28
- "description": "Allow empty string when no signature is provided"
29
- }
30
- ]
31
- },
32
-
33
- "guid": {
34
- "type": "string",
35
- "minLength": 16,
36
- "maxLength": 255
37
- },
38
-
39
- "relayable": {
40
- "type": "object",
41
- "description": "please don't use this object unless you're defining a new child relayable schema",
42
- "properties": {
43
- "entity_data": {
44
- "type": "object",
45
- "properties": {
46
- "author": { "type": "string" },
47
- "guid": { "$ref": "#/definitions/guid" },
48
- "parent_guid": { "$ref": "#/definitions/guid" },
49
- "author_signature": { "$ref": "#/definitions/signature" }
50
- },
51
- "required": [
52
- "author", "guid", "parent_guid"
53
- ]
54
- },
55
- "property_order": {
56
- "type": "array",
57
- "items": { "type": "string" }
58
- }
59
- },
60
- "required": [
61
- "entity_data", "entity_type", "property_order"
62
- ]
63
- },
64
-
65
- "comment": {
66
- "allOf": [
67
- {"$ref": "#/definitions/relayable"},
68
- {
69
- "type": "object",
70
- "properties": {
71
- "entity_data": {
72
- "type": "object",
73
- "properties": {
74
- "text": { "type": "string" },
75
- "created_at": { "type": "string" }
76
- },
77
- "required": ["text"]
78
- },
79
- "entity_type": {
80
- "type": "string",
81
- "pattern": "^comment$"
82
- }
83
- }
84
- }
85
- ]
86
- },
87
-
88
- "like": {
89
- "allOf": [
90
- {"$ref": "#/definitions/relayable"},
91
- {
92
- "type": "object",
93
- "properties": {
94
- "entity_type": {
95
- "type": "string",
96
- "pattern": "^like$"
97
- },
98
- "entity_data": {
99
- "type": "object",
100
- "properties": {
101
- "positive": { "type": "boolean" },
102
- "parent_type": { "enum": ["Post", "Comment"] }
103
- },
104
- "required": ["positive"]
105
- }
106
- }
107
- }
108
- ]
109
- },
110
-
111
- "participation": {
112
- "type": "object",
113
- "properties": {
114
- "entity_type": {
115
- "type": "string",
116
- "pattern": "^participation$"
117
- },
118
- "entity_data": {
119
- "type": "object",
120
- "properties": {
121
- "author": { "type": "string" },
122
- "guid": { "$ref": "#/definitions/guid" },
123
- "parent_guid": { "$ref": "#/definitions/guid" },
124
- "parent_type": {"enum": ["Post"]}
125
- }
126
- }
127
- }
128
- },
129
-
130
- "poll_participation": {
131
- "allOf": [
132
- {"$ref": "#/definitions/relayable"},
133
- {
134
- "type": "object",
135
- "properties": {
136
- "entity_type": {
137
- "type": "string",
138
- "pattern": "^poll_participation$"
139
- },
140
- "entity_data": {
141
- "type": "object",
142
- "properties": {
143
- "poll_answer_guid": { "$ref": "#/definitions/guid" }
144
- },
145
- "required": ["poll_answer_guid"]
146
- }
147
- }
148
- }
149
- ]
150
- },
151
-
152
- "post": {
153
- "type": "object",
154
- "description": "please don't use this object unless you're defining a new child post schema",
155
- "properties": {
156
- "entity_data": {
157
- "type": "object",
158
- "properties": {
159
- "guid": { "$ref": "#/definitions/guid" },
160
- "public": { "type": "boolean" },
161
- "created_at": { "type": "string" },
162
- "provider_display_name" : { "type": "string" }
163
- },
164
- "required": [
165
- "guid", "public", "created_at"
166
- ]
167
- },
168
- "required": [
169
- "entity_type", "entity_data"
170
- ]
171
- }
172
- },
173
-
174
- "status_message": {
175
- "allOf": [
176
- {"$ref": "#/definitions/post"},
177
- {
178
- "type": "object",
179
- "properties": {
180
- "entity_type": {
181
- "type": "string",
182
- "pattern": "^status_message$"
183
- },
184
-
185
- "entity_data": {
186
- "type": "object",
187
- "properties": {
188
- "text": { "type": "string" },
189
-
190
- "location": {
191
- "oneOf": [
192
- { "$ref": "#/definitions/location" },
193
- { "type": "null" }
194
- ]
195
- },
196
-
197
- "poll": {
198
- "oneOf": [
199
- { "$ref": "#/definitions/poll" },
200
- { "type": "null" }
201
- ]
202
- },
203
-
204
- "photos": {
205
- "type": ["array", "null"],
206
- "items": { "$ref": "#/definitions/photo" }
207
- }
208
- },
209
-
210
- "required": ["text"]
211
- }
212
- }
213
- }
214
- ]
215
- },
216
-
217
- "reshare": {
218
- "allOf": [
219
- {"$ref": "#/definitions/post"},
220
- {
221
- "type": "object",
222
- "properties": {
223
- "entity_type": {
224
- "type": "string",
225
- "pattern": "^reshare$"
226
- },
227
-
228
- "entity_data": {
229
- "type": "object",
230
- "properties": {
231
- "root_author": {"type": "string"},
232
- "root_guid": {"$ref": "#/definitions/guid"}
233
- },
234
-
235
- "required": ["root_author", "root_guid"]
236
- }
237
- }
238
- }
239
- ]
240
- },
241
-
242
- "profile": {
243
- "type": "object",
244
- "properties": {
245
- "entity_type": {
246
- "type": "string",
247
- "pattern": "^profile$"
248
- },
249
- "entity_data": {
250
- "type": "object",
251
- "properties": {
252
- "first_name": { "type": ["string", "null"] },
253
- "last_name": { "type": ["string", "null"] },
254
- "gender": { "type": ["string", "null"] },
255
- "bio": { "type": ["string", "null"] },
256
- "birthday": { "type": ["string", "null"] },
257
- "location": { "type": ["string", "null"] },
258
- "image_url": { "type": ["string", "null"] },
259
- "author": { "type": "string" }
260
- },
261
- "required": [
262
- "author"
263
- ]
264
- }
265
- },
266
- "required" :["entity_data", "entity_type"]
267
- },
268
-
269
- "photo": {
270
- "type": "object",
271
- "properties": {
272
- "entity_type": {
273
- "type": "string",
274
- "pattern": "^photo$"
275
- },
276
- "entity_data": {
277
- "type": "object",
278
- "properties": {
279
- "author": { "type": "string" },
280
- "guid": {"$ref": "#/definitions/guid"},
281
- "public": {"type": "boolean"},
282
- "created_at": {"type": "string"},
283
- "remote_photo_path": {"type": "string"},
284
- "remote_photo_name": {"type": "string"},
285
- "text": {"type": ["null", "string"]},
286
- "status_message_guid": {"$ref": "#/definitions/guid"},
287
- "width": {"type": "number"},
288
- "height": {"type": "number"}
289
- },
290
- "required": [
291
- "author", "guid", "public", "created_at", "remote_photo_path", "remote_photo_name", "width", "height"
292
- ]
293
- }
294
- }
295
- },
296
-
297
- "poll_answer": {
298
- "type": "object",
299
- "properties": {
300
- "entity_type": {
301
- "type": "string",
302
- "pattern": "^poll_answer$"
303
- },
304
- "entity_data": {
305
- "type": "object",
306
- "properties": {
307
- "guid": { "$ref": "#/definitions/guid" },
308
- "answer": { "type": "string" }
309
- },
310
- "required": [
311
- "answer",
312
- "guid"
313
- ]
314
- }
315
- }
316
- },
317
-
318
- "poll": {
319
- "type": "object",
320
- "properties": {
321
- "entity_type": {
322
- "type": "string",
323
- "pattern": "^poll$"
324
- },
325
- "entity_data": {
326
- "type": "object",
327
- "properties": {
328
- "guid": {
329
- "$ref": "#/definitions/guid"
330
- },
331
- "question": {
332
- "type": "string"
333
- },
334
- "poll_answers": {
335
- "type": "array",
336
- "items": {
337
- "$ref": "#/definitions/poll_answer"
338
- }
339
- }
340
- },
341
- "required": [
342
- "guid",
343
- "question",
344
- "poll_answers"
345
- ]
346
- }
347
- }
348
- },
349
-
350
- "location": {
351
- "type": "object",
352
- "properties": {
353
- "entity_type": {
354
- "type": "string",
355
- "pattern": "^location$"
356
- },
357
- "entity_data": {
358
- "type": "object",
359
- "properties": {
360
- "address": {
361
- "type": "string"
362
- },
363
- "lat": {
364
- "type": "string"
365
- },
366
- "lng": {
367
- "type": "string"
368
- }
369
- },
370
- "required": [
371
- "address",
372
- "lat",
373
- "lng"
374
- ]
375
- }
376
- }
377
- }
378
- }
379
- }