Class: WCAPI::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/wcapi/client.rb

Overview

The WCAPI::Client object provides a public facing interface to interacting with the various WorldCat API Grid Services.

client = WCAPI::Client.new :query => 'query', :format => [atom|rss], :start => [position], :count => [max records], :cformat => [mla|apa], :wskey => [your world cat key

options:

wskey

More information can be found at:

http://worldcat.org/devnet/wiki/SearchAPIDetails

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

The constructor which must be passed a valid base url for an oai service:

If you want to see debugging messages on STDERR use: :debug => true



26
27
28
29
# File 'lib/wcapi/client.rb', line 26

def initialize(options={})
  @debug = options[:debug]
  @wskey = options[:wskey]
end

Instance Method Details

#GetCitation(opts = {}) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/wcapi/client.rb', line 67

def GetCitation(opts = {})
 if opts[:type] == 'oclc'
     @base = URI.parse "http://www.worldcat.org/webservices/catalog/content/citations/" + opts[:id]
  else
     @base = URI.parse 'http://www.worldcat.org/webservices/catalog/content/citations/isbn/' + opts[:id]
  end
  opts.delete("type")
  opts["wskey"] = @wskey
  xml = do_request(opts)
  #Returns an HTML representation
  return xml
end

#GetLocations(opts = {}) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/wcapi/client.rb', line 55

def GetLocations(opts={})
   if opts[:type] == 'oclc'
     @base = URI.parse "http://www.worldcat.org/webservices/catalog/content/libraries/" + opts[:id]
  else
     @base = URI.parse 'http://www.worldcat.org/webservices/catalog/content/libraries/isbn/' + opts[:id]
  end
  opts.delete("type")
  opts["wskey"] = @wskey
  xml = do_request(opts)
  return GetLocationResponse.new(xml)
end

#GetRecord(opts = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/wcapi/client.rb', line 42

def GetRecord(opts={})
  if opts[:type] == 'oclc'
     @base = URI.parse "http://www.worldcat.org/webservices/catalog/content/" + opts[:id]
  else
	 @base = URI.parse 'http://www.worldcat.org/webservices/catalog/content/isbn/' + opts[:id]
  end
  opts.delete("type")
  opts["wskey"] = @wskey
  xml = do_request(opts)
  return GetRecordResponse.new(xml)
end

#OpenSearch(opts = {}) ⇒ Object

Equivalent to a Identify request. You’ll get back a OAI::IdentifyResponse object which is essentially just a wrapper around a REXML::Document for the response.



35
36
37
38
39
40
# File 'lib/wcapi/client.rb', line 35

def OpenSearch(opts={}) 
  @base = URI.parse WORLDCAT_OPENSEARCH
  opts["wskey"] = @wskey
  xml = do_request(opts)
  return OpenSearchResponse.new(xml)
end

#SRUSearch(opts = {}) ⇒ Object



80
81
82
83
84
85
# File 'lib/wcapi/client.rb', line 80

def SRUSearch(opts={})
  @base = URI.parse WORLDCAT_SRU
  opts["wskey"] = @wskey
  xml = do_request(opts)
  return SruSearchResponse.new(xml)
end