Class: Stellar::Client
Overview
Client session for accessing the Stellar API.
Instance Method Summary collapse
- #course(number, year, semester) ⇒ Object
-
#courses ⇒ Stellar::Courses
A Stellar client specialized to answer course queries.
-
#get(path) ⇒ Mechanize::Page
Fetches a page from the Stellar site.
-
#get_file(path) ⇒ String
Fetches a file from the Stellar site.
-
#get_nokogiri(path) ⇒ Nokogiri::HTML::Document
Fetches a page from the Stellar site.
-
#initialize ⇒ Client
constructor
Client for accessing public information.
-
#mech(&block) ⇒ Object
New Mechanize instance.
Methods included from Auth
#auth, get_certificate, #mitca_path
Constructor Details
#initialize ⇒ Client
Client for accessing public information.
Call auth to authenticate as a user and access restricted functionality.
11 12 13 14 15 |
# File 'lib/stellar/client.rb', line 11 def initialize @mech = mech @courses = nil end |
Instance Method Details
#course(number, year, semester) ⇒ Object
65 66 67 |
# File 'lib/stellar/client.rb', line 65 def course(number, year, semester) Stellar::Course.for number, year, semester, self end |
#courses ⇒ Stellar::Courses
A Stellar client specialized to answer course queries.
60 61 62 |
# File 'lib/stellar/client.rb', line 60 def courses @courses ||= Stellar::Courses.new self end |
#get(path) ⇒ Mechanize::Page
Fetches a page from the Stellar site.
33 34 35 36 |
# File 'lib/stellar/client.rb', line 33 def get(path) uri = URI.join('https://stellar.mit.edu', path) page_bytes = @mech.get uri end |
#get_file(path) ⇒ String
Fetches a file from the Stellar site.
52 53 54 55 |
# File 'lib/stellar/client.rb', line 52 def get_file(path) uri = URI.join('https://stellar.mit.edu', path) @mech.get_file uri end |
#get_nokogiri(path) ⇒ Nokogiri::HTML::Document
Fetches a page from the Stellar site.
42 43 44 45 46 |
# File 'lib/stellar/client.rb', line 42 def get_nokogiri(path) uri = URI.join('https://stellar.mit.edu', path) raw_html = @mech.get_file uri Nokogiri.HTML raw_html, uri.to_s end |
#mech(&block) ⇒ Object
New Mechanize instance.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/stellar/client.rb', line 18 def mech(&block) m = Mechanize.new do |m| m.cert_store = OpenSSL::X509::Store.new m.cert_store.add_file mitca_path m.user_agent_alias = 'Linux Firefox' yield m if block m end m end |