nabeta-wcapi 0.0.1 → 0.0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/wcapi/client.rb +3 -3
- data/lib/wcapi/open_search_response.rb +39 -38
- metadata +1 -1
data/lib/wcapi/client.rb
CHANGED
@@ -46,10 +46,10 @@ module WCAPI
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def GetRecord(opts={})
|
49
|
-
if opts[:type] == '
|
50
|
-
@base = URI.parse "http://www.worldcat.org/webservices/catalog/content/" + opts[:id]
|
51
|
-
else
|
49
|
+
if opts[:type] == 'isbn'
|
52
50
|
@base = URI.parse 'http://www.worldcat.org/webservices/catalog/content/isbn/' + opts[:id]
|
51
|
+
else
|
52
|
+
@base = URI.parse "http://www.worldcat.org/webservices/catalog/content/" + opts[:id]
|
53
53
|
end
|
54
54
|
opts.delete(:type)
|
55
55
|
opts.delete(:id)
|
@@ -9,7 +9,7 @@ module WCAPI
|
|
9
9
|
if doc.index('rss')
|
10
10
|
parse_rss(doc)
|
11
11
|
else
|
12
|
-
|
12
|
+
parse_atom(doc)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -27,16 +27,17 @@ module WCAPI
|
|
27
27
|
|
28
28
|
begin
|
29
29
|
require 'xml/libxml'
|
30
|
-
_parser = LibXML::XML::Parser.new()
|
31
|
-
_parser.string = xml
|
32
|
-
doc = LibXML::XML::Document.new()
|
33
|
-
doc = _parser.parse
|
30
|
+
#_parser = LibXML::XML::Parser.new()
|
31
|
+
#_parser.string = xml
|
32
|
+
#doc = LibXML::XML::Document.new()
|
33
|
+
#doc = _parser.parse
|
34
|
+
doc = LibXML::XML::Document.string(xml)
|
34
35
|
rescue
|
35
|
-
|
36
|
-
|
37
|
-
|
36
|
+
begin
|
37
|
+
require 'rexml/document'
|
38
|
+
doc = REXML::Document.new(xml)
|
38
39
|
rescue
|
39
|
-
|
40
|
+
#likely some kind of xml error
|
40
41
|
end
|
41
42
|
end
|
42
43
|
|
@@ -54,34 +55,34 @@ module WCAPI
|
|
54
55
|
|
55
56
|
nodes = xpath_all(doc, "//item", namespaces)
|
56
57
|
nodes.each { |item |
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
58
|
+
_title = xpath_get_text(xpath_first(item, "title"))
|
59
|
+
if xpath_first(item, "author/name", namespaces) != nil
|
60
|
+
xpath_all(item, "author/name", namespaces).each { |i|
|
61
|
+
_author.push(xpath_get_text(i))
|
62
|
+
}
|
63
|
+
end
|
64
|
+
if xpath_first(item, "link", namespaces) != nil
|
64
65
|
_link = xpath_get_text(xpath_first(item, "link", namespaces))
|
65
|
-
|
66
|
+
end
|
66
67
|
|
67
|
-
|
68
|
+
if _link != ''
|
68
69
|
_id = _link.slice(_link.rindex("/")+1, _link.length-_link.rindex("/"))
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
70
|
+
end
|
71
|
+
if xpath_first(item, "content:encoded", namespaces) != nil
|
72
|
+
_citation = xpath_get_text(xpath_first(item, "content:encoded", namespaces))
|
73
|
+
end
|
73
74
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
75
|
+
if xpath_first(item, "description", namespaces) != nil
|
76
|
+
_summary = xpath_get_text(xpath_first(item, "description", namespaces))
|
77
|
+
end
|
78
|
+
_rechash = {:title => _title, :author => _author, :link => _link, :id => _id, :citation => _citation,
|
79
|
+
:summary => _summary, :xml => item.to_s}
|
80
|
+
_record.push(_rechash)
|
80
81
|
}
|
81
82
|
@records = _record
|
82
|
-
|
83
|
+
end
|
83
84
|
|
84
|
-
|
85
|
+
def parse_atom(xml)
|
85
86
|
_title = ""
|
86
87
|
#this is an array
|
87
88
|
_author = Array.new()
|
@@ -105,7 +106,7 @@ module WCAPI
|
|
105
106
|
require 'rexml/document'
|
106
107
|
doc = REXML::Document.new(xml)
|
107
108
|
rescue
|
108
|
-
|
109
|
+
#likely some kind of xml error
|
109
110
|
end
|
110
111
|
end
|
111
112
|
|
@@ -125,13 +126,13 @@ module WCAPI
|
|
125
126
|
_title = xpath_get_text(xpath_first(item, "*[local-name() = 'title']"))
|
126
127
|
_tmpauthor = xpath_first(item, "*[local-name() = 'author']")
|
127
128
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
129
|
+
if _tmpauthor != nil
|
130
|
+
if xpath_first(item, "*[local-name() = 'author']/*[local-name() = 'name']") != nil
|
131
|
+
xpath_all(item, "*[local-name() = 'author']/*[local-name() = 'name']").each { |i|
|
132
|
+
_author.push(xpath_get_text(i))
|
133
|
+
}
|
134
|
+
end
|
135
|
+
end
|
135
136
|
|
136
137
|
if xpath_first(item, "*[local-name() = 'id']") != nil
|
137
138
|
_link = xpath_get_text(xpath_first(item, "*[local-name() = 'id']"))
|