w3c_api 0.1.0 → 0.1.1

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 (64) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.md +1 -1
  3. data/README.adoc +845 -436
  4. data/lib/w3c_api/cli.rb +20 -20
  5. data/lib/w3c_api/client.rb +66 -195
  6. data/lib/w3c_api/commands/affiliation.rb +33 -33
  7. data/lib/w3c_api/commands/ecosystem.rb +47 -47
  8. data/lib/w3c_api/commands/group.rb +68 -68
  9. data/lib/w3c_api/commands/output_formatter.rb +11 -11
  10. data/lib/w3c_api/commands/participation.rb +20 -22
  11. data/lib/w3c_api/commands/series.rb +26 -26
  12. data/lib/w3c_api/commands/specification.rb +77 -52
  13. data/lib/w3c_api/commands/translation.rb +18 -18
  14. data/lib/w3c_api/commands/user.rb +60 -60
  15. data/lib/w3c_api/hal.rb +164 -0
  16. data/lib/w3c_api/models/account.rb +44 -0
  17. data/lib/w3c_api/models/affiliation.rb +54 -65
  18. data/lib/w3c_api/models/affiliation_index.rb +11 -0
  19. data/lib/w3c_api/models/call_for_translation.rb +15 -39
  20. data/lib/w3c_api/models/chair_index.rb +11 -0
  21. data/lib/w3c_api/models/charter.rb +48 -89
  22. data/lib/w3c_api/models/charter_index.rb +11 -0
  23. data/lib/w3c_api/models/connected_account.rb +21 -30
  24. data/lib/w3c_api/models/ecosystem.rb +20 -42
  25. data/lib/w3c_api/models/{ecosystems.rb → ecosystem_index.rb} +4 -10
  26. data/lib/w3c_api/models/evangelist_index.rb +11 -0
  27. data/lib/w3c_api/models/extension.rb +5 -7
  28. data/lib/w3c_api/models/group.rb +63 -142
  29. data/lib/w3c_api/models/group_index.rb +12 -0
  30. data/lib/w3c_api/models/join_emails.rb +5 -7
  31. data/lib/w3c_api/models/participant_index.rb +11 -0
  32. data/lib/w3c_api/models/participation.rb +31 -90
  33. data/lib/w3c_api/models/participation_index.rb +11 -0
  34. data/lib/w3c_api/models/photo.rb +26 -0
  35. data/lib/w3c_api/models/serie.rb +21 -51
  36. data/lib/w3c_api/models/{series.rb → serie_index.rb} +22 -13
  37. data/lib/w3c_api/models/spec_version.rb +69 -83
  38. data/lib/w3c_api/models/spec_version_index.rb +13 -0
  39. data/lib/w3c_api/models/spec_version_ref.rb +11 -13
  40. data/lib/w3c_api/models/specification.rb +54 -66
  41. data/lib/w3c_api/models/specification_index.rb +10 -0
  42. data/lib/w3c_api/models/team_contact_index.rb +11 -0
  43. data/lib/w3c_api/models/testimonial.rb +17 -0
  44. data/lib/w3c_api/models/translation.rb +33 -72
  45. data/lib/w3c_api/models/{translations.rb → translation_index.rb} +4 -12
  46. data/lib/w3c_api/models/user.rb +95 -165
  47. data/lib/w3c_api/models/user_index.rb +11 -0
  48. data/lib/w3c_api/models.rb +35 -12
  49. data/lib/w3c_api/version.rb +1 -1
  50. data/lib/w3c_api.rb +3 -2
  51. metadata +35 -19
  52. data/lib/w3c_api/models/affiliations.rb +0 -33
  53. data/lib/w3c_api/models/base.rb +0 -39
  54. data/lib/w3c_api/models/call_for_translation_ref.rb +0 -15
  55. data/lib/w3c_api/models/charters.rb +0 -17
  56. data/lib/w3c_api/models/collection_base.rb +0 -79
  57. data/lib/w3c_api/models/delegate_enumerable.rb +0 -54
  58. data/lib/w3c_api/models/groups.rb +0 -38
  59. data/lib/w3c_api/models/link.rb +0 -17
  60. data/lib/w3c_api/models/participations.rb +0 -17
  61. data/lib/w3c_api/models/series_collection.rb +0 -17
  62. data/lib/w3c_api/models/spec_versions.rb +0 -17
  63. data/lib/w3c_api/models/specifications.rb +0 -17
  64. data/lib/w3c_api/models/users.rb +0 -44
@@ -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,13 @@
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 :spec_versions, key: 'version-history', realize_class: 'SpecVersion', collection: true
9
+ hal_link :predecessor_version, key: 'predecessor-version', realize_class: 'SpecVersionIndex', collection: true
10
+ hal_link :successor_version, key: 'successor-version', realize_class: 'SpecVersionIndex', collection: true
11
+ end
12
+ end
13
+ 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
@@ -1,79 +1,67 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'base'
4
- require_relative 'link'
5
-
3
+ # https://api.w3.org/specifications/html5
6
4
  # {
7
- # "shortlink"=>"https://www.w3.org/TR/PNG/",
8
- # "description"=>"<p>This document describes PNG (Portable Network Graphics), an extensible file format for the lossless, portable, well-compressed storage of raster images. PNG provides a patent-free replacement for GIF and can also replace many common uses of TIFF. Indexed-color, grayscale, and truecolor images are supported, plus an optional alpha channel. Sample depths range from 1 to 16 bits.</p>\r\n<p>PNG is designed to work well in online viewing applications, such as the World Wide Web, so it is fully streamable with a progressive display option. PNG is robust, providing both full file integrity checking and simple detection of common transmission errors. Also, PNG can store gamma and chromaticity data for improved color matching on heterogeneous platforms.</p>\r\n<p>This specification defines an Internet Media Type image/png.</p>",
9
- # "title"=>"Portable Network Graphics (PNG) Specification (Second Edition)",
10
- # "shortname"=>"png-2",
11
- # "editor-draft"=>"https://w3c.github.io/png/",
12
- # "_links"=>{
13
- # "self"=>{
14
- # "href"=>"https://api.w3.org/specifications/png-2"
15
- # },
16
- # "version-history"=>{
17
- # "href"=>"https://api.w3.org/specifications/png-2/versions"
18
- # },
19
- # "first-version"=>{
20
- # "href"=>"https://api.w3.org/specifications/png-2/versions/20030520",
21
- # "title"=>"Proposed Recommendation"
22
- # },
23
- # "latest-version"=>{
24
- # "href"=>"https://api.w3.org/specifications/png-2/versions/20031110",
25
- # "title"=>"Recommendation"
26
- # },
27
- # "series"=>{
28
- # "href"=>"https://api.w3.org/specification-series/png"
5
+ # "shortlink": "https://www.w3.org/TR/html5/",
6
+ # "description": "<p>This specification defines the 5th major revision of the core language of the World Wide Web: the Hypertext Markup Language (HTML). In this version, new features are introduced to help Web application authors, new elements are introduced based on research into prevailing authoring practices, and special attention has been given to defining clear conformance criteria for user agents in an effort to improve interoperability.</p>",
7
+ # "title": "HTML5",
8
+ # "shortname": "html5",
9
+ # "series-version": "5",
10
+ # "_links": {
11
+ # "self": {
12
+ # "href": "https://api.w3.org/specifications/html5"
13
+ # },
14
+ # "version-history": {
15
+ # "href": "https://api.w3.org/specifications/html5/versions"
16
+ # },
17
+ # "first-version": {
18
+ # "href": "https://api.w3.org/specifications/html5/versions/20080122",
19
+ # "title": "Working Draft"
20
+ # },
21
+ # "latest-version": {
22
+ # "href": "https://api.w3.org/specifications/html5/versions/20180327",
23
+ # "title": "Retired"
24
+ # },
25
+ # "supersedes": {
26
+ # "href": "https://api.w3.org/specifications/html5/supersedes"
27
+ # },
28
+ # "series": {
29
+ # "href": "https://api.w3.org/specification-series/html"
30
+ # }
29
31
  # }
30
- # }
31
32
  # }
32
33
 
33
34
  module W3cApi
34
- module Models
35
- class SpecificationLinks < Lutaml::Model::Serializable
36
- attribute :self, Link
37
- attribute :version_history, Link
38
- attribute :first_version, Link
39
- attribute :latest_version, Link
40
- attribute :series, Link
41
- end
42
-
43
- class Specification < Base
44
- attribute :shortlink, :string
45
- attribute :description, :string
46
- attribute :title, :string
47
- attribute :href, :string
48
- attribute :shortname, :string
49
- attribute :editor_draft, :string
50
- attribute :series_version, :string
51
- attribute :_links, SpecificationLinks
52
-
53
- # Return versions of this specification
54
- def versions(client = nil)
55
- return nil unless client && shortname
56
-
57
- client.specification_versions(shortname)
58
- end
35
+ module Models
36
+ class Specification < Lutaml::Hal::Resource
37
+ attribute :shortlink, :string
38
+ attribute :description, :string
39
+ attribute :title, :string
40
+ attribute :href, :string
41
+ attribute :shortname, :string
42
+ attribute :editor_draft, :string
43
+ attribute :series_version, :string
59
44
 
60
- def self.from_response(response)
61
- transformed_response = transform_keys(response)
45
+ hal_link :self, key: 'self', realize_class: 'Specification'
46
+ hal_link :version_history, key: 'version-history', realize_class: 'SpecVersionIndex'
47
+ hal_link :first_version, key: 'first-version', realize_class: 'SpecVersion'
48
+ hal_link :latest_version, key: 'latest-version', realize_class: 'SpecVersion'
49
+ hal_link :supersedes, key: 'supersedes', realize_class: 'SpecificationIndex', collection: true
50
+ hal_link :series, key: 'series', realize_class: 'Serie'
62
51
 
63
- spec = new
64
- transformed_response.each do |key, value|
65
- case key
66
- when :_links
67
- links = value.each_with_object({}) do |(link_name, link_data), acc|
68
- acc[link_name] = Link.new(href: link_data[:href], title: link_data[:title])
69
- end
70
- spec._links = SpecificationLinks.new(links)
71
- else
72
- spec.send("#{key}=", value) if spec.respond_to?("#{key}=")
73
- end
74
- end
75
- spec
52
+ key_value do
53
+ %i[
54
+ shortlink
55
+ description
56
+ title
57
+ href
58
+ shortname
59
+ editor_draft
60
+ series_version
61
+ ].each do |key|
62
+ map key.to_s.tr('_', '-'), to: key
76
63
  end
77
64
  end
78
65
  end
66
+ end
79
67
  end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module W3cApi
4
+ module Models
5
+ # SpecificationIndex class that models `/specifications`
6
+ class SpecificationIndex < Lutaml::Hal::Page
7
+ hal_link :specifications, key: 'specifications', realize_class: 'Specification', collection: true
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'user'
4
+
5
+ module W3cApi
6
+ module Models
7
+ class TeamContactIndex < Lutaml::Hal::Page
8
+ hal_link :team_contacts, key: 'team-contacts', realize_class: 'User', collection: true
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ require 'lutaml/hal'
2
+
3
+ # "testimonials": {
4
+ # "en": "Google's mission is to organize the world’s information and make it universally accessible and useful."
5
+ # },
6
+
7
+ module W3cApi
8
+ module Models
9
+ class Testimonial < Lutaml::Hal::Resource
10
+ attribute :en, :string
11
+
12
+ key_value do
13
+ map 'en', to: :en
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'base'
4
- require_relative 'call_for_translation_ref'
5
- require_relative 'link'
3
+ require_relative 'call_for_translation'
6
4
  require_relative 'user'
7
5
 
8
6
  # {
@@ -85,78 +83,41 @@ require_relative 'user'
85
83
  # }
86
84
 
87
85
  module W3cApi
88
- module Models
89
- class TranslationLinks < Lutaml::Model::Serializable
90
- attribute :self, Link
91
- end
92
-
93
- class Translation < Base
94
- attribute :uri, :string
95
- attribute :title, :string
96
- attribute :href, :string
97
- attribute :language, :string
98
- attribute :published, :string # Date-time format
99
- attribute :updated, :string # Date-time format
100
- attribute :authorized, :boolean
101
- attribute :lto_name, :string
102
- attribute :call_for_translation, CallForTranslationRef
103
- attribute :comments, :string
104
- attribute :states, :string, collection: true
105
- attribute :translators, User, collection: true
106
- attribute :_links, TranslationLinks
107
-
108
- # Parse date strings to Date objects
109
- def published_date
110
- Date.parse(published) if published
111
- rescue Date::Error
112
- nil
113
- end
114
-
115
- def updated_date
116
- Date.parse(updated) if updated
117
- rescue Date::Error
118
- nil
119
- end
120
-
121
- # Get the call for translation as a CallForTranslation object
122
- def call_for_translation_object
123
- return nil unless call_for_translation
124
-
125
- Models::CallForTranslation.new(call_for_translation)
126
- end
127
-
128
- # Get the specification version associated with this translation
129
- def specification_version(client = nil)
130
- return nil unless call_for_translation&.spec_version
131
-
132
- call_for_translation.spec_version
133
- end
86
+ module Models
87
+ class Translation < Lutaml::Hal::Resource
88
+ attribute :uri, :string
89
+ attribute :title, :string
90
+ attribute :href, :string
91
+ attribute :language, :string
92
+ attribute :published, :date_time
93
+ attribute :updated, :date_time
94
+ attribute :authorized, :boolean
95
+ attribute :lto_name, :string
96
+ attribute :call_for_translation, CallForTranslation
97
+ attribute :comments, :string
98
+ attribute :states, :string, collection: true
99
+ attribute :translators, User, collection: true
134
100
 
135
- def self.from_response(response)
136
- transformed_response = transform_keys(response)
101
+ hal_link :self, key: 'self', realize_class: 'Translation'
137
102
 
138
- translation = new
139
- transformed_response.each do |key, value|
140
- case key
141
- when :_links
142
- links = value.each_with_object({}) do |(link_name, link_data), acc|
143
- acc[link_name] = Link.new(href: link_data[:href], title: link_data[:title])
144
- end
145
- translation._links = TranslationLinks.new(links)
146
- when :call_for_translation
147
- translation.call_for_translation = CallForTranslationRef.new(value)
148
- when :translators
149
- # Handle translators as User objects if present
150
- if value.is_a?(Array)
151
- users = value.map { |user_data| User.from_response(user_data) }
152
- translation.translators = users
153
- end
154
- else
155
- translation.send("#{key}=", value) if translation.respond_to?("#{key}=")
156
- end
157
- end
158
- translation
103
+ key_value do
104
+ %i[
105
+ uri
106
+ title
107
+ href
108
+ language
109
+ published
110
+ updated
111
+ authorized
112
+ lto_name
113
+ call_for_translation
114
+ comments
115
+ states
116
+ translators
117
+ ].each do |key|
118
+ map key.to_s.tr('_', '-'), to: key
159
119
  end
160
120
  end
161
121
  end
122
+ end
162
123
  end