Sha256: aeeab92bd4780b9810273c04ceb794351070e831710751884877e759916d27bd

Contents?: true

Size: 1.13 KB

Versions: 17

Compression:

Stored size: 1.13 KB

Contents

# -*- encoding: utf-8 -*-
class NdlBook
  def self.search(query, page = 1, per_page = self.per_page)
    if query
      cnt = self.per_page
      page = 1 if page.to_i < 1
      idx = (page.to_i - 1) * cnt + 1
      doc = Nokogiri::XML(Manifestation.search_ndl(query, {:cnt => cnt, :page => page, :idx => idx, :raw => true}).to_s)
      items = doc.xpath('//channel/item')
      total_entries = doc.at('//channel/openSearch:totalResults').content.to_i

      {:items => items, :total_entries => total_entries}
    else
      {:items => [], :total_entries => 0}
    end
  end

  def self.per_page
    10
  end

  def self.import_from_sru_response(jpno)
    manifestation = Manifestation.where(:nbn => jpno).first
    return if manifestation
    url = "http://iss.ndl.go.jp/api/sru?operation=searchRetrieve&recordSchema=dcndl&&maximumRecords=1&&query=%28jpno=#{jpno}%29"
    xml = open(url).read
    response = Nokogiri::XML(xml).at('//xmlns:recordData')
    return unless response.try(:content)
    doc = Nokogiri::XML(response.content)
    Manifestation.import_record(doc)
  end

  attr_accessor :url

  class AlreadyImported < StandardError
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
enju_ndl-0.0.35 app/models/ndl_book.rb
enju_ndl-0.0.34 app/models/ndl_book.rb
enju_ndl-0.0.33 app/models/ndl_book.rb
enju_ndl-0.0.32 app/models/ndl_book.rb
enju_ndl-0.0.31 app/models/ndl_book.rb
enju_ndl-0.0.30 app/models/ndl_book.rb
enju_ndl-0.0.29 app/models/ndl_book.rb
enju_ndl-0.0.27 app/models/ndl_book.rb
enju_ndl-0.0.26 app/models/ndl_book.rb
enju_ndl-0.0.25 app/models/ndl_book.rb
enju_ndl-0.0.24 app/models/ndl_book.rb
enju_ndl-0.0.23 app/models/ndl_book.rb
enju_ndl-0.0.22 app/models/ndl_book.rb
enju_ndl-0.0.21 app/models/ndl_book.rb
enju_ndl-0.0.20 app/models/ndl_book.rb
enju_ndl-0.0.19 app/models/ndl_book.rb
enju_ndl-0.0.18 app/models/ndl_book.rb