unapi 0.0.1 → 0.0.2
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.
- data/lib/unapi/service.rb +3 -1
- data/lib/unapi/utils.rb +0 -1
- data/lib/unapi/validator.rb +1 -0
- data/test.rb +1 -1
- data/test/index.html +1 -1
- data/test/unapi_test.rb +11 -11
- data/test/validate_test.rb +2 -2
- metadata +2 -2
data/lib/unapi/service.rb
CHANGED
@@ -14,8 +14,10 @@ module UnAPI
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def formats()
|
17
|
-
formats = []
|
18
17
|
@status_code, @document, @content_type = Utils.get_document(@url)
|
18
|
+
return [] if ! @document
|
19
|
+
|
20
|
+
formats = []
|
19
21
|
@document.elements.each('.//formats/format') do |e|
|
20
22
|
formats << Format.new_from_element(e)
|
21
23
|
end
|
data/lib/unapi/utils.rb
CHANGED
data/lib/unapi/validator.rb
CHANGED
data/test.rb
CHANGED
@@ -14,7 +14,7 @@ logger = WEBrick::BasicLog.new('logs/webrick.log')
|
|
14
14
|
access_log_stream = File.open('logs/webrick_access.log','w')
|
15
15
|
access_log = [[access_log_stream, WEBrick::AccessLog::COMBINED_LOG_FORMAT]]
|
16
16
|
server = WEBrick::HTTPServer.new(
|
17
|
-
:Port =>
|
17
|
+
:Port => 9000,
|
18
18
|
:DocumentRoot => 'test/',
|
19
19
|
:Logger => logger,
|
20
20
|
:AccessLog => access_log)
|
data/test/index.html
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
<title>
|
4
4
|
Amazon.com: Online Shopping for Electronics, Apparel, Computers, Books, DVDs & more
|
5
5
|
</title>
|
6
|
-
<link rel="meta" type="application/xml" title="unAPI" href="http://localhost:
|
6
|
+
<link rel="meta" type="application/xml" title="unAPI" href="http://localhost:9000/unapi" />
|
7
7
|
<meta name="description" content="Online shopping from the earth's biggest selection of books, magazines, music, DVDs, videos, electronics, computers, software, apparel & accessories, shoes, jewelry, tools & hardware, housewares, furniture, sporting goods, beauty & personal care, gourmet food & just about anything else.">
|
8
8
|
<meta name="keywords" content="Amazon, Amazon.com, Books, Online Shopping, Book Store, Magazine, Subscription, Music, CDs, DVDs, Videos, Electronics, Video Games, Computers, Cell Phones, Toys, Games, Apparel, Accessories, Shoes, Jewelry, Watches, Office Products, Sports & Outdoors, Sporting Goods, Baby Products, Health, Personal Care, Beauty, Home, Garden, Bed & Bath, Furniture, Tools, Hardware, Vacuums, Outdoor Living, Automotive Parts, Pet Supplies">
|
9
9
|
<style type="text/css"><!-- .serif { font-family: times,serif; font-size: small; }
|
data/test/unapi_test.rb
CHANGED
@@ -3,25 +3,25 @@ require 'unapi'
|
|
3
3
|
class UnAPITest < Test::Unit::TestCase
|
4
4
|
|
5
5
|
def test_service_url
|
6
|
-
page = UnAPI::Page.new 'http://localhost:
|
7
|
-
assert_equal page.service_url, 'http://localhost:
|
6
|
+
page = UnAPI::Page.new 'http://localhost:9000/index.html'
|
7
|
+
assert_equal page.service_url, 'http://localhost:9000/unapi'
|
8
8
|
end
|
9
9
|
|
10
10
|
def test_uris
|
11
|
-
page = UnAPI::Page.new 'http://localhost:
|
11
|
+
page = UnAPI::Page.new 'http://localhost:9000/index.html'
|
12
12
|
assert_equal [ 'urn:isbn:0553804790', 'urn:isbn:030723827X',
|
13
13
|
'urn:isbn:0307236579'], page.uris
|
14
14
|
end
|
15
15
|
|
16
16
|
def test_service
|
17
|
-
page = UnAPI::Page.new 'http://localhost:
|
17
|
+
page = UnAPI::Page.new 'http://localhost:9000/index.html'
|
18
18
|
service = page.service
|
19
19
|
assert_equal service.class, UnAPI::Service
|
20
|
-
assert_equal service.url, 'http://localhost:
|
20
|
+
assert_equal service.url, 'http://localhost:9000/unapi'
|
21
21
|
end
|
22
22
|
|
23
23
|
def test_formats
|
24
|
-
service = UnAPI::Service.new 'http://localhost:
|
24
|
+
service = UnAPI::Service.new 'http://localhost:9000/unapi'
|
25
25
|
formats = service.formats
|
26
26
|
assert_equal 2, formats.length
|
27
27
|
assert_equal formats[0].name, 'dc'
|
@@ -39,7 +39,7 @@ class UnAPITest < Test::Unit::TestCase
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def test_uri_formats
|
42
|
-
service = UnAPI::Service.new 'http://localhost:
|
42
|
+
service = UnAPI::Service.new 'http://localhost:9000/unapi'
|
43
43
|
formats = service.formats_for_uri('urn:isbn:0553804790')
|
44
44
|
assert_equal 2, formats.length
|
45
45
|
assert_equal formats[0].name, 'dc'
|
@@ -50,14 +50,14 @@ class UnAPITest < Test::Unit::TestCase
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def test_bad_uri_formats
|
53
|
-
service = UnAPI::Service.new 'http://localhost:
|
53
|
+
service = UnAPI::Service.new 'http://localhost:9000/unapi'
|
54
54
|
formats = service.formats_for_uri('urn:isbn:foobarf')
|
55
55
|
assert_equal 0, formats.length
|
56
56
|
assert_equal 404, service.status_code
|
57
57
|
end
|
58
58
|
|
59
59
|
def test_get_uri_in_format
|
60
|
-
service = UnAPI::Service.new 'http://localhost:
|
60
|
+
service = UnAPI::Service.new 'http://localhost:9000/unapi'
|
61
61
|
uri = 'urn:isbn:0553804790'
|
62
62
|
assert_equal '<dc/>', service.get_uri_in_format(uri, 'dc')
|
63
63
|
assert_equal 200, service.status_code
|
@@ -66,14 +66,14 @@ class UnAPITest < Test::Unit::TestCase
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def test_get_bad_uri
|
69
|
-
service = UnAPI::Service.new 'http://localhost:
|
69
|
+
service = UnAPI::Service.new 'http://localhost:9000/unapi'
|
70
70
|
assert_equal nil, service.get_uri_in_format('foobar', 'dc')
|
71
71
|
assert_equal 404, service.status_code
|
72
72
|
end
|
73
73
|
|
74
74
|
def test_get_bad_uri_in_format
|
75
75
|
uri = 'urn:isbn:0553804790'
|
76
|
-
service = UnAPI::Service.new 'http://localhost:
|
76
|
+
service = UnAPI::Service.new 'http://localhost:9000/unapi'
|
77
77
|
assert_equal nil, service.get_uri_in_format(uri, 'cheese')
|
78
78
|
assert_equal 415, service.status_code
|
79
79
|
end
|
data/test/validate_test.rb
CHANGED
@@ -7,14 +7,14 @@ class ValidateTest < Test::Unit::TestCase
|
|
7
7
|
buffer = StringIO.new
|
8
8
|
handler = UnAPI::PrintHandler.new(buffer)
|
9
9
|
validator = UnAPI::Validator.new(handler)
|
10
|
-
validator.validate_page('http://localhost:
|
10
|
+
validator.validate_page('http://localhost:9000/unapi')
|
11
11
|
assert buffer.to_s.length > 0
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_output_to_array
|
15
15
|
handler = UnAPI::ListHandler.new
|
16
16
|
validator = UnAPI::Validator.new(handler)
|
17
|
-
validator.validate_page('http://localhost:
|
17
|
+
validator.validate_page('http://localhost:9000/unapi')
|
18
18
|
assert handler.messages.length > 0
|
19
19
|
end
|
20
20
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: unapi
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
7
|
-
date: 2006-03-
|
6
|
+
version: 0.0.2
|
7
|
+
date: 2006-03-14 00:00:00 -06:00
|
8
8
|
summary: A library for working with the unapi protocol
|
9
9
|
require_paths:
|
10
10
|
- lib
|