gcm_middleware 0.0.1 → 0.0.2
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac61ade0afe4dbe472d9eadd91962d9f52e1df20
|
4
|
+
data.tar.gz: 2747f613ef9131048a6658c7372260d6254f949a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 218463a6fe419556cee7aeef96708a7f6e93b95061141e171389349f59b1c73dd04ca2bec760260c86d68d5dd2a9d9335517653dfec2ce413559bd55674d0986
|
7
|
+
data.tar.gz: b8c545b3d5504c40535a9a831e77e1d4f0acc484c2bfc53d16581572253d54f28d7ce9c66393caf3f1fdd3ee9510ac0c6770b8a4ae929c36a3907ac14f4e5912
|
@@ -1,21 +1,26 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
1
3
|
module GCMMiddleware
|
2
|
-
class Authentication
|
4
|
+
class Authentication < Faraday::Middleware
|
3
5
|
def initialize(app, options = {})
|
4
|
-
|
6
|
+
super(app)
|
7
|
+
@key = options.fetch(:key, '')
|
8
|
+
|
9
|
+
raise ArgumentError.new('No api key was provided') if @key.nil? || @key.empty?
|
5
10
|
end
|
6
11
|
|
7
12
|
def call(env)
|
8
13
|
env.request_headers['Authorization'] = auth_key
|
9
14
|
|
10
|
-
app.call(env).on_complete { |env| }
|
15
|
+
@app.call(env).on_complete { |env| }
|
11
16
|
end
|
12
17
|
|
13
18
|
private
|
14
19
|
|
15
|
-
attr_reader :
|
20
|
+
attr_reader :key
|
16
21
|
|
17
22
|
def auth_key
|
18
|
-
@auth_key ||= "key=#{
|
23
|
+
@auth_key ||= "key=#{key}".freeze
|
19
24
|
end
|
20
25
|
end
|
21
26
|
end
|
@@ -1,20 +1,18 @@
|
|
1
|
-
|
2
|
-
class CanonicalId
|
3
|
-
def initialize(app, options = {})
|
4
|
-
@app = app
|
5
|
-
end
|
1
|
+
require 'faraday'
|
6
2
|
|
3
|
+
module GCMMiddleware
|
4
|
+
class CanonicalId < Faraday::Middleware
|
7
5
|
def call(env)
|
8
6
|
save_ids(env.body)
|
9
7
|
|
10
|
-
app.call(env).on_complete do |env|
|
8
|
+
@app.call(env).on_complete do |env|
|
11
9
|
inject_original_ids(env.body) if has_registration_ids && env.body
|
12
10
|
end
|
13
11
|
end
|
14
12
|
|
15
13
|
private
|
16
14
|
|
17
|
-
attr_reader :registration_ids
|
15
|
+
attr_reader :registration_ids
|
18
16
|
|
19
17
|
def inject_original_ids(body)
|
20
18
|
body['results'].each_with_index do |result, i|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
describe GCMMiddleware::Authentication do
|
2
2
|
let(:faraday) do
|
3
3
|
Faraday.new('http://www.example.com') do |builder|
|
4
|
-
builder.use GCMMiddleware::Authentication, key:
|
4
|
+
builder.use GCMMiddleware::Authentication, key: auth_key
|
5
5
|
|
6
6
|
builder.adapter :test do |stub|
|
7
7
|
stub.get('/test') { |env| [ 200, {}, {} ] }
|
@@ -9,10 +9,35 @@ describe GCMMiddleware::Authentication do
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
context 'with auth key' do
|
13
|
+
let(:auth_key) { 'auth-key' }
|
14
14
|
|
15
|
-
|
15
|
+
it 'injects the key into the header' do
|
16
|
+
response = faraday.get '/test'
|
17
|
+
|
18
|
+
expect(response.env.request_headers['Authorization']).to eq('key=auth-key')
|
19
|
+
end
|
16
20
|
end
|
17
|
-
end
|
18
21
|
|
22
|
+
context 'with no auth key' do
|
23
|
+
context 'with nil auth key' do
|
24
|
+
let(:auth_key) { nil }
|
25
|
+
|
26
|
+
it 'throws a error if no api key is provided' do
|
27
|
+
expect {
|
28
|
+
faraday.get '/test'
|
29
|
+
}.to raise_error(ArgumentError, 'No api key was provided')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'with empty api key' do
|
34
|
+
let(:auth_key) { '' }
|
35
|
+
|
36
|
+
it 'throws a error if no api key is provided' do
|
37
|
+
expect {
|
38
|
+
faraday.get '/test'
|
39
|
+
}.to raise_error(ArgumentError, 'No api key was provided')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gcm_middleware
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Trevor John
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|