jawbit 0.0.3 → 0.1.0

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: 02cfb4a2ba5c805af02a075023fc9265f181e3cd
4
- data.tar.gz: 472c898d95d5b6a27383b63ad17af073a55b871d
3
+ metadata.gz: b8b0ddedd97d7962f0938fa8583ca72b7cd45314
4
+ data.tar.gz: 2449e0bbe7175602b3ff392fc11b17ddb6097836
5
5
  SHA512:
6
- metadata.gz: 8cc597800a7802e35513a8f1d7bb3258adac9e986f56e8defea72c4f7551d610ff0a3acd74ce72acef5df4871be6a50e326a89b705637fd93991e4d01e2e3260
7
- data.tar.gz: 02b776e04c3fe74ae8676f8450ea3eac7b47180601304a6a8d134c384c20c211c27f6a648d337adc227c49d8e537d0a489a0fd9b5836d8e40a1bc7e4b6ac920f
6
+ metadata.gz: 94ed35949b74db605176b775ff993fcafe9a59ee40fcfb6031c8a4635bab324b995a6185be047e4dd8eddc6240bbd55cf3be614ddc24b97875c2426e0351bd36
7
+ data.tar.gz: bdd21d714d7205e5e641a96ca81a1c6e8f74299db1556abb3eff45aebbe5e42745671e44f68440be0c2533657689dda0e81c6c0d71d9bf58ffd47ae5eb58e6dc
data/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  # Jawbit
2
2
 
3
- For receiving Fitbit and/or Jawbone subscription requests in a Rails (or Rack) app.
3
+ For receiving Fitbit, Jawbone and/or Validic subscription requests in a Rails (or Rack) app.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  Add this line to your application's Gemfile:
8
8
 
9
9
  ```ruby
10
- gem 'jawbit', '0.0.3'
10
+ gem 'jawbit', '0.1.0'
11
11
  ```
12
12
 
13
13
  ## Usage
@@ -18,6 +18,7 @@ post '/fitbit/subscriptions', to: Jawbit::FitbitRack.new(
18
18
  subscriber_id, consumer_secret
19
19
  )
20
20
  post '/jawbone/subscriptions', to: Jawbit::JawboneRack.new
21
+ post '/validic/subscriptions', to: Jawbit::ValidicRack.new
21
22
 
22
23
  # in an initialiser:
23
24
  ActiveSupport::Notifications.subscribe('notification.fitbit') do |*args|
@@ -29,6 +30,11 @@ ActiveSupport::Notifications.subscribe('notification.jawbone') do |*args|
29
30
  event = ActiveSupport::Notifications::Event.new *args
30
31
  # use event.payload[:json] however you like.
31
32
  end
33
+
34
+ ActiveSupport::Notifications.subscribe('notification.validic') do |*args|
35
+ event = ActiveSupport::Notifications::Event.new *args
36
+ # use event.payload[:json] however you like.
37
+ end
32
38
  ```
33
39
 
34
40
  ## Contributing
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = 'jawbit'
4
- spec.version = '0.0.3'
4
+ spec.version = '0.1.0'
5
5
  spec.authors = ['Pat Allan']
6
6
  spec.email = ['pat@freelancing-gods.com']
7
7
  spec.summary = %q{Captures Fitbit and Jawbone subscription notifications.}
@@ -8,3 +8,4 @@ end
8
8
 
9
9
  require 'jawbit/fitbit_rack'
10
10
  require 'jawbit/jawbone_rack'
11
+ require 'jawbit/validic_rack'
@@ -18,8 +18,6 @@ class Jawbit::FitbitRack
18
18
  attr_reader :subscriber_id, :consumer_secret
19
19
 
20
20
  def json(request)
21
- MultiJson.load request.body.read
22
- rescue MultiJson::ParseError
23
- []
21
+ MultiJson.load request.params['updates'][:tempfile].read
24
22
  end
25
23
  end
@@ -13,7 +13,5 @@ class Jawbit::JawboneRack
13
13
 
14
14
  def json(request)
15
15
  MultiJson.load request.body.read
16
- rescue MultiJson::ParseError
17
- []
18
16
  end
19
17
  end
@@ -0,0 +1,17 @@
1
+ class Jawbit::ValidicRack
2
+ delegate :instrument, to: ActiveSupport::Notifications
3
+
4
+ def call(env)
5
+ request = Rack::Request.new env
6
+
7
+ instrument 'notification.validic', json: json(request)
8
+
9
+ [200, {}, ['']]
10
+ end
11
+
12
+ private
13
+
14
+ def json(request)
15
+ MultiJson.load request.body.read
16
+ end
17
+ end
@@ -16,6 +16,14 @@ describe 'Fitbit Subscriptions' do
16
16
  )
17
17
  end
18
18
 
19
+ def multipart_update(string)
20
+ tempfile = Tempfile.new 'updates'
21
+ tempfile.write string
22
+ tempfile.rewind
23
+
24
+ Rack::Test::UploadedFile.new(tempfile.path, 'application/json')
25
+ end
26
+
19
27
  after :each do
20
28
  subscriptions.each do |subscription|
21
29
  ActiveSupport::Notifications.unsubscribe(subscription)
@@ -23,7 +31,7 @@ describe 'Fitbit Subscriptions' do
23
31
  end
24
32
 
25
33
  it 'returns a 204' do
26
- post '/'
34
+ post '/', updates: multipart_update('[]')
27
35
 
28
36
  expect(last_response.status).to eq(204)
29
37
  end
@@ -32,7 +40,7 @@ describe 'Fitbit Subscriptions' do
32
40
  notification = false
33
41
  subscribe { |*args| notification = true }
34
42
 
35
- post '/'
43
+ post '/', updates: multipart_update('[]')
36
44
 
37
45
  expect(notification).to eq(true)
38
46
  end
@@ -43,6 +51,6 @@ describe 'Fitbit Subscriptions' do
43
51
  expect(event.payload[:json]).to eq([{'foo' => 'bar'}])
44
52
  }
45
53
 
46
- post '/', '[{"foo":"bar"}]'
54
+ post '/', updates: multipart_update('[{"foo":"bar"}]')
47
55
  end
48
56
  end
@@ -19,7 +19,7 @@ describe 'Jawbone Subscriptions' do
19
19
  end
20
20
 
21
21
  it 'returns a 200' do
22
- post '/'
22
+ post '/', '[]'
23
23
 
24
24
  expect(last_response.status).to eq(200)
25
25
  end
@@ -28,7 +28,7 @@ describe 'Jawbone Subscriptions' do
28
28
  notification = false
29
29
  subscribe { |*args| notification = true }
30
30
 
31
- post '/'
31
+ post '/', '[]'
32
32
 
33
33
  expect(notification).to eq(true)
34
34
  end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Validic Subscriptions' do
4
+ include Rack::Test::Methods
5
+
6
+ let(:app) { Jawbit::ValidicRack.new }
7
+ let(:subscriptions) { [] }
8
+
9
+ def subscribe(&block)
10
+ subscriptions << ActiveSupport::Notifications.subscribe(
11
+ 'notification.validic', &block
12
+ )
13
+ end
14
+
15
+ after :each do
16
+ subscriptions.each do |subscription|
17
+ ActiveSupport::Notifications.unsubscribe(subscription)
18
+ end
19
+ end
20
+
21
+ it 'returns a 200' do
22
+ post '/', '[]'
23
+
24
+ expect(last_response.status).to eq(200)
25
+ end
26
+
27
+ it 'fires an event' do
28
+ notification = false
29
+ subscribe { |*args| notification = true }
30
+
31
+ post '/', '[]'
32
+
33
+ expect(notification).to eq(true)
34
+ end
35
+
36
+ it 'includes the JSON body' do
37
+ subscribe { |*args|
38
+ event = ActiveSupport::Notifications::Event.new *args
39
+ expect(event.payload[:json]).to eq([{'foo' => 'bar'}])
40
+ }
41
+
42
+ post '/', '[{"foo":"bar"}]'
43
+ end
44
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jawbit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Allan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-03 00:00:00.000000000 Z
11
+ date: 2014-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -99,8 +99,10 @@ files:
99
99
  - lib/jawbit.rb
100
100
  - lib/jawbit/fitbit_rack.rb
101
101
  - lib/jawbit/jawbone_rack.rb
102
+ - lib/jawbit/validic_rack.rb
102
103
  - spec/acceptance/fitbit_notifications_spec.rb
103
104
  - spec/acceptance/jawbone_notifications_spec.rb
105
+ - spec/acceptance/validic_notifications_spec.rb
104
106
  - spec/spec_helper.rb
105
107
  homepage: https://github.com/inspire9/jawbit
106
108
  licenses:
@@ -122,12 +124,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
124
  version: '0'
123
125
  requirements: []
124
126
  rubyforge_project:
125
- rubygems_version: 2.2.2
127
+ rubygems_version: 2.3.0
126
128
  signing_key:
127
129
  specification_version: 4
128
130
  summary: Captures Fitbit and Jawbone subscription notifications.
129
131
  test_files:
130
132
  - spec/acceptance/fitbit_notifications_spec.rb
131
133
  - spec/acceptance/jawbone_notifications_spec.rb
134
+ - spec/acceptance/validic_notifications_spec.rb
132
135
  - spec/spec_helper.rb
133
136
  has_rdoc: