sleeper_ff 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d2eabd815df1063832834aa7efcfa764631331510fab7a4efe816b6ee149171f
4
+ data.tar.gz: e420eb29b532a533e53e8dd38c0357e477d9465f5eda757e24be9991033960ce
5
+ SHA512:
6
+ metadata.gz: 83b97c33a2122a7d668f8d8c95788f1b2ec80522617bdfb3895db0395c869c454c92e9846f3ddc1a9a7d94a412f71c967a67dbaf5f6f8b62d2e9cfe14c5330cd
7
+ data.tar.gz: 5b6d6c0071ddc254bddef7049802dbf19ff98f4362f103f782188a9f56c9ba3e257f00180b6865d662dd285e13f4204343642e7ef31ab6ed81aecac4e876d804
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Josh Mejia
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,122 @@
1
+ # SleeperFF
2
+
3
+ A Ruby toolkit for the Sleeper Fantasy Football API. This gem provides a simple way to interact with Sleeper's API endpoints.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'sleeper_ff'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```bash
16
+ $ bundle install
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```bash
22
+ $ gem install sleeper_ff
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ### Quick Start
28
+
29
+ ```ruby
30
+ # Create a new client
31
+ client = SleeperFF.new
32
+
33
+ # Get user information
34
+ user = client.user("username")
35
+ puts user.display_name
36
+ ```
37
+
38
+ ### Configuration
39
+
40
+ You can configure the client with custom options:
41
+
42
+ ```ruby
43
+ # Configure with a custom user agent
44
+ client = SleeperFF.new(user_agent: "My App v1.0")
45
+
46
+ # Or configure globally
47
+ SleeperFF.configure do |config|
48
+ config.user_agent = "My App v1.0"
49
+ config.api_endpoint = "https://api.sleeper.app/v1" # default
50
+ end
51
+ ```
52
+
53
+ ### Available Methods
54
+
55
+ #### Users
56
+
57
+ ```ruby
58
+ # Get user by username
59
+ user = client.user("username")
60
+
61
+ # Access user attributes
62
+ user.username # => "username"
63
+ user.user_id # => "123456789"
64
+ user.display_name # => "Display Name"
65
+ user.avatar # => "avatar_url"
66
+ ```
67
+
68
+ ### Leagues
69
+
70
+ ```ruby
71
+ # Get all leagues for a user in a season
72
+ leagues = client.user_leagues("username", 2023)
73
+
74
+ # Get a specific league
75
+ league = client.league("league_id")
76
+
77
+ # Get all rosters in a league
78
+ rosters = client.league_rosters("league_id")
79
+
80
+ # Get all users in a league
81
+ users = client.league_users("league_id")
82
+ ```
83
+
84
+ You can access various attributes on the returned objects:
85
+
86
+ ```ruby
87
+ # League attributes
88
+ league.name # => "My Fantasy League"
89
+ league.season # => "2023"
90
+ league.settings # => { scoring_settings: {...}, roster_settings: {...} }
91
+ league.roster_positions # => ["QB", "RB", "WR", "TE", "FLEX", "BN", ...]
92
+
93
+ # Roster attributes
94
+ roster.owner_id # => "user_id"
95
+ roster.players # => ["player_id1", "player_id2", ...]
96
+ roster.starters # => ["player_id1", "player_id2", ...]
97
+ roster.settings # => { wins: 10, losses: 4, ... }
98
+ ```
99
+
100
+ More endpoints coming soon:
101
+ - Players
102
+ - Drafts
103
+ - Matchups
104
+ - Transactions
105
+
106
+ ## Development
107
+
108
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
109
+
110
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
111
+
112
+ ## Contributing
113
+
114
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jmejia/sleeper_ff. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/jmejia/sleeper_ff/blob/main/CODE_OF_CONDUCT.md).
115
+
116
+ ## License
117
+
118
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
119
+
120
+ ## Code of Conduct
121
+
122
+ Everyone interacting in the SleeperFF project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/jmejia/sleeper_ff/blob/main/CODE_OF_CONDUCT.md).
data/bin/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "sleeper_ff"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ require "irb"
11
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SleeperFF
4
+ class Client
5
+ module Leagues
6
+ # Get all leagues for a user in a season
7
+ #
8
+ # @param username [String] Username of the Sleeper user
9
+ # @param season [Integer] NFL season year (e.g., 2023)
10
+ # @return [Array<Sawyer::Resource>] Array of league information
11
+ def user_leagues(username, season)
12
+ get "user/#{username}/leagues/nfl/#{season}"
13
+ end
14
+
15
+ # Get a specific league
16
+ #
17
+ # @param league_id [String] League ID
18
+ # @return [Sawyer::Resource] League information
19
+ def league(league_id)
20
+ get "league/#{league_id}"
21
+ end
22
+
23
+ # Get all rosters in a league
24
+ #
25
+ # @param league_id [String] League ID
26
+ # @return [Array<Sawyer::Resource>] Array of roster information
27
+ def league_rosters(league_id)
28
+ get "league/#{league_id}/rosters"
29
+ end
30
+
31
+ # Get all users in a league
32
+ #
33
+ # @param league_id [String] League ID
34
+ # @return [Array<Sawyer::Resource>] Array of user information
35
+ def league_users(league_id)
36
+ get "league/#{league_id}/users"
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SleeperFF
4
+ class Client
5
+ module Users
6
+ # Get a user by username
7
+ #
8
+ # @param username [String] Username of the Sleeper user
9
+ # @return [Sawyer::Resource] User information
10
+ def user(username)
11
+ get "user/#{username}"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "sawyer"
4
+ require "sleeper_ff/configurable"
5
+ require "sleeper_ff/client/users"
6
+ require "sleeper_ff/client/leagues"
7
+
8
+ module SleeperFF
9
+ class Client
10
+ include SleeperFF::Configurable
11
+ include SleeperFF::Client::Users
12
+ include SleeperFF::Client::Leagues
13
+
14
+ # Header keys that can be passed in options hash
15
+ CONVENIENCE_HEADERS = Set.new([:accept, :content_type])
16
+
17
+ def initialize(options = {})
18
+ SleeperFF::Configurable.keys.each do |key|
19
+ value = options[key].nil? ? SleeperFF::Default.send(key) : options[key]
20
+ instance_variable_set(:"@#{key}", value)
21
+ end
22
+ end
23
+
24
+ # Make a HTTP GET request
25
+ #
26
+ # @param url [String] The path, relative to {#api_endpoint}
27
+ # @param options [Hash] Query and header params for request
28
+ # @return [Sawyer::Resource]
29
+ def get(url, options = {})
30
+ request :get, url, options
31
+ end
32
+
33
+ private
34
+
35
+ def request(method, path, data, options = {})
36
+ if data.is_a?(Hash)
37
+ options[:query] = data.delete(:query) || {}
38
+ options[:headers] = data.delete(:headers) || {}
39
+ if accept = data.delete(:accept)
40
+ options[:headers][:accept] = accept
41
+ end
42
+ end
43
+
44
+ @last_response = response = agent.call(method, URI::Parser.new.escape(path.to_s), data, options)
45
+ response.data
46
+ end
47
+
48
+ def agent
49
+ @agent ||= Sawyer::Agent.new(api_endpoint) do |http|
50
+ http.headers[:accept] = default_media_type
51
+ http.headers[:user_agent] = user_agent
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SleeperFF
4
+ module Configurable
5
+ attr_accessor :api_endpoint, :user_agent, :default_media_type
6
+
7
+ class << self
8
+ def keys
9
+ @keys ||= [
10
+ :api_endpoint,
11
+ :user_agent,
12
+ :default_media_type
13
+ ]
14
+ end
15
+ end
16
+
17
+ def configure
18
+ yield self
19
+ end
20
+
21
+ private
22
+
23
+ def reset!
24
+ SleeperFF::Configurable.keys.each do |key|
25
+ instance_variable_set(:"@#{key}", SleeperFF::Default.send(key))
26
+ end
27
+ self
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SleeperFF
4
+ module Default
5
+ API_ENDPOINT = "https://api.sleeper.app/v1".freeze
6
+ USER_AGENT = "SleeperFF Ruby Gem #{SleeperFF::VERSION}".freeze
7
+ MEDIA_TYPE = "application/json".freeze
8
+
9
+ class << self
10
+ def api_endpoint
11
+ API_ENDPOINT
12
+ end
13
+
14
+ def user_agent
15
+ USER_AGENT
16
+ end
17
+
18
+ def default_media_type
19
+ MEDIA_TYPE
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SleeperFF
4
+ # Custom error class for rescuing from all SleeperFF errors
5
+ class Error < StandardError; end
6
+
7
+ # Raised when Sleeper returns a 400 HTTP status code
8
+ class BadRequest < Error; end
9
+
10
+ # Raised when Sleeper returns a 401 HTTP status code
11
+ class Unauthorized < Error; end
12
+
13
+ # Raised when Sleeper returns a 403 HTTP status code
14
+ class Forbidden < Error; end
15
+
16
+ # Raised when Sleeper returns a 404 HTTP status code
17
+ class NotFound < Error; end
18
+
19
+ # Raised when Sleeper returns a 429 HTTP status code
20
+ class TooManyRequests < Error; end
21
+
22
+ # Raised when Sleeper returns a 500 HTTP status code
23
+ class InternalServerError < Error; end
24
+
25
+ # Raised when Sleeper returns a 502 HTTP status code
26
+ class BadGateway < Error; end
27
+
28
+ # Raised when Sleeper returns a 503 HTTP status code
29
+ class ServiceUnavailable < Error; end
30
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SleeperFF
4
+ VERSION = "0.1.0"
5
+ end
data/lib/sleeper_ff.rb ADDED
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "sleeper_ff/version"
4
+ require "sleeper_ff/client"
5
+ require "sleeper_ff/default"
6
+ require "sleeper_ff/error"
7
+
8
+ module SleeperFF
9
+ class Error < StandardError; end
10
+
11
+ # Return a new SleeperFF::Client instance
12
+ #
13
+ # @return [SleeperFF::Client]
14
+ def self.new(options = {})
15
+ SleeperFF::Client.new(options)
16
+ end
17
+
18
+ # Delegate to SleeperFF::Client.new
19
+ #
20
+ # @return [SleeperFF::Client]
21
+ def self.client(options = {})
22
+ SleeperFF::Client.new(options)
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sleeper_ff
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Josh Mejia
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 2025-04-03 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: faraday
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '1.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '1.0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: sawyer
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: 0.9.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 0.9.0
40
+ - !ruby/object:Gem::Dependency
41
+ name: rspec
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '3.0'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '3.0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: webmock
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '3.0'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.0'
68
+ - !ruby/object:Gem::Dependency
69
+ name: vcr
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '6.0'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '6.0'
82
+ - !ruby/object:Gem::Dependency
83
+ name: pry
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 0.14.0
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: 0.14.0
96
+ description: Ruby toolkit for the Sleeper Fantasy Football API
97
+ email:
98
+ - joshua.mejia@gmail.com
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - LICENSE.txt
104
+ - README.md
105
+ - bin/console
106
+ - bin/setup
107
+ - lib/sleeper_ff.rb
108
+ - lib/sleeper_ff/client.rb
109
+ - lib/sleeper_ff/client/leagues.rb
110
+ - lib/sleeper_ff/client/users.rb
111
+ - lib/sleeper_ff/configurable.rb
112
+ - lib/sleeper_ff/default.rb
113
+ - lib/sleeper_ff/error.rb
114
+ - lib/sleeper_ff/version.rb
115
+ homepage: https://github.com/jmejia/sleeper_ff
116
+ licenses:
117
+ - MIT
118
+ metadata: {}
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: 3.0.0
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubygems_version: 3.6.2
134
+ specification_version: 4
135
+ summary: Ruby toolkit for the Sleeper Fantasy Football API
136
+ test_files: []