osu-ctl-scraper 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0f61f5674ffa411e662d676ca6a1a5c68c3c35b8
4
- data.tar.gz: 08336a7892b67f47adf6ad823005f23b057ff9b6
3
+ metadata.gz: 37bb61bf74de86fd115f1b1f882cd7ba718a1c58
4
+ data.tar.gz: ae2c386e394e04c5dcaf47b0d4305279522388fa
5
5
  SHA512:
6
- metadata.gz: b9283653ac17768853f815ecad02e26011df72bf67b099e70b5469c60a4873e73ca717457ba568948b4f473ac646905521d1a5c48298831c63494c8ea144ecb1
7
- data.tar.gz: d427cdc637e0eecf8072ba812b7d1d08b44b8614f09e25537c415b39b94c634a74e3027ab77fd47d9281ad797ad65763d85d987c6d09a0f583c86f7adc964ad8
6
+ metadata.gz: 60432b3d327c03fc4b351bb9209b101d1cca9b0e26d092cc541cfb26dcd16b6d6ff1f1530013a447287c21f5494fbcc627ccccb279028c6f0f0d922fd3b89e34
7
+ data.tar.gz: df06011ff10ca5aeecfbba2544ab3497185a06b2cc1a7ec3827eba54ccea108774dc3f447da829acc46c5111e097c3491fdd5f3bf69482959b7ad8494b0e58d2
@@ -4,6 +4,7 @@ require "json"
4
4
  require "open-uri"
5
5
 
6
6
  module OsuCtlScraper
7
+ ENDPOINT = "http://osubeaverstore.com"
7
8
  end
8
9
 
9
10
  require "osu-ctl-scraper/department"
@@ -1,10 +1,14 @@
1
1
  module OsuCtlScraper
2
2
  class Book
3
- # Returns an array of Books for the given options
3
+ RESOURCE = "/Faculty/GetTextbooks/"
4
+
5
+ # Returns an array of Books
4
6
  #
5
- # @param [Hash] options
7
+ # @param [String] subject_code
8
+ # @param [Integer] year
9
+ # @param [Symbol] term Must be one of: "winter", "spring", "summer", or "fall"
6
10
  # @return [Array<Hash>]
7
- def self.where(subject_code, year, term)
11
+ def self.find_by(subject_code, year, term)
8
12
  res = get_html(subject_code, year, term)
9
13
  html = format_response(res.body)
10
14
  process_html(subject_code, html)
@@ -15,7 +19,7 @@ module OsuCtlScraper
15
19
  # @param [Symbol] term Must be one of: "winter", "spring", "summer", or "fall"
16
20
  # @return [String]
17
21
  def self.get_html(subject_code, year, term)
18
- url = URI.parse("http://osubeaverstore.com/Faculty/GetTextbooks/")
22
+ url = URI.parse("#{ENDPOINT}#{RESOURCE}")
19
23
  params = form_params(subject_code, year, term)
20
24
  res = Net::HTTP.post_form(url, params)
21
25
  end
@@ -60,16 +64,18 @@ module OsuCtlScraper
60
64
  ng = Nokogiri::HTML(html)
61
65
  ng.css("tr:not(:first-child)").each do |row|
62
66
  book = process_row(row)
63
- book[:subject_code] = subject_code
64
- books << book
67
+ unless book.nil?
68
+ book[:subject_code] = subject_code
69
+ books << book
70
+ end
65
71
  end
66
72
  books
67
73
  end
68
74
 
69
75
  # @param [Nokogiri::XML::Element] row
70
- # @return [Hash]
76
+ # @return [Hash, nil]
71
77
  def self.process_row(row)
72
- {
78
+ book = {
73
79
  course: row.css("td:nth-child(1)").text.strip,
74
80
  section: row.css("td:nth-child(2)").text.strip,
75
81
  instructor: row.css("td:nth-child(3)").text.strip,
@@ -83,6 +89,9 @@ module OsuCtlScraper
83
89
  comments: row.css("td:nth-child(11)").text.strip,
84
90
  req_date: row.css("td:nth-child(12)").text.strip
85
91
  }
92
+
93
+ # Only return the book if is has an ISBN
94
+ book[:isbn].empty? ? nil : book
86
95
  end
87
96
  end
88
97
  end
@@ -1,5 +1,7 @@
1
1
  module OsuCtlScraper
2
2
  class Department
3
+ RESOURCE = "/faculty/textbooks/"
4
+
3
5
  # @return [Array<Hash>]
4
6
  def self.all
5
7
  html = get_html
@@ -8,7 +10,7 @@ module OsuCtlScraper
8
10
 
9
11
  # @return [String] html
10
12
  def self.get_html
11
- open("http://osubeaverstore.com/faculty/textbooks/").read
13
+ open("#{ENDPOINT}#{RESOURCE}").read
12
14
  end
13
15
 
14
16
  # @param [String] html
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: osu-ctl-scraper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonah George