require "addressable/template" require "async/http/internet/instance" module NCMall # Share a pool of persistent connections, rather than reconnecting on # each request. (This library does that automatically!) INTERNET = Async::HTTP::Internet.instance # Load the NC Mall home page content area, and return its useful data. HOME_PAGE_URL = "https://ncmall.neopets.com/mall/ajax/home_page.phtml" def self.load_home_page load_page_by_url HOME_PAGE_URL end # Load the NC Mall page for a specific type and category ID. CATEGORY_PAGE_URL_TEMPLATE = Addressable::Template.new( "https://ncmall.neopets.com/mall/ajax/load_page.phtml?lang=en{&type,cat}" ) def self.load_page(type, cat) load_page_by_url CATEGORY_PAGE_URL_TEMPLATE.expand(type:, cat:) end # Load the NC Mall root document HTML, and extract the list of links to # other pages ("New", "Popular", etc.) ROOT_DOCUMENT_URL = "https://ncmall.neopets.com/mall/shop.phtml" PAGE_LINK_PATTERN = /load_items_pane\(['"](.+?)['"], ([0-9]+)\).+?>(.+?) 0 { price: discount_price, begins_at: item_info["discountBegin"], ends_at: item_info["discountEnd"], } end class ResponseNotOK < StandardError attr_reader :status def initialize(status) super @status = status end end class UnexpectedResponseFormat < StandardError;end end