Class: Illiad::Webcirc

Inherits:
Object
  • Object
show all
Defined in:
lib/illiad/webcirc.rb

Instance Method Summary collapse

Constructor Details

#initialize(url, username, password) ⇒ Webcirc

Returns a new instance of Webcirc.



6
7
8
9
10
11
# File 'lib/illiad/webcirc.rb', line 6

def initialize(url, username, password)
  @url = url
  @username = username
  @password = password
  @conn = Mechanize.new
end

Instance Method Details

#charge!(id) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/illiad/webcirc.rb', line 28

def charge!(id)
  page = @conn.get(@url + '/Default.aspx')
  page = page.form('aspnetForm') do |f|
    f['ctl00$TextBoxCheckOutTransaction'] = id
  end.click_button page.form('aspnetForm').button_with(:value => "Check Out")

  msg = page.at("#ctl00_UpdatePanelStatusMessages .failure, #ctl00_UpdatePanelStatusMessages .success, #ctl00_UpdatePanelStatusMessages .warning").inner_html

  raise msg if page.at("#ctl00_UpdatePanelStatusMessages .success").nil?

  true
end

#connectObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/illiad/webcirc.rb', line 13

def connect
  # Load Illiad Web Circulation
  page = @conn.get(@url + '/Logon.aspx')

  # Select, fill in, and submit the logon form.
  page = page.form('formLogon') do |f|
    f.TextBoxUsername = @username
    f.TextBoxPassword = @password
  end.click_button

  # A successful login will redirect to /illiad/WebCirc/Default.aspx
  # A failed login will return to /illiadWebCirc/Logon.aspx
  page.uri.request_uri == '/illiad/WebCirc/Default.aspx'
end

#discharge!(id) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/illiad/webcirc.rb', line 41

def discharge!(id)
  page = @conn.get(@url + '/Default.aspx')
  page = page.form('aspnetForm') do |f|
    f['ctl00$TextBoxCheckInTransaction'] = id
  end.click_button page.form('aspnetForm').button_with(:value => "Check In")

  msg = page.at("#ctl00_UpdatePanelStatusMessages .failure, #ctl00_UpdatePanelStatusMessages .success, #ctl00_UpdatePanelStatusMessages .warning").inner_html

  raise msg if page.at("#ctl00_UpdatePanelStatusMessages .success").nil?

  true
end