Class: Client

Inherits:
Object
  • Object
show all
Defined in:
lib/deadlist/cli/client.rb

Overview

The Client class manages HTML scraping and parsing for the CLI and other classes above it. Any HTML work should be handled here.

Instance Method Summary collapse

Instance Method Details

#query_show_info(show_id) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/deadlist/cli/client.rb', line 3

def query_show_info(show_id)
    url = 'https://archive.org/metadata/' + show_id
    response = HTTParty.get(url)

    unless response.success?
        raise "API request failed: #{response.code}"
    end

    unless response["metadata"]
        raise "Invalid show ID: #{show_id}"
    end

    show_data = {
        date: response["metadata"]["date"],
        location: response["metadata"]["coverage"],
        venue: response["metadata"]["venue"],
        transferred_by: response["metadata"]["transferer"],
        duration: response["metadata"]["runtime"],
        dir: response["metadata"]["identifier"],
        files: response["files"]
    }

    return show_data
rescue HTTParty::Error, StandardError => e
    raise "Failed to fetch show data: #{e.message}"
end