sip2 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/README.md +11 -1
- data/lib/sip2.rb +3 -0
- data/lib/sip2/connection.rb +28 -41
- data/lib/sip2/messages/login.rb +31 -0
- data/lib/sip2/messages/patron_information.rb +27 -0
- data/lib/sip2/version.rb +1 -1
- data/sip2.gemspec +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3b0916dbfd4d2c9b14716d3a245e249229a85a2
|
4
|
+
data.tar.gz: 4be89cf798d034635dbf3a330c54fb9d44640cd4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e6e118916e0f2ec98fd1f2d129b5b522201684b62f925908d3ecbcfc88bed2e688008171abd0a0c723c3d6f45e881496588dc3c8e2bb87a52956803680a2186
|
7
|
+
data.tar.gz: 9910a5f01b3c1696a292788ae01c68f83ffccb9f1acd4a2d8112973373f263660a646dc35f84b481f7f8094731472d3b09cba986de96ffc9bc29b499ea5aa1ef
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -26,7 +26,17 @@ $ bundle
|
|
26
26
|
|
27
27
|
## Usage
|
28
28
|
|
29
|
-
|
29
|
+
```ruby
|
30
|
+
client = Sip2::Client.new(host: 'my.sip2.host.net', port: 6001)
|
31
|
+
patron =
|
32
|
+
client.connect do |connection|
|
33
|
+
if connection.login 'sip_username', 'sip_password'
|
34
|
+
connection.patron_information 'patron_username', 'patron_password'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
puts 'Valid patron' if patron && patron.authenticated?
|
39
|
+
```
|
30
40
|
|
31
41
|
|
32
42
|
## Contributing
|
data/lib/sip2.rb
CHANGED
data/lib/sip2/connection.rb
CHANGED
@@ -3,36 +3,51 @@ module Sip2
|
|
3
3
|
# Sip2 Connection
|
4
4
|
#
|
5
5
|
class Connection
|
6
|
+
@connection_modules = []
|
7
|
+
|
8
|
+
class << self
|
9
|
+
attr_reader :connection_modules
|
10
|
+
|
11
|
+
def add_connection_module(module_name)
|
12
|
+
@connection_modules << module_name
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
include Messages::Login
|
17
|
+
include Messages::PatronInformation
|
18
|
+
|
6
19
|
def initialize(socket, ignore_error_detection)
|
7
20
|
@socket = socket
|
8
21
|
@ignore_error_detection = ignore_error_detection
|
9
22
|
@sequence = 1
|
10
23
|
end
|
11
24
|
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
|
25
|
+
def method_missing(method_name, *args)
|
26
|
+
if Connection.connection_modules.include?(method_name.to_sym)
|
27
|
+
send_and_handle_message(method_name, *args)
|
28
|
+
else
|
29
|
+
super
|
30
|
+
end
|
16
31
|
end
|
17
32
|
|
18
|
-
def
|
19
|
-
|
20
|
-
response = send_message patron_message
|
21
|
-
return unless sequence_and_checksum_valid?(response)
|
22
|
-
PatronInformation.new response
|
33
|
+
def respond_to_missing?(method_name, _include_private = false)
|
34
|
+
Connection.connection_modules.include?(method_name.to_sym) || super
|
23
35
|
end
|
24
36
|
|
25
37
|
private
|
26
38
|
|
39
|
+
def send_and_handle_message(message_type, *args)
|
40
|
+
message = send "build_#{message_type}_message", *args
|
41
|
+
message = with_checksum with_error_detection message
|
42
|
+
response = send_message message
|
43
|
+
send "handle_#{message_type}_response", response
|
44
|
+
end
|
45
|
+
|
27
46
|
def send_message(message)
|
28
47
|
@socket.send(message + "\r", 0)
|
29
48
|
@socket.gets "\r"
|
30
49
|
end
|
31
50
|
|
32
|
-
def with_error_detection_and_checksum(message)
|
33
|
-
with_checksum with_error_detection message
|
34
|
-
end
|
35
|
-
|
36
51
|
def with_error_detection(message)
|
37
52
|
message + '|AY' + @sequence.to_s
|
38
53
|
end
|
@@ -60,33 +75,5 @@ module Sip2
|
|
60
75
|
ensure
|
61
76
|
@sequence += 1
|
62
77
|
end
|
63
|
-
|
64
|
-
def build_login_message(username, password, location_code)
|
65
|
-
code = '93' # Login
|
66
|
-
uid_algorithm = pw_algorithm = '0' # Plain text
|
67
|
-
username_field = 'CN' + username
|
68
|
-
password_field = 'CO' + password
|
69
|
-
location_code = location_code.strip if location_code.is_a? String
|
70
|
-
location_field = location_code ? "|CP#{location_code}" : ''
|
71
|
-
|
72
|
-
message = [
|
73
|
-
code, uid_algorithm, pw_algorithm, username_field, '|', password_field, location_field
|
74
|
-
].join
|
75
|
-
|
76
|
-
with_error_detection_and_checksum message
|
77
|
-
end
|
78
|
-
|
79
|
-
def login_successful?(response)
|
80
|
-
sequence_and_checksum_valid?(response) && response[/^94([01])AY/, 1] == '1'
|
81
|
-
end
|
82
|
-
|
83
|
-
def build_patron_message(uid, password)
|
84
|
-
code = '63' # Patron information
|
85
|
-
language = '000' # Unknown
|
86
|
-
timestamp = Time.now.strftime('%Y%m%d %H%M%S')
|
87
|
-
summary = ' ' * 10
|
88
|
-
message = "#{code}#{language}#{timestamp}#{summary}AO|AA#{uid}|AC|AD#{password}"
|
89
|
-
with_error_detection_and_checksum message
|
90
|
-
end
|
91
78
|
end
|
92
79
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Sip2
|
2
|
+
module Messages
|
3
|
+
#
|
4
|
+
# Sip2 Login message module
|
5
|
+
#
|
6
|
+
module Login
|
7
|
+
def self.included(klass)
|
8
|
+
klass.add_connection_module :login
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def build_login_message(username, password, location_code = nil)
|
14
|
+
code = '93' # Login
|
15
|
+
uid_algorithm = pw_algorithm = '0' # Plain text
|
16
|
+
username_field = 'CN' + username
|
17
|
+
password_field = 'CO' + password
|
18
|
+
location_code = location_code.strip if location_code.is_a? String
|
19
|
+
location_field = location_code ? "|CP#{location_code}" : ''
|
20
|
+
|
21
|
+
[
|
22
|
+
code, uid_algorithm, pw_algorithm, username_field, '|', password_field, location_field
|
23
|
+
].join
|
24
|
+
end
|
25
|
+
|
26
|
+
def handle_login_response(response)
|
27
|
+
sequence_and_checksum_valid?(response) && response[/^94([01])AY/, 1] == '1'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Sip2
|
2
|
+
module Messages
|
3
|
+
#
|
4
|
+
# Sip2 Patron information message module
|
5
|
+
#
|
6
|
+
module PatronInformation
|
7
|
+
def self.included(klass)
|
8
|
+
klass.add_connection_module :patron_information
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def build_patron_information_message(uid, password)
|
14
|
+
code = '63' # Patron information
|
15
|
+
language = '000' # Unknown
|
16
|
+
timestamp = Time.now.strftime('%Y%m%d %H%M%S')
|
17
|
+
summary = ' ' * 10
|
18
|
+
[code, language, timestamp, summary, 'AO|AA', uid, '|AC|AD', password].join
|
19
|
+
end
|
20
|
+
|
21
|
+
def handle_patron_information_response(response)
|
22
|
+
return unless sequence_and_checksum_valid?(response)
|
23
|
+
Sip2::PatronInformation.new response
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/sip2/version.rb
CHANGED
data/sip2.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
|
22
|
-
spec.required_ruby_version = '>= 2.
|
22
|
+
spec.required_ruby_version = '>= 2.1.0'
|
23
23
|
|
24
24
|
spec.add_development_dependency 'bundler', '~> 1.11'
|
25
25
|
spec.add_development_dependency 'rake', '~> 10.0'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sip2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- abrom
|
@@ -97,6 +97,8 @@ files:
|
|
97
97
|
- lib/sip2.rb
|
98
98
|
- lib/sip2/client.rb
|
99
99
|
- lib/sip2/connection.rb
|
100
|
+
- lib/sip2/messages/login.rb
|
101
|
+
- lib/sip2/messages/patron_information.rb
|
100
102
|
- lib/sip2/non_blocking_socket.rb
|
101
103
|
- lib/sip2/patron_information.rb
|
102
104
|
- lib/sip2/version.rb
|
@@ -113,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
113
115
|
requirements:
|
114
116
|
- - ">="
|
115
117
|
- !ruby/object:Gem::Version
|
116
|
-
version: 2.
|
118
|
+
version: 2.1.0
|
117
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
120
|
requirements:
|
119
121
|
- - ">="
|