w3c_api 0.1.2 → 0.1.4

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.
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require_relative 'lib/w3c_api'
6
+
7
+ puts 'Testing W3C API Embed Functionality'
8
+ puts '=' * 40
9
+
10
+ # Initialize the client
11
+ client = W3cApi::Client.new
12
+
13
+ begin
14
+ puts "\n1. Testing Groups endpoint with embed..."
15
+ groups_with_embed = client.groups(embed: true, items: 5)
16
+
17
+ puts " Response type: #{groups_with_embed.class}"
18
+ puts " Has embedded content: #{groups_with_embed.respond_to?(:has_embedded?) && groups_with_embed.has_embedded?('groups')}"
19
+
20
+ if groups_with_embed.respond_to?(:has_embedded?) && groups_with_embed.has_embedded?('groups')
21
+ puts " Available methods: #{groups_with_embed.methods.grep(/embed/).join(', ')}"
22
+
23
+ embedded_groups = groups_with_embed.get_embedded('groups')
24
+ puts " Number of embedded groups: #{embedded_groups.length}"
25
+ puts " First embedded group: #{embedded_groups.first['name'] if embedded_groups.first}"
26
+ end
27
+
28
+ puts "\n2. Testing Specifications endpoint with embed..."
29
+ specs_with_embed = client.specifications(embed: true, items: 5)
30
+
31
+ puts " Response type: #{specs_with_embed.class}"
32
+ puts " Has embedded content: #{specs_with_embed.respond_to?(:has_embedded?) && specs_with_embed.has_embedded?('specifications')}"
33
+
34
+ if specs_with_embed.respond_to?(:has_embedded?) && specs_with_embed.has_embedded?('specifications')
35
+ puts " Available methods: #{specs_with_embed.methods.grep(/embed/).join(', ')}"
36
+
37
+ embedded_specs = specs_with_embed.get_embedded('specifications')
38
+ puts " Number of embedded specifications: #{embedded_specs.length}"
39
+ puts " First embedded spec: #{embedded_specs.first['title'] if embedded_specs.first}"
40
+ end
41
+
42
+ puts "\n3. Testing comparison: with vs without embed..."
43
+
44
+ # Without embed
45
+ start_time = Time.now
46
+ client.groups(items: 3)
47
+ without_embed_time = Time.now - start_time
48
+ puts " Without embed: #{without_embed_time.round(3)}s"
49
+
50
+ # With embed
51
+ start_time = Time.now
52
+ groups_with_embed = client.groups(embed: true, items: 3)
53
+ with_embed_time = Time.now - start_time
54
+ puts " With embed: #{with_embed_time.round(3)}s"
55
+
56
+ if groups_with_embed.respond_to?(:has_embedded?) && groups_with_embed.has_embedded?('groups')
57
+ puts ' ✓ Embed functionality working correctly!'
58
+ else
59
+ puts ' ⚠ Embed parameter accepted but no embedded content returned'
60
+ end
61
+
62
+ puts "\n4. Testing link realization with embedded content..."
63
+
64
+ if groups_with_embed.respond_to?(:links) && groups_with_embed.links.respond_to?(:groups)
65
+ first_group_link = groups_with_embed.links.groups.first
66
+ if first_group_link
67
+ puts " First group link: #{first_group_link.href}"
68
+
69
+ # Test realization with parent_resource (should use embedded data)
70
+ if first_group_link.respond_to?(:realize)
71
+ begin
72
+ realized_group = first_group_link.realize(parent_resource: groups_with_embed)
73
+ puts ' ✓ Link realization with embedded data successful'
74
+ puts " Realized group name: #{realized_group.name if realized_group.respond_to?(:name)}"
75
+ rescue StandardError => e
76
+ puts " ⚠ Link realization failed: #{e.message}"
77
+ end
78
+ end
79
+ end
80
+ end
81
+
82
+ puts "\n✅ Embed functionality test completed successfully!"
83
+ rescue StandardError => e
84
+ puts "\n❌ Error during testing: #{e.message}"
85
+ puts 'Backtrace:'
86
+ puts e.backtrace.first(5).join("\n")
87
+ end
data/lib/w3c_api/cli.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'thor'
4
4
  require_relative 'commands/specification'
5
+ require_relative 'commands/specification_version'
5
6
  require_relative 'commands/group'
6
7
  require_relative 'commands/user'
7
8
  require_relative 'commands/translation'
@@ -17,6 +18,9 @@ module W3cApi
17
18
  desc 'specification SUBCOMMAND ...ARGS', 'Work with W3C specifications'
18
19
  subcommand 'specification', Commands::Specification
19
20
 
21
+ desc 'specification_version SUBCOMMAND ...ARGS', 'Work with W3C specification versions'
22
+ subcommand 'specification_version', Commands::SpecificationVersion
23
+
20
24
  desc 'group SUBCOMMAND ...ARGS', 'Work with W3C groups'
21
25
  subcommand 'group', Commands::Group
22
26
 
@@ -7,8 +7,30 @@ require_relative 'hal'
7
7
 
8
8
  module W3cApi
9
9
  class Client
10
+ # Class method to list endpoints that support embed parameter
11
+ def self.embed_supported_endpoints
12
+ hal_instance = W3cApi::Hal.instance
13
+ endpoints_with_embed = []
14
+
15
+ hal_instance.register.models.each do |endpoint_id, endpoint_config|
16
+ # Check if this endpoint has embed parameter support
17
+ has_embed = endpoint_config[:parameters].any? do |param|
18
+ param.name == 'embed' && param.location == :query
19
+ end
20
+
21
+ endpoints_with_embed << endpoint_id if has_embed
22
+ end
23
+
24
+ endpoints_with_embed.sort
25
+ end
26
+
27
+ # Instance method to check if a specific endpoint supports embed
28
+ def embed_supported?(endpoint_id)
29
+ self.class.embed_supported_endpoints.include?(endpoint_id)
30
+ end
31
+
10
32
  # Specification methods
11
- def specifications(options = nil)
33
+ def specifications(options = {})
12
34
  fetch_resource(:specification_index, **(options || {}))
13
35
  end
14
36
 
@@ -22,8 +44,12 @@ module W3cApi
22
44
  end
23
45
 
24
46
  def specification_version(shortname, version, options = {})
25
- fetch_resource(:specification_resource_version_resource,
26
- shortname: shortname, version: version, **options)
47
+ fetch_resource(
48
+ :specification_resource_version_resource,
49
+ shortname: shortname,
50
+ version: version,
51
+ **options
52
+ )
27
53
  end
28
54
 
29
55
  def specifications_by_status(status, options = {})
@@ -37,6 +63,16 @@ module W3cApi
37
63
  end
38
64
  end
39
65
 
66
+ def specification_version_editors(shortname, version, options = {})
67
+ fetch_resource(:specification_version_editors_index,
68
+ shortname: shortname, version: version, **options)
69
+ end
70
+
71
+ def specification_version_deliverers(shortname, version, options = {})
72
+ fetch_resource(:specification_version_deliverers_index,
73
+ shortname: shortname, version: version, **options)
74
+ end
75
+
40
76
  # Series methods
41
77
  def series(options = {})
42
78
  fetch_resource(:serie_index, **options)
@@ -51,6 +87,11 @@ module W3cApi
51
87
  shortname: shortname, **options)
52
88
  end
53
89
 
90
+ def series_current_specification(shortname, options = {})
91
+ fetch_resource(:serie_current_specification_resource,
92
+ shortname: shortname, **options)
93
+ end
94
+
54
95
  # Group methods
55
96
  def groups(options = {})
56
97
  fetch_resource(:group_index, **options)
@@ -107,8 +148,8 @@ module W3cApi
107
148
  fetch_resource(:ecosystem_index, **options)
108
149
  end
109
150
 
110
- def ecosystem(id, options = {})
111
- fetch_resource(:ecosystem_resource, id: id, **options)
151
+ def ecosystem(shortname, options = {})
152
+ fetch_resource(:ecosystem_resource, shortname: shortname, **options)
112
153
  end
113
154
 
114
155
  %w[groups evangelists member_organizations].each do |resource|
@@ -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
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module W3cApi
4
+ # Module for discovering and working with embed-supported endpoints
5
+ module Embed
6
+ class << self
7
+ # Get list of endpoints that support embed parameter
8
+ def supported_endpoints
9
+ W3cApi::Client.embed_supported_endpoints
10
+ end
11
+
12
+ # Check if a specific endpoint supports embed
13
+ def supports_embed?(endpoint_id)
14
+ supported_endpoints.include?(endpoint_id.to_sym)
15
+ end
16
+
17
+ # Get human-readable descriptions of embed-supported endpoints
18
+ def endpoint_descriptions
19
+ {
20
+ specification_index: 'Specifications index with embedded specification details',
21
+ group_index: 'Groups index with embedded group details',
22
+ serie_index: 'Series index with embedded series details'
23
+ }
24
+ end
25
+
26
+ # Get comprehensive embed information
27
+ def embed_info
28
+ {
29
+ supported_endpoints: supported_endpoints,
30
+ descriptions: endpoint_descriptions,
31
+ usage_example: {
32
+ discovery: 'W3cApi::Client.embed_supported_endpoints',
33
+ usage: 'W3cApi::Client.new.specifications(embed: true, items: 2)',
34
+ automatic_realization: 'spec_link.realize # Uses embedded content automatically'
35
+ }
36
+ }
37
+ end
38
+ end
39
+ end
40
+ end