nostos-source-illiad 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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 nostos-source-illiad.gemspec
4
+ gemspec
@@ -0,0 +1,32 @@
1
+ # Nostos Source Driver: Illiad
2
+
3
+ This is an Illiad source driver for Nostos.
4
+
5
+ See [Nostos](https://github.com/bricestacey/nostos) for more information.
6
+
7
+ ## Installation
8
+
9
+ Add the following to your Gemfile and run `bundle install`
10
+
11
+ gem 'nostos-source-illiad'
12
+
13
+ ## Configuration
14
+
15
+ In `config/application.rb` add the following options:
16
+
17
+ config.source_illiad.number_of_days_to_poll = 2
18
+ config.source_illiad.db = {
19
+ :dataserver => '',
20
+ :adapter => 'sqlserver',
21
+ :host => '',
22
+ :dsn => '',
23
+ :username => '',
24
+ :password => '',
25
+ :database => ''
26
+ }
27
+
28
+ `dataserver` is the name for your server as defined in freetds.conf. `number_of_days_to_poll` is how many days you want to poll into the past. This number must be greater than how often you run Nostos in order to stay synchronized. I recommend polling 2-3 days in the past at most.
29
+
30
+ # Author
31
+
32
+ Nostos was written by [Brice Stacey](https://github.com/bricestacey)
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,11 @@
1
+ # Extend Illiad::Transaction to map to a Source::Illiad object.
2
+ module Illiad
3
+ class Transaction
4
+ def to_record
5
+ Source::Illiad::Record.new(:id => read_attribute(:TransactionNumber),
6
+ :title => read_attribute(:LoanTitle),
7
+ :due_date => read_attribute(:DueDate),
8
+ :charged => charged?)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,56 @@
1
+ # Source::Illiad, Nostos Source Driver for Illiad
2
+
3
+ require 'nostos-source-illiad/railtie.rb'
4
+ require 'nostos-source-illiad/config.rb'
5
+ require 'nostos-source-illiad/record.rb'
6
+ require 'illiad/transaction.rb'
7
+ require 'activerecord-illiad-adapter'
8
+
9
+
10
+ # activerecord-illiad-adapter is named Illiad, so we must rename it to avoid
11
+ # naming conflict.
12
+ IlliadAR = Illiad
13
+
14
+ module Source
15
+ module Illiad
16
+ def self.config
17
+ @@config ||= Source::Illiad::Config.new
18
+ end
19
+
20
+ def self.configure
21
+ yield self.config
22
+ end
23
+
24
+ def self.find(id)
25
+ IlliadAR::Transaction.find(id).to_record
26
+ end
27
+
28
+ # Poll Illiad for new transactions to process. The strategy is to find
29
+ # all transactions that have had the status Customer Notified Via E-Mail
30
+ # within the past `number_of_days_old_transactions` days. We must join
31
+ # the Tracking table because a transaction theoretically could go from
32
+ # `Customer Notified Via E-Mail` to another status quicker than our
33
+ # processing runs.
34
+ def self.poll
35
+ # SQL to identify records as old as 60 days
36
+ sql = <<-SQL
37
+ SELECT
38
+ Tracking.TransactionNumber
39
+ , Username
40
+ , LoanTitle
41
+ , LoanAuthor
42
+ , DueDate
43
+ , TransactionStatus
44
+ FROM
45
+ Tracking
46
+ INNER JOIN Transactions ON Tracking.TransactionNumber = Transactions.TransactionNumber
47
+ WHERE
48
+ Tracking.ChangedTo = 'Customer Notified Via E-Mail' AND
49
+ Tracking.DateTime > CURRENT_TIMESTAMP - #{config.number_of_days_to_poll} AND
50
+ Transactions.RequestType = 'Loan'
51
+ SQL
52
+
53
+ IlliadAR::Transaction.find_by_sql(sql).map {|t| t.to_record}
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,7 @@
1
+ module Source
2
+ module Illiad
3
+ class Config
4
+ attr_accessor :number_of_days_to_poll, :db
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,21 @@
1
+ require 'rails'
2
+ require 'activerecord-illiad-adapter'
3
+
4
+ module Source
5
+ module Illiad
6
+ class Railtie < Rails::Railtie
7
+ config.source_illiad = ActiveSupport::OrderedOptions.new
8
+
9
+ initializer "source_illiad.configure" do |app|
10
+ Source::Illiad.configure do |config|
11
+ config.number_of_days_to_poll = app.config.source_illiad[:number_of_days_to_poll]
12
+ config.db = app.config.source_illiad[:db]
13
+ end
14
+ end
15
+
16
+ initializer "source_illiad.establish_connection", :after => "source_illiad.configure" do |app|
17
+ IlliadAR::Base.establish_connection(Source::Illiad.config.db)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,34 @@
1
+ module Source
2
+ module Illiad
3
+ class Record
4
+
5
+ def initialize(attributes = {})
6
+ @id = attributes[:id]
7
+ @title = attributes[:title]
8
+ @charged = attributes[:charged]
9
+ @due_date = attributes[:due_date]
10
+ end
11
+
12
+ attr_reader :id, :title, :due_date
13
+
14
+ def charged?(force = false)
15
+ if force then
16
+ t = IlliadAR::Transaction.find(@id)
17
+ @due_date = t.due_date
18
+ @charged = t.charged?
19
+ end
20
+
21
+ @charged
22
+ end
23
+
24
+ private
25
+
26
+ attr_reader :charged
27
+ attr_writer :id, :title, :due_date, :charged
28
+
29
+
30
+
31
+
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,5 @@
1
+ module Source
2
+ module Illiad
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "nostos-source-illiad/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "nostos-source-illiad"
7
+ s.version = Source::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/nostos-source-illiad"
12
+ s.summary = %q{Nostos Source Driver for Illiad}
13
+ s.description = %q{Nostos Source Driver for Illiad}
14
+
15
+ s.rubyforge_project = "nostos-source-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
+ s.add_dependency('activerecord-illiad-adapter')
22
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nostos-source-illiad
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Brice Stacey
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-04-12 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activerecord-illiad-adapter
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: :runtime
25
+ version_requirements: *id001
26
+ description: Nostos Source Driver for Illiad
27
+ email:
28
+ - bricestacey@gmail.com
29
+ executables: []
30
+
31
+ extensions: []
32
+
33
+ extra_rdoc_files: []
34
+
35
+ files:
36
+ - .gitignore
37
+ - Gemfile
38
+ - README.md
39
+ - Rakefile
40
+ - lib/illiad/transaction.rb
41
+ - lib/nostos-source-illiad.rb
42
+ - lib/nostos-source-illiad/config.rb
43
+ - lib/nostos-source-illiad/railtie.rb
44
+ - lib/nostos-source-illiad/record.rb
45
+ - lib/nostos-source-illiad/version.rb
46
+ - nostos-source-illiad.gemspec
47
+ homepage: https://github.com/bricestacey/nostos-source-illiad
48
+ licenses: []
49
+
50
+ post_install_message:
51
+ rdoc_options: []
52
+
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ requirements: []
68
+
69
+ rubyforge_project: nostos-source-illiad
70
+ rubygems_version: 1.7.2
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: Nostos Source Driver for Illiad
74
+ test_files: []
75
+