w3c_api 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -0
  3. data/.rubocop_todo.yml +40 -0
  4. data/LICENSE.md +1 -1
  5. data/README.adoc +1032 -439
  6. data/Rakefile +7 -3
  7. data/lib/w3c_api/cli.rb +20 -20
  8. data/lib/w3c_api/client.rb +57 -237
  9. data/lib/w3c_api/commands/affiliation.rb +33 -33
  10. data/lib/w3c_api/commands/ecosystem.rb +47 -47
  11. data/lib/w3c_api/commands/group.rb +68 -68
  12. data/lib/w3c_api/commands/output_formatter.rb +11 -11
  13. data/lib/w3c_api/commands/participation.rb +20 -22
  14. data/lib/w3c_api/commands/series.rb +26 -26
  15. data/lib/w3c_api/commands/specification.rb +77 -52
  16. data/lib/w3c_api/commands/translation.rb +18 -18
  17. data/lib/w3c_api/commands/user.rb +60 -60
  18. data/lib/w3c_api/hal.rb +294 -0
  19. data/lib/w3c_api/models/account.rb +46 -0
  20. data/lib/w3c_api/models/affiliation.rb +54 -65
  21. data/lib/w3c_api/models/affiliation_index.rb +11 -0
  22. data/lib/w3c_api/models/call_for_translation.rb +15 -39
  23. data/lib/w3c_api/models/chair_index.rb +11 -0
  24. data/lib/w3c_api/models/charter.rb +48 -89
  25. data/lib/w3c_api/models/charter_index.rb +11 -0
  26. data/lib/w3c_api/models/connected_account.rb +21 -30
  27. data/lib/w3c_api/models/ecosystem.rb +20 -42
  28. data/lib/w3c_api/models/{ecosystems.rb → ecosystem_index.rb} +4 -10
  29. data/lib/w3c_api/models/evangelist_index.rb +11 -0
  30. data/lib/w3c_api/models/extension.rb +5 -7
  31. data/lib/w3c_api/models/group.rb +63 -142
  32. data/lib/w3c_api/models/group_index.rb +12 -0
  33. data/lib/w3c_api/models/group_link_set.rb +24 -0
  34. data/lib/w3c_api/models/join_emails.rb +5 -7
  35. data/lib/w3c_api/models/participant_index.rb +11 -0
  36. data/lib/w3c_api/models/participation.rb +31 -90
  37. data/lib/w3c_api/models/participation_index.rb +11 -0
  38. data/lib/w3c_api/models/photo.rb +28 -0
  39. data/lib/w3c_api/models/serie.rb +21 -51
  40. data/lib/w3c_api/models/{series.rb → serie_index.rb} +22 -13
  41. data/lib/w3c_api/models/spec_version.rb +69 -83
  42. data/lib/w3c_api/models/spec_version_index.rb +14 -0
  43. data/lib/w3c_api/models/spec_version_ref.rb +11 -13
  44. data/lib/w3c_api/models/specification.rb +54 -66
  45. data/lib/w3c_api/models/specification_index.rb +12 -0
  46. data/lib/w3c_api/models/team_contact_index.rb +11 -0
  47. data/lib/w3c_api/models/testimonial.rb +19 -0
  48. data/lib/w3c_api/models/translation.rb +33 -72
  49. data/lib/w3c_api/models/{translations.rb → translation_index.rb} +5 -11
  50. data/lib/w3c_api/models/user.rb +95 -165
  51. data/lib/w3c_api/models/user_index.rb +11 -0
  52. data/lib/w3c_api/models.rb +36 -12
  53. data/lib/w3c_api/version.rb +1 -1
  54. data/lib/w3c_api.rb +3 -2
  55. metadata +38 -19
  56. data/lib/w3c_api/models/affiliations.rb +0 -33
  57. data/lib/w3c_api/models/base.rb +0 -39
  58. data/lib/w3c_api/models/call_for_translation_ref.rb +0 -15
  59. data/lib/w3c_api/models/charters.rb +0 -17
  60. data/lib/w3c_api/models/collection_base.rb +0 -79
  61. data/lib/w3c_api/models/delegate_enumerable.rb +0 -54
  62. data/lib/w3c_api/models/groups.rb +0 -38
  63. data/lib/w3c_api/models/link.rb +0 -17
  64. data/lib/w3c_api/models/participations.rb +0 -17
  65. data/lib/w3c_api/models/series_collection.rb +0 -17
  66. data/lib/w3c_api/models/spec_versions.rb +0 -17
  67. data/lib/w3c_api/models/specifications.rb +0 -17
  68. data/lib/w3c_api/models/users.rb +0 -44
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'user'
4
+
5
+ module W3cApi
6
+ module Models
7
+ class ParticipantIndex < Lutaml::Hal::Page
8
+ hal_link :participants, key: 'participants', realize_class: 'User', collection: true
9
+ end
10
+ end
11
+ end
@@ -1,109 +1,50 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'base'
4
- require_relative 'link'
5
-
6
- # Example participation response:
3
+ # https://api.w3.org/participations/38785
7
4
  # {
8
- # "created": "2023-01-01T12:00:00Z",
5
+ # "individual": false,
6
+ # "invited-expert": false,
7
+ # "created": "2022-11-17 22:54:08",
9
8
  # "_links": {
10
9
  # "self": {
11
- # "href": "https://api.w3.org/participations/123"
10
+ # "href": "https://api.w3.org/participations/38785"
12
11
  # },
13
12
  # "group": {
14
- # "href": "https://api.w3.org/groups/456",
15
- # "title": "Example Group"
16
- # },
17
- # "user": {
18
- # "href": "https://api.w3.org/users/789",
19
- # "title": "John Doe"
13
+ # "href": "https://api.w3.org/groups/cg/silver",
14
+ # "title": "Silver Community Group"
20
15
  # },
21
16
  # "organization": {
22
- # "href": "https://api.w3.org/affiliations/101",
23
- # "title": "Example Organization"
17
+ # "href": "https://api.w3.org/affiliations/1092",
18
+ # "title": "MITRE Corporation"
24
19
  # },
25
20
  # "participants": {
26
- # "href": "https://api.w3.org/participations/123/participants"
21
+ # "href": "https://api.w3.org/participations/38785/participants"
27
22
  # }
28
23
  # }
29
24
  # }
30
-
31
25
  module W3cApi
32
- module Models
33
- class ParticipationLinks < Lutaml::Model::Serializable
34
- attribute :self, Link
35
- attribute :group, Link
36
- attribute :user, Link
37
- attribute :organization, Link
38
- attribute :participants, Link
39
- end
40
-
41
- class Participation < Base
42
- attribute :title, :string
43
- attribute :href, :string
44
- attribute :created, :date_time # Date-time format
45
- attribute :_links, ParticipationLinks
46
-
47
- # Parse date strings to Date objects
48
- def created_date
49
- Date.parse(created) if created
50
- rescue Date::Error
51
- nil
52
- end
53
-
54
- # Get the group this participation is for
55
- def group(client = nil)
56
- return nil unless client && _links&.group
57
-
58
- href = _links.group.href
59
- id = href.split('/').last
60
- client.group(id)
61
- end
62
-
63
- # Get the user participating
64
- def user(client = nil)
65
- return nil unless client && _links&.user
66
-
67
- href = _links.user.href
68
- id = href.split('/').last
69
- client.user(id)
70
- end
71
-
72
- # Get the organization participating
73
- def organization(client = nil)
74
- return nil unless client && _links&.organization
75
-
76
- href = _links.organization.href
77
- id = href.split('/').last
78
- client.affiliation(id)
79
- end
80
-
81
- # Get participants in this participation
82
- def participants(client = nil)
83
- return nil unless client && _links&.participants
84
-
85
- href = _links.participants.href
86
- id = href.split('/').last
87
- client.participation_participants(id)
88
- end
89
-
90
- def self.from_response(response)
91
- transformed_response = transform_keys(response)
92
-
93
- participation = new
94
- transformed_response.each do |key, value|
95
- case key
96
- when :_links
97
- links = value.each_with_object({}) do |(link_name, link_data), acc|
98
- acc[link_name] = Link.new(href: link_data[:href], title: link_data[:title])
99
- end
100
- participation._links = ParticipationLinks.new(links)
101
- else
102
- participation.send("#{key}=", value) if participation.respond_to?("#{key}=")
103
- end
104
- end
105
- participation
26
+ module Models
27
+ class Participation < Lutaml::Hal::Resource
28
+ attribute :title, :string
29
+ attribute :href, :string
30
+ attribute :created, :date_time
31
+ attribute :individual, :boolean
32
+ attribute :invited_expert, :boolean
33
+
34
+ hal_link :self, key: 'self', realize_class: 'Participation'
35
+ hal_link :group, key: 'group', realize_class: 'Group'
36
+ hal_link :organization, key: 'organization', realize_class: 'Affiliation'
37
+ hal_link :participants, key: 'participants', realize_class: 'ParticipantIndex'
38
+
39
+ key_value do
40
+ %i[
41
+ individual
42
+ invited_expert
43
+ created
44
+ ].each do |key|
45
+ map key.to_s.tr('_', '-'), to: key
106
46
  end
107
47
  end
108
48
  end
49
+ end
109
50
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'participation'
4
+
5
+ module W3cApi
6
+ module Models
7
+ class ParticipationIndex < Lutaml::Hal::Page
8
+ hal_link :participations, key: 'participations', realize_class: 'Participation', collection: true
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'lutaml/model'
4
+
5
+ # "photos": [
6
+ # {
7
+ # "href": "https://www.w3.org/thumbnails/360/avatar-images/f1ovb5rydm8s0go04oco0cgk0sow44w.webp?x-version=3",
8
+ # "name": "large"
9
+ # },
10
+
11
+ module W3cApi
12
+ module Models
13
+ # User model representing a W3C user/participant
14
+ class Photo < Lutaml::Model::Serializable
15
+ attribute :href, :string
16
+ attribute :name, :string
17
+
18
+ key_value do
19
+ %i[
20
+ href
21
+ name
22
+ ].each do |key|
23
+ map key.to_s, to: key
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,11 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'base'
4
- require_relative 'link'
5
-
3
+ # https://api.w3.org/specification-series/css-backgrounds
6
4
  # {
7
5
  # "shortname": "css-backgrounds",
8
- # "name": "CSS Backgrounds and Borders Module",
6
+ # "name": "CSS Backgrounds and Borders",
9
7
  # "_links": {
10
8
  # "self": {
11
9
  # "href": "https://api.w3.org/specification-series/css-backgrounds"
@@ -18,7 +16,7 @@ require_relative 'link'
18
16
  # }
19
17
  # }
20
18
  # }
21
- #
19
+
22
20
  # {
23
21
  # "shortname": "2dcontext",
24
22
  # "name": "HTML Canvas 2D Context",
@@ -36,53 +34,25 @@ require_relative 'link'
36
34
  # }
37
35
 
38
36
  module W3cApi
39
- module Models
40
- class SerieLinks < Lutaml::Model::Serializable
41
- attribute :self, Link
42
- attribute :specifications, Link
43
- attribute :current_specification, Link
44
- end
45
-
46
- class Serie < Base
47
- attribute :shortname, :string
48
- attribute :name, :string
49
- attribute :href, :string
50
- attribute :title, :string
51
- attribute :_links, SerieLinks
52
-
53
- # Get specifications in this series
54
- def specifications(client = nil)
55
- return nil unless client && _links&.specifications
56
-
57
- client.series_specifications(shortname)
58
- end
59
-
60
- # Get current specification in this series
61
- def current_specification(client = nil)
62
- return nil unless client && _links&.current_specification
63
-
64
- href = _links.current_specification.href
65
- shortname = href.split('/').last
66
- client.specification(shortname)
67
- end
68
-
69
- def self.from_response(response)
70
- transformed_response = transform_keys(response)
71
-
72
- series = new
73
- transformed_response.each do |key, value|
74
- case key
75
- when :_links
76
- links = value.each_with_object({}) do |(link_name, link_data), acc|
77
- acc[link_name] = Link.new(href: link_data[:href], title: link_data[:title])
78
- end
79
- series._links = SerieLinks.new(links)
80
- else
81
- series.send("#{key}=", value) if series.respond_to?("#{key}=")
82
- end
83
- end
84
- series
37
+ module Models
38
+ class Serie < Lutaml::Hal::Resource
39
+ attribute :shortname, :string
40
+ attribute :name, :string
41
+ attribute :href, :string
42
+ attribute :title, :string
43
+
44
+ hal_link :self, key: 'self', realize_class: 'Serie'
45
+ hal_link :specifications, key: 'specifications', realize_class: 'SpecificationIndex'
46
+ hal_link :current_specification, key: 'current-specification', realize_class: 'SpecVersion'
47
+
48
+ key_value do
49
+ %i[
50
+ shortname
51
+ name
52
+ ].each do |key|
53
+ map key.to_s.tr('_', '-'), to: key
85
54
  end
86
55
  end
87
56
  end
57
+ end
88
58
  end
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'lutaml/model'
4
3
  require_relative 'serie'
5
- require_relative 'delegate_enumerable'
6
- require_relative 'collection_base'
7
4
 
5
+ # https://api.w3.org/specification-series
8
6
  # {
9
7
  # "page": 1,
10
- # "limit": 1000,
11
- # "pages": 2,
8
+ # "limit": 100,
9
+ # "pages": 15,
12
10
  # "total": 1426,
13
11
  # "_links": {
14
12
  # "specification-series": [
@@ -28,14 +26,25 @@ require_relative 'collection_base'
28
26
  # "href": "https://api.w3.org/specification-series/accessibility-metrics-report",
29
27
  # "title": "accessibility-metrics-report"
30
28
  # },
31
-
29
+ # ],
30
+ # "self": {
31
+ # "href": "https://api.w3.org/specification-series?page=1&items=100"
32
+ # },
33
+ # "first": {
34
+ # "href": "https://api.w3.org/specification-series?page=1&items=100"
35
+ # },
36
+ # "last": {
37
+ # "href": "https://api.w3.org/specification-series?page=15&items=100"
38
+ # },
39
+ # "next": {
40
+ # "href": "https://api.w3.org/specification-series?page=2&items=100"
41
+ # }
42
+ # }
43
+ # }
32
44
  module W3cApi
33
- module Models
34
- class Series < CollectionBase
35
- attribute :series, Serie, collection: true
36
-
37
- delegate_enumerable :series
38
- collection_instance_class Serie, :series
39
- end
45
+ module Models
46
+ class SerieIndex < Lutaml::Hal::Page
47
+ hal_link :series, key: 'specification-series', realize_class: 'Serie', collection: true
40
48
  end
49
+ end
41
50
  end
@@ -1,96 +1,82 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'base'
4
- require_relative 'link'
5
-
6
- # Example spec version response format:
3
+ # https://api.w3.org/specifications/html5/versions/20180327
7
4
  # {
8
- # "date": "2023-09-21"
9
- # "status": "REC"
10
- # "rec_track": true
11
- # "editor-draft": "https://w3c.github.io/example-draft/"
12
- # "uri": "https://www.w3.org/TR/2023/REC-example-20230921/"
13
- # "title": "Example Specification"
14
- # "shortlink": "https://www.w3.org/TR/example/"
15
- # "process-rules": "2021"
16
- # "_links": {
17
- # "self": {
18
- # "href": "https://api.w3.org/specifications/example/versions/20230921"
19
- # },
20
- # "specification": {
21
- # "href": "https://api.w3.org/specifications/example"
5
+ # "status": "Retired",
6
+ # "rec-track": true,
7
+ # "uri": "https://www.w3.org/TR/2018/SPSD-html5-20180327/",
8
+ # "date": "2018-03-27",
9
+ # "informative": false,
10
+ # "title": "HTML5",
11
+ # "shortlink": "https://www.w3.org/TR/html5/",
12
+ # "_links": {
13
+ # "self": {
14
+ # "href": "https://api.w3.org/specifications/html5/versions/20180327"
15
+ # },
16
+ # "editors": {
17
+ # "href": "https://api.w3.org/specifications/html5/versions/20180327/editors"
18
+ # },
19
+ # "deliverers": {
20
+ # "href": "https://api.w3.org/specifications/html5/versions/20180327/deliverers"
21
+ # },
22
+ # "specification": {
23
+ # "href": "https://api.w3.org/specifications/html5"
24
+ # },
25
+ # "predecessor-version": {
26
+ # "href": "https://api.w3.org/specifications/html5/versions/20180327/predecessors"
27
+ # }
22
28
  # }
23
- # }
24
29
  # }
25
30
 
26
31
  module W3cApi
27
- module Models
28
- class SpecVersionLinks < Lutaml::Model::Serializable
29
- attribute :self, Link
30
- attribute :specification, Link
31
- end
32
-
33
- class SpecVersion < Base
34
- attribute :status, :string
35
- attribute :rec_track, :boolean
36
- attribute :editor_draft, :string
37
- attribute :uri, :string, pattern: %r{https://www\.w3\.org/.*}
38
- attribute :date, :date_time # Date-time format
39
- attribute :last_call_feedback_due, :date_time # Date-time format
40
- attribute :pr_reviews_date, :date_time # Date-time format
41
- attribute :implementation_feedback_due, :date_time # Date-time format
42
- attribute :per_reviews_due, :date_time # Date-time format
43
- attribute :informative, :boolean
44
- attribute :title, :string
45
- attribute :href, :string
46
- attribute :shortlink, :string, pattern: %r{https://www\.w3\.org/.*}
47
- attribute :translation, :string
48
- attribute :errata, :string
49
- attribute :process_rules, :string
50
- attribute :_links, SpecVersionLinks
51
-
52
- # Return the specification this version belongs to
53
- def specification(client = nil)
54
- return nil unless client && _links&.specification
55
-
56
- spec_href = _links.specification.href
57
- spec_shortname = spec_href.split('/').last
58
-
59
- client.specification(spec_shortname)
60
- end
61
-
62
- # Check if this spec version is a Recommendation
63
- def recommendation?
64
- status == 'REC'
65
- end
66
-
67
- # Check if this spec version is a Working Draft
68
- def working_draft?
69
- status == 'WD'
70
- end
71
-
72
- # Check if this spec version is a Candidate Recommendation
73
- def candidate_recommendation?
74
- status == 'CR'
75
- end
32
+ module Models
33
+ class SpecVersion < Lutaml::Hal::Resource
34
+ attribute :status, :string
35
+ attribute :rec_track, :boolean
36
+ attribute :editor_draft, :string
37
+ attribute :uri, :string
38
+ attribute :date, :date_time
39
+ attribute :last_call_feedback_due, :date_time
40
+ attribute :pr_reviews_date, :date_time
41
+ attribute :implementation_feedback_due, :date_time
42
+ attribute :per_reviews_due, :date_time
43
+ attribute :informative, :boolean
44
+ attribute :title, :string
45
+ attribute :href, :string
46
+ attribute :shortlink, :string
47
+ attribute :translation, :string
48
+ attribute :errata, :string
49
+ attribute :process_rules, :string
76
50
 
77
- def self.from_response(response)
78
- transformed_response = transform_keys(response)
51
+ hal_link :self, key: 'self', realize_class: 'SpecVersion'
52
+ hal_link :editors, key: 'editors', realize_class: 'UserIndex'
53
+ hal_link :deliverers, key: 'deliverers', realize_class: 'UserIndex'
54
+ hal_link :specification, key: 'specification', realize_class: 'Specification'
55
+ hal_link :predecessor_version, key: 'predecessor-version', realize_class: 'SpecVersionIndex'
56
+ hal_link :successor_version, key: 'successor-version', realize_class: 'SpecVersionIndex'
79
57
 
80
- spec_version = new
81
- transformed_response.each do |key, value|
82
- case key
83
- when :_links
84
- links = value.each_with_object({}) do |(link_name, link_data), acc|
85
- acc[link_name] = Link.new(href: link_data[:href], title: link_data[:title])
86
- end
87
- spec_version._links = SpecVersionLinks.new(links)
88
- else
89
- spec_version.send("#{key}=", value) if spec_version.respond_to?("#{key}=")
90
- end
91
- end
92
- spec_version
58
+ key_value do
59
+ %i[
60
+ status
61
+ rec_track
62
+ editor_draft
63
+ uri
64
+ date
65
+ last_call_feedback_due
66
+ pr_reviews_date
67
+ implementation_feedback_due
68
+ per_reviews_due
69
+ informative
70
+ title
71
+ href
72
+ shortlink
73
+ translation
74
+ errata
75
+ process_rules
76
+ ].each do |key|
77
+ map key.to_s.tr('_', '-'), to: key
93
78
  end
94
79
  end
95
80
  end
81
+ end
96
82
  end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'spec_version'
4
+
5
+ module W3cApi
6
+ module Models
7
+ class SpecVersionIndex < Lutaml::Hal::Page
8
+ hal_link :versions, key: 'versions', realize_class: 'SpecVersion', collection: true
9
+ hal_link :spec_versions, key: 'version-history', realize_class: 'SpecVersion', collection: true
10
+ hal_link :predecessor_version, key: 'predecessor-version', realize_class: 'SpecVersion', collection: true
11
+ hal_link :successor_version, key: 'successor-version', realize_class: 'SpecVersion', collection: true
12
+ end
13
+ end
14
+ end
@@ -1,18 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'lutaml/model'
4
-
5
3
  module W3cApi
6
- module Models
7
- class SpecVersionRef < Lutaml::Model::Serializable
8
- attribute :status, :string
9
- attribute :rec_track, :boolean
10
- attribute :editor_draft, :string
11
- attribute :uri, :string
12
- attribute :date, :string
13
- attribute :title, :string
14
- attribute :shortlink, :string
15
- attribute :process_rules, :string
16
- end
4
+ module Models
5
+ class SpecVersionRef < Lutaml::Model::Serializable
6
+ attribute :status, :string
7
+ attribute :rec_track, :boolean
8
+ attribute :editor_draft, :string
9
+ attribute :uri, :string
10
+ attribute :date, :string
11
+ attribute :title, :string
12
+ attribute :shortlink, :string
13
+ attribute :process_rules, :string
17
14
  end
15
+ end
18
16
  end