webfinger 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 20903f1ccf0e5605a976381cdbb8d97a0a810b84
4
+ data.tar.gz: 57304dadd541de3ff4b15561d469a9ceea73feca
5
+ SHA512:
6
+ metadata.gz: 5c4031213d7a1a145b377e1e4c87b2433904202c468009bdee24d8c016298df1c51244ba435ab23ca809ed14fb6010b674773234e9777a69c98cf6b359c2384f
7
+ data.tar.gz: 182b375638a9dbc3b201a1992aafae95a0d1903b52a97c5959281c34abd1ce2742474da53e85932791f3607939ef34eabb57c294e32ac82b00d33804abeb2b62
data/README.rdoc CHANGED
@@ -23,17 +23,45 @@ Or install it yourself as:
23
23
 
24
24
  == Usage
25
25
 
26
- # Basic
27
- WebFinger.discover! 'acct:nov@gmail.com'
26
+ === Basic
28
27
 
29
- # Only specific relations
30
- WebFinger.discover! 'acct:nov@gmail.com', rel: 'http://openid.net/specs/connect/1.0/issuer'
31
- WebFinger.discover! 'acct:nov@gmail.com', rel: ['http://openid.net/specs/connect/1.0/issuer', 'vcard']
28
+ You can discover resource metadata.
32
29
 
33
- # Specify host
34
- WebFinger.discover! 'acct:nov@gmail.com', host: 'mail.google.com'
30
+ WebFinger.discover! 'acct:nov@connect-op.heroku.com'
31
+ WebFinger.discover! 'connect-op.heroku.com'
32
+ WebFinger.discover! 'http://connect-op.heroku.com'
35
33
 
36
- For more detailed usage, read <code>spec/webfinger_spec.rb</code>.
34
+ You can also specify link relations via "rel" option.
35
+
36
+ WebFinger.discover! 'acct:nov@connect-op.heroku.com', rel: 'http://openid.net/specs/connect/1.0/issuer'
37
+ WebFinger.discover! 'acct:nov@connect-op.heroku.com', rel: ['http://openid.net/specs/connect/1.0/issuer', 'vcard']
38
+
39
+ === Caching
40
+
41
+ Caching is important in HTTP-based discovery.
42
+
43
+ If you set your own cache object to <code>WebFinger.cache</code>, this gem caches the discovery result until it expires.
44
+ (the expiry is calculated based on the "expires" value in JRD response)
45
+
46
+ # Set Cache
47
+ WebFinger.cache = Rails.cache
48
+
49
+ WebFinger.discover! 'acct:nov@connect-op.heroku.com' # do HTTP request
50
+ WebFinger.discover! 'acct:nov@connect-op.heroku.com' # use cache, no HTTP request
51
+
52
+ === Debugging
53
+
54
+ Once you turn-on debugging, you can see all HTTP request/response in your log.
55
+
56
+ # Turn on debugging
57
+ WebFinger.debug!
58
+
59
+ # Set logger (OPTIONAL, ::Logger.new(STDOUT) is used as default)
60
+ WebFinger.logger = Rails.logger
61
+
62
+ You can also specify URL builder to force non-HTTPS access. (NOTE: allow non-HTTPS access only for debugging, not on your production.)
63
+
64
+ WebFinger.url_builder = URI::HTTP # default URI::HTTPS
37
65
 
38
66
  == Contributing
39
67
 
@@ -45,4 +73,4 @@ For more detailed usage, read <code>spec/webfinger_spec.rb</code>.
45
73
 
46
74
  == Copyright
47
75
 
48
- Copyright (c) 2010 nov matake. See LICENSE for details.
76
+ Copyright (c) 2012 nov matake. See LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -8,27 +8,14 @@ module WebFinger
8
8
  @options = options
9
9
  end
10
10
 
11
- def discover!(cache_options = nil)
12
- cached = WebFinger.cache.read cache_key
13
- if cached.blank? || cached.expired?
14
- fetched = handle_response do
15
- WebFinger.http_client.get_content endpoint.to_s
16
- end
17
- cache_options ||= {}
18
- cache_options[:expires_in] ||= fetched.expires_in
19
- WebFinger.cache.write cache_key, fetched, cache_options
20
- fetched
21
- else
22
- cached
11
+ def discover!
12
+ handle_response do
13
+ WebFinger.http_client.get_content endpoint.to_s
23
14
  end
24
15
  end
25
16
 
26
17
  private
27
18
 
28
- def cache_key
29
- "webfinger:resource:#{Digest::MD5.hexdigest query_string}"
30
- end
31
-
32
19
  def endpoint
33
20
  path = '/.well-known/webfinger'
34
21
  host, port = host_and_port
@@ -64,7 +51,7 @@ module WebFinger
64
51
 
65
52
  def handle_response
66
53
  raw_response = yield
67
- jrd = MultiJson.load raw_response, symbolize_keys: true
54
+ jrd = MultiJson.load(raw_response).with_indifferent_access
68
55
  Response.new jrd
69
56
  rescue HTTPClient::BadResponseError => e
70
57
  case e.res.try(:status)
@@ -3,8 +3,8 @@
3
3
 
4
4
  module WebFinger
5
5
  class Response < Hash
6
- def initialize(hash)
7
- replace hash
6
+ def initialize(jrd)
7
+ replace jrd
8
8
  end
9
9
 
10
10
  [:subject, :aliases, :properties, :links].each do |method|
@@ -13,20 +13,9 @@ module WebFinger
13
13
  end
14
14
  end
15
15
 
16
- def expired?
17
- expires.try(:past?)
18
- end
19
- def expires
20
- @expires ||= case self[:expires]
21
- when Time
22
- self[:expires]
23
- when String
24
- Time.parse self[:expires]
25
- end
26
- end
27
- def expires_in
28
- if expires.present?
29
- (expires - Time.now).to_i
16
+ def link_for(rel)
17
+ links.detect do |link|
18
+ link[:rel] == rel
30
19
  end
31
20
  end
32
21
  end
data/lib/webfinger.rb CHANGED
@@ -11,14 +11,7 @@ module WebFinger
11
11
  module_function
12
12
 
13
13
  def discover!(resource, options = {})
14
- Request.new(resource, options).discover!(options[:cache])
15
- end
16
-
17
- def cache=(cache)
18
- @cache = cache
19
- end
20
- def cache
21
- @cache
14
+ Request.new(resource, options).discover!
22
15
  end
23
16
 
24
17
  def logger
@@ -63,8 +56,5 @@ end
63
56
 
64
57
  require 'webfinger/debugger'
65
58
  require 'webfinger/exception'
66
- require 'webfinger/cache'
67
59
  require 'webfinger/request'
68
- require 'webfinger/response'
69
-
70
- WebFinger.cache = WebFinger::Cache.new
60
+ require 'webfinger/response'
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe WebFinger::Response do
4
- let(:expires) { 10.minutes.from_now }
5
4
  let(:_subject_) { 'acct:nov@matake.jp' }
6
5
  let(:aliases) { ['mailto:nov@matake.jp'] }
7
6
  let(:properties) do
@@ -15,7 +14,6 @@ describe WebFinger::Response do
15
14
  end
16
15
  subject do
17
16
  WebFinger::Response.new(
18
- expires: expires,
19
17
  subject: _subject_,
20
18
  aliases: aliases,
21
19
  properties: properties,
@@ -23,11 +21,22 @@ describe WebFinger::Response do
23
21
  )
24
22
  end
25
23
 
26
- its(:expired?) { should be_false }
27
- its(:expires) { should == expires }
28
- its(:expires_in) { should == (expires - Time.now).to_i }
29
- its(:subject) { should == subject }
24
+ its(:subject) { should == _subject_ }
30
25
  its(:aliases) { should == aliases }
31
26
  its(:properties) { should == properties }
32
27
  its(:links) { should == links }
28
+
29
+ describe '#link_for' do
30
+ context 'when unknown' do
31
+ it do
32
+ subject.link_for('unknown').should be_nil
33
+ end
34
+ end
35
+
36
+ context 'otherwise' do
37
+ it do
38
+ subject.link_for('http://openid.net/specs/connect/1.0/issuer').should == links.first
39
+ end
40
+ end
41
+ end
33
42
  end
@@ -108,20 +108,6 @@ describe WebFinger do
108
108
  end
109
109
  end
110
110
 
111
- describe '#cache' do
112
- subject { WebFinger.cache }
113
-
114
- context 'as default' do
115
- it { should be_instance_of WebFinger::Cache }
116
- end
117
-
118
- context 'when specified' do
119
- let(:cacher) { 'Rails.cache or something' }
120
- before { WebFinger.cache = cacher }
121
- it { should == cacher }
122
- end
123
- end
124
-
125
111
  describe '#logger' do
126
112
  subject { WebFinger.logger }
127
113
 
data/webfinger.gemspec CHANGED
@@ -14,6 +14,7 @@ Gem::Specification.new do |gem|
14
14
  gem.add_runtime_dependency "httpclient", ">= 2.2.0.2"
15
15
  gem.add_runtime_dependency "multi_json"
16
16
  gem.add_runtime_dependency "activesupport", ">= 3"
17
+ gem.add_development_dependency "rake"
17
18
  gem.add_development_dependency "rspec", ">= 2"
18
19
  gem.add_development_dependency "cover_me", ">= 1.2.0"
19
20
  gem.add_development_dependency "webmock", ">= 1.6.2"
metadata CHANGED
@@ -1,110 +1,111 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webfinger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
5
- prerelease:
4
+ version: 0.0.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - nov matake
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-12-23 00:00:00.000000000 Z
11
+ date: 2013-03-02 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: httpclient
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: 2.2.0.2
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: 2.2.0.2
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: multi_json
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: activesupport
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '3'
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
62
69
  - !ruby/object:Gem::Dependency
63
70
  name: rspec
64
71
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
72
  requirements:
67
- - - ! '>='
73
+ - - '>='
68
74
  - !ruby/object:Gem::Version
69
75
  version: '2'
70
76
  type: :development
71
77
  prerelease: false
72
78
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
79
  requirements:
75
- - - ! '>='
80
+ - - '>='
76
81
  - !ruby/object:Gem::Version
77
82
  version: '2'
78
83
  - !ruby/object:Gem::Dependency
79
84
  name: cover_me
80
85
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
86
  requirements:
83
- - - ! '>='
87
+ - - '>='
84
88
  - !ruby/object:Gem::Version
85
89
  version: 1.2.0
86
90
  type: :development
87
91
  prerelease: false
88
92
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
93
  requirements:
91
- - - ! '>='
94
+ - - '>='
92
95
  - !ruby/object:Gem::Version
93
96
  version: 1.2.0
94
97
  - !ruby/object:Gem::Dependency
95
98
  name: webmock
96
99
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
100
  requirements:
99
- - - ! '>='
101
+ - - '>='
100
102
  - !ruby/object:Gem::Version
101
103
  version: 1.6.2
102
104
  type: :development
103
105
  prerelease: false
104
106
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
107
  requirements:
107
- - - ! '>='
108
+ - - '>='
108
109
  - !ruby/object:Gem::Version
109
110
  version: 1.6.2
110
111
  description: Ruby WebFinger client library
@@ -121,7 +122,6 @@ files:
121
122
  - Rakefile
122
123
  - VERSION
123
124
  - lib/webfinger.rb
124
- - lib/webfinger/cache.rb
125
125
  - lib/webfinger/debugger.rb
126
126
  - lib/webfinger/debugger/request_filter.rb
127
127
  - lib/webfinger/exception.rb
@@ -139,27 +139,26 @@ files:
139
139
  - webfinger.gemspec
140
140
  homepage: https://github.com/nov/webfinger
141
141
  licenses: []
142
+ metadata: {}
142
143
  post_install_message:
143
144
  rdoc_options: []
144
145
  require_paths:
145
146
  - lib
146
147
  required_ruby_version: !ruby/object:Gem::Requirement
147
- none: false
148
148
  requirements:
149
- - - ! '>='
149
+ - - '>='
150
150
  - !ruby/object:Gem::Version
151
151
  version: '0'
152
152
  required_rubygems_version: !ruby/object:Gem::Requirement
153
- none: false
154
153
  requirements:
155
- - - ! '>='
154
+ - - '>='
156
155
  - !ruby/object:Gem::Version
157
156
  version: '0'
158
157
  requirements: []
159
158
  rubyforge_project:
160
- rubygems_version: 1.8.24
159
+ rubygems_version: 2.0.0
161
160
  signing_key:
162
- specification_version: 3
161
+ specification_version: 4
163
162
  summary: Ruby WebFinger client library, following IETF WebFinger WG spec updates.
164
163
  test_files:
165
164
  - spec/helpers/webmock_helper.rb
@@ -1,12 +0,0 @@
1
- module WebFinger
2
- class Cache
3
- def read(cache_key)
4
- nil
5
- end
6
-
7
- def write(cache_key, object, options = {})
8
- # do nothing
9
- true
10
- end
11
- end
12
- end