quadhook 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +10 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +56 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/quadhook.rb +13 -0
- data/lib/quadhook/endpoint.rb +33 -0
- data/lib/quadhook/verifier.rb +45 -0
- data/quadhook.gemspec +23 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7faa47d65ab2b4808fddfea83e1e3bcca8c1b7e9
|
4
|
+
data.tar.gz: 71135c6a0ef3d879c0aade93cd1084e80a74f42f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1f6464d1889828fb08af87334682c76a9d14dd7bc3cab5bbfef4c8c293029db5175646a5ff5d5802b8c713a180ee3849fb6a987e426bc22f7788069b26e6222f
|
7
|
+
data.tar.gz: 04478ccf74f767dfe5cc6234120eb728026711a91821813ad5da09128534fab69fbe5d73c6ce6ec274564410012f8b83b855801317bedf5728c14678f6553761
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
language: ruby
|
2
|
+
script: bundle exec rspec
|
3
|
+
cache: bundler
|
4
|
+
rvm:
|
5
|
+
- 2.2.1
|
6
|
+
notifications:
|
7
|
+
slack:
|
8
|
+
secure: "RUwMNyz+MYc7VvH+ZhcxyLxUKO1/CqqE11/AxCPrWIf0nJUAjb5qlAYaj6HaJqIiW/JgV19pQgZgtA2bZZE9vOjm2w0i+G7a+89betFEKHkCifiok9DBYJ8jynvWaB1KFWaHYUWbJ5VuBQGFBqGCLHzxIFautBN9FfxIdNaKGZM="
|
9
|
+
on_success: change
|
10
|
+
on_failure: change
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 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.
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# Quadhook
|
2
|
+
|
3
|
+
A Rack endpoint for handling Quaderno webhooks, and fires an ActiveSupport notification for each succesful request.
|
4
|
+
|
5
|
+
[![Build Status](https://travis-ci.org/inspire9/quadhook.svg)](https://travis-ci.org/inspire9/quadhook)
|
6
|
+
[![Code Climate](https://codeclimate.com/github/inspire9/quadhook/badges/gpa.svg)](https://codeclimate.com/github/inspire9/quadhook)
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'quadhook', '~> 0.0.1'
|
14
|
+
```
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
Mount an instance of `Quadhook::Endpoint` to your preferred route. In a Rails app, that'd look something like this:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
post '/quaderno/webhook', to: Quaderno::Endpoint.new(
|
22
|
+
ENV['QUADERNO_AUTH_KEY'],
|
23
|
+
ENV['QUADERNO_HOOK_URI']
|
24
|
+
)
|
25
|
+
```
|
26
|
+
|
27
|
+
Then, handle the notifications using something like the following (which would probably go in an initialiser for a Rails app):
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
ActiveSupport::Notifications.subscribe(
|
31
|
+
'notification.quaderno.webhook'
|
32
|
+
) do |*args|
|
33
|
+
event = ActiveSupport::Notifications::Event.new *args
|
34
|
+
# use event.payload[:event_type] and event.payload[:data] however you like.
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
## Development
|
39
|
+
|
40
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
41
|
+
|
42
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
Firstly, please note the Code of Conduct for all contributions to this project. If you accept that, then the steps for contributing are probably something along the lines of:
|
47
|
+
|
48
|
+
1. Fork it ( https://github.com/inspire9/quadhook/fork )
|
49
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
50
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
51
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
52
|
+
5. Create a new Pull Request
|
53
|
+
|
54
|
+
## Licence
|
55
|
+
|
56
|
+
Copyright (c) 2015, Quadhook is developed and maintained by [Inspire9](http://development.inspire9.com), and is released under the open MIT Licence.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "quadhook"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/quadhook.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'openssl'
|
3
|
+
require 'rack'
|
4
|
+
require 'json'
|
5
|
+
require 'active_support/notifications'
|
6
|
+
require 'active_support/core_ext/module/delegation'
|
7
|
+
|
8
|
+
module Quadhook
|
9
|
+
#
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'quadhook/endpoint'
|
13
|
+
require 'quadhook/verifier'
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class Quadhook::Endpoint
|
2
|
+
delegate :instrument, to: ActiveSupport::Notifications
|
3
|
+
|
4
|
+
def initialize(api_key, uri)
|
5
|
+
@api_key, @uri = api_key, uri
|
6
|
+
end
|
7
|
+
|
8
|
+
def call(env)
|
9
|
+
request = Rack::Request.new env
|
10
|
+
|
11
|
+
if Quadhook::Verifier.new(request, api_key, uri).call
|
12
|
+
json = json_from_body request
|
13
|
+
|
14
|
+
instrument 'notification.quadhook.webhook',
|
15
|
+
event_type: json['event_type'],
|
16
|
+
data: json['data']
|
17
|
+
|
18
|
+
[200, {}, ['']]
|
19
|
+
else
|
20
|
+
[400, {}, ['']]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
attr_reader :api_key, :uri
|
27
|
+
|
28
|
+
def json_from_body(request)
|
29
|
+
request.body.rewind
|
30
|
+
|
31
|
+
JSON.parse request.body.read
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
class Quadhook::Verifier
|
2
|
+
def initialize(request, api_key, uri)
|
3
|
+
@request, @api_key, @uri = request, api_key, uri
|
4
|
+
end
|
5
|
+
|
6
|
+
def call
|
7
|
+
hmac == header
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
attr_reader :request, :api_key, :uri
|
13
|
+
|
14
|
+
def body
|
15
|
+
request.body.rewind
|
16
|
+
request.body.read
|
17
|
+
end
|
18
|
+
|
19
|
+
def data
|
20
|
+
"#{uri}#{params.sort.flatten.join}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def digest
|
24
|
+
OpenSSL::Digest.new 'sha1'
|
25
|
+
end
|
26
|
+
|
27
|
+
def header
|
28
|
+
request.env['HTTP_X_QUADERNO_SIGNATURE'] ||
|
29
|
+
request.env['X-Quaderno-Signature']
|
30
|
+
end
|
31
|
+
|
32
|
+
def hmac
|
33
|
+
Base64.encode64(
|
34
|
+
OpenSSL::HMAC.digest(digest, api_key, data)
|
35
|
+
).strip
|
36
|
+
end
|
37
|
+
|
38
|
+
def params
|
39
|
+
@params ||= begin
|
40
|
+
JSON.parse body
|
41
|
+
rescue JSON::ParserError
|
42
|
+
{}
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/quadhook.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
Gem::Specification.new do |spec|
|
3
|
+
spec.name = "quadhook"
|
4
|
+
spec.version = '0.0.1'
|
5
|
+
spec.authors = ["Pat Allan"]
|
6
|
+
spec.email = ["pat@freelancing-gods.com"]
|
7
|
+
|
8
|
+
spec.summary = %q{Webhook handler for Quaderno}
|
9
|
+
spec.description = %q{Rack endpoint for capturing webhook requests from Quaderno's invoicing service.}
|
10
|
+
spec.homepage = "https://github.com/inspire9/quadhook"
|
11
|
+
|
12
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
13
|
+
spec.bindir = "exe"
|
14
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
15
|
+
spec.require_paths = ["lib"]
|
16
|
+
|
17
|
+
spec.add_runtime_dependency 'activesupport', '>= 3.1.0'
|
18
|
+
spec.add_runtime_dependency 'json', '>= 1.8.0'
|
19
|
+
spec.add_runtime_dependency 'rack'
|
20
|
+
|
21
|
+
spec.add_development_dependency 'rack-test', '~> 0.6.3'
|
22
|
+
spec.add_development_dependency 'rspec', '~> 3.2.0'
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: quadhook
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pat Allan
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-21 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: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.8.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.8.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.3
|
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.3
|
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.2.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.2.0
|
83
|
+
description: Rack endpoint for capturing webhook requests from Quaderno's invoicing
|
84
|
+
service.
|
85
|
+
email:
|
86
|
+
- pat@freelancing-gods.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".travis.yml"
|
93
|
+
- CODE_OF_CONDUCT.md
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- bin/console
|
99
|
+
- bin/setup
|
100
|
+
- lib/quadhook.rb
|
101
|
+
- lib/quadhook/endpoint.rb
|
102
|
+
- lib/quadhook/verifier.rb
|
103
|
+
- quadhook.gemspec
|
104
|
+
homepage: https://github.com/inspire9/quadhook
|
105
|
+
licenses: []
|
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.4.5
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: Webhook handler for Quaderno
|
127
|
+
test_files: []
|
128
|
+
has_rdoc:
|