rest-firebase 0.9.2 → 0.9.3

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: 8dca5beda4578735562a476964ad93b23d7b9709
4
- data.tar.gz: 4bc1fb75725927cc7f243d6e60175149175580e6
3
+ metadata.gz: 958b43ae367f1f450bc52b507ef98a72216a0a07
4
+ data.tar.gz: 6c37c91216017e9b2c35d8f97607d055a9336c4a
5
5
  SHA512:
6
- metadata.gz: a381558128fced5ef49b8a16eef953382357f271f3fd13100face98cdb91cbd4d56f228c818113796eccf84cb3b6ce0726265b172d99e12b57c3f696eef397ad
7
- data.tar.gz: f27f1b64f9dc5d91c010a1f3533d9ce12b46af9f2dd94e74b660bbb85a6ec15d507da0dfa2a6bed41df0d8a817572bb4612b905c217ebc6dbedd0670e5998fd6
6
+ metadata.gz: 336e0c017f944ea20b2b006229694d61efe40abf157312efdbaee219291cbfb18bbc95513182b15c6a9ea85e46d290835564b03e5733c4d3bf0e9998c89004d5
7
+ data.tar.gz: ee75ad502085b86c6fc675cf8c8ce8e72b9a068511970fd59289ae6e3712229e427f7028259c98ce0aabea99d65ff962f877ec407999465f33d74832d69ee7cb
data/CHANGES.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # CHANGES
2
2
 
3
+ ## rest-firebase 0.9.3 -- 2014-08-25
4
+
5
+ * Adopted rest-core 3.3.0
6
+ * Introduce `RestFirebase#auth_ttl` to setup when to refresh the auth token.
7
+ Default to 23 hours (82800 seconds)
8
+ * Properly refresh the auth token by resetting `RestFirebase#iat`.
9
+
3
10
  ## rest-firebase 0.9.2 -- 2014-08-06
4
11
 
5
12
  * Now it would auto-refresh auth if it's also expired (>= 23 hours)
data/README.md CHANGED
@@ -65,6 +65,12 @@ f = RestFirebase.new :site => 'https://SampleChat.firebaseIO-demo.com/',
65
65
  :secret => 'secret',
66
66
  :d => {:auth_data => 'something'},
67
67
  :log_method => method(:puts),
68
+ # `auth_ttl` describes when we should refresh the auth
69
+ # token. Set it to `false` to disable auto-refreshing.
70
+ # The default is 23 hours.
71
+ :auth_ttl => 82800,
72
+ # `auth` is the auth token from Firebase. Leave it alone
73
+ # to auto-generate. Set it to `false` to disable it.
68
74
  :auth => false # Ignore auth for this example!
69
75
 
70
76
  @reconnect = true
data/Rakefile CHANGED
@@ -10,13 +10,13 @@ $LOAD_PATH.unshift(File.expand_path("#{dir}/rest-core/lib"))
10
10
 
11
11
  Gemgem.init(dir) do |s|
12
12
  s.name = 'rest-firebase'
13
- s.version = '0.9.2'
13
+ s.version = '0.9.3'
14
14
  s.homepage = 'https://github.com/CodementorIO/rest-firebase'
15
15
 
16
16
  s.authors = ['Codementor', 'Lin Jen-Shin (godfat)']
17
17
  s.email = ['help@codementor.io']
18
18
 
19
- %w[rest-core].each{ |g| s.add_runtime_dependency(g, '>=3.1.1') }
19
+ %w[rest-core].each{ |g| s.add_runtime_dependency(g, '>=3.3.0') }
20
20
 
21
21
  # exclude rest-core
22
22
  s.files.reject!{ |f| f.start_with?('rest-core/') }
data/lib/rest-firebase.rb CHANGED
@@ -3,7 +3,7 @@ require 'rest-core'
3
3
 
4
4
  # https://www.firebase.com/docs/security/custom-login.html
5
5
  # https://www.firebase.com/docs/rest-api.html
6
- RestFirebase = RC::Builder.client(:d, :secret, :auth, :iat) do
6
+ RestFirebase = RC::Builder.client(:d, :secret, :auth, :auth_ttl, :iat) do
7
7
  use RC::Timeout , 10
8
8
 
9
9
  use RC::DefaultSite , 'https://SampleChat.firebaseIO-demo.com/'
@@ -13,11 +13,10 @@ RestFirebase = RC::Builder.client(:d, :secret, :auth, :iat) do
13
13
 
14
14
  use RC::FollowRedirect, 1
15
15
  use RC::CommonLogger , nil
16
- use RC::Cache , nil, 600 do
17
- use RC::ErrorHandler, lambda{ |env| RestFirebase::Error.call(env) }
18
- use RC::ErrorDetectorHttp
19
- use RC::JsonResponse, true
20
- end
16
+ use RC::ErrorHandler , lambda{ |env| RestFirebase::Error.call(env) }
17
+ use RC::ErrorDetectorHttp
18
+ use RC::JsonResponse , true
19
+ use RC::Cache , nil, 600
21
20
  end
22
21
 
23
22
  class RestFirebase::Error < RestCore::Error
@@ -91,6 +90,7 @@ module RestFirebase::Client
91
90
  raise RestFirebase::Error::ClientError.new(
92
91
  "Please set your secret") unless secret
93
92
 
93
+ self.iat = nil
94
94
  header = {:typ => 'JWT', :alg => 'HS256'}
95
95
  claims = {:v => 0, :iat => iat, :d => d}.merge(opts)
96
96
  # http://tools.ietf.org/html/draft-ietf-jose-json-web-signature-26
@@ -101,12 +101,13 @@ module RestFirebase::Client
101
101
 
102
102
  private
103
103
  def base64url str; [str].pack('m').tr('+/', '-_'); end
104
- def default_query; {:auth => auth}; end
105
- def default_auth ; generate_auth ; end
106
- def default_iat ; Time.now.to_i ; end
104
+ def default_query ; {:auth => auth}; end
105
+ def default_auth ; generate_auth ; end
106
+ def default_auth_ttl; 82800 ; end
107
+ def default_iat ; Time.now.to_i ; end
107
108
 
108
109
  def check_auth
109
- self.auth = nil if iat && Time.now.to_i - iat > 82800
110
+ self.auth = nil if auth_ttl && Time.now.to_i - iat > auth_ttl
110
111
  end
111
112
  end
112
113
 
@@ -1,16 +1,16 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: rest-firebase 0.9.2 ruby lib
2
+ # stub: rest-firebase 0.9.3 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "rest-firebase"
6
- s.version = "0.9.2"
6
+ s.version = "0.9.3"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib"]
10
10
  s.authors = [
11
11
  "Codementor",
12
12
  "Lin Jen-Shin (godfat)"]
13
- s.date = "2014-08-06"
13
+ s.date = "2014-08-25"
14
14
  s.description = "Ruby Firebase REST API client built on top of [rest-core][].\n\n[rest-core]: https://github.com/godfat/rest-core"
15
15
  s.email = ["help@codementor.io"]
16
16
  s.files = [
@@ -39,11 +39,11 @@ Gem::Specification.new do |s|
39
39
  s.specification_version = 4
40
40
 
41
41
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
42
- s.add_runtime_dependency(%q<rest-core>, [">= 3.1.1"])
42
+ s.add_runtime_dependency(%q<rest-core>, [">= 3.3.0"])
43
43
  else
44
- s.add_dependency(%q<rest-core>, [">= 3.1.1"])
44
+ s.add_dependency(%q<rest-core>, [">= 3.3.0"])
45
45
  end
46
46
  else
47
- s.add_dependency(%q<rest-core>, [">= 3.1.1"])
47
+ s.add_dependency(%q<rest-core>, [">= 3.3.0"])
48
48
  end
49
49
  end
data/test/test_api.rb CHANGED
@@ -4,7 +4,7 @@ require 'rest-core/test'
4
4
 
5
5
  Pork::API.describe RestFirebase do
6
6
  before do
7
- stub(Time).now{ Time.at(0) }
7
+ stub(Time).now{ Time.at(86400) }
8
8
  end
9
9
 
10
10
  after do
@@ -12,13 +12,13 @@ Pork::API.describe RestFirebase do
12
12
  Muack.verify
13
13
  end
14
14
 
15
- path = 'https://a.json?auth=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9%0A.eyJ2IjowLCJpYXQiOjAsImQiOm51bGx9%0A.C9JtzZhiCrsClNdAQcE7Irngr2BZJCH4x1p-IHxfrAo%3D%0A'
15
+ path = 'https://a.json?auth=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9%0A.eyJ2IjowLCJpYXQiOjg2NDAwLCJkIjpudWxsfQ%3D%3D%0A.cAZWmKD66jARF-BXEi5J1aqJ6khDbFdPAfAqXVbGpZk%3D%0A'
16
16
 
17
17
  json = '{"status":"ok"}'
18
18
  rbon = {'status' => 'ok'}
19
19
 
20
20
  def firebase
21
- RestFirebase.new(:secret => 'nnf')
21
+ @firebase ||= RestFirebase.new(:secret => 'nnf')
22
22
  end
23
23
 
24
24
  would 'get true' do
@@ -60,10 +60,10 @@ SSE
60
60
  end
61
61
 
62
62
  would 'refresh token' do
63
- mock(Time).now{ Time.at(1) }
63
+ mock(Time).now{ Time.at(0) }
64
64
  auth = firebase.auth
65
65
  Muack.verify(Time)
66
- stub(Time).now{ Time.at(0) }
66
+ stub(Time).now{ Time.at(86400) }
67
67
 
68
68
  stub_request(:get, path).to_return(:body => 'true')
69
69
  firebase.get('https://a').should.eq true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest-firebase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Codementor
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-08-06 00:00:00.000000000 Z
12
+ date: 2014-08-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-core
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: 3.1.1
20
+ version: 3.3.0
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: 3.1.1
27
+ version: 3.3.0
28
28
  description: |-
29
29
  Ruby Firebase REST API client built on top of [rest-core][].
30
30