w3c_api 0.1.3 → 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.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +22 -13
- data/README.adoc +246 -827
- data/demo/test_embed_functionality.rb +87 -0
- data/lib/w3c_api/client.rb +23 -1
- data/lib/w3c_api/embed.rb +40 -0
- data/lib/w3c_api/hal.rb +290 -115
- data/lib/w3c_api/models.rb +37 -37
- data/lib/w3c_api/version.rb +1 -1
- data/lib/w3c_api.rb +1 -0
- metadata +6 -18
@@ -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/client.rb
CHANGED
@@ -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 =
|
33
|
+
def specifications(options = {})
|
12
34
|
fetch_resource(:specification_index, **(options || {}))
|
13
35
|
end
|
14
36
|
|
@@ -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
|