swd 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/Gemfile.lock +1 -1
  2. data/VERSION +1 -1
  3. data/lib/swd.rb +1 -1
  4. data/lib/swd/resource.rb +7 -4
  5. metadata +2 -2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- swd (0.0.1)
4
+ swd (0.0.2)
5
5
  activesupport (>= 3)
6
6
  attr_required (>= 0.0.3)
7
7
  httpclient (>= 2.2.1)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
data/lib/swd.rb CHANGED
@@ -6,7 +6,7 @@ module SWD
6
6
  @@cache
7
7
  end
8
8
  def self.discover!(attributes = {})
9
- Resource.new(attributes).discover!
9
+ Resource.new(attributes).discover!(attributes[:cache])
10
10
  end
11
11
  end
12
12
 
data/lib/swd/resource.rb CHANGED
@@ -16,12 +16,11 @@ module SWD
16
16
  self.send "#{key}=", attributes[key]
17
17
  end
18
18
  @path ||= '/.well-known/simple-web-discovery'
19
- @cache_options = attributes[:cache] || {}
20
19
  attr_missing!
21
20
  end
22
21
 
23
- def discover!
24
- SWD.cache.fetch(cache_key, @cache_options) do
22
+ def discover!(cache_options = {})
23
+ SWD.cache.fetch(cache_key, cache_options) do
25
24
  handle_response do
26
25
  HTTPClient.get_content endpoint.to_s
27
26
  end
@@ -44,7 +43,7 @@ module SWD
44
43
  if redirect = res[:SWD_service_redirect]
45
44
  redirect_to redirect[:location], redirect[:expires]
46
45
  else
47
- Response.new res
46
+ to_response_object(res)
48
47
  end
49
48
  rescue HTTPClient::BadResponseError => e
50
49
  case e.res.try(:status)
@@ -65,6 +64,10 @@ module SWD
65
64
  raise Exception.new(e.message)
66
65
  end
67
66
 
67
+ def to_response_object(hash)
68
+ Response.new hash
69
+ end
70
+
68
71
  def redirect_to(location, expires)
69
72
  uri = URI.parse(location)
70
73
  @host, @path = uri.host, uri.path
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: swd
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - nov matake
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-08-19 00:00:00 Z
13
+ date: 2011-08-20 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json