illiad 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in illiad.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/illiad.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "illiad/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "illiad"
7
+ s.version = Illiad::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Brice Stacey"]
10
+ s.email = ["bricestacey@gmail.com"]
11
+ s.homepage = "https://github.com/bricestacey/illiad"
12
+ s.summary = %q{ActiveRecord, webcirc, and other utilities for Illiad Interlibrary Loan}
13
+ s.description = %q{ActiveRecord, webcirc, and other utilities for Illiad Interlibrary Loan}
14
+
15
+ s.rubyforge_project = "illiad"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_development_dependency('rspec')
23
+
24
+ s.add_dependency('activerecord')
25
+ s.add_dependency('activerecord-sqlserver-adapter')
26
+ s.add_dependency('tiny_tds')
27
+ end
data/lib/illiad.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'illiad/webcirc'
2
+
3
+ require 'active_record'
4
+ require 'tiny_tds'
5
+ require 'illiad/activerecord/base'
6
+ require 'illiad/activerecord/transaction'
7
+
8
+
9
+ module Illiad
10
+ end
@@ -0,0 +1,6 @@
1
+ module Illiad
2
+ module AR
3
+ class Base < ActiveRecord::Base
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,17 @@
1
+ module Illiad
2
+ module AR
3
+ class Transaction < Illiad::AR::Base
4
+ set_table_name 'Transactions'
5
+ set_primary_key 'TransactionNumber'
6
+
7
+ def charged?
8
+ status = read_attribute(:TransactionStatus)
9
+ (status == 'Checked Out to Customer' or
10
+ status == 'Renewal Denied' or
11
+ status =~ /Renewed by Customer to .*/ or
12
+ status =~ /Renewed by ILL Staff to .*/ or
13
+ status == 'Loans Recalled from Patrons') ? true : false
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module Illiad
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,54 @@
1
+ require 'mechanize'
2
+
3
+ module Illiad
4
+ class Webcirc
5
+
6
+ def initialize(url, username, password)
7
+ @url = url
8
+ @username = username
9
+ @password = password
10
+ @conn = Mechanize.new
11
+ end
12
+
13
+ def connect
14
+ # Load Illiad Web Circulation
15
+ page = @conn.get(@url + '/Logon.aspx')
16
+
17
+ # Select, fill in, and submit the logon form.
18
+ page = page.form('formLogon') do |f|
19
+ f.TextBoxUsername = @username
20
+ f.TextBoxPassword = @password
21
+ end.click_button
22
+
23
+ # A successful login will redirect to /illiad/WebCirc/Default.aspx
24
+ # A failed login will return to /illiadWebCirc/Logon.aspx
25
+ page.uri.request_uri == '/illiad/WebCirc/Default.aspx'
26
+ end
27
+
28
+ def charge!(id)
29
+ page = @conn.get(@url + '/Default.aspx')
30
+ page = page.form('aspnetForm') do |f|
31
+ f['ctl00$TextBoxCheckOutTransaction'] = id
32
+ end.click_button page.form('aspnetForm').button_with(:value => "Check Out")
33
+
34
+ msg = page.at("#ctl00_UpdatePanelStatusMessages .failure, #ctl00_UpdatePanelStatusMessages .success, #ctl00_UpdatePanelStatusMessages .warning").inner_html
35
+
36
+ raise msg if page.at("#ctl00_UpdatePanelStatusMessages .success").nil?
37
+
38
+ true
39
+ end
40
+
41
+ def discharge!(id)
42
+ page = @conn.get(@url + '/Default.aspx')
43
+ page = page.form('aspnetForm') do |f|
44
+ f['ctl00$TextBoxCheckInTransaction'] = id
45
+ end.click_button page.form('aspnetForm').button_with(:value => "Check In")
46
+
47
+ msg = page.at("#ctl00_UpdatePanelStatusMessages .failure, #ctl00_UpdatePanelStatusMessages .success, #ctl00_UpdatePanelStatusMessages .warning").inner_html
48
+
49
+ raise msg if page.at("#ctl00_UpdatePanelStatusMessages .success").nil?
50
+
51
+ true
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,14 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'illiad'
5
+ require 'rspec'
6
+
7
+ Rspec.configure do |config|
8
+ config.mock_with :rspec
9
+
10
+ # Do not include a trailing slash in the URL!
11
+ config.add_setting :webcirc_url, :default => 'http://hostname/illiad/WebCirc'
12
+ config.add_setting :webcirc_username, :default => 'username'
13
+ config.add_setting :webcirc_password, :default => 'password'
14
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe Illiad::Webcirc, "#connect" do
4
+ before(:all) do
5
+ @url = Rspec.configuration.webcirc_url
6
+ @username = Rspec.configuration.webcirc_username
7
+ @password = Rspec.configuration.webcirc_password
8
+ end
9
+
10
+ it "should return true on success" do
11
+ @webcirc = Illiad::Webcirc.new(@url, @username, @password)
12
+ @webcirc.connect.should == true
13
+ end
14
+ end
15
+
16
+ describe Illiad::Webcirc, "#charge!" do
17
+ before(:all) do
18
+ @url = Rspec.configuration.webcirc_url
19
+ @username = Rspec.configuration.webcirc_username
20
+ @password = Rspec.configuration.webcirc_password
21
+ @webcirc = Illiad::Webcirc.new(@url, @username, @password)
22
+ @webcirc.connect
23
+ end
24
+
25
+ it "should return true on success" do
26
+ @webcirc.charge!(91818).should == true
27
+ end
28
+ end
29
+
30
+ describe Illiad::Webcirc, "#discharge!" do
31
+ before(:all) do
32
+ @url = Rspec.configuration.webcirc_url
33
+ @username = Rspec.configuration.webcirc_username
34
+ @password = Rspec.configuration.webcirc_password
35
+ @webcirc = Illiad::Webcirc.new(@url, @username, @password)
36
+ @webcirc.connect
37
+ end
38
+
39
+ it "should return true on success" do
40
+ @webcirc.discharge!(91818).should == true
41
+ end
42
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: illiad
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.2
6
+ platform: ruby
7
+ authors:
8
+ - Brice Stacey
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-04-15 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :development
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: activerecord
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ type: :runtime
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: activerecord-sqlserver-adapter
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ type: :runtime
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
49
+ name: tiny_tds
50
+ prerelease: false
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ type: :runtime
58
+ version_requirements: *id004
59
+ description: ActiveRecord, webcirc, and other utilities for Illiad Interlibrary Loan
60
+ email:
61
+ - bricestacey@gmail.com
62
+ executables: []
63
+
64
+ extensions: []
65
+
66
+ extra_rdoc_files: []
67
+
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - Rakefile
72
+ - illiad.gemspec
73
+ - lib/illiad.rb
74
+ - lib/illiad/activerecord/base.rb
75
+ - lib/illiad/activerecord/transaction.rb
76
+ - lib/illiad/version.rb
77
+ - lib/illiad/webcirc.rb
78
+ - spec/spec_helper.rb
79
+ - spec/webcirc/connect_spec.rb
80
+ homepage: https://github.com/bricestacey/illiad
81
+ licenses: []
82
+
83
+ post_install_message:
84
+ rdoc_options: []
85
+
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: "0"
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: "0"
100
+ requirements: []
101
+
102
+ rubyforge_project: illiad
103
+ rubygems_version: 1.7.2
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: ActiveRecord, webcirc, and other utilities for Illiad Interlibrary Loan
107
+ test_files: []
108
+