File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
lib/baseballbot/templates/components Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments