Class: NyplSiteScraper::Client
- Inherits:
-
Object
- Object
- NyplSiteScraper::Client
- Defined in:
- lib/nypl_site_scraper/scraper.rb
Instance Attribute Summary collapse
-
#barcode ⇒ Object
readonly
Returns the value of attribute barcode.
-
#homepage ⇒ Object
readonly
Returns the value of attribute homepage.
-
#pin ⇒ Object
readonly
Returns the value of attribute pin.
Instance Method Summary collapse
- #get_checkouts ⇒ Object
- #get_fines ⇒ Object
- #get_holds ⇒ Object
-
#initialize(options = {barcode: nil, }) ⇒ Client
constructor
A new instance of Client.
- #login! ⇒ Object
Constructor Details
#initialize(options = {barcode: nil, }) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 |
# File 'lib/nypl_site_scraper/scraper.rb', line 8 def initialize( = {barcode: nil, }) @barcode = [:barcode] @pin = [:pin] @agent = Mechanize.new end |
Instance Attribute Details
#barcode ⇒ Object (readonly)
Returns the value of attribute barcode.
6 7 8 |
# File 'lib/nypl_site_scraper/scraper.rb', line 6 def @barcode end |
#homepage ⇒ Object (readonly)
Returns the value of attribute homepage.
6 7 8 |
# File 'lib/nypl_site_scraper/scraper.rb', line 6 def homepage @homepage end |
#pin ⇒ Object (readonly)
Returns the value of attribute pin.
6 7 8 |
# File 'lib/nypl_site_scraper/scraper.rb', line 6 def pin @pin end |
Instance Method Details
#get_checkouts ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/nypl_site_scraper/scraper.rb', line 23 def get_checkouts @check_outs_page ||= @homepage.link_with(text: "My Checked Out Items").click check_cout_rows = @check_outs_page.search('tr.patFuncEntry') check_outs_response = [] check_cout_rows.each do |check_out_row| check_outs_response << { title: check_out_row.search('td.patFuncTitle').text.strip, dueDate: check_out_row.search('td.patFuncStatus').text.strip } end {checkouts: check_outs_response} end |
#get_fines ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/nypl_site_scraper/scraper.rb', line 38 def get_fines @fines_page ||= @agent.get("https://catalog.nypl.org/patroninfo~S1/thisurlsegment-doesnt-seem-to-matter-hahahah/overdues") fines_rows = @fines_page.search('tr.patFuncFinesEntryTitle') fines_response = [] fines_rows.each_with_index do |overdue_row, index| fines_response << { title: overdue_row.text.strip, fineAmount: @fines_page.search('td.patFuncFinesDetailAmt')[index].text.strip } end {fines: fines_response} end |
#get_holds ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/nypl_site_scraper/scraper.rb', line 53 def get_holds @holds_page ||= @homepage.link_with(text: "My Holds").click holds_rows = @holds_page.css('tr.patFuncEntry') response_holds = [] holds_rows.each do |hold_row| status_string = hold_row.css('td.patFuncStatus').text.strip response_holds << { title: hold_row.css('td.patFuncTitle').text.strip, statusString: status_string, status: map_status_string(status_string), pickupLocation: get_pickup_location(hold_row), } end {holds: response_holds} end |
#login! ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/nypl_site_scraper/scraper.rb', line 14 def login! login_page = @agent.get('https://catalog.nypl.org/iii/cas/login?service=https%3A%2F%2Fcatalog.nypl.org%3A443%2Fpatroninfo~S1%2FIIITICKET&scope=1') form = login_page.form form.code = form.pin = pin @homepage = @agent.submit(form, form..first) true end |