Class: RelatonAsme::Fetcher::IndexPage

Inherits:
BasicPage
  • Object
show all
Defined in:
lib/relaton_asme/fetcher/index_page.rb

Overview

Handles fetching ASME standards index via JSON API

Constant Summary collapse

API_URL =
"https://www.asme.org/api/products"
DEFAULT_PER_PAGE =
100

Instance Attribute Summary

Attributes inherited from BasicPage

#agent, #page, #url

Instance Method Summary collapse

Methods inherited from BasicPage

#ensure_page, #fetch

Constructor Details

#initialize(page_number: 1, per_page: DEFAULT_PER_PAGE, agent: nil) ⇒ IndexPage

Initialize index page for a specific page number



18
19
20
21
22
23
# File 'lib/relaton_asme/fetcher/index_page.rb', line 18

def initialize(page_number: 1, per_page: DEFAULT_PER_PAGE, agent: nil)
  @page_number = page_number
  @per_page = per_page
  url = build_api_url(page_number, per_page)
  super(url, agent: agent)
end

Instance Method Details

#more_pages?Boolean

Check if there are more pages



36
37
38
39
40
41
42
# File 'lib/relaton_asme/fetcher/index_page.rb', line 36

def more_pages?
  ensure_page
  data = parse_json_response
  return false unless data

  data["page"] < data["pages"]
end

#publication_urlsArray<String>

Extract publication URLs from the API response



28
29
30
31
# File 'lib/relaton_asme/fetcher/index_page.rb', line 28

def publication_urls
  ensure_page
  extract_urls_from_json
end