goldfinger 1.0.5 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fc820ab656edf8cb51e9e515f3b511d630d9dfe7
4
- data.tar.gz: 1512d16c46857a137482aad40afa8ef73b7b2bc5
3
+ metadata.gz: 06a8ef2a1e5478c256b81c6a152c5fdd8681f626
4
+ data.tar.gz: ca099d14c413a8b3825e19efcd2e2c1930d6fc29
5
5
  SHA512:
6
- metadata.gz: 3100976ad899644f228ab156571cef90a9bc03b5e0b09ef5ed842d2488e47d21fc1c818c811dc3160af6332ad87fabe02360a59393fb149ae93f7bf163cfe731
7
- data.tar.gz: 2139ccddfd20b492d6fa99692f3fb3bac53245e2e08fc426f34aba25f8b90460e4093b1c976742f52116eb7ff36085f60ab875fb0cf0140db4b160a74bc3a2f6
6
+ metadata.gz: 856a7925e94dce04b68bbc7ca1c116f35f916cd75709b0db1596bb2c8c1424ff8ade41392dcac6d1aa612ec918b7e9d2cb19b53d42b3b7939b7ca7215692e308
7
+ data.tar.gz: 9bef19672f88c9abf5d29e10c2f1412168ae868277d918c8cadccea39c89d3c1cd8614704b7beba8b7977dfb3f89bee28fe720eb7de9d58321eed9e9f540a6f8
@@ -13,7 +13,7 @@ module Goldfinger
13
13
  ssl = true
14
14
 
15
15
  begin
16
- _, template = perform_get(url(ssl))
16
+ template = perform_get(url(ssl))
17
17
  rescue HTTP::Error
18
18
  if ssl
19
19
  ssl = false
@@ -23,11 +23,13 @@ module Goldfinger
23
23
  end
24
24
  end
25
25
 
26
- headers, body = perform_get(url_from_template(template))
26
+ raise Goldfinger::NotFoundError, "No host-meta on the server" if template.code != 200
27
27
 
28
- raise Goldfinger::Error, "Invalid response mime type: #{headers.get(HTTP::Headers::CONTENT_TYPE).first}" unless ['application/jrd+json', 'application/xrd+xml'].include?(headers.get(HTTP::Headers::CONTENT_TYPE).first)
28
+ response = perform_get(url_from_template(template.body))
29
29
 
30
- Goldfinger::Result.new(headers, body)
30
+ raise Goldfinger::NotFoundError, "No such user on the server" if response.code != 200
31
+
32
+ Goldfinger::Result.new(response)
31
33
  rescue HTTP::Error
32
34
  raise Goldfinger::NotFoundError
33
35
  rescue OpenSSL::SSL::SSLError
@@ -48,7 +50,7 @@ module Goldfinger
48
50
 
49
51
  links.first.attribute('template').value.gsub('{uri}', @uri)
50
52
  rescue Nokogiri::XML::XPath::SyntaxError
51
- raise Goldfinger::Error, 'Bad XML'
53
+ raise Goldfinger::Error, "Bad XML: #{template}"
52
54
  end
53
55
 
54
56
  def domain
@@ -10,14 +10,13 @@ module Goldfinger
10
10
  end
11
11
 
12
12
  def perform
13
- response = http_client.request(@request_method, @uri.to_s, @options)
14
- [response.headers, response.body]
13
+ http_client.request(@request_method, @uri.to_s, @options)
15
14
  end
16
15
 
17
16
  private
18
17
 
19
18
  def http_client
20
- HTTP.timeout(:per_operation, write: 60, connect: 20, read: 60)
19
+ HTTP.timeout(:per_operation, write: 60, connect: 20, read: 60).follow
21
20
  end
22
21
  end
23
22
  end
@@ -1,8 +1,16 @@
1
1
  module Goldfinger
2
2
  class Result
3
- def initialize(headers, body)
4
- @mime_type = headers.get(HTTP::Headers::CONTENT_TYPE).first
5
- @body = body
3
+ MIME_TYPES = [
4
+ 'application/jrd+json',
5
+ 'application/json',
6
+ 'application/xrd+xml',
7
+ 'application/xml',
8
+ 'text/xml'
9
+ ].freeze
10
+
11
+ def initialize(response)
12
+ @mime_type = response.mime_type
13
+ @body = response.body
6
14
  @subject = nil
7
15
  @aliases = []
8
16
  @links = {}
@@ -62,8 +70,10 @@ module Goldfinger
62
70
  case @mime_type
63
71
  when 'application/jrd+json', 'application/json'
64
72
  parse_json
65
- when 'application/xrd+xml'
73
+ when 'application/xrd+xml', 'application/xml', 'text/xml'
66
74
  parse_xml
75
+ else
76
+ raise Goldfinger::Error, "Invalid response mime type: #{@mime_type}"
67
77
  end
68
78
  end
69
79
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: goldfinger
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eugen Rochko