fitbit_subscriptions 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 66fdd780843d854a27114601c73f481db7ec9c23
4
+ data.tar.gz: 58b7108d5777c4f150f4bb7fa51916a01e529224
5
+ SHA512:
6
+ metadata.gz: 51f06074e6ec417a5cee54741a3dd74905af6e6c69c9a14b6b5f0c69d864f27bf605871a40c43f609f3d517ea10be4a4a07bbd973d3e454a6b30d916738e53e5
7
+ data.tar.gz: f446ff890e4966c126c6475b8e66e739794a6114bdb93e991d3556ee56f0c5acdf354485866c64b82b91ed2bbe4bd71ac5e3b06aee897e1a0d7d9d3e7dc69354
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ script: bundle exec rspec spec
3
+ cache: bundler
4
+ rvm:
5
+ - 1.9.3
6
+ - 2.0.0
7
+ - 2.1.1
8
+ notifications:
9
+ slack:
10
+ secure: "jHdpTKZw0/7FAmBH6y5uRjFiY9cxRMbWN2F8pQcffmiCncBK59PZC8ppF5tGLV/NEX4knZPkU4gw2e6/IfFsP6cznj6SpzaQAgHJko2e7+I1P0AGNkizzVbWK4ix55YP59v+/9cBa5ldargD2/qUdqpdAv1EVzU2GslNWooq6qQ="
11
+ on_success: change
12
+ on_failure: change
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Inspire9
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,38 @@
1
+ # Fitbit Subscriptions
2
+
3
+ For receiving Fitbit subscription requests in a Rails (or Rack) app.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'fitbit_subscriptions', '0.0.1'
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ruby
16
+ # in config/routes.rb
17
+ post '/fitbit/subscriptions', to: FitbitSubscriptions::Rack.new(
18
+ subscriber_id, consumer_secret
19
+ )
20
+
21
+ # in an initialiser:
22
+ ActiveSupport::Notifications.subscribe('notification.fitbit') do |*args|
23
+ event = ActiveSupport::Notifications::Event.new *args
24
+ # use event.payload[:json] however you like.
25
+ end
26
+ ```
27
+
28
+ ## Contributing
29
+
30
+ 1. Fork it ( https://github.com/[my-github-username]/fitbit_subscriptions/fork )
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create a new Pull Request
35
+
36
+ ## Licence
37
+
38
+ Copyright (c) 2014, Fitbit Subscriptions is developed and maintained by [Inspire9](http://development.inspire9.com), and is released under the open MIT Licence.
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ Gem::Specification.new do |spec|
3
+ spec.name = 'fitbit_subscriptions'
4
+ spec.version = '0.0.1'
5
+ spec.authors = ['Pat Allan']
6
+ spec.email = ['pat@freelancing-gods.com']
7
+ spec.summary = %q{Captures Fitbit subscription notifications.}
8
+ spec.description = <<-DESC
9
+ Handle Fitbit subscription notifications within a Rails or Rack app, and pass
10
+ them on via ActiveSupport::Notifications.
11
+ DESC
12
+ spec.homepage = 'https://github.com/inspire9/fitbit_subscriptions'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files`.split("\n")
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ['lib']
18
+
19
+ spec.add_runtime_dependency 'activesupport', '>= 3.1.0'
20
+ spec.add_runtime_dependency 'multi_json', '>= 1.3.0'
21
+ spec.add_runtime_dependency 'rack'
22
+
23
+ spec.add_development_dependency 'rack-test', '~> 0.6.2'
24
+ spec.add_development_dependency 'rspec', '~> 3.0.0.beta2'
25
+ end
@@ -0,0 +1,9 @@
1
+ require 'active_support/notifications'
2
+ require 'active_support/core_ext/module/delegation'
3
+ require 'multi_json'
4
+
5
+ module FitbitSubscriptions
6
+ #
7
+ end
8
+
9
+ require 'fitbit_subscriptions/rack'
@@ -0,0 +1,25 @@
1
+ class FitbitSubscriptions::Rack
2
+ delegate :instrument, to: ActiveSupport::Notifications
3
+
4
+ def initialize(subscriber_id, consumer_secret)
5
+ @subscriber_id, @consumer_secret = subscriber_id, consumer_secret
6
+ end
7
+
8
+ def call(env)
9
+ request = Rack::Request.new env
10
+
11
+ instrument 'notification.fitbit', json: json(request)
12
+
13
+ [204, {}, ['']]
14
+ end
15
+
16
+ private
17
+
18
+ attr_reader :subscriber_id, :consumer_secret
19
+
20
+ def json(request)
21
+ MultiJson.load request.body.read
22
+ rescue MultiJson::ParseError
23
+ []
24
+ end
25
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Fitbit Subscriptions' do
4
+ include Rack::Test::Methods
5
+
6
+ let(:app) {
7
+ FitbitSubscriptions::Rack.new subscription_id, consumer_secret
8
+ }
9
+ let(:subscription_id) { 'sub' }
10
+ let(:consumer_secret) { '12345678901234567890123456789012' }
11
+ let(:subscriptions) { [] }
12
+
13
+ def subscribe(&block)
14
+ subscriptions << ActiveSupport::Notifications.subscribe(
15
+ 'notification.fitbit', &block
16
+ )
17
+ end
18
+
19
+ after :each do
20
+ subscriptions.each do |subscription|
21
+ ActiveSupport::Notifications.unsubscribe(subscription)
22
+ end
23
+ end
24
+
25
+ it 'returns a 204' do
26
+ post '/'
27
+
28
+ expect(last_response.status).to eq(204)
29
+ end
30
+
31
+ it 'fires an event' do
32
+ notification = false
33
+ subscribe { |*args| notification = true }
34
+
35
+ post '/'
36
+
37
+ expect(notification).to eq(true)
38
+ end
39
+
40
+ it 'includes the JSON body' do
41
+ subscribe { |*args|
42
+ event = ActiveSupport::Notifications::Event.new *args
43
+ expect(event.payload[:json]).to eq([{'foo' => 'bar'}])
44
+ }
45
+
46
+ post '/', '[{"foo":"bar"}]'
47
+ end
48
+ end
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ Bundler.require :default, :development
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fitbit_subscriptions
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Pat Allan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: multi_json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.3.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.3.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rack
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rack-test
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.6.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.6.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 3.0.0.beta2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.0.0.beta2
83
+ description: |
84
+ Handle Fitbit subscription notifications within a Rails or Rack app, and pass
85
+ them on via ActiveSupport::Notifications.
86
+ email:
87
+ - pat@freelancing-gods.com
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".gitignore"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - fitbit_subscriptions.gemspec
99
+ - lib/fitbit_subscriptions.rb
100
+ - lib/fitbit_subscriptions/rack.rb
101
+ - spec/acceptance/notifications_spec.rb
102
+ - spec/spec_helper.rb
103
+ homepage: https://github.com/inspire9/fitbit_subscriptions
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.2.2
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Captures Fitbit subscription notifications.
127
+ test_files:
128
+ - spec/acceptance/notifications_spec.rb
129
+ - spec/spec_helper.rb
130
+ has_rdoc: