Class: W3cApi::Hal

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/w3c_api/hal.rb

Constant Summary collapse

API_URL =
"https://api.w3.org/"

Instance Method Summary collapse

Constructor Details

#initializeHal

Returns a new instance of Hal.



46
47
48
# File 'lib/w3c_api/hal.rb', line 46

def initialize
  # Don't call setup here - it will be called when register is first accessed
end

Instance Method Details

#clientObject



50
51
52
53
54
55
# File 'lib/w3c_api/hal.rb', line 50

def client
  @client ||= Lutaml::Hal::Client.new(
    api_url: API_URL,
    rate_limiting: rate_limiting_options,
  )
end

#configure_rate_limiting(options = {}) ⇒ Object

Set rate limiting options



69
70
71
72
73
# File 'lib/w3c_api/hal.rb', line 69

def configure_rate_limiting(options = {})
  @rate_limiting_options = rate_limiting_options.merge(options)
  # Reset client to pick up new options
  @client = nil
end

#disable_rate_limitingObject

Disable rate limiting



76
77
78
# File 'lib/w3c_api/hal.rb', line 76

def disable_rate_limiting
  configure_rate_limiting(enabled: false)
end

#enable_rate_limitingObject

Enable rate limiting



81
82
83
# File 'lib/w3c_api/hal.rb', line 81

def enable_rate_limiting
  configure_rate_limiting(enabled: true)
end

#rate_limiting_optionsObject

Configure rate limiting options



58
59
60
61
62
63
64
65
66
# File 'lib/w3c_api/hal.rb', line 58

def rate_limiting_options
  @rate_limiting_options ||= {
    enabled: true,
    max_retries: 5,
    base_delay: 0.1,
    max_delay: 10.0,
    backoff_factor: 1.5,
  }
end

#registerObject



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/w3c_api/hal.rb', line 85

def register
  return @register if @register

  @register = Lutaml::Hal::ModelRegister.new(name: :w3c_api, client: client)
  Lutaml::Hal::GlobalRegister.instance.register(:w3c_api, @register)

  # Re-run setup to register all endpoints with the new register
  setup

  @register
end

#reset_registerObject



97
98
99
# File 'lib/w3c_api/hal.rb', line 97

def reset_register
  @register = nil
end