diaspora_federation 0.1.6 → 0.1.7

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: 70e250962994a4f76c0232c5ea58fd2c02411766
4
- data.tar.gz: 131351687ab2b4cd5e63fe7a1783103b3b43f83c
3
+ metadata.gz: bccc4300ee15d68f43e71ba93c0f5e5f9946b65d
4
+ data.tar.gz: ba2a345fbf4775253d8cecd0a56618eb2acbc4d8
5
5
  SHA512:
6
- metadata.gz: 31ca9ff248eb49ba2b1ca310e7ab1f3447c488677ff6ed026f1bf39a1dbe16dde6fbf0cbc307e7fc6c1d9bb6c3123635711d8006546d5149395ab9acb13ff944
7
- data.tar.gz: 569623cc75eeefcb9e6bdea8851495fd4fb5319664847234d4f0ddb51b4be457fce75d8deb722ee1c858fb42eb89c52be7054e6259428e23fe3ba3dc2ca30540
6
+ metadata.gz: 58c1303160966d0fd6e82f7383aaa073f518fe3905a4975fd8a799473a3802abbf9af10d97d3b6d683211d094a999f3dd9c8d907f456982f085e8843baa38868
7
+ data.tar.gz: 387570d4c545ae549afa95647c1c5e9648c0be32065b2ac2cbe1e14fae4a7b169b6243a82ba893ff7eb5d1c2e8718e6fbf946bb29b6dc43924717a104f93f4dc
data/Changelog.md CHANGED
@@ -1,3 +1,17 @@
1
+ # 0.1.7
2
+
3
+ ## Feature
4
+
5
+ * Add event entities [#44](https://github.com/diaspora/diaspora_federation/pull/44)
6
+
7
+ ## Refactor
8
+
9
+ * Add generated signatures of relayables to `#to_h` [#48](https://github.com/diaspora/diaspora_federation/pull/48)
10
+
11
+ ## Bug fixes
12
+
13
+ * Fix parsing of false value [9a7fd27](https://github.com/diaspora/diaspora_federation/commit/9a7fd278b528c809b3a8c53b86c5fa8d6efaf8aa)
14
+
1
15
  # 0.1.6
2
16
 
3
17
  ## Feature
data/README.md CHANGED
@@ -11,7 +11,7 @@
11
11
  [![Gem Version](https://badge.fury.io/rb/diaspora_federation.svg)](https://badge.fury.io/rb/diaspora_federation)
12
12
 
13
13
  [Gem Documentation](http://www.rubydoc.info/gems/diaspora_federation/) |
14
- [Protocol Documentation](http://diaspora.github.io/diaspora_federation/) |
14
+ [Protocol Documentation](https://diaspora.github.io/diaspora_federation/) |
15
15
  [Bugtracker](https://github.com/diaspora/diaspora_federation/issues)
16
16
 
17
17
  This repository contains two gems:
@@ -76,7 +76,7 @@ module DiasporaFederation
76
76
  # @param [String] url validation subject
77
77
  # @return [Boolean] validation result
78
78
  private_class_method def self.webfinger_url_valid?(url)
79
- !url.nil? && url.instance_of?(String) && url =~ %r{^https?:\/\/.*\/.*\{uri\}.*}i
79
+ !url.nil? && url.instance_of?(String) && url =~ %r{\Ahttps?:\/\/.*\/.*\{uri\}.*}i
80
80
  end
81
81
 
82
82
  # Gets the webfinger url from an XRD data structure
@@ -28,6 +28,10 @@ require "diaspora_federation/entities/poll"
28
28
  require "diaspora_federation/entities/poll_participation"
29
29
 
30
30
  require "diaspora_federation/entities/location"
31
+
32
+ require "diaspora_federation/entities/event"
33
+ require "diaspora_federation/entities/event_participation"
34
+
31
35
  require "diaspora_federation/entities/photo"
32
36
  require "diaspora_federation/entities/status_message"
33
37
  require "diaspora_federation/entities/reshare"
@@ -0,0 +1,55 @@
1
+ module DiasporaFederation
2
+ module Entities
3
+ # This entity represents an event and it is federated as a part of a status message.
4
+ #
5
+ # @see Validators::EventValidator
6
+ class Event < Entity
7
+ # @!attribute [r] author
8
+ # The diaspora* ID of the person who created the event
9
+ # @see Person#author
10
+ # @return [String] author diaspora* ID
11
+ property :author, :string
12
+
13
+ # @!attribute [r] guid
14
+ # A random string of at least 16 chars
15
+ # @see Validation::Rule::Guid
16
+ # @return [String] guid
17
+ property :guid, :string
18
+
19
+ # @!attribute [r] summary
20
+ # The summary of the event
21
+ # @return [String] event summary
22
+ property :summary, :string
23
+
24
+ # @!attribute [r] description
25
+ # Description of the event
26
+ # @return [String] event description
27
+ property :description, :string, default: nil
28
+
29
+ # @!attribute [r] start
30
+ # The start time of the event
31
+ # @return [String] event start
32
+ property :start, :timestamp
33
+
34
+ # @!attribute [r] end
35
+ # The end time of the event
36
+ # @return [String] event end
37
+ property :end, :timestamp, default: nil
38
+
39
+ # @!attribute [r] all_day
40
+ # Points if the event is an all day event
41
+ # @return [Boolean] is it an all day event
42
+ property :all_day, :boolean, default: false
43
+
44
+ # @!attribute [r] timezone
45
+ # Timezone to which the event is fixed to
46
+ # @return [String] timezone
47
+ property :timezone, :string, default: nil
48
+
49
+ # @!attribute [r] location
50
+ # Location of the event
51
+ # @return [Entities::Location] location
52
+ entity :location, Entities::Location, default: nil
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,27 @@
1
+ module DiasporaFederation
2
+ module Entities
3
+ # This entity represents a participation in an event, i.e. it is issued when a user responds to en event.
4
+ #
5
+ # @see Validators::EventParticipationValidator
6
+ class EventParticipation < Entity
7
+ # Old signature order
8
+ # @deprecated
9
+ LEGACY_SIGNATURE_ORDER = %i(author guid parent_guid status).freeze
10
+
11
+ # The {EventParticipation} parent is an {Event}
12
+ PARENT_TYPE = "Event".freeze
13
+
14
+ include Relayable
15
+
16
+ # Redefine the author property without +diaspora_handle+ +xml_name+
17
+ # @deprecated Can be removed after XMLs are generated with new names
18
+ property :author, :string
19
+
20
+ # @!attribute [r] status
21
+ # The participation status of the user
22
+ # "accepted", "declined" or "tentative"
23
+ # @return [String] event participation status
24
+ property :status, :string
25
+ end
26
+ end
27
+ end
@@ -33,6 +33,11 @@ module DiasporaFederation
33
33
  sender == author || (sender == parent_author && verify_author_signature)
34
34
  end
35
35
 
36
+ # @deprecated remove after {Message} doesn't include {Relayable} anymore
37
+ def to_h
38
+ super.tap {|hash| hash[:created_at] = created_at.utc.iso8601 }
39
+ end
40
+
36
41
  private
37
42
 
38
43
  # @deprecated remove after {Message} doesn't include {Relayable} anymore
@@ -26,6 +26,11 @@ module DiasporaFederation
26
26
  # @return [Entities::Poll] poll
27
27
  entity :poll, Entities::Poll, default: nil
28
28
 
29
+ # @!attribute [r] event
30
+ # Optional event attached to the status message
31
+ # @return [Entities::Event] event
32
+ entity :event, Entities::Event, default: nil
33
+
29
34
  # @!attribute [r] public
30
35
  # Shows whether the status message is visible to everyone or only to some aspects
31
36
  # @return [Boolean] is it public
@@ -73,7 +73,7 @@ module DiasporaFederation
73
73
  # Nested entities are also converted to a Hash.
74
74
  # @return [Hash] entity data (mostly equal to the hash used for initialization).
75
75
  def to_h
76
- properties.map {|key, value|
76
+ enriched_properties.map {|key, value|
77
77
  type = self.class.class_props[key]
78
78
 
79
79
  if type.instance_of?(Symbol) || value.nil?
@@ -135,8 +135,8 @@ module DiasporaFederation
135
135
  # @param [String] entity_name "snake_case" class name
136
136
  # @return [Class] entity class
137
137
  def self.entity_class(entity_name)
138
- raise InvalidEntityName, "'#{entity_name}' is invalid" unless entity_name =~ /^[a-z]*(_[a-z]*)*$/
139
- class_name = entity_name.sub(/^[a-z]/, &:upcase)
138
+ raise InvalidEntityName, "'#{entity_name}' is invalid" unless entity_name =~ /\A[a-z]*(_[a-z]*)*\z/
139
+ class_name = entity_name.sub(/\A[a-z]/, &:upcase)
140
140
  class_name.gsub!(/_([a-z])/) { Regexp.last_match[1].upcase }
141
141
 
142
142
  raise UnknownEntity, "'#{class_name}' not found" unless Entities.const_defined?(class_name)
@@ -275,7 +275,7 @@ module DiasporaFederation
275
275
  private_class_method def self.entity_data(root_node)
276
276
  class_props.map {|name, type|
277
277
  value = parse_element_from_node(name, type, root_node)
278
- [name, value] if value
278
+ [name, value] unless value.nil?
279
279
  }.compact.to_h
280
280
  end
281
281
 
@@ -302,13 +302,13 @@ module DiasporaFederation
302
302
  private_class_method def self.parse_string_from_node(name, type, root_node)
303
303
  node = root_node.xpath(name.to_s)
304
304
  node = root_node.xpath(xml_names[name].to_s) if node.empty?
305
- parse_property(type, node.first.text) if node.any?
305
+ parse_string(type, node.first.text) if node.any?
306
306
  end
307
307
 
308
308
  # @param [Symbol] type target type to parse
309
309
  # @param [String] text data as string
310
310
  # @return [String, Boolean, Integer, Time] data
311
- private_class_method def self.parse_property(type, text)
311
+ private_class_method def self.parse_string(type, text)
312
312
  case type
313
313
  when :timestamp
314
314
  begin
@@ -317,10 +317,10 @@ module DiasporaFederation
317
317
  nil
318
318
  end
319
319
  when :integer
320
- text.to_i if text =~ /^\d+$/
320
+ text.to_i if text =~ /\A\d+\z/
321
321
  when :boolean
322
- return true if text =~ /(true|t|yes|y|1)$/i
323
- false if text =~ /(false|f|no|n|0)$/i
322
+ return true if text =~ /\A(true|t|yes|y|1)\z/i
323
+ false if text =~ /\A(false|f|no|n|0)\z/i
324
324
  else
325
325
  text
326
326
  end
@@ -21,7 +21,7 @@ module DiasporaFederation
21
21
  end
22
22
 
23
23
  private_class_method def self.entity_name(class_name)
24
- return class_name if class_name =~ /^[a-z]*(_[a-z]*)*$/
24
+ return class_name if class_name =~ /\A[a-z]*(_[a-z]*)*\z/
25
25
 
26
26
  raise DiasporaFederation::Entity::UnknownEntity, class_name unless Entities.const_defined?(class_name)
27
27
 
@@ -44,6 +44,8 @@ require "diaspora_federation/validators/account_deletion_validator"
44
44
  require "diaspora_federation/validators/comment_validator"
45
45
  require "diaspora_federation/validators/contact_validator"
46
46
  require "diaspora_federation/validators/conversation_validator"
47
+ require "diaspora_federation/validators/event_participation_validator"
48
+ require "diaspora_federation/validators/event_validator"
47
49
  require "diaspora_federation/validators/h_card_validator"
48
50
  require "diaspora_federation/validators/like_validator"
49
51
  require "diaspora_federation/validators/location_validator"
@@ -0,0 +1,12 @@
1
+ module DiasporaFederation
2
+ module Validators
3
+ # This validates a {Entities::EventParticipation}.
4
+ class EventParticipationValidator < Validation::Validator
5
+ include Validation
6
+
7
+ include RelayableValidator
8
+
9
+ rule :status, regular_expression: {regex: /\A(accepted|declined|tentative)\z/}
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,21 @@
1
+ module DiasporaFederation
2
+ module Validators
3
+ # This validates a {Entities::Event}.
4
+ class EventValidator < Validation::Validator
5
+ include Validation
6
+
7
+ rule :author, %i(not_empty diaspora_id)
8
+
9
+ rule :guid, :guid
10
+
11
+ rule :summary, [:not_empty, length: {maximum: 255}]
12
+ rule :description, length: {maximum: 65_535}
13
+
14
+ rule :start, :not_nil
15
+
16
+ rule :all_day, :boolean
17
+
18
+ rule :timezone, regular_expression: {regex: %r{\A[A-Za-z_-]{,14}(/[A-Za-z_-]{,14}){1,2}\z}}
19
+ end
20
+ end
21
+ end
@@ -1,4 +1,4 @@
1
1
  module DiasporaFederation
2
2
  # the gem version
3
- VERSION = "0.1.6".freeze
3
+ VERSION = "0.1.7".freeze
4
4
  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:environment:set db:test:load)
3
+ task prepare_db: %w(db:create db:test:load)
4
4
  task :prepare_fixtures do
5
5
  ENV["NO_COVERAGE"] = "true"
6
6
  Rake::Task["spec:generate_fixtures"].invoke
@@ -8,7 +8,7 @@ if defined?(RSpec)
8
8
  end
9
9
 
10
10
  desc "Prepare for rspec"
11
- task prepare: %w(prepare_db prepare_fixtures)
11
+ task prepare: %w(db:environment:set prepare_db prepare_fixtures)
12
12
 
13
13
  desc "Run all specs that generate fixtures for rspec"
14
14
  RSpec::Core::RakeTask.new(:generate_fixtures) do |t|
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.6
4
+ version: 0.1.7
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-12-28 00:00:00.000000000 Z
11
+ date: 2017-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -118,6 +118,8 @@ files:
118
118
  - lib/diaspora_federation/entities/comment.rb
119
119
  - lib/diaspora_federation/entities/contact.rb
120
120
  - lib/diaspora_federation/entities/conversation.rb
121
+ - lib/diaspora_federation/entities/event.rb
122
+ - lib/diaspora_federation/entities/event_participation.rb
121
123
  - lib/diaspora_federation/entities/like.rb
122
124
  - lib/diaspora_federation/entities/location.rb
123
125
  - lib/diaspora_federation/entities/message.rb
@@ -163,6 +165,8 @@ files:
163
165
  - lib/diaspora_federation/validators/comment_validator.rb
164
166
  - lib/diaspora_federation/validators/contact_validator.rb
165
167
  - lib/diaspora_federation/validators/conversation_validator.rb
168
+ - lib/diaspora_federation/validators/event_participation_validator.rb
169
+ - lib/diaspora_federation/validators/event_validator.rb
166
170
  - lib/diaspora_federation/validators/h_card_validator.rb
167
171
  - lib/diaspora_federation/validators/like_validator.rb
168
172
  - lib/diaspora_federation/validators/location_validator.rb