-
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathstrategies.rb
More file actions
46 lines (42 loc) · 1.48 KB
/
strategies.rb
File metadata and controls
46 lines (42 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# frozen_string_literal: true
module Html2rss
module Web
module Api
module V1
##
# Strategy metadata endpoints for API v1.
#
# Exposes only lightweight strategy metadata so clients can render
# choices without coupling to backend strategy internals.
module Strategies
class << self
# @param _request [Rack::Request]
# @return [Hash{Symbol=>Object}] response with strategy list.
# @option return [Hash] :data strategies payload.
# @option return [Array<Hash>] :strategies available strategy metadata.
# @option return [Hash] :meta list metadata.
# @option return [Integer] :total number of strategies.
def index(_request)
strategies = Html2rss::RequestService.strategy_names.map do |name|
{
id: name.to_s,
name: name.to_s,
display_name: display_name_for(name)
}
end
Response.success(data: { strategies: strategies }, meta: { total: strategies.count })
end
private
def display_name_for(name)
case name.to_s
when 'faraday' then 'Default'
when 'browserless' then 'JavaScript pages (recommended)'
else name.to_s.split('_').map(&:capitalize).join(' ')
end
end
end
end
end
end
end
end