Skip to content

Commit f3c0f45

Browse files
committed
happy-ier linters
1 parent dd78503 commit f3c0f45

File tree

10 files changed

+421
-1638
lines changed

10 files changed

+421
-1638
lines changed

.rubocop.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ require:
77
AllCops:
88
DisplayCopNames: true
99
NewCops: enable
10+
Exclude:
11+
- '**/*.yml'
12+
- '**/*.yaml'
13+
- '**/.tool-versions'
1014

1115
Metrics/BlockLength:
1216
Exclude:
1317
- Rakefile
14-
ExcludedMethods:
18+
AllowedMethods:
1519
- route
1620

1721
Naming/RescuedExceptionsVariableName:

app/api/v1/feeds.rb

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -131,19 +131,25 @@ def default_strategy
131131
def feed_response_payload(feed_data)
132132
{
133133
success: true,
134-
data: { feed: {
135-
id: feed_data[:id],
136-
name: feed_data[:name],
137-
url: feed_data[:url],
138-
strategy: feed_data[:strategy],
139-
public_url: feed_data[:public_url],
140-
created_at: Time.now.iso8601,
141-
updated_at: Time.now.iso8601
142-
} },
134+
data: { feed: feed_attributes(feed_data) },
143135
meta: { created: true }
144136
}
145137
end
146138

139+
def feed_attributes(feed_data)
140+
timestamp = Time.now.iso8601
141+
142+
{
143+
id: feed_data[:id],
144+
name: feed_data[:name],
145+
url: feed_data[:url],
146+
strategy: feed_data[:strategy],
147+
public_url: feed_data[:public_url],
148+
created_at: timestamp,
149+
updated_at: timestamp
150+
}
151+
end
152+
147153
def extract_site_title(url)
148154
Html2rss::Url.for_channel(url).channel_titleized
149155
rescue StandardError
@@ -152,10 +158,10 @@ def extract_site_title(url)
152158

153159
module_function :extract_create_params, :validate_create_params, :build_create_response,
154160
:authenticate_request, :select_strategy, :supported_strategies, :default_strategy,
155-
:feed_response_payload, :extract_site_title
161+
:feed_response_payload, :feed_attributes, :extract_site_title
156162
private_class_method :extract_create_params, :validate_create_params, :build_create_response,
157163
:authenticate_request, :select_strategy, :supported_strategies, :default_strategy,
158-
:feed_response_payload, :extract_site_title
164+
:feed_response_payload, :feed_attributes, :extract_site_title
159165
end
160166
end
161167
end

app/api/v1/health.rb

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,23 @@ def show(request)
2020
authorize_health_check!(request)
2121
verify_configuration!
2222

23+
health_response
24+
end
25+
26+
def health_response
2327
{
2428
success: true,
25-
data: {
26-
health: {
27-
status: 'healthy',
28-
timestamp: Time.now.iso8601,
29-
environment: ENV.fetch('RACK_ENV', 'development'),
30-
uptime: Process.clock_gettime(Process::CLOCK_MONOTONIC),
31-
checks: {}
32-
}
33-
}
29+
data: { health: health_payload }
30+
}
31+
end
32+
33+
def health_payload
34+
{
35+
status: 'healthy',
36+
timestamp: Time.now.iso8601,
37+
environment: ENV.fetch('RACK_ENV', 'development'),
38+
uptime: Process.clock_gettime(Process::CLOCK_MONOTONIC),
39+
checks: {}
3440
}
3541
end
3642

app/auto_source.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ def create_stable_feed(name, url, token_data, strategy = 'ssrf_filter')
2929
feed_token = Auth.generate_feed_token(token_data[:username], url)
3030
return nil unless feed_token
3131

32-
build_feed_data(name, url, token_data, strategy, feed_id, feed_token)
32+
identifiers = { feed_id: feed_id, feed_token: feed_token }
33+
34+
build_feed_data(name, url, token_data, strategy, identifiers)
3335
end
3436

3537
# @param token_data [Hash]
@@ -60,11 +62,11 @@ def generate_feed_content(url, strategy = 'ssrf_filter')
6062
FeedGenerator.process_feed_content(url, strategy, feed_content)
6163
end
6264

63-
def build_feed_data(name, url, token_data, strategy, feed_id, feed_token)
64-
public_url = "/api/v1/feeds/#{feed_token}"
65+
def build_feed_data(name, url, token_data, strategy, identifiers)
66+
public_url = "/api/v1/feeds/#{identifiers[:feed_token]}"
6567

6668
{
67-
id: feed_id,
69+
id: identifiers[:feed_id],
6870
name: name,
6971
url: url,
7072
username: token_data[:username],

app/xml_builder.rb

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ def build_error_feed(message:, title: 'Error')
5454
# Build an access denied RSS feed
5555
# @param url [String] The denied URL
5656
# @return [String] Valid RSS XML
57-
# rubocop:disable Metrics/MethodLength
5857
def build_access_denied_feed(url)
5958
title = 'Access Denied'
6059
description = 'This URL is not allowed for public auto source generation.'
@@ -71,46 +70,49 @@ def build_access_denied_feed(url)
7170
]
7271
)
7372
end
74-
# rubocop:enable Metrics/MethodLength
7573

7674
##
7775
# Build an empty feed warning RSS
7876
# @param url [String] The URL that failed to extract content
7977
# @param strategy [String] The strategy that was used
8078
# @param site_title [String, nil] Extracted site title
8179
# @return [String] Valid RSS XML
82-
# rubocop:disable Metrics/MethodLength
8380
def build_empty_feed_warning(url:, strategy:, site_title: nil)
8481
display_title = site_title ? "#{site_title} - Content Extraction Issue" : 'Content Extraction Issue'
85-
description = <<~DESC
86-
Unable to extract content from #{url} using #{strategy} strategy.
87-
The site may use JavaScript, have anti-bot protection, or have a
88-
structure that's difficult to parse.
89-
DESC
90-
91-
item_description = "No content could be extracted from #{url}. This could be due to:
92-
• JavaScript-heavy site (try browserless strategy)
93-
• Anti-bot protection
94-
• Complex page structure
95-
• Site blocking automated requests
96-
97-
Try a different strategy or contact the site administrator."
98-
9982
build_rss_feed(
10083
title: display_title,
101-
description: description,
84+
description: empty_feed_description(url, strategy),
10285
link: url,
10386
items: [
10487
{
10588
title: 'Content Extraction Failed',
106-
description: item_description,
89+
description: empty_feed_item_description(url),
10790
link: url,
10891
pubDate: Time.now.rfc2822
10992
}
11093
]
11194
)
11295
end
113-
# rubocop:enable Metrics/MethodLength
96+
97+
def empty_feed_description(url, strategy)
98+
<<~DESC
99+
Unable to extract content from #{url} using #{strategy} strategy.
100+
The site may use JavaScript, have anti-bot protection, or have a
101+
structure that's difficult to parse.
102+
DESC
103+
end
104+
105+
def empty_feed_item_description(url)
106+
<<~DESC
107+
No content could be extracted from #{url}. This could be due to:
108+
• JavaScript-heavy site (try browserless strategy)
109+
• Anti-bot protection
110+
• Complex page structure
111+
• Site blocking automated requests
112+
113+
Try a different strategy or contact the site administrator.
114+
DESC
115+
end
114116

115117
def build_channel_content(xml, title, description, link)
116118
xml.title title.to_s

config/rack_attack.rb

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
module Html2rss
3939
module Web
40+
# Provides consistent throttled responses for Rack::Attack
4041
module RackAttackResponse
4142
module_function
4243

@@ -58,15 +59,9 @@ def api_response(retry_after)
5859
success: false,
5960
error: { code: 'TOO_MANY_REQUESTS', message: 'Too many requests. Please try again later.' }
6061
}.to_json
62+
headers = { 'Content-Type' => 'application/json', 'Retry-After' => retry_after.to_s }
6163

62-
[
63-
429,
64-
{
65-
'Content-Type' => 'application/json',
66-
'Retry-After' => retry_after.to_s
67-
},
68-
[body]
69-
]
64+
[429, headers, [body]]
7065
end
7166

7267
def text_response(retry_after)

0 commit comments

Comments
 (0)