Sha256: 9b639dd76797eee4747413daf3c902528a1232ea15eb1a0ba4a2cd5e9b3bbfa9

Contents?: true

Size: 820 Bytes

Versions: 2

Compression:

Stored size: 820 Bytes

Contents

# frozen_string_literal: true

module AhlScraper
  class GameDataFetcher
    BROKEN_GAMES = [1_018_774, 1_001_050, 1_020_527].freeze

    def initialize(game_id)
      @game_id = game_id
    end

    def call
      return fixed_game if BROKEN_GAMES.include? @game_id

      JSON.parse(Nokogiri::HTML(URI.parse(url).open).text[5..-2], symbolize_names: true)
    end

    private

    def fixed_game
      path = File.join(File.dirname(__FILE__), "../fixed_games/#{@game_id}.json")
      file = File.read(path)
      JSON.parse(file, symbolize_names: true)
    end

    def url
      "http://lscluster.hockeytech.com/feed/index.php?feed=statviewfeed&view=gameSummary&game_id=#{@game_id}&key=50c2cd9b5e18e390&site_id=1&client_code=ahl&lang=en&league_id=&callback=json" # rubocop:disable Layout/LineLength
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ahl_scraper-0.2.0 lib/ahl_scraper/fetchers/game_data_fetcher.rb
ahl_scraper-0.1.1 lib/ahl_scraper/fetchers/game_data_fetcher.rb