dsx-dml 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 985e1ae81c22db93542c4c73d9d889c6e859f40a
4
+ data.tar.gz: 912e303900bc2b98fb45c97ac3b7af5bd32f1333
5
+ SHA512:
6
+ metadata.gz: 3aea101507cd4b8bea450195093618bbd9a9c7cf8e89bf9f174d9bbfd3c36f84012670ddea1795783c3780d1447883dc597e7687fb8feabe1ed49b1b1ff2f2a5
7
+ data.tar.gz: 0b65ced27ae8560f9780f3bb8938476cc7ad19b41457cd170943ce508b06c9df47ded046928441811e2d4af0bad8fa5591b78834a3de372b9a56c1d0d3366f5b
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in amerx-dml.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 dgsan
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,79 @@
1
+ # DSX::Dml
2
+
3
+ Provides tools to ease working with the DSX DML command syntax, an archaic and obnoxious format used by DSX Access systems' SFTP APIs for making changes to records in their access control system's database(s).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'dsx-dml'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install dsx-dml
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ require 'dsx/dml'
23
+
24
+
25
+ # Declare what Location Number (zone) to make changes in and set the UDF field for UID string
26
+
27
+ zone = Dsx::Dml::Zone.new(1111, 2)
28
+
29
+
30
+ # Use a unique identifier to create a changeset for that unique identifier
31
+
32
+ changeset_0 = zone.use('123456789100')
33
+
34
+
35
+ # Chain together changes for tables related to that unique identifier
36
+
37
+ changeset_0.table('Names').write({
38
+ FName: 'Harry',
39
+ LName: 'Bird',
40
+ Company: 'Harry Bird Co',
41
+ Visitor: '',
42
+ Trace: '',
43
+ Notes: 'Often wears bowties'
44
+ }).table('UDF').write({
45
+ UdfNum: 2,
46
+ UdfText: number
47
+ }).table('Cards').write({
48
+ Code: '123456789100',
49
+ PIN: 1234,
50
+ StartDate: '01/01/2001',
51
+ StopDate: '11/11/2111',
52
+ NumUses: 9999
53
+ })
54
+
55
+
56
+ # create another changeset for a different unique identifier
57
+
58
+ changeset_1 = zone.use('123456789101')
59
+
60
+ changeset_1.table('Cards').add_acl('Parking Garage')
61
+
62
+
63
+ # Push changesets to SFTP receiver
64
+
65
+ changeset_0.net_sftp({address: '127.0.0.1', user: 'dsx_user', password: 'dsx_password' })
66
+ changeset_1.curl({address: '127.0.0.1', user: 'dsx_user', password: 'dsx_password' })
67
+
68
+
69
+ ```
70
+
71
+
72
+
73
+ ## Contributing
74
+
75
+ 1. Fork it
76
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
77
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
78
+ 4. Push to the branch (`git push origin my-new-feature`)
79
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dsx/dml/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dsx-dml"
8
+ spec.version = Dsx::Dml::VERSION
9
+ spec.authors = ["dgsan"]
10
+ spec.email = ["dgsan@server.fake"]
11
+ spec.description = "Provides tools to ease working with the DSX Access Systems DML command syntax, an archaic and obnoxious format used by DSX Access Systems' SFTP APIs for making changes to records in their WinDSX SQL access control system's database(s)."
12
+ spec.summary = "Ease communication with DSX Access Systems' SFTP 'API.'"
13
+ spec.homepage = "https://github.com/dgsan/dsx-dml"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec", "~> 2.14"
24
+
25
+ spec.add_runtime_dependency "net-sftp", "~> 2.1"
26
+
27
+ end
@@ -0,0 +1,208 @@
1
+ require 'dsx/dml/version'
2
+ require 'net/sftp'
3
+ require 'securerandom'
4
+ require 'tmpdir'
5
+ require 'tempfile'
6
+
7
+ module Dsx
8
+ module Dml
9
+
10
+ class Zone
11
+
12
+ def initialize(location_num, udf_field_num)
13
+ @location_num = location_num
14
+ @udf_field_num = udf_field_num
15
+ end
16
+
17
+ def use(id_num)
18
+ return Changeset.new(self, id_num)
19
+ end
20
+
21
+ def location_num
22
+ @location_num
23
+ end
24
+
25
+ def udf_field_num
26
+ @udf_field_num
27
+ end
28
+
29
+ end
30
+
31
+
32
+ class Changeset
33
+
34
+ def initialize(zone, id_num)
35
+ @id_num = id_num
36
+ @zone = zone
37
+ @stack = []
38
+ start_command
39
+ end
40
+
41
+ def table(table_name)
42
+ case table_name
43
+ when 'Cards'
44
+ return Cards.new(self, table_name)
45
+ when 'Names'
46
+ return Names.new(self, table_name)
47
+ else
48
+ return Table.new(self, table_name)
49
+ end
50
+ end
51
+
52
+ # Their system won't work correctly with \n, but will with \r.
53
+ # It'd also be possible to change the record separator, but that seems like a worse idea.
54
+ def to_string
55
+ @stack.join("\r")
56
+ end
57
+
58
+ # params: {address: server_address, user: user, password: password}
59
+ def net_sftp(params)
60
+ Net::SFTP::start(params[:address], params[:user], :password => params[:password]) do |sftp|
61
+ sftp.file.open("/^Imp_Bio5_#{Time.now.utc.to_i}_#{SecureRandom::hex(4)}.txt", 'w') do |file|
62
+ file.write to_string
63
+
64
+ end
65
+ end
66
+ return self
67
+ end
68
+
69
+ # Alternative to Net::SFTP.
70
+ def curl(params)
71
+ Dir.mktmpdir do |tmpdir|
72
+ file = Tempfile.new(["^Imp_Bio5_#{Time.now.utc.to_i}_", '.txt'], tmpdir)
73
+ file.write to_string
74
+ file.close()
75
+ result = `curl -s -S -u #{params[:user]}:#{params[:password]} -T #{file.path} -w "okay\n" sftp://#{params[:address]}/`
76
+ file.unlink()
77
+ end
78
+ return self
79
+ end
80
+
81
+ def stack
82
+ @stack
83
+ end
84
+
85
+ private
86
+
87
+ def start_command
88
+ @stack << "I L#{@zone.location_num} U#{@zone.udf_field_num} ^#{@id_num}^^^"
89
+ end
90
+
91
+ end
92
+
93
+
94
+ class Table
95
+
96
+ def initialize(changeset, table_name)
97
+ @changeset = changeset
98
+ @table_name = table_name
99
+ @changeset.stack << "T #{@table_name}"
100
+ end
101
+
102
+ def table(table_name)
103
+ @changeset.table(table_name)
104
+ end
105
+
106
+ def done
107
+ @changeset
108
+ end
109
+
110
+ def batch
111
+ @changeset
112
+ end
113
+
114
+ def net_sftp(params)
115
+ @changeset.net_sftp(params)
116
+ end
117
+
118
+ def curl(params)
119
+ @changeset.curl(params)
120
+ end
121
+
122
+ def write(data)
123
+ fields(data)
124
+ @changeset.stack << 'W'
125
+ return self
126
+ end
127
+
128
+ def update(data)
129
+ fields(data)
130
+ @changeset.stack << 'U'
131
+ return self
132
+ end
133
+
134
+ def delete
135
+ fields(data)
136
+ @changeset.stack << 'D'
137
+ return self
138
+ end
139
+
140
+ private
141
+
142
+ def fields(hash)
143
+ hash.each { |k,v| single(k,v) }
144
+ end
145
+
146
+ def blank(command)
147
+ single(command, '')
148
+ end
149
+
150
+ def single(command, val)
151
+ @changeset.stack << "F #{command} ^#{val}^^^"
152
+ return self
153
+ end
154
+
155
+ end
156
+
157
+
158
+ class Cards < Table
159
+
160
+ def relace_code(code)
161
+ single('ReplaceCode', code)
162
+ end
163
+
164
+ def copy_to_code(code)
165
+ single('Copy2Code', code)
166
+ end
167
+
168
+ def add_acl(acl)
169
+ single('AddAcl', acl)
170
+ end
171
+
172
+ def add_tmp_acl(acl)
173
+ single('AddTempAcl', acl)
174
+ end
175
+
176
+ def del_acl(acl)
177
+ single('DelAcl', acl)
178
+ end
179
+
180
+ def del_tmp_acl(acl)
181
+ single('DelTempAcl', acl)
182
+ end
183
+
184
+ def clear_all_acl
185
+ blank('ClearTempAcl')
186
+ end
187
+
188
+ def clear_all_tmp_acl
189
+ blank('ClearTempAcl')
190
+ end
191
+
192
+ def copy_perm_to_tmp
193
+ blank('CopyPerm2Temp')
194
+ end
195
+
196
+ end
197
+
198
+
199
+ class Names < Table
200
+
201
+ def dc
202
+ @changeset.stack << 'DC'
203
+ end
204
+
205
+ end
206
+
207
+ end
208
+ end
@@ -0,0 +1,5 @@
1
+ module Dsx
2
+ module Dml
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,45 @@
1
+ require 'dsx/dml'
2
+ require 'securerandom'
3
+
4
+ describe Dsx::Dml do
5
+ describe "Creating a changset string" do
6
+
7
+ name = 'test_' + SecureRandom::hex(4)
8
+ number = rand(10000000000..99999999999)
9
+ zone = Dsx::Dml::Zone.new(130, 2)
10
+
11
+ changeset = zone.use(number)
12
+
13
+ changeset.table('Names').write({
14
+ FName: name,
15
+ LName: name + "_L",
16
+ Company: 'Bio5',
17
+ Visitor: '',
18
+ Trace: '',
19
+ Notes: ''
20
+ }).table('UDF').write({
21
+ UdfNum: 2,
22
+ UdfText: number
23
+ }).table('Cards').write({
24
+ Code: number,
25
+ PIN: 1234,
26
+ StartDate: '09/15/2013',
27
+ StopDate: '04/11/2023',
28
+ NumUses: 9999
29
+ })
30
+
31
+ changeset_string = changeset.to_string
32
+
33
+ it "Should use DML compatible newlines" do
34
+ changeset_string.should include("\r")
35
+ changeset_string.should_not include("\n")
36
+ end
37
+
38
+ it "Should have some properly formatted fields and values" do
39
+ changeset_string.should include("^#{name}^^^")
40
+ changeset_string.should include("^#{number}^^^")
41
+ changeset_string.should include("\rF UdfNum ^2^^^\r")
42
+ end
43
+
44
+ end
45
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dsx-dml
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - dgsan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '2.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.14'
55
+ - !ruby/object:Gem::Dependency
56
+ name: net-sftp
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '2.1'
69
+ description: Provides tools to ease working with the DSX Access Systems DML command
70
+ syntax, an archaic and obnoxious format used by DSX Access Systems' SFTP APIs for
71
+ making changes to records in their WinDSX SQL access control system's database(s).
72
+ email:
73
+ - dgsan@server.fake
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - .gitignore
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - dsx-dml.gemspec
84
+ - lib/dsx/dml.rb
85
+ - lib/dsx/dml/version.rb
86
+ - spec/dsx/dml_spec.rb
87
+ homepage: https://github.com/dgsan/dsx-dml
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.0.7
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Ease communication with DSX Access Systems' SFTP 'API.'
111
+ test_files:
112
+ - spec/dsx/dml_spec.rb