w3c_api 0.1.1 → 0.1.3

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.
@@ -7,185 +7,153 @@ require_relative 'hal'
7
7
 
8
8
  module W3cApi
9
9
  class Client
10
- def specifications(options = {})
11
- Hal.instance.register.fetch(:specification_index)
10
+ # Specification methods
11
+ def specifications(options = nil)
12
+ fetch_resource(:specification_index, **(options || {}))
12
13
  end
13
14
 
14
15
  def specification(shortname, options = {})
15
- Hal.instance.register.fetch(:specification_resource, shortname: shortname)
16
+ fetch_resource(:specification_resource, shortname: shortname, **options)
16
17
  end
17
18
 
18
19
  def specification_versions(shortname, options = {})
19
- Hal.instance.register.fetch(:specification_resource_version_index, shortname: shortname)
20
+ fetch_resource(:specification_resource_version_index,
21
+ shortname: shortname, **options)
20
22
  end
21
23
 
22
24
  def specification_version(shortname, version, options = {})
23
- Hal.instance.register.fetch(:specification_resource_version_resource, shortname: shortname, version: version)
25
+ fetch_resource(
26
+ :specification_resource_version_resource,
27
+ shortname: shortname,
28
+ version: version,
29
+ **options
30
+ )
24
31
  end
25
32
 
26
33
  def specifications_by_status(status, options = {})
27
- Hal.instance.register.fetch(:specification_by_status_index, status: status)
34
+ fetch_resource(:specification_by_status_index, status: status, **options)
28
35
  end
29
36
 
30
- def specification_supersedes(shortname, options = {})
31
- Hal.instance.register.fetch(:specification_supersedes_index, shortname: shortname)
37
+ %w[supersedes superseded_by editors deliverers].each do |method_suffix|
38
+ define_method("specification_#{method_suffix}") do |shortname, options = {}|
39
+ fetch_resource(:"specification_#{method_suffix}_index",
40
+ shortname: shortname, **options)
41
+ end
32
42
  end
33
43
 
34
- def specification_superseded_by(shortname, options = {})
35
- Hal.instance.register.fetch(:specification_superseded_by_index, shortname: shortname)
44
+ def specification_version_editors(shortname, version, options = {})
45
+ fetch_resource(:specification_version_editors_index,
46
+ shortname: shortname, version: version, **options)
36
47
  end
37
48
 
38
- # New methods for editors and deliverers
39
-
40
- def specification_editors(shortname, options = {})
41
- Hal.instance.register.fetch(:specification_editors_index, shortname: shortname)
42
- end
43
-
44
- def specification_deliverers(shortname, options = {})
45
- Hal.instance.register.fetch(:specification_deliverers_index, shortname: shortname)
49
+ def specification_version_deliverers(shortname, version, options = {})
50
+ fetch_resource(:specification_version_deliverers_index,
51
+ shortname: shortname, version: version, **options)
46
52
  end
47
53
 
48
54
  # Series methods
49
-
50
55
  def series(options = {})
51
- Hal.instance.register.fetch(:serie_index)
56
+ fetch_resource(:serie_index, **options)
52
57
  end
53
58
 
54
59
  def series_by_shortname(shortname, options = {})
55
- Hal.instance.register.fetch(:serie_resource, shortname: shortname)
60
+ fetch_resource(:serie_resource, shortname: shortname, **options)
56
61
  end
57
62
 
58
63
  def series_specifications(shortname, options = {})
59
- Hal.instance.register.fetch(:serie_specification_resource, shortname: shortname)
64
+ fetch_resource(:serie_specification_resource,
65
+ shortname: shortname, **options)
60
66
  end
61
67
 
62
- # Group methods
68
+ def series_current_specification(shortname, options = {})
69
+ fetch_resource(:serie_current_specification_resource,
70
+ shortname: shortname, **options)
71
+ end
63
72
 
73
+ # Group methods
64
74
  def groups(options = {})
65
- Hal.instance.register.fetch(:group_index)
75
+ fetch_resource(:group_index, **options)
66
76
  end
67
77
 
68
78
  def group(id, options = {})
69
- Hal.instance.register.fetch(:group_resource, id: id)
70
- end
71
-
72
- def group_specifications(id, options = {})
73
- Hal.instance.register.fetch(:group_specifications_index, id: id)
74
- end
75
-
76
- def group_users(id, options = {})
77
- Hal.instance.register.fetch(:group_users_index, id: id)
79
+ fetch_resource(:group_resource, id: id, **options)
78
80
  end
79
81
 
80
- def group_charters(id, options = {})
81
- Hal.instance.register.fetch(:group_charters_index, id: id)
82
- end
83
-
84
- def group_chairs(id, options = {})
85
- Hal.instance.register.fetch(:group_chairs_index, id: id)
86
- end
87
-
88
- def group_team_contacts(id, options = {})
89
- Hal.instance.register.fetch(:group_team_contacts_index, id: id)
90
- end
91
-
92
- def group_participations(id, options = {})
93
- Hal.instance.register.fetch(:group_participations_index, id: id)
82
+ %w[specifications users charters chairs team_contacts participations].each do |resource|
83
+ define_method("group_#{resource}") do |id, options = {}|
84
+ fetch_resource(:"group_#{resource}_index", id: id, **options)
85
+ end
94
86
  end
95
87
 
96
88
  # User methods
97
-
98
- # def users(options = {})
99
- # raise ArgumentError,
100
- # 'The W3C API does not support fetching all users. You must provide a specific user ID with the user method.'
101
- # end
102
-
103
89
  def user(hash, options = {})
104
- Hal.instance.register.fetch(:user_resource, hash: hash)
105
- end
106
-
107
- def user_groups(hash, options = {})
108
- Hal.instance.register.fetch(:user_groups_index, hash: hash)
90
+ fetch_resource(:user_resource, hash: hash, **options)
109
91
  end
110
92
 
111
- def user_affiliations(hash, options = {})
112
- Hal.instance.register.fetch(:user_affiliations_index, hash: hash)
113
- end
114
-
115
- def user_participations(hash, options = {})
116
- Hal.instance.register.fetch(:user_participations_index, hash: hash)
117
- end
118
-
119
- def user_chair_of_groups(hash, options = {})
120
- Hal.instance.register.fetch(:user_chair_of_groups_index, hash: hash)
121
- end
122
-
123
- def user_team_contact_of_groups(hash, options = {})
124
- Hal.instance.register.fetch(:user_team_contact_of_groups_index, hash: hash)
125
- end
126
-
127
- def user_specifications(hash, options = {})
128
- Hal.instance.register.fetch(:user_specifications_index, hash: hash)
93
+ %w[groups affiliations participations chair_of_groups
94
+ team_contact_of_groups specifications].each do |resource|
95
+ define_method("user_#{resource}") do |hash, options = {}|
96
+ fetch_resource(:"user_#{resource}_index", hash: hash, **options)
97
+ end
129
98
  end
130
99
 
131
100
  # Translation methods
132
-
133
101
  def translations(options = {})
134
- Hal.instance.register.fetch(:translation_index)
102
+ fetch_resource(:translation_index, **options)
135
103
  end
136
104
 
137
105
  def translation(id, options = {})
138
- Hal.instance.register.fetch(:translation_resource, id: id)
106
+ fetch_resource(:translation_resource, id: id, **options)
139
107
  end
140
108
 
141
109
  # Affiliation methods
142
-
143
110
  def affiliations(options = {})
144
- Hal.instance.register.fetch(:affiliation_index)
111
+ fetch_resource(:affiliation_index, **options)
145
112
  end
146
113
 
147
114
  def affiliation(id, options = {})
148
- Hal.instance.register.fetch(:affiliation_resource, id: id)
115
+ fetch_resource(:affiliation_resource, id: id, **options)
149
116
  end
150
117
 
151
- def affiliation_participants(id, options = {})
152
- Hal.instance.register.fetch(:affiliation_participants_index, id: id)
153
- end
154
-
155
- def affiliation_participations(id, options = {})
156
- Hal.instance.register.fetch(:affiliation_participations_index, id: id)
118
+ %w[participants participations].each do |resource|
119
+ define_method("affiliation_#{resource}") do |id, options = {}|
120
+ fetch_resource(:"affiliation_#{resource}_index", id: id, **options)
121
+ end
157
122
  end
158
123
 
159
124
  # Ecosystem methods
160
-
161
125
  def ecosystems(options = {})
162
- Hal.instance.register.fetch(:ecosystem_index)
163
- end
164
-
165
- def ecosystem(id, options = {})
166
- Hal.instance.register.fetch(:ecosystem_resource, id: id)
167
- end
168
-
169
- def ecosystem_groups(shortname, options = {})
170
- Hal.instance.register.fetch(:ecosystem_groups_index, shortname: shortname)
126
+ fetch_resource(:ecosystem_index, **options)
171
127
  end
172
128
 
173
- def ecosystem_evangelists(shortname, options = {})
174
- Hal.instance.register.fetch(:ecosystem_evangelists_index, shortname: shortname)
129
+ def ecosystem(shortname, options = {})
130
+ fetch_resource(:ecosystem_resource, shortname: shortname, **options)
175
131
  end
176
132
 
177
- def ecosystem_member_organizations(shortname, options = {})
178
- Hal.instance.register.fetch(:ecosystem_member_organizations_index, shortname: shortname)
133
+ %w[groups evangelists member_organizations].each do |resource|
134
+ define_method("ecosystem_#{resource}") do |shortname, options = {}|
135
+ fetch_resource(:"ecosystem_#{resource}_index",
136
+ shortname: shortname, **options)
137
+ end
179
138
  end
180
139
 
181
140
  # Participation methods
182
-
183
141
  def participation(id, options = {})
184
- Hal.instance.register.fetch(:participation_resource, id: id)
142
+ fetch_resource(:participation_resource, id: id, **options)
185
143
  end
186
144
 
187
145
  def participation_participants(id, options = {})
188
- Hal.instance.register.fetch(:participation_participants_index, id: id)
146
+ fetch_resource(:participation_participants_index, id: id, **options)
147
+ end
148
+
149
+ private
150
+
151
+ def fetch_resource(resource_key, **params)
152
+ if params.any?
153
+ Hal.instance.register.fetch(resource_key, **params)
154
+ else
155
+ Hal.instance.register.fetch(resource_key)
156
+ end
189
157
  end
190
158
  end
191
159
  end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'thor'
4
+ require_relative 'output_formatter'
5
+
6
+ module W3cApi
7
+ module Commands
8
+ class SpecificationVersion < Thor
9
+ include OutputFormatter
10
+
11
+ desc 'editors', 'Fetch editors of a specification version'
12
+ option :shortname, type: :string, required: true, desc: 'Specification shortname'
13
+ option :version, type: :string, required: true, desc: 'Specification version'
14
+ option :format, type: :string, default: 'yaml', enum: %w[json yaml], desc: 'Output format'
15
+ def editors
16
+ client = W3cApi::Client.new
17
+ result = client.specification_version_editors(options[:shortname], options[:version])
18
+ output_results(result, options[:format])
19
+ rescue StandardError => e
20
+ puts "Error: #{e.message}"
21
+ exit 1
22
+ end
23
+
24
+ desc 'deliverers', 'Fetch deliverers (working groups) of a specification version'
25
+ option :shortname, type: :string, required: true, desc: 'Specification shortname'
26
+ option :version, type: :string, required: true, desc: 'Specification version'
27
+ option :format, type: :string, default: 'yaml', enum: %w[json yaml], desc: 'Output format'
28
+ def deliverers
29
+ client = W3cApi::Client.new
30
+ result = client.specification_version_deliverers(options[:shortname], options[:version])
31
+ output_results(result, options[:format])
32
+ rescue StandardError => e
33
+ puts "Error: #{e.message}"
34
+ exit 1
35
+ end
36
+ end
37
+ end
38
+ end