unapi 0.0.2 → 0.0.3

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.
Files changed (3) hide show
  1. data/lib/unapi/service.rb +8 -6
  2. data/lib/unapi/validator.rb +26 -20
  3. metadata +34 -31
data/lib/unapi/service.rb CHANGED
@@ -7,7 +7,7 @@ module UnAPI
7
7
  # a class that represents the UnAPI Service
8
8
 
9
9
  class Service
10
- attr_reader :url, :status_code, :document, :content_type
10
+ attr_reader :url, :status_code, :document, :content_type, :last_url
11
11
 
12
12
  def initialize(url)
13
13
  @url = url
@@ -21,26 +21,28 @@ module UnAPI
21
21
  @document.elements.each('.//formats/format') do |e|
22
22
  formats << Format.new_from_element(e)
23
23
  end
24
+ @last_url = @url
24
25
  return formats
25
26
  end
26
27
 
27
28
  def formats_for_uri(uri)
28
29
  formats = []
29
- uri_esc = CGI.escape(uri)
30
- @status_code, @document, @content_type =
31
- Utils.get_document(@url + "?uri=#{uri_esc}")
30
+ request_url = @url + "?uri=#{CGI.escape(uri)}"
31
+ @status_code, @document, @content_type = Utils.get_document request_url
32
32
  @document.elements.each('.//formats/format') do |e|
33
33
  formats << Format.new_from_element(e)
34
34
  end
35
+ @last_url = request_url
35
36
  return formats
36
37
  end
37
38
 
38
39
  def get_uri_in_format(uri, format)
39
40
  uri_esc = CGI.escape(uri)
40
41
  format_esc = CGI.escape(format)
42
+ request_url = @url + "?uri=#{uri_esc}&format=#{format_esc}"
41
43
  @document = nil
42
- @status_code, body, @content_type =
43
- Utils.get(@url + "?uri=#{uri_esc}&format=#{format_esc}")
44
+ @status_code, body, @content_type = Utils.get url
45
+ @last_url = request_url
44
46
  return body
45
47
  end
46
48
  end
@@ -5,11 +5,11 @@ require 'unapi'
5
5
  module UnAPI
6
6
 
7
7
  class Message < String
8
- attr_accessor :for_url
8
+ attr_accessor :url
9
9
 
10
10
  def initialize(string, url=nil)
11
11
  super string
12
- @for_url = url
12
+ @url = url
13
13
  end
14
14
  end
15
15
 
@@ -27,14 +27,14 @@ module UnAPI
27
27
  @failures = 0
28
28
  end
29
29
 
30
- def pass(msg)
30
+ def pass(msg, url=nil)
31
31
  @passes += 1
32
- handle Pass.new(msg)
32
+ handle Pass.new(msg, url)
33
33
  end
34
34
 
35
- def fail(msg)
35
+ def fail(msg, url=nil)
36
36
  @failures += 1
37
- handle Fail.new(msg)
37
+ handle Fail.new(msg, url)
38
38
  end
39
39
 
40
40
  def count
@@ -52,7 +52,7 @@ module UnAPI
52
52
  @filehandle.print "#{count}: "
53
53
  case msg
54
54
  when Pass: @filehandle.print("PASS: #{msg}\n")
55
- when Fail: @filehandle.print("FAIL: #{msg}\n")
55
+ when Fail: @filehandle.print("FAIL: #{msg} #{msg.url}\n")
56
56
  when Warn: @filehandle.print("WARN: #{msg}\n")
57
57
  end
58
58
  end
@@ -86,7 +86,7 @@ module UnAPI
86
86
  def check_service(page)
87
87
  # make sure there is a service url
88
88
  service_url = page.service_url
89
- test service_url, "<link> url for unapi service"
89
+ test service_url, "<link> url for unapi service", service_url
90
90
  return unless service_url
91
91
 
92
92
  # get the unapi service from the page
@@ -105,7 +105,7 @@ module UnAPI
105
105
 
106
106
  # go through each identifier
107
107
  uris.each do |uri|
108
- @handler.pass "got unapi-uri #{uri}"
108
+ @handler.pass "got unapi-uri #{uri}"
109
109
 
110
110
  # verify it has formats available
111
111
  formats = service.formats_for_uri(uri)
@@ -121,31 +121,37 @@ module UnAPI
121
121
  formats.each do |format|
122
122
  content = service.get_uri_in_format(uri, format.name)
123
123
  test service.status_code == 200,
124
- "request for #{uri} content responded with 200 status code"
124
+ "request for #{uri} content responded with 200 status code",
125
+ service.last_url
125
126
  test (content != nil and content.length > 0),
126
- "request for #{uri} returned data"
127
+ "request for #{uri} returned data",
128
+ service.last_url
127
129
  test service.content_type == format.type,
128
- "request for #{uri} returned mime type #{service.content_type}"
130
+ "request for #{uri} returned mime type #{service.content_type}",
131
+ service.last_url
129
132
 
130
133
  # request an invalid uri with a valid format
131
134
  service.get_uri_in_format('invaliduriinvaliduri', format.name)
132
135
  test service.status_code == 404,
133
136
  "request for invalid uri with valid format #{format.name} " +
134
- "returned 404"
137
+ "returned 404", service.last_url
135
138
  end
136
139
  end
137
140
  end
138
141
 
139
142
  def check_formats(formats, service, target)
140
143
  test service.content_type == 'application/xml',
141
- "formats request for #{target} has content-type #{service.content_type}"
144
+ "formats for #{target} has content-type #{service.content_type}",
145
+ service.last_url
142
146
 
143
147
  if target == 'unapi service'
144
148
  test service.status_code == 200,
145
- "formats request for #{target} returned 200 status code"
149
+ "formats request for #{target} returned 200 status code",
150
+ service.last_url
146
151
  else
147
152
  test service.status_code == 300,
148
- "formats request for #{target} return 300 status code"
153
+ "formats request for #{target} return 300 status code",
154
+ service.last_url
149
155
  end
150
156
 
151
157
  if formats.length > 0
@@ -159,15 +165,15 @@ module UnAPI
159
165
  "format #{count} for #{target} has a type"
160
166
  end
161
167
  else
162
- @handler.fail "no formats found for #{target}"
168
+ @handler.fail "no formats found for #{target}", service.last_url
163
169
  end
164
170
  end
165
171
 
166
- def test(ok, msg)
172
+ def test(ok, msg, url=nil)
167
173
  if ok
168
- @handler.pass(msg)
174
+ @handler.pass(msg, url)
169
175
  else
170
- @handler.fail(msg)
176
+ @handler.fail(msg, url)
171
177
  end
172
178
  end
173
179
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
- --- !ruby/object:Gem::Specification
1
+ !ruby/object:Gem::Specification
2
2
  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.2
7
- date: 2006-03-14 00:00:00 -06:00
6
+ version: 0.0.3
7
+ date: 2006-03-14 00:00:00 -05:00
8
8
  summary: A library for working with the unapi protocol
9
9
  require_paths:
10
- - lib
10
+ - lib
11
11
  email: ehs@pobox.com
12
12
  homepage: http://www.textualize.com/unapi
13
13
  rubyforge_project:
@@ -18,43 +18,46 @@ bindir: bin
18
18
  has_rdoc: true
19
19
  required_ruby_version: !ruby/object:Gem::Version::Requirement
20
20
  requirements:
21
- -
22
- - ">"
23
- - !ruby/object:Gem::Version
24
- version: 0.0.0
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
25
24
  version:
26
25
  platform: ruby
27
26
  signing_key:
28
27
  cert_chain:
29
28
  authors:
30
- - Ed Summers
29
+ - Ed Summers
31
30
  files:
32
- - lib/unapi
33
- - lib/unapi.rb
34
- - lib/unapi/format.rb
35
- - lib/unapi/page.rb
36
- - lib/unapi/service.rb
37
- - lib/unapi/utils.rb
38
- - lib/unapi/validator.rb
39
- - test/index.html
40
- - test/unapi_servlet.rb
41
- - test/unapi_test.rb
42
- - test/validate_test.rb
31
+ - lib/unapi
32
+ - lib/unapi.rb
33
+ - lib/unapi/validator.rb
34
+ - lib/unapi/service.rb
35
+ - lib/unapi/utils.rb
36
+ - lib/unapi/format.rb
37
+ - lib/unapi/page.rb
38
+ - test/unapi_servlet.rb
39
+ - test/index.html
40
+ - test/unapi_test.rb
41
+ - test/validate_test.rb
43
42
  test_files:
44
- - test.rb
43
+ - test.rb
45
44
  rdoc_options: []
45
+
46
46
  extra_rdoc_files: []
47
+
47
48
  executables: []
49
+
48
50
  extensions: []
51
+
49
52
  requirements: []
53
+
50
54
  dependencies:
51
- - !ruby/object:Gem::Dependency
52
- name: rubyful_soup
53
- version_requirement:
54
- version_requirements: !ruby/object:Gem::Version::Requirement
55
- requirements:
56
- -
57
- - ">="
58
- - !ruby/object:Gem::Version
59
- version: 1.0.4
60
- version:
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubyful_soup
57
+ version_requirement:
58
+ version_requirements: !ruby/object:Gem::Version::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 1.0.4
63
+ version: