goldfinger 1.2.0 → 2.0.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b9f439ace3badfbfd7be9f56df56d275b831973
4
- data.tar.gz: 6bfef9289937a10a6681a22b6ff8f02fd39024ed
3
+ metadata.gz: dddcce07ce9462a9e37c4339d722d7a93687d49a
4
+ data.tar.gz: c520b7d8b7504f46d2c33f13020359856c25865f
5
5
  SHA512:
6
- metadata.gz: 88dae51709e0a492b830f57f6e57b5b47714f42c572b4b582aa54d330bcd9ffacfcbb640a7b677e1b8ec586fcee62477353a42addeb2f9759075405c8948d13d
7
- data.tar.gz: 02af661772034400db9f96df7097d5f0c838b83c11778931afbd7551718d0e403158c4ab6eed1d9bb5f2ca2334964c04170377382f89288efb9a87436c6c020c
6
+ metadata.gz: 16b82f58d3b734b7a254d06214ca1875953cda6b134a57e00a63b057029041e1b238af087c8a87ff36db00afc5f5c7c5871b29f42c079dfc88b10ee6708f3461
7
+ data.tar.gz: 58c4b87d7834551e51372e3244aa6d00e4eeff7fb1c809cdf97404e459b857c2b35a4b38268da452105ca89ee5c59db062235c214dc0b0bcdd9c99b756a848a0
data/README.md CHANGED
@@ -1,15 +1,18 @@
1
- Goldfinger, a Webfinger client for Ruby
1
+ Goldfinger, a WebFinger client for Ruby
2
2
  =======================================
3
3
 
4
4
  [![Gem Version](http://img.shields.io/gem/v/goldfinger.svg)][gem]
5
- [![Build Status](http://img.shields.io/travis/Gargron/goldfinger.svg)][travis]
6
- [![Dependency Status](http://img.shields.io/gemnasium/Gargron/goldfinger.svg)][gemnasium]
5
+ [![Build Status](http://img.shields.io/travis/tootsuite/goldfinger.svg)][travis]
6
+ [![Dependency Status](http://img.shields.io/gemnasium/tootsuite/goldfinger.svg)][gemnasium]
7
7
 
8
8
  [gem]: https://rubygems.org/gems/goldfinger
9
- [travis]: https://travis-ci.org/Gargron/goldfinger
10
- [gemnasium]: https://gemnasium.com/Gargron/goldfinger
9
+ [travis]: https://travis-ci.org/tootsuite/goldfinger
10
+ [gemnasium]: https://gemnasium.com/tootsuite/goldfinger
11
11
 
12
- A Webfinger client for Ruby. Supports `application/xrd+xml` and `application/jrd+json` responses. Raises `Goldfinger::NotFoundError` on failure to fetch the Webfinger or XRD data, or `Goldfinger::SSLError` if something is wrong with the HTTPS connection it uses.
12
+ A WebFinger client for Ruby. Supports `application/xrd+xml` and `application/jrd+json` responses. Raises `Goldfinger::NotFoundError` on failure to fetch the Webfinger or XRD data, can also raise `HTTP:Error` or `OpenSSL::SSL::SSLError` if something is wrong with the HTTPS connection it uses.
13
+
14
+ - **Does not** fall back to HTTP if HTTPS is not available
15
+ - **Does** check host-meta XRD, but *only* if the standard WebFinger path yielded no result
13
16
 
14
17
  ## Installation
15
18
 
@@ -30,4 +33,4 @@ A Webfinger client for Ruby. Supports `application/xrd+xml` and `application/jrd
30
33
 
31
34
  ## RFC support
32
35
 
33
- The official Webfinger RFC is [7033](https://tools.ietf.org/html/rfc7033).
36
+ The official WebFinger RFC is [7033](https://tools.ietf.org/html/rfc7033).
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'goldfinger/request'
2
4
  require 'goldfinger/link'
3
5
  require 'goldfinger/result'
@@ -11,9 +13,6 @@ module Goldfinger
11
13
  class NotFoundError < Error
12
14
  end
13
15
 
14
- class SSLError < Error
15
- end
16
-
17
16
  # Returns result for the Webfinger query
18
17
  #
19
18
  # @raise [Goldfinger::NotFoundError] Error raised when the Webfinger resource could not be retrieved
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'addressable'
2
4
  require 'nokogiri'
3
5
 
@@ -10,24 +12,11 @@ module Goldfinger
10
12
  end
11
13
 
12
14
  def finger
13
- ssl = true
14
-
15
- begin
16
- response = perform_get(standard_url(ssl))
17
-
18
- return finger_from_template if response.code != 200
15
+ response = perform_get(standard_url)
19
16
 
20
- Goldfinger::Result.new(response)
21
- rescue HTTP::Error
22
- raise Goldfinger::NotFoundError unless ssl
17
+ return finger_from_template if response.code != 200
23
18
 
24
- ssl = false
25
- retry
26
- end
27
- rescue HTTP::Error
28
- raise Goldfinger::NotFoundError
29
- rescue OpenSSL::SSL::SSLError
30
- raise Goldfinger::SSLError
19
+ Goldfinger::Result.new(response)
31
20
  rescue Addressable::URI::InvalidURIError
32
21
  raise Goldfinger::NotFoundError, 'Invalid URI'
33
22
  end
@@ -35,16 +24,7 @@ module Goldfinger
35
24
  private
36
25
 
37
26
  def finger_from_template
38
- ssl = true
39
-
40
- begin
41
- template = perform_get(url(ssl))
42
- rescue HTTP::Error
43
- raise Goldfinger::NotFoundError unless ssl
44
-
45
- ssl = false
46
- retry
47
- end
27
+ template = perform_get(url)
48
28
 
49
29
  raise Goldfinger::NotFoundError, 'No host-meta on the server' if template.code != 200
50
30
 
@@ -55,12 +35,12 @@ module Goldfinger
55
35
  Goldfinger::Result.new(response)
56
36
  end
57
37
 
58
- def url(ssl = true)
59
- "http#{'s' if ssl}://#{domain}/.well-known/host-meta"
38
+ def url
39
+ "https://#{domain}/.well-known/host-meta"
60
40
  end
61
41
 
62
- def standard_url(ssl = true)
63
- "http#{'s' if ssl}://#{domain}/.well-known/webfinger?resource=#{@uri}"
42
+ def standard_url
43
+ "https://#{domain}/.well-known/webfinger?resource=#{@uri}"
64
44
  end
65
45
 
66
46
  def url_from_template(template)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Goldfinger
2
4
  # @!attribute [r] href
3
5
  # @return [String] The href the link points to
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'http'
2
4
  require 'addressable'
3
5
 
@@ -1,13 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'oj'
4
+
1
5
  module Goldfinger
6
+ # @!attribute [r] subject
7
+ # @return [String] URI that identifies the entity that the JRD describes.
8
+ # @!attribute [r] aliases
9
+ # @return [Array] Zero or more URI strings that identify the same entity as the "subject" URI.
2
10
  class Result
3
11
  MIME_TYPES = [
4
12
  'application/jrd+json',
5
13
  'application/json',
6
14
  'application/xrd+xml',
7
15
  'application/xml',
8
- 'text/xml'
16
+ 'text/xml',
9
17
  ].freeze
10
18
 
19
+ attr_reader :subject, :aliases
20
+
11
21
  def initialize(response)
12
22
  @mime_type = response.mime_type
13
23
  @body = response.body
@@ -19,20 +29,6 @@ module Goldfinger
19
29
  parse
20
30
  end
21
31
 
22
- # The value of the "subject" member is a URI that identifies the entity
23
- # that the JRD describes.
24
- # @return [String]
25
- def subject
26
- @subject
27
- end
28
-
29
- # The "aliases" array is an array of zero or more URI strings that
30
- # identify the same entity as the "subject" URI.
31
- # @return [Array]
32
- def aliases
33
- @aliases
34
- end
35
-
36
32
  # The "properties" object comprises zero or more name/value pairs whose
37
33
  # names are URIs (referred to as "property identifiers") and whose
38
34
  # values are strings or nil.
@@ -78,7 +74,7 @@ module Goldfinger
78
74
  end
79
75
 
80
76
  def parse_json
81
- json = JSON.parse(@body)
77
+ json = Oj.load(@body, mode: :null)
82
78
 
83
79
  @subject = json['subject']
84
80
  @aliases = json['aliases'] || []
@@ -94,7 +90,7 @@ module Goldfinger
94
90
  xml = Nokogiri::XML(@body)
95
91
 
96
92
  @subject = xml.at_xpath('//xmlns:Subject').content
97
- @aliases = xml.xpath('//xmlns:Alias').map { |a| a.content }
93
+ @aliases = xml.xpath('//xmlns:Alias').map(&:content)
98
94
 
99
95
  properties = xml.xpath('/xmlns:XRD/xmlns:Property')
100
96
  properties.each { |prop| @properties[prop.attribute('type').value] = prop.attribute('nil') ? nil : prop.content }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Goldfinger
2
4
  module Utils
3
5
  def perform_get(path, options = {})
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.2.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eugen Rochko
@@ -16,56 +16,70 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.0'
19
+ version: '2.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.0'
26
+ version: '2.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: addressable
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.4'
33
+ version: '2.5'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.4'
40
+ version: '2.5'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: nokogiri
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.6'
47
+ version: '1.8'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.6'
54
+ version: '1.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: oj
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: bundler
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '1.3'
75
+ version: '1.15'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: '1.3'
82
+ version: '1.15'
69
83
  description: A Webfinger utility for Ruby
70
84
  email: eugen@zeonfederated.com
71
85
  executables: []
@@ -92,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
92
106
  requirements:
93
107
  - - ">="
94
108
  - !ruby/object:Gem::Version
95
- version: 2.0.0
109
+ version: 2.3.0
96
110
  required_rubygems_version: !ruby/object:Gem::Requirement
97
111
  requirements:
98
112
  - - ">="
@@ -100,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
114
  version: '0'
101
115
  requirements: []
102
116
  rubyforge_project:
103
- rubygems_version: 2.4.5.1
117
+ rubygems_version: 2.6.11
104
118
  signing_key:
105
119
  specification_version: 4
106
120
  summary: A Webfinger utility for Ruby