nabeta-wcapi 0.0.1 → 0.0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -46,10 +46,10 @@ module WCAPI
46
46
  end
47
47
 
48
48
  def GetRecord(opts={})
49
- if opts[:type] == 'oclc'
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
- parse_atom(doc)
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
- begin
36
- require 'rexml/document'
37
- doc = REXML::Document.new(xml)
36
+ begin
37
+ require 'rexml/document'
38
+ doc = REXML::Document.new(xml)
38
39
  rescue
39
- #likely some kind of xml error
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
- _title = xpath_get_text(xpath_first(item, "title"))
58
- if xpath_first(item, "author/name", namespaces) != nil
59
- xpath_all(item, "author/name", namespaces).each { |i|
60
- _author.push(xpath_get_text(i))
61
- }
62
- end
63
- if xpath_first(item, "link", namespaces) != nil
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
- end
66
+ end
66
67
 
67
- if _link != ''
68
+ if _link != ''
68
69
  _id = _link.slice(_link.rindex("/")+1, _link.length-_link.rindex("/"))
69
- end
70
- if xpath_first(item, "content:encoded", namespaces) != nil
71
- _citation = xpath_get_text(xpath_first(item, "content:encoded", namespaces))
72
- end
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
- if xpath_first(item, "description", namespaces) != nil
75
- _summary = xpath_get_text(xpath_first(item, "description", namespaces))
76
- end
77
- _rechash = {:title => _title, :author => _author, :link => _link, :id => _id, :citation => _citation,
78
- :summary => _summary, :xml => item.to_s}
79
- _record.push(_rechash)
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
- end
83
+ end
83
84
 
84
- def parse_atom(xml)
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
- #likely some kind of xml error
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
- if _tmpauthor != nil
129
- if xpath_first(item, "*[local-name() = 'author']/*[local-name() = 'name']") != nil
130
- xpath_all(item, "*[local-name() = 'author']/*[local-name() = 'name']").each { |i|
131
- _author.push(xpath_get_text(i))
132
- }
133
- end
134
- end
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']"))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nabeta-wcapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kosuke Tanabe