Module: Target::Voyager

Defined in:
lib/nostos-target-voyager.rb,
lib/nostos-target-voyager/config.rb,
lib/nostos-target-voyager/record.rb,
lib/nostos-target-voyager/railtie.rb,
lib/nostos-target-voyager/version.rb

Defined Under Namespace

Classes: Config, Railtie, Record

Constant Summary collapse

VERSION =
"0.0.4"

Class Method Summary collapse

Class Method Details

.chargedObject



85
86
87
88
89
90
91
92
# File 'lib/nostos-target-voyager.rb', line 85

def self.charged
  ::Voyager::AR::Item.joins(:circ_transaction).includes(:circ_transaction, :bib_text, :barcode).where(:item_type_id => 24).all.map do |item|
    Target::Voyager::Record.new(:id => item.barcode.item_barcode,
                                :title => item.bib_item.bib_text.title,
                                :due_date => item.circ_transaction.current_due_date,
                                :charged => !item.circ_transaction.nil?)
  end
end

.configObject



9
10
11
# File 'lib/nostos-target-voyager.rb', line 9

def self.config
  @@config ||= Target::Voyager::Config.new
end

.configure {|self.config| ... } ⇒ Object

Yields:



13
14
15
# File 'lib/nostos-target-voyager.rb', line 13

def self.configure
  yield self.config
end

.create(item = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
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
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/nostos-target-voyager.rb', line 33

def self.create(item = {})
  return nil if item.id.nil? || item.title.nil?

  # Check if the item already exists.
  if ::Voyager::AR::Item::Barcode.where(:item_barcode => item.id.to_s).exists?
    item_barcode = ::Voyager::AR::Item::Barcode.includes(:item => [:circ_transaction, :bib_text]).where(:item_barcode => item.id.to_s).first
    return Target::Voyager::Record.new(:id => item_barcode.item_barcode,
                                :title => item_barcode.item.bib_text.title,
                                :due_date => item_barcode.item.circ_transaction.try(:current_due_date),
                                :charged => !item_barcode.item.circ_transaction.nil?)
  end

  # Title should truncate to 32 characters and append "/ *12345*"
  title = "#{item.title[0..31]} / *#{item.id}*"

  # Illiad encodes strings in Windows-1252, but Voyager SIP requires all messages be ASCII.
  if item.class.to_s == 'Source::Illiad'
    title = Iconv.iconv('ASCII//IGNORE', 'Windows-1252', title).join
  end
  # Illiad encodes strings in Windows-1252, but Voyager SIP requires all messages be ASCII.

  ::Voyager::SIP::Client.new(config.sip["host"], config.sip["port"]) do |sip|
    sip.(config.sip["username"], config.sip["password"], config.sip["location"]) do |response|
      # First be sure that an item doesn't already exist.
      sip.item_status(item.id) do |item_status|
        unless item_status[:AF] == 'Item barcode not found.  Please consult library personnel for assistance.'
          # Item already exists
          # This should pretty much never happen since we check above for existence.
          return Target::Voyager::Record.new(:id => item.id,
                                             :title => item_status[:AJ],
                                             :due_date => item_status[:AH],
                                             :charged => !item_status[:AH].empty?)
        else
          # Item doesn't exist
          sip.create_bib(config.sip["operator"], title, item.id) do |response|
            # Bib/MFHD/Item created. Store values.
            #
            # Values must be stored in order to delete the items via SIP.
            # Note: Voyager does not return mfhd_id.
            Rails::logger.info "Successfully created item with barcode #{item.id}"
            return Target::Voyager::Record.new(:id => item.id,
                                               :title => title,
                                               :due_date => nil,
                                               :charged => false)
          end
        end
      end
    end
  end
  nil
end

.find(id) ⇒ Object

Target Interface



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/nostos-target-voyager.rb', line 18

def self.find(id)
  id = id.to_s unless id.is_a?(String)

  item_barcode = ::Voyager::AR::Item::Barcode.includes(:item => [:circ_transaction, :bib_text]).where(:item_barcode => id).first

  if item_barcode
    Target::Voyager::Record.new(:id => item_barcode.item_barcode,
                                :title => item_barcode.item.bib_text.title,
                                :due_date => item_barcode.item.circ_transaction.try(:current_due_date),
                                :charged => !item_barcode.item.circ_transaction.nil?)
  else
    nil
  end
end