Class: Voyager::SIP::Client

Inherits:
Object
  • Object
show all
Includes:
BasicSipClient
Defined in:
lib/voyager/sip/client.rb

Constant Summary

Constants included from BasicSipClient

BasicSipClient::TIMESTAMP_FORMAT, BasicSipClient::VERBOSE

Instance Method Summary collapse

Methods included from BasicSipClient

#close, #initialize, #recv, #send

Instance Method Details

#create_bib(operator, title, barcode) ⇒ Object

– Sends a Create Bib Message

Example create bib request:

8120100813    133505AO|MFSelfchk|AJThe transformation of learning : / *77087*|AB77087|AC|^M

Example create bib response:

821MJ633124|MA630995|AFCreate Bib successful.|^M

++



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/voyager/sip/client.rb', line 46

def create_bib(operator, title, barcode)
  msg = "81#{self.timestamp}|AO|MF#{operator}|AJ#{title}|AB#{barcode}|AC|"

  send(msg) do |response|
    response = parse_create_bib(response)

    # Bib/MFHD/Item create failed
    raise "Bib/MFHD/Item create failed: #{response['raw']}" if response[:ok] == '0'

    # Bib was created, but not the item
    #
    # This is possible if we have a duplicate barcode, however we
    # check for that. Possible race condition, though unlikely.
    #
    # Store the bib_id for troubleshooting
    raise "Duplicate barcode. A bib exists without an item and should be deleted: #{response['raw']}" if response[:item_id].empty?


    if block_given?
      yield response
    end

    response
  end
end

#item_status(item_identifier) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/voyager/sip/client.rb', line 90

def item_status(item_identifier)
  msg = "17#{self.timestamp}|AO|AB#{item_identifier}|AC|"

  send(msg) do |response|
    response = parse_item_status(response)

    if block_given?
      yield response
    end

    response
  end
end

#login(username, password, location) ⇒ Object

– Sends a Login Message

Example login request:

9300CNusername|COpassword|CPCIRC|

Example login response:

941

++



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/voyager/sip/client.rb', line 13

def (username, password, location)
  msg = "9300CN#{username}|CO#{password}|CP#{location}|\r"

  send(msg) do |response|
    response = (response)

    raise "Invalid login: #{response[:raw]}" unless response[:ok] == '1'

    if block_given?
      yield response
    end

    response
  end
end

#parse_create_bib(msg) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/voyager/sip/client.rb', line 72

def parse_create_bib(msg)
  # 821MJ640267|MA818432|AFCreate Bib successful.|
  # [2] - OK? 1:yes, 0:no
  # MJ - Item number
  # MA - Bib number
  # AF - Print screen
  match = msg.match(/^82(.)MJ(.*)\|MA(.*)\|AF(.*)\|\r$/)
  if match
    {:raw => msg,
     :id => 82,
     :ok => match[1],
     :item_id => match[2],
     :bib_id => match[3],
     :print_msg => match[4]
    }
  end
end

#parse_item_status(msg) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/voyager/sip/client.rb', line 104

def parse_item_status(msg)
  # 1803000120110408    150732CF0|AH|CJ|AB96917|AJBokml - Test for Nostos *96917*|BGHealey_Library|AQCirculation Desk|AFItem Info retrieved successfully.|
  match = msg.match(/^18([0-9]{2})([0-9]{2})([0-9]{2})(.{18})(.*)\r$/)
  # 1 - Circulation Status
  # 2 - Security Marker
  # 3 - Fee Type
  # 4 - Transaction Date
  # 5 - Variable Fields
  var_fields = msg.scan(/([A-Z]{2})([^|]*)\|/)
  if match
    r = {:raw => msg,
         :id => 18,
         :circ_status => match[1],
         :security_marker => match[2],
         :fee_type => match[3],
         :transaction_date => match[4],
    }
    var_fields.each do |field|
      r[field.first.to_sym] = field.last
    end
    r
  end
end

#parse_login(msg) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/voyager/sip/client.rb', line 29

def (msg)
  match = msg.match(/^94(0|1)\r$/)
  if match
    {:raw => msg,
     :id => 94,
     :ok => match[1]}
  end
end

#timestampObject

Utilities



129
130
131
# File 'lib/voyager/sip/client.rb', line 129

def timestamp
  Time.now.strftime("%Y%m%d    %H%M%S")
end