rest-firebase 0.9.1 → 0.9.2

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: 38ac75dc25a2212b5493f30523502a0c524e5423
4
- data.tar.gz: 194f4cafa79ce00c6d33dd9dbdf086ce0c30bda3
3
+ metadata.gz: 8dca5beda4578735562a476964ad93b23d7b9709
4
+ data.tar.gz: 4bc1fb75725927cc7f243d6e60175149175580e6
5
5
  SHA512:
6
- metadata.gz: 9e9dfc59ecf61bcdd560d72bfe851464f3a183bc514a98b1c5464d58f013cac9d2de2404be278005ed33f821f5becfd4a38984187fbfa83de96d95619ed04a53
7
- data.tar.gz: 502858f091acd477c0e6ad2ed4c142845899ddaa8b16686ef2df5ff4e2134966bf7a54d3fd8c3e43b16a7f7bbfbc6c039a57d18d39ec66e235e01634195ab9e2
6
+ metadata.gz: a381558128fced5ef49b8a16eef953382357f271f3fd13100face98cdb91cbd4d56f228c818113796eccf84cb3b6ce0726265b172d99e12b57c3f696eef397ad
7
+ data.tar.gz: f27f1b64f9dc5d91c010a1f3533d9ce12b46af9f2dd94e74b660bbb85a6ec15d507da0dfa2a6bed41df0d8a817572bb4612b905c217ebc6dbedd0670e5998fd6
data/CHANGES.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGES
2
2
 
3
+ ## rest-firebase 0.9.2 -- 2014-08-06
4
+
5
+ * Now it would auto-refresh auth if it's also expired (>= 23 hours)
6
+
3
7
  ## rest-firebase 0.9.1 -- 2014-06-28
4
8
 
5
9
  * Now it would properly send JSON payload and headers.
data/Gemfile CHANGED
@@ -8,7 +8,7 @@ gem 'rest-core', :path => 'rest-core' if
8
8
  File.exist?("#{File.dirname(File.expand_path(__FILE__))}/rest-core/Gemfile")
9
9
 
10
10
  gem 'rake'
11
- gem 'bacon'
11
+ gem 'pork'
12
12
  gem 'muack'
13
13
  gem 'webmock'
14
14
 
data/Rakefile CHANGED
@@ -10,7 +10,7 @@ $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.1'
13
+ s.version = '0.9.2'
14
14
  s.homepage = 'https://github.com/CodementorIO/rest-firebase'
15
15
 
16
16
  s.authors = ['Codementor', 'Lin Jen-Shin (godfat)']
data/TODO.md CHANGED
@@ -1,3 +1 @@
1
1
  # TODO
2
-
3
- * auto-refresh the auth
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) do
6
+ RestFirebase = RC::Builder.client(:d, :secret, :auth, :iat) do
7
7
  use RC::Timeout , 10
8
8
 
9
9
  use RC::DefaultSite , 'https://SampleChat.firebaseIO-demo.com/'
@@ -75,6 +75,8 @@ module RestFirebase::Client
75
75
  end
76
76
 
77
77
  def request env, app=app
78
+ check_auth
79
+
78
80
  path = "#{env[REQUEST_PATH]}.json"
79
81
  payload = if env[REQUEST_PAYLOAD]
80
82
  {REQUEST_PAYLOAD => Json.encode(env[REQUEST_PAYLOAD])}
@@ -90,7 +92,7 @@ module RestFirebase::Client
90
92
  "Please set your secret") unless secret
91
93
 
92
94
  header = {:typ => 'JWT', :alg => 'HS256'}
93
- claims = {:v => 0, :iat => Time.now.to_i, :d => d}.merge(opts)
95
+ claims = {:v => 0, :iat => iat, :d => d}.merge(opts)
94
96
  # http://tools.ietf.org/html/draft-ietf-jose-json-web-signature-26
95
97
  input = [header, claims].map{ |d| base64url(Json.encode(d)) }.join('.')
96
98
  # http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-20
@@ -101,6 +103,11 @@ module RestFirebase::Client
101
103
  def base64url str; [str].pack('m').tr('+/', '-_'); end
102
104
  def default_query; {:auth => auth}; end
103
105
  def default_auth ; generate_auth ; end
106
+ def default_iat ; Time.now.to_i ; end
107
+
108
+ def check_auth
109
+ self.auth = nil if iat && Time.now.to_i - iat > 82800
110
+ end
104
111
  end
105
112
 
106
113
  class RestFirebase
@@ -1,16 +1,16 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: rest-firebase 0.9.1 ruby lib
2
+ # stub: rest-firebase 0.9.2 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "rest-firebase"
6
- s.version = "0.9.1"
6
+ s.version = "0.9.2"
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-06-28"
13
+ s.date = "2014-08-06"
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 = [
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
31
31
  "test/test_api.rb"]
32
32
  s.homepage = "https://github.com/CodementorIO/rest-firebase"
33
33
  s.licenses = ["Apache License 2.0"]
34
- s.rubygems_version = "2.2.2"
34
+ s.rubygems_version = "2.4.1"
35
35
  s.summary = "Ruby Firebase REST API client built on top of [rest-core][]."
36
36
  s.test_files = ["test/test_api.rb"]
37
37
 
data/task/gemgem.rb CHANGED
@@ -227,10 +227,6 @@ end # of gem namespace
227
227
  desc 'Run tests'
228
228
  task :test do
229
229
  next if Gemgem.test_files.empty?
230
-
231
- require 'bacon'
232
- Bacon.extend(Bacon::TestUnitOutput)
233
- Bacon.summary_on_exit
234
230
  Gemgem.test_files.each{ |file| require "#{Gemgem.dir}/#{file[0..-4]}" }
235
231
  end
236
232
 
data/test/test_api.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  require 'rest-firebase'
3
3
  require 'rest-core/test'
4
4
 
5
- describe RestFirebase do
5
+ Pork::API.describe RestFirebase do
6
6
  before do
7
7
  stub(Time).now{ Time.at(0) }
8
8
  end
@@ -21,22 +21,22 @@ describe RestFirebase do
21
21
  RestFirebase.new(:secret => 'nnf')
22
22
  end
23
23
 
24
- should 'get true' do
24
+ would 'get true' do
25
25
  stub_request(:get, path).to_return(:body => 'true')
26
26
  firebase.get('https://a').should.eq true
27
27
  end
28
28
 
29
- should 'put {"status":"ok"}' do
29
+ would 'put {"status":"ok"}' do
30
30
  stub_request(:put, path).with(:body => json).to_return(:body => json)
31
31
  firebase.put('https://a', rbon).should.eq rbon
32
32
  end
33
33
 
34
- should 'have no payload for delete' do
34
+ would 'have no payload for delete' do
35
35
  stub_request(:delete, path).with(:body => nil).to_return(:body => json)
36
36
  firebase.delete('https://a').should.eq rbon
37
37
  end
38
38
 
39
- should 'parse event source' do
39
+ would 'parse event source' do
40
40
  stub_request(:get, path).to_return(:body => <<-SSE)
41
41
  event: put
42
42
  data: {}
@@ -50,16 +50,27 @@ SSE
50
50
  m = [{'event' => 'put' , 'data' => {}},
51
51
  {'event' => 'keep-alive', 'data' => nil}]
52
52
  es = firebase.event_source('https://a')
53
- es.should.kind_of RestFirebase::Client::EventSource
53
+ es.should.kind_of? RestFirebase::Client::EventSource
54
54
  es.onmessage do |event, data|
55
55
  {'event' => event, 'data' => data}.should.eq m.shift
56
56
  end.onerror do |error|
57
- error.should.kind_of RC::Json::ParseError
57
+ error.should.kind_of? RC::Json::ParseError
58
58
  end.start.wait
59
- m.should.empty
59
+ m.should.empty?
60
60
  end
61
61
 
62
- check = lambda do |status, klass|
62
+ would 'refresh token' do
63
+ mock(Time).now{ Time.at(1) }
64
+ auth = firebase.auth
65
+ Muack.verify(Time)
66
+ stub(Time).now{ Time.at(0) }
67
+
68
+ stub_request(:get, path).to_return(:body => 'true')
69
+ firebase.get('https://a').should.eq true
70
+ firebase.auth.should.not.eq auth
71
+ end
72
+
73
+ define_method :check do |status, klass|
63
74
  stub_request(:delete, path).to_return(
64
75
  :body => '{}', :status => status)
65
76
 
@@ -68,12 +79,12 @@ SSE
68
79
  WebMock.reset!
69
80
  end
70
81
 
71
- should 'raise exception when encountering error' do
82
+ would 'raise exception when encountering error' do
72
83
  [400, 401, 402, 403, 404, 406, 417].each do |status|
73
- check[status, RestFirebase::Error]
84
+ check(status, RestFirebase::Error)
74
85
  end
75
86
  [500, 502, 503].each do |status|
76
- check[status, RestFirebase::Error::ServerError]
87
+ check(status, RestFirebase::Error::ServerError)
77
88
  end
78
89
  end
79
90
  end
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.1
4
+ version: 0.9.2
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-06-28 00:00:00.000000000 Z
12
+ date: 2014-08-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-core
@@ -70,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
70
  version: '0'
71
71
  requirements: []
72
72
  rubyforge_project:
73
- rubygems_version: 2.2.2
73
+ rubygems_version: 2.4.1
74
74
  signing_key:
75
75
  specification_version: 4
76
76
  summary: Ruby Firebase REST API client built on top of [rest-core][].