espn_pub 0.1.3 → 0.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 39ccc2c710cc3da7638c7b0471a14a091007afe60eb54d9c7ff82c4c2cebdff2
4
- data.tar.gz: 3fc94b08470f001ac7bf59ef5d44910c3f981e8a6934eddfa49ba68633a80e7a
3
+ metadata.gz: 2fbdccec83321ef32990d4db7408783c70d3d4d93f4e53fb748a24d3cbd97d69
4
+ data.tar.gz: 370ee304e44bf7b79d68fcd0263f80ba0b5e4b38101edfe840f85289e7684fd8
5
5
  SHA512:
6
- metadata.gz: e1888c3976d0013fb1f8ed12013ca16e320a46135c3666324870cd3ab4d2913223b6f2c536f571067deb660e924a2bdddae5f67da440b9007743112ad447e736
7
- data.tar.gz: 983e4c30d6e86a00a7ddab38cf56b905abb7e9b7fdbfb2e9ea9bdb5f59c3391e3ad2c3938d70645aadddbae7094f4e6c7c3a6bb111e308bc1a3fe4105f834197
6
+ metadata.gz: 3679819cb7956a302e553b96ce92f460a12d9f7d19fb079d07a714237d7d06e67f64bb09cb539a65b9348732f881ac0172a9456b25d7955af4a45e44e6538612
7
+ data.tar.gz: 0ca9ead84f8a2d7713f0b63cae3cbb4e5f6570719d6262a357d69aa6d7a67f128ef95d50f128824043427a964aaf45c7b7c7faca4fd0e7a6c43f74d077d273f4
@@ -9,10 +9,11 @@ module EspnPub
9
9
  # Raised when the API returns an unexpected HTTP response code.
10
10
  class UnexpectedResponseCodeError < StandardError; end
11
11
 
12
- BASE_URI = 'https://site.api.espn.com/'
12
+ BASE_URI = 'https://site.api.espn.com'
13
13
  API_VERSION = 'v2'
14
14
 
15
15
  attr_reader :uri, :version
16
+ attr_accessor :user_agent
16
17
 
17
18
  # Initialize a new Client.
18
19
  #
@@ -29,8 +30,12 @@ module EspnPub
29
30
  # @return [Hash] The parsed JSON response.
30
31
  # @raise [UnexpectedResponseCodeError] if the response status is not 200.
31
32
  def send_request(path)
32
- response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
33
- http.request_get path
33
+ request_uri = URI "#{BASE_URI}#{path}"
34
+ request = Net::HTTP::Get.new(request_uri)
35
+
36
+ request['User-Agent'] = user_agent if user_agent
37
+ response = Net::HTTP.start(request_uri.host, request_uri.port, use_ssl: true) do |http|
38
+ http.request request
34
39
  end
35
40
 
36
41
  raise UnexpectedResponseCodeError, "Unexpected response code: #{response.code}" unless response.code.to_i == 200
@@ -16,9 +16,9 @@ module EspnPub
16
16
  :position,
17
17
  :team_id,
18
18
  :date_of_birth,
19
- :birthCity,
20
- :birthState,
21
- :birthCountry,
19
+ :birth_city,
20
+ :birth_state,
21
+ :birth_country,
22
22
  :height,
23
23
  :weight,
24
24
  :debut_year
@@ -33,14 +33,14 @@ module EspnPub
33
33
  # @param position [String, nil] The player's position abbreviation.
34
34
  # @param team_id [String, nil] The identifier of the player's team.
35
35
  # @param date_of_birth [Date, nil] The player's date of birth.
36
- # @param birthCity [String, nil] The player's birth city.
37
- # @param birthState [String, nil] The player's birth state.
38
- # @param birthCountry [String, nil] The player's birth country.
36
+ # @param birth_city [String, nil] The player's birth city.
37
+ # @param birth_state [String, nil] The player's birth state.
38
+ # @param birth_country [String, nil] The player's birth country.
39
39
  # @param height [String, nil] The player's listed height.
40
40
  # @param weight [String, nil] The player's listed weight.
41
41
  # @param debut_year [Integer, nil] The year the player made their debut.
42
42
  def initialize(id:, sport:, league:, first_name: nil, last_name: nil, position: nil, team_id: nil,
43
- date_of_birth: nil, birthCity: nil, birthState: nil, birthCountry: nil, height: nil, weight: nil, debut_year: nil)
43
+ date_of_birth: nil, birth_city: nil, birth_state: nil, birth_country: nil, height: nil, weight: nil, debut_year: nil)
44
44
  @id = id
45
45
  @sport = sport
46
46
  @league = league
@@ -49,9 +49,9 @@ module EspnPub
49
49
  @position = position
50
50
  @team_id = team_id
51
51
  @date_of_birth = self.class.parse_date_of_birth(date_of_birth)
52
- @birthCity = birthCity
53
- @birthState = birthState
54
- @birthCountry = birthCountry
52
+ @birth_city = birth_city
53
+ @birth_state = birth_state
54
+ @birth_country = birth_country
55
55
  @height = height
56
56
  @weight = weight
57
57
  @debut_year = debut_year
@@ -85,9 +85,9 @@ module EspnPub
85
85
  position: athlete_data.dig('position', 'abbreviation'),
86
86
  team_id: athlete_data.dig('team', 'id'),
87
87
  date_of_birth: parse_date_of_birth(athlete_data['dateOfBirth']),
88
- birthCity: athlete_data.dig('birthPlace', 'city'),
89
- birthState: athlete_data.dig('birthPlace', 'state'),
90
- birthCountry: athlete_data.dig('birthPlace', 'country'),
88
+ birth_city: athlete_data.dig('birthPlace', 'city'),
89
+ birth_state: athlete_data.dig('birthPlace', 'state'),
90
+ birth_country: athlete_data.dig('birthPlace', 'country'),
91
91
  height: athlete_data['displayHeight'],
92
92
  weight: athlete_data['displayWeight'],
93
93
  debut_year: athlete_data['debutYear']
@@ -35,8 +35,10 @@ module EspnPub
35
35
  super()
36
36
  end
37
37
 
38
- def self.fetch_by_id(id:, sport:, league:)
38
+ def self.fetch_by_id(id:, sport:, league:, user_agent: nil)
39
39
  client = EspnPub::Client.new
40
+ client.user_agent = user_agent if user_agent
41
+
40
42
  path = format TEAM_PATH, client.version, sport, league, id
41
43
  begin
42
44
  team_data = client.send_request(path)['team']
@@ -75,9 +77,9 @@ module EspnPub
75
77
  last_name: athlete_data['lastName'],
76
78
  position: athlete_data['position']['abbreviation'],
77
79
  team_id: id,
78
- birthCity: athlete_data.dig('birthPlace', 'city'),
79
- birthState: athlete_data.dig('birthPlace', 'state'),
80
- birthCountry: athlete_data.dig('birthPlace', 'country'),
80
+ birth_city: athlete_data.dig('birthPlace', 'city'),
81
+ birth_state: athlete_data.dig('birthPlace', 'state'),
82
+ birth_country: athlete_data.dig('birthPlace', 'country'),
81
83
  date_of_birth: athlete_data['dateOfBirth'],
82
84
  height: athlete_data['height'],
83
85
  weight: athlete_data['weight'],
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EspnPub
4
- VERSION = '0.1.3'
4
+ VERSION = '0.1.5'
5
5
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: espn_pub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeffrey Bowman
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2026-09-07 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: date
@@ -162,7 +161,6 @@ metadata:
162
161
  homepage_uri: https://github.com/bowmanje/espn-pub-rb
163
162
  source_code_uri: https://github.com/bowmanje/espn-pub-rb
164
163
  documentation_uri: https://www.rubydoc.info/gems/espn_pub
165
- post_install_message:
166
164
  rdoc_options: []
167
165
  require_paths:
168
166
  - lib
@@ -177,8 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
175
  - !ruby/object:Gem::Version
178
176
  version: '0'
179
177
  requirements: []
180
- rubygems_version: 3.5.3
181
- signing_key:
178
+ rubygems_version: 4.0.20
182
179
  specification_version: 4
183
180
  summary: A Ruby client for the public ESPN API
184
181
  test_files: []