diaspora_federation 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog.md +12 -0
  3. data/lib/diaspora_federation/discovery/h_card.rb +11 -11
  4. data/lib/diaspora_federation/discovery/web_finger.rb +10 -10
  5. data/lib/diaspora_federation/entities/account_deletion.rb +1 -1
  6. data/lib/diaspora_federation/entities/comment.rb +2 -2
  7. data/lib/diaspora_federation/entities/contact.rb +4 -4
  8. data/lib/diaspora_federation/entities/conversation.rb +5 -5
  9. data/lib/diaspora_federation/entities/like.rb +2 -2
  10. data/lib/diaspora_federation/entities/location.rb +3 -3
  11. data/lib/diaspora_federation/entities/message.rb +13 -3
  12. data/lib/diaspora_federation/entities/participation.rb +1 -1
  13. data/lib/diaspora_federation/entities/person.rb +4 -4
  14. data/lib/diaspora_federation/entities/photo.rb +12 -12
  15. data/lib/diaspora_federation/entities/poll.rb +2 -2
  16. data/lib/diaspora_federation/entities/poll_answer.rb +2 -2
  17. data/lib/diaspora_federation/entities/poll_participation.rb +1 -1
  18. data/lib/diaspora_federation/entities/post.rb +4 -4
  19. data/lib/diaspora_federation/entities/profile.rb +13 -13
  20. data/lib/diaspora_federation/entities/related_entity.rb +3 -3
  21. data/lib/diaspora_federation/entities/relayable.rb +21 -14
  22. data/lib/diaspora_federation/entities/relayable_retraction.rb +8 -8
  23. data/lib/diaspora_federation/entities/request.rb +2 -2
  24. data/lib/diaspora_federation/entities/reshare.rb +3 -3
  25. data/lib/diaspora_federation/entities/retraction.rb +3 -3
  26. data/lib/diaspora_federation/entities/signed_retraction.rb +7 -7
  27. data/lib/diaspora_federation/entities/status_message.rb +2 -2
  28. data/lib/diaspora_federation/entity.rb +56 -9
  29. data/lib/diaspora_federation/properties_dsl.rb +15 -6
  30. data/lib/diaspora_federation/version.rb +1 -1
  31. data/lib/tasks/rails4.rake +15 -0
  32. data/lib/tasks/tests.rake +1 -1
  33. metadata +12 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ada8efaa115784225786ce35f925e13179f7d5e2
4
- data.tar.gz: 9ecfc78d096a8f5173ddbcd3665fd22445c9374c
3
+ metadata.gz: 70e250962994a4f76c0232c5ea58fd2c02411766
4
+ data.tar.gz: 131351687ab2b4cd5e63fe7a1783103b3b43f83c
5
5
  SHA512:
6
- metadata.gz: 1ad31c9c21a5e42e0197ccb51ec14d8e5262b6fc527f9b3b7ba95ff9162d69c8be8783275d576a7051bca3ddfbe0913dd3d1b5d46ad9d32a90c2288b510c6f42
7
- data.tar.gz: 1b32aa2ff5b1c4d0763f8b97eb1473cc03d143ae3f7bd028a24557e11780d8a2b6d2f14c89ecd67977eae708b33aba868de867e3c92031c583468577f4fd2c4a
6
+ metadata.gz: 31ca9ff248eb49ba2b1ca310e7ab1f3447c488677ff6ed026f1bf39a1dbe16dde6fbf0cbc307e7fc6c1d9bb6c3123635711d8006546d5149395ab9acb13ff944
7
+ data.tar.gz: 569623cc75eeefcb9e6bdea8851495fd4fb5319664847234d4f0ddb51b4be457fce75d8deb722ee1c858fb42eb89c52be7054e6259428e23fe3ba3dc2ca30540
data/Changelog.md CHANGED
@@ -1,3 +1,15 @@
1
+ # 0.1.6
2
+
3
+ ## Feature
4
+
5
+ * Add rails 5 support [82ea57e](https://github.com/diaspora/diaspora_federation/commit/82ea57ef34fe25d2ffbd6067171d73802735043b)
6
+
7
+ ## Refactor
8
+
9
+ * Add property types [#43](https://github.com/diaspora/diaspora_federation/pull/43)
10
+ * Change timestamp format to ISO 8601 [#43](https://github.com/diaspora/diaspora_federation/pull/43)
11
+ * Move protocol documentation to master branch [a15d285](https://github.com/diaspora/diaspora_federation/commit/a15d285a6e778a04c5e0c2f9428be099d6abddce)
12
+
1
13
  # 0.1.5
2
14
 
3
15
  ## Refactor
@@ -43,16 +43,16 @@ module DiasporaFederation
43
43
  # @!attribute [r] guid
44
44
  # @see Entities::Person#guid
45
45
  # @return [String] guid
46
- property :guid
46
+ property :guid, :string
47
47
 
48
48
  # @!attribute [r] nickname
49
49
  # The first part of the diaspora* ID
50
50
  # @return [String] nickname
51
- property :nickname, default: nil
51
+ property :nickname, :string, default: nil
52
52
 
53
53
  # @!attribute [r] full_name
54
54
  # @return [String] display name of the user
55
- property :full_name
55
+ property :full_name, :string
56
56
 
57
57
  # @!attribute [r] url
58
58
  # @deprecated should be changed to the profile url. The pod url is in
@@ -60,7 +60,7 @@ module DiasporaFederation
60
60
  # installations).
61
61
  #
62
62
  # @return [String] link to the pod
63
- property :url, default: nil
63
+ property :url, :string, default: nil
64
64
 
65
65
  # @!attribute [r] public_key
66
66
  # When a user is created on the pod, the pod MUST generate a pgp keypair
@@ -69,17 +69,17 @@ module DiasporaFederation
69
69
  # "-----BEGIN PUBLIC KEY-----" and ending with "-----END PUBLIC KEY-----".
70
70
  #
71
71
  # @return [String] public key
72
- property :public_key
72
+ property :public_key, :string
73
73
 
74
74
  # @!attribute [r] photo_large_url
75
75
  # @return [String] url to the big avatar (300x300)
76
- property :photo_large_url
76
+ property :photo_large_url, :string
77
77
  # @!attribute [r] photo_medium_url
78
78
  # @return [String] url to the medium avatar (100x100)
79
- property :photo_medium_url
79
+ property :photo_medium_url, :string
80
80
  # @!attribute [r] photo_small_url
81
81
  # @return [String] url to the small avatar (50x50)
82
- property :photo_small_url
82
+ property :photo_small_url, :string
83
83
 
84
84
  # @!attribute [r] first_name
85
85
  # @deprecated We decided to only use one name field, these should be removed
@@ -87,7 +87,7 @@ module DiasporaFederation
87
87
  #
88
88
  # @see #full_name
89
89
  # @return [String] first name
90
- property :first_name
90
+ property :first_name, :string
91
91
 
92
92
  # @!attribute [r] last_name
93
93
  # @deprecated We decided to only use one name field, these should be removed
@@ -95,7 +95,7 @@ module DiasporaFederation
95
95
  #
96
96
  # @see #full_name
97
97
  # @return [String] last name
98
- property :last_name
98
+ property :last_name, :string
99
99
 
100
100
  # @!attribute [r] searchable
101
101
  # @deprecated As this is a simple property, consider move to WebFinger instead
@@ -105,7 +105,7 @@ module DiasporaFederation
105
105
  #
106
106
  # flag if a user is searchable by name
107
107
  # @return [Boolean] searchable flag
108
- property :searchable
108
+ property :searchable, :boolean
109
109
 
110
110
  # CSS selectors for finding all the hCard fields
111
111
  SELECTORS = {
@@ -35,24 +35,24 @@ module DiasporaFederation
35
35
  # The Subject element should contain the webfinger address that was asked
36
36
  # for. If it does not, then this webfinger profile MUST be ignored.
37
37
  # @return [String]
38
- property :acct_uri
38
+ property :acct_uri, :string
39
39
 
40
40
  # @!attribute [r] alias_url
41
41
  # @note could be nil
42
42
  # @return [String] link to the users profile
43
- property :alias_url
43
+ property :alias_url, :string
44
44
 
45
45
  # @!attribute [r] hcard_url
46
46
  # @return [String] link to the +hCard+
47
- property :hcard_url
47
+ property :hcard_url, :string
48
48
 
49
49
  # @!attribute [r] seed_url
50
50
  # @return [String] link to the pod
51
- property :seed_url
51
+ property :seed_url, :string
52
52
 
53
53
  # @!attribute [r] profile_url
54
54
  # @return [String] link to the users profile
55
- property :profile_url
55
+ property :profile_url, :string
56
56
 
57
57
  # @!attribute [r] atom_url
58
58
  # This atom feed is an Activity Stream of the user's public posts. diaspora*
@@ -63,18 +63,18 @@ module DiasporaFederation
63
63
  # Note that this feed MAY also be made available through the PubSubHubbub
64
64
  # mechanism by supplying a <link rel="hub"> in the atom feed itself.
65
65
  # @return [String] atom feed url
66
- property :atom_url
66
+ property :atom_url, :string
67
67
 
68
68
  # @!attribute [r] salmon_url
69
69
  # @note could be nil
70
70
  # @return [String] salmon endpoint url
71
71
  # @see https://cdn.rawgit.com/salmon-protocol/salmon-protocol/master/draft-panzer-salmon-00.html#SMLR
72
72
  # Panzer draft for Salmon, paragraph 3.3
73
- property :salmon_url
73
+ property :salmon_url, :string
74
74
 
75
75
  # @!attribute [r] subscribe_url
76
76
  # This url is used to find another user on the home-pod of the user in the webfinger.
77
- property :subscribe_url
77
+ property :subscribe_url, :string
78
78
 
79
79
  # @!attribute [r] guid
80
80
  # @deprecated Either convert these to +Property+ elements or move to the
@@ -84,7 +84,7 @@ module DiasporaFederation
84
84
  # @see HCard#guid
85
85
  # @see Entities::Person#guid
86
86
  # @return [String] guid
87
- property :guid
87
+ property :guid, :string
88
88
 
89
89
  # @!attribute [r] public_key
90
90
  # @deprecated Either convert these to +Property+ elements or move to the
@@ -98,7 +98,7 @@ module DiasporaFederation
98
98
  # DER-encoded PKCS#1 key beginning with the text
99
99
  # "-----BEGIN PUBLIC KEY-----" and ending with "-----END PUBLIC KEY-----".
100
100
  # @return [String] public key
101
- property :public_key
101
+ property :public_key, :string
102
102
 
103
103
  # +hcard_url+ link relation
104
104
  REL_HCARD = "http://microformats.org/profile/hcard".freeze
@@ -12,7 +12,7 @@ module DiasporaFederation
12
12
  # Alias for author
13
13
  # @see AccountDeletion#author
14
14
  # @return [String] diaspora* ID
15
- property :author, alias: :diaspora_id, xml_name: :diaspora_handle
15
+ property :author, :string, alias: :diaspora_id, xml_name: :diaspora_handle
16
16
 
17
17
  # @return [String] string representation of this object
18
18
  def to_s
@@ -15,12 +15,12 @@ module DiasporaFederation
15
15
 
16
16
  # @!attribute [r] text
17
17
  # @return [String] the comment text
18
- property :text
18
+ property :text, :string
19
19
 
20
20
  # @!attribute [r] created_at
21
21
  # Comment entity creation time
22
22
  # @return [Time] creation time
23
- property :created_at, default: -> { Time.now.utc }
23
+ property :created_at, :timestamp, default: -> { Time.now.utc }
24
24
  end
25
25
  end
26
26
  end
@@ -9,21 +9,21 @@ module DiasporaFederation
9
9
  # The diaspora* ID of the person who shares their profile
10
10
  # @see Person#author
11
11
  # @return [String] sender ID
12
- property :author
12
+ property :author, :string
13
13
 
14
14
  # @!attribute [r] recipient
15
15
  # The diaspora* ID of the person who will be shared with
16
16
  # @see Validation::Rule::DiasporaId
17
17
  # @return [String] recipient ID
18
- property :recipient
18
+ property :recipient, :string
19
19
 
20
20
  # @!attribute [r] following
21
21
  # @return [Boolean] if the author is following the person
22
- property :following, default: true
22
+ property :following, :boolean, default: true
23
23
 
24
24
  # @!attribute [r] sharing
25
25
  # @return [Boolean] if the author is sharing with the person
26
- property :sharing, default: true
26
+ property :sharing, :boolean, default: true
27
27
 
28
28
  # @return [String] string representation of this object
29
29
  def to_s
@@ -8,26 +8,26 @@ module DiasporaFederation
8
8
  # The diaspora* ID of the person initiated the conversation
9
9
  # @see Person#author
10
10
  # @return [String] diaspora* ID
11
- property :author, xml_name: :diaspora_handle
11
+ property :author, :string, xml_name: :diaspora_handle
12
12
 
13
13
  # @!attribute [r] guid
14
14
  # A random string of at least 16 chars
15
15
  # @see Validation::Rule::Guid
16
16
  # @return [String] conversation guid
17
- property :guid
17
+ property :guid, :string
18
18
 
19
19
  # @!attribute [r] subject
20
20
  # @return [String] the conversation subject
21
- property :subject
21
+ property :subject, :string
22
22
 
23
23
  # @!attribute [r] created_at
24
24
  # @return [Time] Conversation creation time
25
- property :created_at, default: -> { Time.now.utc }
25
+ property :created_at, :timestamp, default: -> { Time.now.utc }
26
26
 
27
27
  # @!attribute [r] participants
28
28
  # The diaspora* IDs of the persons participating the conversation separated by ";"
29
29
  # @return [String] participants diaspora* IDs
30
- property :participants, xml_name: :participant_handles
30
+ property :participants, :string, xml_name: :participant_handles
31
31
 
32
32
  # @!attribute [r] messages
33
33
  # @return [[Entities::Message]] Messages of this conversation
@@ -14,14 +14,14 @@ module DiasporaFederation
14
14
  # If +true+ set a like, if +false+, set a dislike (dislikes are currently not
15
15
  # implemented in the diaspora* frontend).
16
16
  # @return [Boolean] is it a like or a dislike
17
- property :positive
17
+ property :positive, :boolean
18
18
 
19
19
  # @!attribute [r] parent_type
20
20
  # A string describing the type of the parent
21
21
  # Can be "Post" or "Comment" (Comments are currently not implemented in the
22
22
  # diaspora* frontend).
23
23
  # @return [String] parent type
24
- property :parent_type, xml_name: :target_type
24
+ property :parent_type, :string, xml_name: :target_type
25
25
  end
26
26
  end
27
27
  end
@@ -7,17 +7,17 @@ module DiasporaFederation
7
7
  # @!attribute [r] address
8
8
  # A string describing your location, e.g. a city name, a street name, etc
9
9
  # @return [String] address
10
- property :address
10
+ property :address, :string
11
11
 
12
12
  # @!attribute [r] lat
13
13
  # Geographical latitude of your location
14
14
  # @return [String] latitude
15
- property :lat
15
+ property :lat, :string
16
16
 
17
17
  # @!attribute [r] lng
18
18
  # Geographical longitude of your location
19
19
  # @return [String] longitude
20
- property :lng
20
+ property :lng, :string
21
21
  end
22
22
  end
23
23
  end
@@ -13,18 +13,18 @@ module DiasporaFederation
13
13
  # @!attribute [r] text
14
14
  # Text of the message composed by a user
15
15
  # @return [String] text
16
- property :text
16
+ property :text, :string
17
17
 
18
18
  # @!attribute [r] created_at
19
19
  # Message creation time
20
20
  # @return [Time] creation time
21
- property :created_at, default: -> { Time.now.utc }
21
+ property :created_at, :timestamp, default: -> { Time.now.utc }
22
22
 
23
23
  # @!attribute [r] conversation_guid
24
24
  # Guid of a conversation this message belongs to
25
25
  # @see Conversation#guid
26
26
  # @return [String] conversation guid
27
- property :conversation_guid
27
+ property :conversation_guid, :string
28
28
 
29
29
  # It is only valid to receive a {Message} from the author itself,
30
30
  # or from the author of the parent {Conversation} if the author signature is valid.
@@ -48,6 +48,16 @@ module DiasporaFederation
48
48
  parent.author
49
49
  end
50
50
 
51
+ # old timestamp format, because this signature is only used from old pods which also relay with old format
52
+ # @deprecated remove after {Message} doesn't include {Relayable} anymore
53
+ def normalize_property(name, value)
54
+ if name == :created_at
55
+ value.to_s
56
+ else
57
+ super
58
+ end
59
+ end
60
+
51
61
  # Default implementation, don't verify signatures for a {Message}.
52
62
  # @see Entity.populate_entity
53
63
  # @deprecated remove after {Message} doesn't include {Relayable} anymore
@@ -14,7 +14,7 @@ module DiasporaFederation
14
14
  # A string describing a type of the target to subscribe on
15
15
  # Currently only "Post" is supported.
16
16
  # @return [String] parent type
17
- property :parent_type, xml_name: :target_type
17
+ property :parent_type, :string, xml_name: :target_type
18
18
 
19
19
  # It is only valid to receive a {Participation} from the author themself.
20
20
  # @deprecated remove after {Participation} doesn't include {Relayable} anymore
@@ -9,7 +9,7 @@ module DiasporaFederation
9
9
  # MUST assign them a guid - a random string of at least 16 chars.
10
10
  # @see Validation::Rule::Guid
11
11
  # @return [String] guid
12
- property :guid
12
+ property :guid, :string
13
13
 
14
14
  # @!attribute [r] author
15
15
  # The diaspora* ID of the person
@@ -19,12 +19,12 @@ module DiasporaFederation
19
19
  # alias for author
20
20
  # @see Person#author
21
21
  # @return [String] diaspora* ID
22
- property :author, alias: :diaspora_id, xml_name: :diaspora_handle
22
+ property :author, :string, alias: :diaspora_id, xml_name: :diaspora_handle
23
23
 
24
24
  # @!attribute [r] url
25
25
  # @see Discovery::WebFinger#seed_url
26
26
  # @return [String] link to the pod
27
- property :url
27
+ property :url, :string
28
28
 
29
29
  # @!attribute [r] profile
30
30
  # All profile data of the person
@@ -34,7 +34,7 @@ module DiasporaFederation
34
34
  # @!attribute [r] exported_key
35
35
  # @see Discovery::HCard#public_key
36
36
  # @return [String] public key
37
- property :exported_key
37
+ property :exported_key, :string
38
38
  end
39
39
  end
40
40
  end
@@ -8,52 +8,52 @@ module DiasporaFederation
8
8
  # A random string of at least 16 chars
9
9
  # @see Validation::Rule::Guid
10
10
  # @return [String] guid
11
- property :guid
11
+ property :guid, :string
12
12
 
13
13
  # @!attribute [r] author
14
14
  # The diaspora* ID of the person who uploaded the photo
15
15
  # @see Person#author
16
16
  # @return [String] author diaspora* ID
17
- property :author, xml_name: :diaspora_handle
17
+ property :author, :string, xml_name: :diaspora_handle
18
18
 
19
19
  # @!attribute [r] public
20
20
  # Points if the photo is visible to everyone or only to some aspects
21
21
  # @return [Boolean] is it public
22
- property :public, default: false
22
+ property :public, :boolean, default: false
23
23
 
24
24
  # @!attribute [r] created_at
25
25
  # Photo entity creation time
26
26
  # @return [Time] creation time
27
- property :created_at, default: -> { Time.now.utc }
27
+ property :created_at, :timestamp, default: -> { Time.now.utc }
28
28
 
29
29
  # @!attribute [r] remote_photo_path
30
30
  # An url of the photo on a remote server
31
31
  # @return [String] remote photo url
32
- property :remote_photo_path
32
+ property :remote_photo_path, :string
33
33
 
34
34
  # @!attribute [r] remote_photo_name
35
35
  # @return [String] remote photo name
36
- property :remote_photo_name
36
+ property :remote_photo_name, :string
37
37
 
38
38
  # @!attribute [r] text
39
39
  # @return [String] text
40
- property :text, default: nil
40
+ property :text, :string, default: nil
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, default: nil
46
+ property :status_message_guid, :string, default: nil
47
47
 
48
48
  # @!attribute [r] height
49
49
  # Photo height
50
- # @return [String] height
51
- property :height
50
+ # @return [Integer] height
51
+ property :height, :integer
52
52
 
53
53
  # @!attribute [r] width
54
54
  # Photo width
55
- # @return [String] width
56
- property :width
55
+ # @return [Integer] width
56
+ property :width, :integer
57
57
  end
58
58
  end
59
59
  end
@@ -8,12 +8,12 @@ module DiasporaFederation
8
8
  # A random string of at least 16 chars
9
9
  # @see Validation::Rule::Guid
10
10
  # @return [String] poll guid
11
- property :guid
11
+ property :guid, :string
12
12
 
13
13
  # @!attribute [r] question
14
14
  # Text of the question posed by a user
15
15
  # @return [String] question
16
- property :question
16
+ property :question, :string
17
17
 
18
18
  # @!attribute [r] poll_answers
19
19
  # Array of possible answers for the poll
@@ -8,12 +8,12 @@ module DiasporaFederation
8
8
  # A random string of at least 16 chars
9
9
  # @see Validation::Rule::Guid
10
10
  # @return [String] guid
11
- property :guid
11
+ property :guid, :string
12
12
 
13
13
  # @!attribute [r] answer
14
14
  # Text of the answer
15
15
  # @return [String] answer
16
- property :answer
16
+ property :answer, :string
17
17
  end
18
18
  end
19
19
  end
@@ -17,7 +17,7 @@ module DiasporaFederation
17
17
  # Guid of the answer selected by the user
18
18
  # @see PollAnswer#guid
19
19
  # @return [String] poll answer guid
20
- property :poll_answer_guid
20
+ property :poll_answer_guid, :string
21
21
  end
22
22
  end
23
23
  end
@@ -26,10 +26,10 @@ module DiasporaFederation
26
26
  # @param [Entity] entity the entity in which it is included
27
27
  def self.included(entity)
28
28
  entity.class_eval do
29
- property :author, xml_name: :diaspora_handle
30
- property :guid
31
- property :created_at, default: -> { Time.now.utc }
32
- property :provider_display_name, default: nil
29
+ property :author, :string, xml_name: :diaspora_handle
30
+ property :guid, :string
31
+ property :created_at, :timestamp, default: -> { Time.now.utc }
32
+ property :provider_display_name, :string, default: nil
33
33
  end
34
34
  end
35
35
  end
@@ -12,7 +12,7 @@ module DiasporaFederation
12
12
  # Alias for author
13
13
  # @see Profile#author
14
14
  # @return [String] diaspora* ID
15
- property :author, alias: :diaspora_id, xml_name: :diaspora_handle
15
+ property :author, :string, alias: :diaspora_id, xml_name: :diaspora_handle
16
16
 
17
17
  # @!attribute [r] first_name
18
18
  # @deprecated We decided to only use one name field, these should be removed
@@ -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, default: nil
23
+ property :first_name, :string, default: nil
24
24
 
25
25
  # @!attribute [r] last_name
26
26
  # @deprecated We decided to only use one name field, these should be removed
@@ -28,33 +28,33 @@ module DiasporaFederation
28
28
  # @see #full_name
29
29
  # @see Discovery::HCard#last_name
30
30
  # @return [String] last name
31
- property :last_name, default: nil
31
+ property :last_name, :string, default: nil
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, default: nil
36
+ property :image_url, :string, default: nil
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, default: nil
40
+ property :image_url_medium, :string, default: nil
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, default: nil
44
+ property :image_url_small, :string, default: nil
45
45
 
46
- property :birthday, default: nil
47
- property :gender, default: nil
48
- property :bio, default: nil
49
- property :location, default: nil
46
+ property :birthday, :string, default: nil
47
+ property :gender, :string, default: nil
48
+ property :bio, :string, default: nil
49
+ property :location, :string, default: nil
50
50
 
51
51
  # @!attribute [r] searchable
52
52
  # @see Discovery::HCard#searchable
53
53
  # @return [Boolean] searchable flag
54
- property :searchable, default: true
54
+ property :searchable, :boolean, default: true
55
55
 
56
- property :nsfw, default: false
57
- property :tag_string, default: nil
56
+ property :nsfw, :boolean, default: false
57
+ property :tag_string, :string, default: nil
58
58
 
59
59
  # @return [String] string representation of this object
60
60
  def to_s
@@ -7,17 +7,17 @@ module DiasporaFederation
7
7
  # The diaspora* ID of the author
8
8
  # @see Person#author
9
9
  # @return [String] diaspora* ID
10
- property :author
10
+ property :author, :string
11
11
 
12
12
  # @!attribute [r] local
13
13
  # +true+ if the owner of the entity is local on the pod
14
14
  # @return [Boolean] is it a like or a dislike
15
- property :local
15
+ property :local, :boolean
16
16
 
17
17
  # @!attribute [r] public
18
18
  # Shows whether the entity is visible to everyone or only to some aspects
19
19
  # @return [Boolean] is it public
20
- property :public, default: false
20
+ property :public, :boolean, default: false
21
21
 
22
22
  # @!attribute [r] parent
23
23
  # Parent if the entity also has a parent (Comment or Like) or +nil+ if it has no parent
@@ -54,11 +54,11 @@ module DiasporaFederation
54
54
  # @param [Entity] klass the entity in which it is included
55
55
  def self.included(klass)
56
56
  klass.class_eval do
57
- property :author, xml_name: :diaspora_handle
58
- property :guid
59
- property :parent_guid
60
- property :author_signature, default: nil
61
- property :parent_author_signature, default: nil
57
+ property :author, :string, xml_name: :diaspora_handle
58
+ property :guid, :string
59
+ property :parent_guid, :string
60
+ property :author_signature, :string, default: nil
61
+ property :parent_author_signature, :string, default: nil
62
62
  entity :parent, Entities::RelatedEntity
63
63
  end
64
64
 
@@ -146,19 +146,26 @@ module DiasporaFederation
146
146
  Base64.strict_encode64(privkey.sign(DIGEST, signature_data))
147
147
  end
148
148
 
149
- # Sort all XML elements according to the order used for the signatures.
150
- # It updates also the signatures with the keys of the author and the parent
149
+ # Update the signatures with the keys of the author and the parent
151
150
  # if the signatures are not there yet and if the keys are available.
152
151
  #
153
- # @return [Hash] sorted xml elements with updated signatures
154
- def xml_elements
155
- xml_data = super.merge(additional_xml_elements)
156
- signature_order.map {|element| [element, xml_data[element] || ""] }.to_h.tap do |xml_elements|
157
- xml_elements[:author_signature] = author_signature || sign_with_author
158
- xml_elements[:parent_author_signature] = parent_author_signature || sign_with_parent_author_if_available.to_s
152
+ # @return [Hash] properties with updated signatures
153
+ def enriched_properties
154
+ super.merge(additional_xml_elements).tap do |hash|
155
+ hash[:author_signature] = author_signature || sign_with_author
156
+ hash[:parent_author_signature] = parent_author_signature || sign_with_parent_author_if_available.to_s
159
157
  end
160
158
  end
161
159
 
160
+ # Sort all XML elements according to the order used for the signatures.
161
+ #
162
+ # @return [Hash] sorted xml elements
163
+ def xml_elements
164
+ data = super
165
+ order = signature_order + %i(author_signature parent_author_signature)
166
+ order.map {|element| [element, data[element] || ""] }.to_h
167
+ end
168
+
162
169
  # The order for signing
163
170
  # @return [Array]
164
171
  def signature_order
@@ -172,7 +179,7 @@ module DiasporaFederation
172
179
 
173
180
  # @return [String] signature data string
174
181
  def signature_data
175
- data = to_h.merge(additional_xml_elements)
182
+ data = normalized_properties.merge(additional_xml_elements)
176
183
  signature_order.map {|name| data[name] }.join(";")
177
184
  end
178
185
 
@@ -24,25 +24,25 @@ module DiasporaFederation
24
24
  # This signature is mandatory only when federating from an upstream author to the subscribers.
25
25
  # @see Relayable#parent_author_signature
26
26
  # @return [String] parent author signature
27
- property :parent_author_signature, default: nil
27
+ property :parent_author_signature, :string, default: nil
28
28
 
29
29
  # @!attribute [r] target_guid
30
30
  # Guid of a relayable to be deleted
31
31
  # @see Comment#guid
32
32
  # @return [String] target guid
33
- property :target_guid
33
+ property :target_guid, :string
34
34
 
35
35
  # @!attribute [r] target_type
36
36
  # A string describing a type of the target
37
37
  # @see Retraction#target_type
38
38
  # @return [String] target type
39
- property :target_type
39
+ property :target_type, :string
40
40
 
41
41
  # @!attribute [r] author
42
42
  # The diaspora* ID of the person who deletes a relayable
43
43
  # @see Person#author
44
44
  # @return [String] diaspora* ID
45
- property :author, xml_name: :sender_handle
45
+ property :author, :string, xml_name: :sender_handle
46
46
 
47
47
  # @!attribute [r] target_author_signature
48
48
  # Contains a signature of the entity using the private key of the
@@ -51,7 +51,7 @@ module DiasporaFederation
51
51
  # author is done.
52
52
  # @see Relayable#author_signature
53
53
  # @return [String] target author signature
54
- property :target_author_signature, default: nil
54
+ property :target_author_signature, :string, default: nil
55
55
 
56
56
  # @!attribute [r] target
57
57
  # Target entity
@@ -83,11 +83,11 @@ module DiasporaFederation
83
83
  # if the signatures are not there yet and if the keys are available.
84
84
  #
85
85
  # @return [Hash] xml elements with updated signatures
86
- def xml_elements
86
+ def enriched_properties
87
87
  privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key, author)
88
88
 
89
- super.tap do |xml_elements|
90
- fill_required_signature(privkey, xml_elements) unless privkey.nil?
89
+ super.tap do |hash|
90
+ fill_required_signature(privkey, hash) unless privkey.nil?
91
91
  end
92
92
  end
93
93
 
@@ -10,13 +10,13 @@ module DiasporaFederation
10
10
  # The diaspora* ID of the person who share their profile
11
11
  # @see Person#author
12
12
  # @return [String] sender ID
13
- property :author, xml_name: :sender_handle
13
+ property :author, :string, xml_name: :sender_handle
14
14
 
15
15
  # @!attribute [r] recipient
16
16
  # The diaspora* ID of the person who will be shared with
17
17
  # @see Validation::Rule::DiasporaId
18
18
  # @return [String] recipient ID
19
- property :recipient, xml_name: :recipient_handle
19
+ property :recipient, :string, xml_name: :recipient_handle
20
20
 
21
21
  # Use only {Contact} for receive
22
22
  # @return [Contact] instance as contact
@@ -10,18 +10,18 @@ module DiasporaFederation
10
10
  # The diaspora* ID of the person who posted the original post
11
11
  # @see Person#author
12
12
  # @return [String] diaspora* ID
13
- property :root_author, xml_name: :root_diaspora_id
13
+ property :root_author, :string, xml_name: :root_diaspora_id
14
14
 
15
15
  # @!attribute [r] root_guid
16
16
  # Guid of the original post
17
17
  # @see StatusMessage#guid
18
18
  # @return [String] root guid
19
- property :root_guid
19
+ property :root_guid, :string
20
20
 
21
21
  # @!attribute [r] public
22
22
  # Has no meaning at the moment
23
23
  # @return [Boolean] public
24
- property :public, default: true # always true? (we only reshare public posts)
24
+ property :public, :boolean, 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
@@ -8,17 +8,17 @@ module DiasporaFederation
8
8
  # The diaspora* ID of the person who deletes the entity
9
9
  # @see Person#author
10
10
  # @return [String] diaspora* ID
11
- property :author, xml_name: :diaspora_handle
11
+ property :author, :string, xml_name: :diaspora_handle
12
12
 
13
13
  # @!attribute [r] target_guid
14
14
  # Guid of the entity to be deleted
15
15
  # @return [String] target guid
16
- property :target_guid, xml_name: :post_guid
16
+ property :target_guid, :string, xml_name: :post_guid
17
17
 
18
18
  # @!attribute [r] target_type
19
19
  # A string describing the type of the target
20
20
  # @return [String] target type
21
- property :target_type, xml_name: :type
21
+ property :target_type, :string, xml_name: :type
22
22
 
23
23
  # @!attribute [r] target
24
24
  # Target entity
@@ -10,25 +10,25 @@ module DiasporaFederation
10
10
  # Guid of a post to be deleted
11
11
  # @see Retraction#target_guid
12
12
  # @return [String] target guid
13
- property :target_guid
13
+ property :target_guid, :string
14
14
 
15
15
  # @!attribute [r] target_type
16
16
  # A string describing the type of the target
17
17
  # @see Retraction#target_type
18
18
  # @return [String] target type
19
- property :target_type
19
+ property :target_type, :string
20
20
 
21
21
  # @!attribute [r] author
22
22
  # The diaspora* ID of the person who deletes a post
23
23
  # @see Person#author
24
24
  # @return [String] diaspora* ID
25
- property :author, xml_name: :sender_handle
25
+ property :author, :string, xml_name: :sender_handle
26
26
 
27
27
  # @!attribute [r] author_signature
28
28
  # Contains a signature of the entity using the private key of the author of a post
29
29
  # This signature is mandatory.
30
30
  # @return [String] author signature
31
- property :target_author_signature, default: nil
31
+ property :target_author_signature, :string, default: nil
32
32
 
33
33
  # @!attribute [r] target
34
34
  # Target entity
@@ -68,9 +68,9 @@ module DiasporaFederation
68
68
  # if the signatures are not there yet and if the keys are available.
69
69
  #
70
70
  # @return [Hash] xml elements with updated signatures
71
- def xml_elements
72
- super.tap do |xml_elements|
73
- xml_elements[:target_author_signature] = target_author_signature || sign_with_author.to_s
71
+ def enriched_properties
72
+ super.tap do |hash|
73
+ hash[:target_author_signature] = target_author_signature || sign_with_author.to_s
74
74
  end
75
75
  end
76
76
 
@@ -9,7 +9,7 @@ module DiasporaFederation
9
9
  # @!attribute [r] text
10
10
  # Text of the status message composed by the user
11
11
  # @return [String] text of the status message
12
- property :text, xml_name: :raw_message
12
+ property :text, :string, xml_name: :raw_message
13
13
 
14
14
  # @!attribute [r] photos
15
15
  # Optional photos attached to the status message
@@ -29,7 +29,7 @@ module DiasporaFederation
29
29
  # @!attribute [r] public
30
30
  # Shows whether the status message is visible to everyone or only to some aspects
31
31
  # @return [Boolean] is it public
32
- property :public, default: false
32
+ property :public, :boolean, default: false
33
33
 
34
34
  private
35
35
 
@@ -76,7 +76,7 @@ module DiasporaFederation
76
76
  properties.map {|key, value|
77
77
  type = self.class.class_props[key]
78
78
 
79
- if type == String || value.nil?
79
+ if type.instance_of?(Symbol) || value.nil?
80
80
  [key, value]
81
81
  elsif type.instance_of?(Class)
82
82
  [key, value.to_h]
@@ -160,11 +160,15 @@ module DiasporaFederation
160
160
  type = self.class.class_props[name]
161
161
  return false if type.nil? # property undefined
162
162
 
163
- setable_string?(type, val) || setable_nested?(type, val) || setable_multi?(type, val)
163
+ setable_property?(type, val) || setable_nested?(type, val) || setable_multi?(type, val)
164
+ end
165
+
166
+ def setable_property?(type, val)
167
+ setable_string?(type, val) || type == :timestamp && val.is_a?(Time)
164
168
  end
165
169
 
166
170
  def setable_string?(type, val)
167
- type == String && val.respond_to?(:to_s)
171
+ %i(string integer boolean).include?(type) && val.respond_to?(:to_s)
168
172
  end
169
173
 
170
174
  def setable_nested?(type, val)
@@ -215,8 +219,29 @@ module DiasporaFederation
215
219
  end
216
220
  end
217
221
 
222
+ def normalized_properties
223
+ properties.map {|name, value| [name, normalize_property(name, value)] }.to_h
224
+ end
225
+
226
+ def normalize_property(name, value)
227
+ case self.class.class_props[name]
228
+ when :string, :integer, :boolean
229
+ value.to_s
230
+ when :timestamp
231
+ value.nil? ? "" : value.utc.iso8601
232
+ else
233
+ value
234
+ end
235
+ end
236
+
237
+ # default: nothing to enrich
238
+ def enriched_properties
239
+ normalized_properties
240
+ end
241
+
242
+ # default: no special order
218
243
  def xml_elements
219
- properties.map {|name, value| [name, self.class.class_props[name] == String ? value.to_s : value] }.to_h
244
+ enriched_properties
220
245
  end
221
246
 
222
247
  def add_property_to_xml(doc, root_element, name, value)
@@ -255,12 +280,12 @@ module DiasporaFederation
255
280
  end
256
281
 
257
282
  # @param [String] name property name to parse
258
- # @param [Class] type target type to parse
283
+ # @param [Class, Symbol] type target type to parse
259
284
  # @param [Nokogiri::XML::Element] root_node XML node to parse
260
285
  # @return [Object] parsed data
261
286
  private_class_method def self.parse_element_from_node(name, type, root_node)
262
- if type == String
263
- parse_string_from_node(name, root_node)
287
+ if type.instance_of?(Symbol)
288
+ parse_string_from_node(name, type, root_node)
264
289
  elsif type.instance_of?(Array)
265
290
  parse_array_from_node(type.first, root_node)
266
291
  elsif type.ancestors.include?(Entity)
@@ -271,12 +296,34 @@ module DiasporaFederation
271
296
  # Create simple entry in data hash
272
297
  #
273
298
  # @param [String] name xml tag to parse
299
+ # @param [Class, Symbol] type target type to parse
274
300
  # @param [Nokogiri::XML::Element] root_node XML root_node to parse
275
301
  # @return [String] data
276
- private_class_method def self.parse_string_from_node(name, root_node)
302
+ private_class_method def self.parse_string_from_node(name, type, root_node)
277
303
  node = root_node.xpath(name.to_s)
278
304
  node = root_node.xpath(xml_names[name].to_s) if node.empty?
279
- node.first.text if node.any?
305
+ parse_property(type, node.first.text) if node.any?
306
+ end
307
+
308
+ # @param [Symbol] type target type to parse
309
+ # @param [String] text data as string
310
+ # @return [String, Boolean, Integer, Time] data
311
+ private_class_method def self.parse_property(type, text)
312
+ case type
313
+ when :timestamp
314
+ begin
315
+ Time.parse(text).utc
316
+ rescue
317
+ nil
318
+ end
319
+ when :integer
320
+ text.to_i if text =~ /^\d+$/
321
+ when :boolean
322
+ return true if text =~ /(true|t|yes|y|1)$/i
323
+ false if text =~ /(false|f|no|n|0)$/i
324
+ else
325
+ text
326
+ end
280
327
  end
281
328
 
282
329
  # Create an entry in the data hash for the nested entity
@@ -18,12 +18,15 @@ module DiasporaFederation
18
18
 
19
19
  # Define a generic (string-type) property
20
20
  # @param [Symbol] name property name
21
+ # @param [Symbol] type property type
21
22
  # @param [Hash] opts further options
22
23
  # @option opts [Object, #call] :default a default value, making the
23
24
  # property optional
24
25
  # @option opts [Symbol] :xml_name another name used for xml generation
25
- def property(name, opts={})
26
- define_property name, String, opts
26
+ def property(name, type, opts={})
27
+ raise InvalidType unless property_type_valid?(type)
28
+
29
+ define_property name, type, opts
27
30
  end
28
31
 
29
32
  # Define a property that should contain another Entity or an array of
@@ -35,7 +38,7 @@ module DiasporaFederation
35
38
  # @option opts [Object, #call] :default a default value, making the
36
39
  # property optional
37
40
  def entity(name, type, opts={})
38
- raise InvalidType unless type_valid?(type)
41
+ raise InvalidType unless entity_type_valid?(type)
39
42
 
40
43
  define_property name, type, opts
41
44
  end
@@ -86,9 +89,11 @@ module DiasporaFederation
86
89
 
87
90
  # @deprecated
88
91
  def determine_xml_name(name, type, opts={})
89
- raise ArgumentError, "xml_name is not supported for nested entities" if type != String && opts.has_key?(:xml_name)
92
+ if !type.instance_of?(Symbol) && opts.has_key?(:xml_name)
93
+ raise ArgumentError, "xml_name is not supported for nested entities"
94
+ end
90
95
 
91
- if type == String
96
+ if type.instance_of?(Symbol)
92
97
  if opts.has_key? :xml_name
93
98
  raise InvalidName, "invalid xml_name" unless name_valid?(opts[:xml_name])
94
99
  opts[:xml_name]
@@ -121,10 +126,14 @@ module DiasporaFederation
121
126
  name.instance_of?(Symbol)
122
127
  end
123
128
 
129
+ def property_type_valid?(type)
130
+ %i(string integer boolean timestamp).include?(type)
131
+ end
132
+
124
133
  # Checks if the type extends {Entity}
125
134
  # @param [Class] type the type to check
126
135
  # @return [Boolean]
127
- def type_valid?(type)
136
+ def entity_type_valid?(type)
128
137
  [type].flatten.all? {|type|
129
138
  type.respond_to?(:ancestors) && type.ancestors.include?(Entity)
130
139
  }
@@ -1,4 +1,4 @@
1
1
  module DiasporaFederation
2
2
  # the gem version
3
- VERSION = "0.1.5".freeze
3
+ VERSION = "0.1.6".freeze
4
4
  end
@@ -0,0 +1,15 @@
1
+ if defined?(RSpec)
2
+ namespace :rails4 do
3
+ desc "Run all specs that generate fixtures for rspec with rails 4"
4
+ RSpec::Core::RakeTask.new(:generate_fixtures) do |t|
5
+ t.rspec_opts = ["--tag fixture4"]
6
+ end
7
+
8
+ desc "Run all specs in spec directory (exluding controller specs)"
9
+ RSpec::Core::RakeTask.new(:spec) do |task|
10
+ task.pattern = FileList["spec/**/*_spec.rb"].exclude("spec/controllers/**/*_spec.rb")
11
+ end
12
+
13
+ task test: %w(spec:prepare_db generate_fixtures spec)
14
+ end
15
+ end
data/lib/tasks/tests.rake CHANGED
@@ -1,6 +1,6 @@
1
1
  if defined?(RSpec)
2
2
  namespace :spec do
3
- task prepare_db: %w(db:create db:test:load)
3
+ task prepare_db: %w(db:create db:environment:set db:test:load)
4
4
  task :prepare_fixtures do
5
5
  ENV["NO_COVERAGE"] = "true"
6
6
  Rake::Task["spec:generate_fixtures"].invoke
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.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Neff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-23 00:00:00.000000000 Z
11
+ date: 2016-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -34,16 +34,22 @@ dependencies:
34
34
  name: faraday
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - "~>"
37
+ - - ">="
38
38
  - !ruby/object:Gem::Version
39
39
  version: 0.9.0
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: 0.11.0
40
43
  type: :runtime
41
44
  prerelease: false
42
45
  version_requirements: !ruby/object:Gem::Requirement
43
46
  requirements:
44
- - - "~>"
47
+ - - ">="
45
48
  - !ruby/object:Gem::Version
46
49
  version: 0.9.0
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: 0.11.0
47
53
  - !ruby/object:Gem::Dependency
48
54
  name: faraday_middleware
49
55
  requirement: !ruby/object:Gem::Requirement
@@ -188,6 +194,7 @@ files:
188
194
  - lib/diaspora_federation/version.rb
189
195
  - lib/tasks/build.rake
190
196
  - lib/tasks/diaspora_federation_tasks.rake
197
+ - lib/tasks/rails4.rake
191
198
  - lib/tasks/tests.rake
192
199
  homepage: https://github.com/diaspora/diaspora_federation
193
200
  licenses:
@@ -209,7 +216,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
209
216
  version: '0'
210
217
  requirements: []
211
218
  rubyforge_project:
212
- rubygems_version: 2.5.1
219
+ rubygems_version: 2.5.2
213
220
  signing_key:
214
221
  specification_version: 4
215
222
  summary: diaspora* federation library