Class: TSPScraper::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/tsp_scraper/client.rb

Class Method Summary collapse

Class Method Details

.scrape(start_date = Date.today.prev_month, end_date = Date.today, options = {}) ⇒ Object



26
27
28
29
# File 'lib/tsp_scraper/client.rb', line 26

def self.scrape(start_date = Date.today.prev_month, end_date = Date.today, options = {})
  raw = self.scrape_raw(start_date, end_date, options = {})
  TSPScraper::Converter.raw_csv_to_hash(raw)
end

.scrape_raw(start_date = Date.today.prev_month, end_date = Date.today, options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/tsp_scraper/client.rb', line 9

def self.scrape_raw(start_date = Date.today.prev_month, end_date = Date.today, options = {})
  funds = ["Linc", "L2010", "L2020", "L2030", "L2040", "L2050", "G", "F", "C", "S", "I"]
  default_options = {
    query: {
      reloaded: 1,
      startdate: start_date.strftime("%m/%d/%Y"),
      enddate: end_date.strftime("%m/%d/%Y"),
      whichButton: "CSV",
      fundgroup: funds
    }
  }
  options = default_options.merge(options)

  response = self.get("/index.html", options)
  response.body.strip
end