Sha256: 72130245c40b57a10cb212aeb90f3ad47fc1248752dcf63e4071f91532593834

Contents?: true

Size: 625 Bytes

Versions: 1

Compression:

Stored size: 625 Bytes

Contents

require 'open-uri'

module Ndl
  class OpenSearch
    def initialize
      @url = "http://iss.ndl.go.jp/api/opensearch?"
    end
    def search(*query)
      # delete query that don't have value
      query = query[0].delete_if{|k,v|v==''}
      # make url for ndl-opensearch-api
      query.each_with_index do |(k,v), i|
        @url += "#{k}=#{v}"
        @url += "&" if (i != query.size-1)
      end
      # return #StringIO or #Tempfile via gem 'open-uri'
      # about 'open-uri', please refer to http://docs.ruby-lang.org/ja/2.1.0/library/open=2duri.html
      result = open(@url)
      return result
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ndl-0.1.1 lib/ndl/opensearch.rb