Sha256: 20d05d1884f85930613715bf0175899bdf8ea6e29957be4ae42ec4f62efae30a

Contents?: true

Size: 961 Bytes

Versions: 10

Compression:

Stored size: 961 Bytes

Contents

# frozen_string_literal: true

module AhlScraper
  module PlayerGames
    class DataFetcher
      def initialize(player_id, season_id)
        @player_id = player_id
        @season_id = season_id
      end

      def call
        player_data = JSON.parse(player_data_without_bio, symbolize_names: true)

        player_data&.dig(:gameByGame, 0, :sections, 0, :data)&.map { |data| { **data, position: player_data[:info][:position] } }
      end

      private

      def url
        "https://lscluster.hockeytech.com/feed/index.php?feed=statviewfeed&view=player&player_id=#{@player_id}&season_id=#{@season_id}&site_id=3&key=ccb91f29d6744675&client_code=ahl&league_id=&lang=en&statsType=standard&callback=json" # rubocop:disable Layout/LineLength
      end

      def player_data_without_bio
        data = Nokogiri::HTML(URI.parse(url).open).text[5..-2]
        bio = data[/"bio":(.*?),"teamName/m, 1]
        data.gsub(bio, "\"\"")
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ahl_scraper-0.4.0 lib/ahl_scraper/fetchers/player_games/data_fetcher.rb
ahl_scraper-0.3.8 lib/ahl_scraper/fetchers/player_games/data_fetcher.rb
ahl_scraper-0.3.7 lib/ahl_scraper/fetchers/player_games/data_fetcher.rb
ahl_scraper-0.3.6 lib/ahl_scraper/fetchers/player_games/data_fetcher.rb
ahl_scraper-0.3.5 lib/ahl_scraper/fetchers/player_games/data_fetcher.rb
ahl_scraper-0.3.4 lib/ahl_scraper/fetchers/player_games/data_fetcher.rb
ahl_scraper-0.3.3 lib/ahl_scraper/fetchers/player_games/data_fetcher.rb
ahl_scraper-0.3.2 lib/ahl_scraper/fetchers/player_games/data_fetcher.rb
ahl_scraper-0.3.1 lib/ahl_scraper/fetchers/player_games/data_fetcher.rb
ahl_scraper-0.3.0 lib/ahl_scraper/fetchers/player_games/data_fetcher.rb