class Stellar::Client

Client session for accessing the Stellar API.

Public Class Methods

new() click to toggle source

Client for accessing public information.

Call auth to authenticate as a user and access restricted functionality.

# File lib/stellar/client.rb, line 11
def initialize
  @mech = mech
  
  @courses = nil
end

Public Instance Methods

course(number, year, semester) click to toggle source

(see Stellar::Course#for)

# File lib/stellar/client.rb, line 65
def course(number, year, semester)
  Stellar::Course.for number, year, semester, self
end
courses() click to toggle source

A Stellar client specialized to answer course queries.

@return [Stellar::Courses] client specialized to course queries

# File lib/stellar/client.rb, line 60
def courses
  @courses ||= Stellar::Courses.new self
end
get(path) click to toggle source

Fetches a page from the Stellar site.

@param [String] path relative URL of the page to be fetched @return [Mechanize::Page] the desired page, wrapped in the Mechanize API

# 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) click to toggle source

Fetches a file from the Stellar site.

@param [String] path relative URL of the file to be fetched @return [String] raw contents of the file

# 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) click to toggle source

Fetches a page from the Stellar site.

@param [String] path relative URL of the page to be fetched @return [Nokogiri::HTML::Document] the desired page, parsed with Nokogiri

# 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() { |m| ... } click to toggle source

New Mechanize instance.

# 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