Class: WCKBAPI::Client
- Inherits:
-
Object
- Object
- WCKBAPI::Client
- Defined in:
- lib/wckbapi/client.rb
Overview
The WCKBAPI::Client object provides a public facing interface to interacting with the WorldCat Knowledgebank API
client = WCKBAPI::Client.new :wskey => [your world cat key], :debug => true|false, :institution_id => [your institution id]
options:
wskey
More information can be found at:
http://worldcat.org/devnet/wiki/SearchAPIDetails
Instance Method Summary collapse
- #GetCollectionInfo(opts = {}) ⇒ Object
-
#GetEntry(opts = {}) ⇒ Object
def OpenSearch(opts={}) @base = URI.parse WORLDCAT_OPENSEARCH opts = @wskey xml = do_request(opts) return OpenSearchResponse.new(xml) end.
- #GetProviderInfo(opts = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
The constructor which must be passed a valid base url for an oai service:.
- #SearchCollections(opts = {}) ⇒ Object
- #SearchEntries(opts = {}) ⇒ Object
- #SearchProviders(opts = {}) ⇒ Object
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 30 |
# File 'lib/wckbapi/client.rb', line 26 def initialize(={}) @debug = [:debug] @wskey = [:wskey] @institution_id = [:institution_id] end |
Instance Method Details
#GetCollectionInfo(opts = {}) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/wckbapi/client.rb', line 153 def GetCollectionInfo(opts={}) opts[:wskey] = @wskey opts[:alt] = 'json' if opts[:type] == nil if opts[:institution_id] != nil @base = URI.parse WORLDCAT_KB_URL + "collections/" + opts[:collection_uid] + "," + opts[:institution_id] else @base = URI.parse WORLDCAT_KB_URL + "collections/" + opts[:collection_uid] end opts.delete(:institution_id) opts.delete(:collection_uid) data = do_request(opts) json = JSON.parse(data) objResult = Result.new() objResult.query = "" objResult.startIndex = 1 objResult.totalResults = 1 objResult.itemsPerPage = 1 objC = Collection.new() objC.load(json) return objResult, Array(objC) else opts.delete(:type) @base = URI.parse WORLDCAT_KB_URL + "collections/search" data = do_request(opts) json = JSON.parse(data) objResult = Result.new() objResult.query = json['os:Query'] objResult.startIndex = json['os:startIndex'] objResult.totalResults = json['os:totalResults'] objResult.itemsPerPage = json['os:itemsPerPage'] objArray = Array.new() json['entries'].each {|item| objC = Collection.new() objC.load(item) objArray.push(objC) } return objResult, objArray end end |
#GetEntry(opts = {}) ⇒ Object
def OpenSearch(opts={})
@base = URI.parse WORLDCAT_OPENSEARCH
opts["wskey"] = @wskey
xml = do_request(opts)
return OpenSearchResponse.new(xml)
end
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/wckbapi/client.rb', line 43 def GetEntry(opts = {}) opts[:wskey] = @wskey opts[:alt] = 'json' if opts[:id] == nil @base = URI.parse WORLDCAT_KB_URL + "entries/" + opts[:collection_uid] + "," + opts[:entry_uid] opts.delete(:collection_uid) opts.delete(:entry_uid) else @base = URI.parse opts[:id] opts.delete(:id) end data = do_request(opts) json = JSON.parse(data) objResult = Result.new() objResult.query = "" objResult.startIndex = 1 objResult.totalResults = 1 objResult.itemsPerPage = 1 objE = Entry.new() objE.load(json) return objResult, Array(objE) end |
#GetProviderInfo(opts = {}) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/wckbapi/client.rb', line 92 def GetProviderInfo(opts={}) if opts == nil opts = Hash.new() end opts[:wskey] = @wskey opts[:alt] = 'json' if opts[:type] == nil if opts[:collection_uid] == nil @base = URI.parse WORLDCAT_KB_URL + "providers" else @base = URI.parse WORLDCAT_KB_URL + "providers/" + opts[:title] end opts.delete(:collection_uid) data = do_request(opts) json = JSON.parse(data) objResult = Result.new() if json['entries'] != nil objResult.query =json['os:Query'] objResult.startIndex =json['os:startIndex'] objResult.totalResults = json['os:totalResults'] objResult.itemsPerPage = json['os:itemsPerPage'] objArray = Array.new() json['entries'].each {|item| objP = Provider.new() objP.load(item) objArray.push(objP) } return objResult, objArray else objResult.query = "" objResult.startIndex = 1 objResult.totalResults = 1 objResult.itemsPerPage = 1 objP = Provider.new() objP.load(json) return objResult, Array(objP) end else opts.delete(:type) @base = URI.parse WORLDCAT_KB_URL + "providers/search" data = do_request(opts) json = JSON.parse(data) objResult = Result.new() objResult.query = json['os:Query'] objResult.startIndex = json['os:startIndex'] objResult.totalResults = json['os:totalResults'] objResult.itemsPerPage = json['os:itemsPerPage'] objArray = Array.new() json['entries'].each {|item| objP = Provider.new() objP.load(item) objArray.push(objP) } return objResult, objArray end end |
#SearchCollections(opts = {}) ⇒ Object
196 197 198 199 |
# File 'lib/wckbapi/client.rb', line 196 def SearchCollections(opts={}) opts[:type] = 'search' return GetCollectionInfo(opts) end |
#SearchEntries(opts = {}) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/wckbapi/client.rb', line 67 def SearchEntries(opts={}) opts[:wskey] = @wskey opts[:alt] = 'json' @base = URI.parse WORLDCAT_KB_URL + "entries/search" data = do_request(opts) json = JSON.parse(data) objArray = Array.new() objResult = Result.new() objResult.query = json['os:Query'] objResult.startIndex = json['os:startIndex'] objResult.totalResults = json['os:totalResults'] objResult.itemsPerPage = json['os:itemsPerPage'] json['entries'].each {|item| objE = Entry.new() objE.load(item) objArray.push(objE) } return objResult, objArray end |
#SearchProviders(opts = {}) ⇒ Object
87 88 89 90 |
# File 'lib/wckbapi/client.rb', line 87 def SearchProviders(opts={}) opts[:type] = 'search' return GetProviderInfo(opts) end |