Skip to content

Commit 9c3f9d8

Browse files
committed
start working on PTS support
1 parent a58b422 commit 9c3f9d8

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# frozen_string_literal: true
2+
3+
class Baseballbot
4+
module Templates
5+
module Components
6+
class PickTheStick
7+
BASE_URL = 'https://www.pick-the-stick.com/api/standings?api_token=%<token>s&team=%<team_code>s'
8+
9+
include MarkdownHelpers
10+
11+
def initialize(subreddit)
12+
@subreddit = subreddit
13+
end
14+
15+
def current_standings
16+
return '[](/pickthestick "Team not configured")' unless @subreddit.team&.code
17+
18+
@data = pick_the_stick_data
19+
20+
''
21+
end
22+
23+
protected
24+
25+
def pick_the_stick_data
26+
api_token = ENV.fetch('BASEBALLBOT_PTS_TOKEN', nil)
27+
28+
raise 'API token is required' unless api_token && !api_token.empty?
29+
30+
raise 'Team code is required' if team_code.nil? || team_code.empty?
31+
32+
JSON.parse(URI.parse(format(BASE_URL, api_token:, team_code:)).open.read)
33+
end
34+
end
35+
end
36+
end
37+
end

0 commit comments

Comments
 (0)