nostos-source-illiad 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/illiad/transaction.rb +8 -6
- data/lib/nostos-source-illiad.rb +3 -3
- data/lib/nostos-source-illiad/config.rb +1 -1
- data/lib/nostos-source-illiad/railtie.rb +2 -2
- data/lib/nostos-source-illiad/record.rb +34 -5
- data/lib/nostos-source-illiad/version.rb +1 -1
- data/nostos-source-illiad.gemspec +3 -1
- metadata +14 -3
data/lib/illiad/transaction.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
# Extend Illiad::Transaction to map to a Source::Illiad object.
|
2
2
|
module Illiad
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
module AR
|
4
|
+
class Transaction
|
5
|
+
def to_record
|
6
|
+
Source::Illiad::Record.new(:id => read_attribute(:TransactionNumber),
|
7
|
+
:title => read_attribute(:LoanTitle),
|
8
|
+
:due_date => read_attribute(:DueDate),
|
9
|
+
:charged => charged?)
|
10
|
+
end
|
9
11
|
end
|
10
12
|
end
|
11
13
|
end
|
data/lib/nostos-source-illiad.rb
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
require 'nostos-source-illiad/railtie.rb'
|
4
4
|
require 'nostos-source-illiad/config.rb'
|
5
5
|
require 'nostos-source-illiad/record.rb'
|
6
|
+
require 'illiad'
|
6
7
|
require 'illiad/transaction.rb'
|
7
|
-
require 'activerecord-illiad-adapter'
|
8
8
|
|
9
9
|
|
10
10
|
# activerecord-illiad-adapter is named Illiad, so we must rename it to avoid
|
@@ -22,7 +22,7 @@ module Source
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def self.find(id)
|
25
|
-
IlliadAR::Transaction.find(id).to_record
|
25
|
+
IlliadAR::AR::Transaction.find(id).to_record
|
26
26
|
end
|
27
27
|
|
28
28
|
# Poll Illiad for new transactions to process. The strategy is to find
|
@@ -50,7 +50,7 @@ module Source
|
|
50
50
|
Transactions.RequestType = 'Loan'
|
51
51
|
SQL
|
52
52
|
|
53
|
-
IlliadAR::Transaction.find_by_sql(sql).map {|t| t.to_record}
|
53
|
+
IlliadAR::AR::Transaction.find_by_sql(sql).map {|t| t.to_record}
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'rails'
|
2
|
-
require 'activerecord-illiad-adapter'
|
3
2
|
|
4
3
|
module Source
|
5
4
|
module Illiad
|
@@ -10,11 +9,12 @@ module Source
|
|
10
9
|
Source::Illiad.configure do |config|
|
11
10
|
config.number_of_days_to_poll = app.config.source_illiad[:number_of_days_to_poll]
|
12
11
|
config.db = app.config.source_illiad[:db]
|
12
|
+
config.webcirc = app.config.source_illiad[:webcirc]
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
initializer "source_illiad.establish_connection", :after => "source_illiad.configure" do |app|
|
17
|
-
IlliadAR::Base.establish_connection(Source::Illiad.config.db)
|
17
|
+
IlliadAR::AR::Base.establish_connection(Source::Illiad.config.db)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'mechanize'
|
2
|
+
|
1
3
|
module Source
|
2
4
|
module Illiad
|
3
5
|
class Record
|
@@ -13,7 +15,7 @@ module Source
|
|
13
15
|
|
14
16
|
def charged?(force = false)
|
15
17
|
if force then
|
16
|
-
t = IlliadAR::Transaction.find(@id)
|
18
|
+
t = IlliadAR::AR::Transaction.find(@id)
|
17
19
|
@due_date = t.due_date
|
18
20
|
@charged = t.charged?
|
19
21
|
end
|
@@ -21,14 +23,41 @@ module Source
|
|
21
23
|
@charged
|
22
24
|
end
|
23
25
|
|
26
|
+
def charge!
|
27
|
+
# Create a new mechanize object
|
28
|
+
agent = Mechanize.new# { |a| a.log = Logger.new(STDERR) }
|
29
|
+
|
30
|
+
# Load Illiad Web Circulation
|
31
|
+
page = agent.get(Source::Illiad.config.webcirc[:url])
|
32
|
+
|
33
|
+
# Select, fill in, and submit the logon form.
|
34
|
+
page = page.form('formLogon') do |f|
|
35
|
+
f.TextBoxUsername = Source::Illiad.config.webcirc[:username]
|
36
|
+
f.TextBoxPassword = Source::Illiad.config.webcirc[:password]
|
37
|
+
end.click_button
|
38
|
+
|
39
|
+
# Mechanize::ResponseCodeError - 500 => Net::HTTPInternalServerError:
|
40
|
+
# catch these and try again.
|
41
|
+
page = page.form('aspnetForm') do |f|
|
42
|
+
f['ctl00$TextBoxCheckOutTransaction'] = @id
|
43
|
+
end.click_button
|
44
|
+
|
45
|
+
if !page.at("#ctl00_UpdatePanelStatusMessages .success").nil?
|
46
|
+
type = 'success'
|
47
|
+
elsif !page.at("#ctl00_UpdatePanelStatusMessages .warning").nil?
|
48
|
+
type = 'failure'
|
49
|
+
else
|
50
|
+
type = 'error'
|
51
|
+
end
|
52
|
+
|
53
|
+
puts "#{@id} - #{@title}"
|
54
|
+
puts page.at("#ctl00_UpdatePanelStatusMessages .failure, #ctl00_UpdatePanelStatusMessages .success, #ctl00_UpdatePanelStatusMessages .warning").inner_html
|
55
|
+
end
|
56
|
+
|
24
57
|
private
|
25
58
|
|
26
59
|
attr_reader :charged
|
27
60
|
attr_writer :id, :title, :due_date, :charged
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
61
|
end
|
33
62
|
end
|
34
63
|
end
|
@@ -18,5 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
20
|
s.require_paths = ["lib"]
|
21
|
-
|
21
|
+
|
22
|
+
s.add_dependency('illiad')
|
23
|
+
s.add_dependency('mechanize')
|
22
24
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: nostos-source-illiad
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Brice Stacey
|
@@ -10,10 +10,10 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-04-
|
13
|
+
date: 2011-04-15 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
16
|
+
name: illiad
|
17
17
|
prerelease: false
|
18
18
|
requirement: &id001 !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
@@ -23,6 +23,17 @@ dependencies:
|
|
23
23
|
version: "0"
|
24
24
|
type: :runtime
|
25
25
|
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: mechanize
|
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
|
26
37
|
description: Nostos Source Driver for Illiad
|
27
38
|
email:
|
28
39
|
- bricestacey@gmail.com
|