solidus_webhooks 0.0.1.v0.1.0.beta.1.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +6 -0
- data/.gem_release.yml +1 -1
- data/.github/stale.yml +4 -4
- data/.github_changelog_generator +2 -0
- data/.gitignore +3 -0
- data/.rubocop.yml +21 -0
- data/CHANGELOG.md +52 -0
- data/README.md +56 -33
- data/Rakefile +16 -0
- data/app/controllers/spree/webhooks_controller.rb +3 -2
- data/app/models/spree/webhook.rb +19 -5
- data/bin/rails +7 -0
- data/bin/{r → rails-engine} +0 -0
- data/bin/{sandbox_rails → rails-sandbox} +1 -3
- data/bin/sandbox +2 -0
- data/lib/generators/solidus_webhooks/install/install_generator.rb +10 -5
- data/lib/generators/solidus_webhooks/install/templates/initializer.rb +6 -0
- data/lib/solidus_webhooks.rb +1 -1
- data/lib/solidus_webhooks/configuration.rb +18 -8
- data/lib/solidus_webhooks/errors.rb +4 -0
- data/lib/solidus_webhooks/testing_support/factories.rb +4 -0
- data/lib/solidus_webhooks/version.rb +1 -1
- data/solidus_webhooks.gemspec +4 -4
- data/spec/features/can_register_a_handler_and_receive_webhooks_spec.rb +44 -17
- data/spec/models/spree/webhook_spec.rb +12 -0
- data/spec/solidus_webhooks/configuration_spec.rb +10 -0
- data/spec/spec_helper.rb +11 -4
- data/spec/support/reset_config.rb +3 -0
- metadata +33 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f94eb7d8c956dd983b90ff8ab0d14fde3fbad148400e29222c8be84d403c1baa
|
4
|
+
data.tar.gz: fd828061690984b542190754621d8d9b86ba34ae89070f25db9f838a0de22c78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37142b4bd06257070f31083a3a99a8594654c626e52e21d41b95f075c4f3a3adc2064cd9831f2c36de5500fa91805d763e5913ea07b9b7c184ac11f6bb6755a8
|
7
|
+
data.tar.gz: f4cb38e4f31a7e7e1c60603c79ccc96b35365b5309b35cd959ff29175f7368ca1f95cd16be32ebdd00a8eeeb92cde2c8d1f00287f2f3e6bab42d0a65987e482a
|
data/.circleci/config.yml
CHANGED
@@ -16,12 +16,18 @@ jobs:
|
|
16
16
|
executor: solidusio_extensions/mysql
|
17
17
|
steps:
|
18
18
|
- solidusio_extensions/run-tests
|
19
|
+
lint-code:
|
20
|
+
executor: solidusio_extensions/sqlite-memory
|
21
|
+
steps:
|
22
|
+
- solidusio_extensions/lint-code
|
19
23
|
|
20
24
|
workflows:
|
21
25
|
"Run specs on supported Solidus versions":
|
22
26
|
jobs:
|
23
27
|
- run-specs-with-postgres
|
24
28
|
- run-specs-with-mysql
|
29
|
+
- lint-code
|
30
|
+
|
25
31
|
"Weekly run specs against master":
|
26
32
|
triggers:
|
27
33
|
- schedule:
|
data/.gem_release.yml
CHANGED
data/.github/stale.yml
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
# Number of days of inactivity before an issue becomes stale
|
2
2
|
daysUntilStale: 60
|
3
3
|
# Number of days of inactivity before a stale issue is closed
|
4
|
-
daysUntilClose:
|
4
|
+
daysUntilClose: false
|
5
5
|
# Issues with these labels will never be considered stale
|
6
6
|
exemptLabels:
|
7
7
|
- pinned
|
8
8
|
- security
|
9
9
|
# Label to use when marking an issue as stale
|
10
|
-
staleLabel:
|
10
|
+
staleLabel: stale
|
11
11
|
# Comment to post when marking an issue as stale. Set to `false` to disable
|
12
12
|
markComment: >
|
13
13
|
This issue has been automatically marked as stale because it has not had
|
14
|
-
recent activity. It
|
14
|
+
recent activity. It might be closed if no further activity occurs. Thank you
|
15
15
|
for your contributions.
|
16
16
|
# Comment to post when closing a stale issue. Set to `false` to disable
|
17
|
-
closeComment: false
|
17
|
+
closeComment: false
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -2,6 +2,27 @@ require:
|
|
2
2
|
- solidus_dev_support/rubocop
|
3
3
|
|
4
4
|
AllCops:
|
5
|
+
NewCops: disable
|
5
6
|
Exclude:
|
6
7
|
- sandbox/**/*
|
7
8
|
- spec/dummy/**/*
|
9
|
+
- vendor/bundle/**/*
|
10
|
+
|
11
|
+
|
12
|
+
# This guys are troublemakers
|
13
|
+
RSpec/FactoryBot/CreateList:
|
14
|
+
Enabled: false
|
15
|
+
RSpec/Rails/HttpStatus:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
# Deviations from the standard
|
19
|
+
Style/ClassAndModuleChildren:
|
20
|
+
Enabled: false
|
21
|
+
Style/FrozenStringLiteralComment:
|
22
|
+
Enabled: false
|
23
|
+
RSpec/Capybara/FeatureMethods:
|
24
|
+
Enabled: false
|
25
|
+
RSpec/MultipleExpectations:
|
26
|
+
Enabled: false
|
27
|
+
RSpec/NamedSubject:
|
28
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## [v0.3.0](https://github.com/solidusio-contrib/solidus_webhooks/tree/v0.3.0) (2021-04-20)
|
4
|
+
|
5
|
+
[Full Changelog](https://github.com/solidusio-contrib/solidus_webhooks/compare/v0.3.0...v0.3.0)
|
6
|
+
|
7
|
+
**Closed issues:**
|
8
|
+
|
9
|
+
- Prepare Solidus Webhooks for Solidus 3.0 [\#8](https://github.com/solidusio-contrib/solidus_webhooks/issues/8)
|
10
|
+
|
11
|
+
**Merged pull requests:**
|
12
|
+
|
13
|
+
- Allow Solidus 3 [\#10](https://github.com/solidusio-contrib/solidus_webhooks/pull/10) ([kennyadsl](https://github.com/kennyadsl))
|
14
|
+
- Reconcile master and v0.3.0 [\#7](https://github.com/solidusio-contrib/solidus_webhooks/pull/7) ([elia](https://github.com/elia))
|
15
|
+
- Bump solidus\_support to ~\> 0.6 [\#6](https://github.com/solidusio-contrib/solidus_webhooks/pull/6) ([peterberkenbosch](https://github.com/peterberkenbosch))
|
16
|
+
|
17
|
+
## [v0.3.0](https://github.com/solidusio-contrib/solidus_webhooks/tree/v0.3.0) (2020-10-20)
|
18
|
+
|
19
|
+
[Full Changelog](https://github.com/solidusio-contrib/solidus_webhooks/compare/v0.2.0...v0.3.0)
|
20
|
+
|
21
|
+
**Fixed bugs:**
|
22
|
+
|
23
|
+
- Fix error classes [\#5](https://github.com/solidusio-contrib/solidus_webhooks/pull/5) ([elia](https://github.com/elia))
|
24
|
+
|
25
|
+
## [v0.2.0](https://github.com/solidusio-contrib/solidus_webhooks/tree/v0.2.0) (2020-06-10)
|
26
|
+
|
27
|
+
[Full Changelog](https://github.com/solidusio-contrib/solidus_webhooks/compare/v0.1.0...v0.2.0)
|
28
|
+
|
29
|
+
**Implemented enhancements:**
|
30
|
+
|
31
|
+
- Expose current\_api\_user to webhook handlers [\#4](https://github.com/solidusio-contrib/solidus_webhooks/pull/4) ([elia](https://github.com/elia))
|
32
|
+
|
33
|
+
## [v0.1.0](https://github.com/solidusio-contrib/solidus_webhooks/tree/v0.1.0) (2020-05-14)
|
34
|
+
|
35
|
+
[Full Changelog](https://github.com/solidusio-contrib/solidus_webhooks/compare/v0.1.0.beta.1...v0.1.0)
|
36
|
+
|
37
|
+
## [v0.1.0.beta.1](https://github.com/solidusio-contrib/solidus_webhooks/tree/v0.1.0.beta.1) (2020-05-13)
|
38
|
+
|
39
|
+
[Full Changelog](https://github.com/solidusio-contrib/solidus_webhooks/compare/v0.0.1.v0.1.0.beta.1.1...v0.1.0.beta.1)
|
40
|
+
|
41
|
+
## [v0.0.1.v0.1.0.beta.1.1](https://github.com/solidusio-contrib/solidus_webhooks/tree/v0.0.1.v0.1.0.beta.1.1) (2020-05-13)
|
42
|
+
|
43
|
+
[Full Changelog](https://github.com/solidusio-contrib/solidus_webhooks/compare/9573caa400232ffb44cde7f8cf907171a529ced3...v0.0.1.v0.1.0.beta.1.1)
|
44
|
+
|
45
|
+
**Merged pull requests:**
|
46
|
+
|
47
|
+
- Prepare the repo to be moved to @solidusio-contrib [\#2](https://github.com/solidusio-contrib/solidus_webhooks/pull/2) ([elia](https://github.com/elia))
|
48
|
+
- Add the ability to register and receive webhooks [\#1](https://github.com/solidusio-contrib/solidus_webhooks/pull/1) ([elia](https://github.com/elia))
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
|
data/README.md
CHANGED
@@ -1,10 +1,27 @@
|
|
1
|
-
|
2
|
-
===============
|
1
|
+
# Solidus Webhooks
|
3
2
|
|
4
|
-
|
3
|
+
[![CircleCI](https://circleci.com/gh/solidusio-contrib/solidus_webhooks.svg?style=shield)](https://circleci.com/gh/solidusio-contrib/solidus_webhooks)
|
4
|
+
[![codecov](https://codecov.io/gh/solidusio-contrib/solidus_webhooks/branch/master/graph/badge.svg)](https://codecov.io/gh/solidusio-contrib/solidus_webhooks)
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
<!-- Explain what your extension does. -->
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add solidus_webhooks to your Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'solidus_webhooks'
|
14
|
+
```
|
15
|
+
|
16
|
+
Bundle your dependencies and run the installation generator:
|
17
|
+
|
18
|
+
```shell
|
19
|
+
bin/rails generate solidus_webhooks:install
|
20
|
+
```
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
<!-- Explain how to use your extension once it's been installed. -->
|
8
25
|
|
9
26
|
A Webhook receiver is just a callable and can be registered in the Solidus configuration as follows:
|
10
27
|
|
@@ -33,8 +50,8 @@ The only requirement on handlers is for them to respond to `#call` and accept a
|
|
33
50
|
Example:
|
34
51
|
|
35
52
|
```ruby
|
36
|
-
|
37
|
-
def call(payload)
|
53
|
+
module TrackingNumberHandler
|
54
|
+
def self.call(payload)
|
38
55
|
order = Spree::Order.find_by!(number: payload[:order])
|
39
56
|
shipment = order.shipments.find_by!(number: payload[:shipment])
|
40
57
|
shipment.update!(tracking: payload[:tracking])
|
@@ -108,29 +125,28 @@ Spree::RoleConfiguration.configure do |config|
|
|
108
125
|
end
|
109
126
|
```
|
110
127
|
|
111
|
-
|
112
|
-
------------
|
128
|
+
### Accessing the API User
|
113
129
|
|
114
|
-
|
130
|
+
If you need to access the API user that is making the call to the webhook, you can just accept an additional argument in the callable handler.
|
131
|
+
|
132
|
+
Example:
|
115
133
|
|
116
134
|
```ruby
|
117
|
-
|
135
|
+
SolidusWebhooks.config.register_webhook_handler :tracking_number, -> payload, user {
|
136
|
+
Rails.logger.info "Received payload from user #{user.email}: #{payload.to_json}"
|
137
|
+
# …
|
138
|
+
}
|
118
139
|
```
|
119
140
|
|
120
|
-
|
121
|
-
|
122
|
-
```shell
|
123
|
-
bundle
|
124
|
-
bundle exec rails g solidus_webhooks:install
|
125
|
-
```
|
141
|
+
## Development
|
126
142
|
|
127
|
-
Testing
|
128
|
-
-------
|
143
|
+
### Testing the extension
|
129
144
|
|
130
|
-
First bundle your dependencies, then run `bin/rake`. `bin/rake` will default to building the dummy
|
145
|
+
First bundle your dependencies, then run `bin/rake`. `bin/rake` will default to building the dummy
|
146
|
+
app if it does not exist, then it will run specs. The dummy app can be regenerated by using
|
147
|
+
`bin/rake extension:test_app`.
|
131
148
|
|
132
149
|
```shell
|
133
|
-
bundle
|
134
150
|
bin/rake
|
135
151
|
```
|
136
152
|
|
@@ -147,16 +163,15 @@ Simply add this require statement to your spec_helper:
|
|
147
163
|
require 'solidus_webhooks/factories'
|
148
164
|
```
|
149
165
|
|
150
|
-
|
151
|
-
-----------
|
166
|
+
### Running the sandbox
|
152
167
|
|
153
|
-
To run this extension in a sandboxed Solidus application you can run `bin/sandbox
|
154
|
-
|
155
|
-
|
168
|
+
To run this extension in a sandboxed Solidus application, you can run `bin/sandbox`. The path for
|
169
|
+
the sandbox app is `./sandbox` and `bin/rails` will forward any Rails commands to
|
170
|
+
`sandbox/bin/rails`.
|
156
171
|
|
157
|
-
|
172
|
+
Here's an example:
|
158
173
|
|
159
|
-
```
|
174
|
+
```
|
160
175
|
$ bin/rails server
|
161
176
|
=> Booting Puma
|
162
177
|
=> Rails 6.0.2.1 application starting in development
|
@@ -164,13 +179,21 @@ $ bin/rails server
|
|
164
179
|
Use Ctrl-C to stop
|
165
180
|
```
|
166
181
|
|
167
|
-
|
168
|
-
---------
|
182
|
+
### Updating the changelog
|
169
183
|
|
170
|
-
|
184
|
+
Before and after releases the changelog should be updated to reflect the up-to-date status of
|
185
|
+
the project:
|
171
186
|
|
172
187
|
```shell
|
173
|
-
|
188
|
+
bin/rake changelog
|
189
|
+
git add CHANGELOG.md
|
190
|
+
git commit -m "Update the changelog"
|
174
191
|
```
|
175
192
|
|
176
|
-
|
193
|
+
### Releasing new versions
|
194
|
+
|
195
|
+
Please refer to the dedicated [page](https://github.com/solidusio/solidus/wiki/How-to-release-extensions) on Solidus wiki.
|
196
|
+
|
197
|
+
## License
|
198
|
+
|
199
|
+
Copyright (c) 2020 Nebulab srls, released under the New BSD License.
|
data/Rakefile
CHANGED
@@ -1,6 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'solidus_dev_support/rake_tasks'
|
4
|
+
|
5
|
+
SolidusDevSupport::RakeTasks.class_eval do
|
6
|
+
def install_changelog_task
|
7
|
+
require 'github_changelog_generator/task'
|
8
|
+
|
9
|
+
source_code_uri = URI.parse(gemspec.metadata['source_code_uri'])
|
10
|
+
user, project = source_code_uri.path.split("/", 3)[1..2]
|
11
|
+
|
12
|
+
GitHubChangelogGenerator::RakeTask.new(:changelog) do |config|
|
13
|
+
config.user = user || 'solidus-contrib'
|
14
|
+
config.project = project || gemspec.name
|
15
|
+
config.future_release = "v#{gemspec.version}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
4
20
|
SolidusDevSupport::RakeTasks.install
|
5
21
|
|
6
22
|
task default: 'extension:specs'
|
@@ -1,13 +1,14 @@
|
|
1
1
|
class Spree::WebhooksController < Spree::Api::BaseController
|
2
|
-
rescue_from(
|
2
|
+
rescue_from(SolidusWebhooks::WebhookNotFound) { head :not_found }
|
3
3
|
|
4
4
|
def receive
|
5
5
|
webhook = Spree::Webhook.find(params[:id])
|
6
6
|
payload = request.request_parameters["webhook"]
|
7
|
+
user = current_api_user
|
7
8
|
|
8
9
|
authorize! :receive, webhook
|
9
10
|
|
10
|
-
webhook.receive(payload)
|
11
|
+
webhook.receive(payload, user)
|
11
12
|
|
12
13
|
head :ok
|
13
14
|
end
|
data/app/models/spree/webhook.rb
CHANGED
@@ -1,19 +1,33 @@
|
|
1
|
+
require 'solidus_webhooks/errors'
|
2
|
+
|
1
3
|
class Spree::Webhook
|
2
4
|
include ActiveModel::Model
|
3
5
|
attr_accessor :handler, :id
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
def receive(payload, user)
|
8
|
+
if handler_arity == 1
|
9
|
+
handler.call(payload)
|
10
|
+
else
|
11
|
+
handler.call(payload, user)
|
12
|
+
end
|
9
13
|
end
|
10
14
|
|
11
15
|
def self.find(id)
|
12
16
|
id = id.to_sym # normalize incoming ids
|
13
17
|
|
14
18
|
handler = SolidusWebhooks.config.find_webhook_handler(id) or
|
15
|
-
raise WebhookNotFound, "Cannot find a webhook handler for #{id.inspect}"
|
19
|
+
raise SolidusWebhooks::WebhookNotFound, "Cannot find a webhook handler for #{id.inspect}"
|
16
20
|
|
17
21
|
new(id: id, handler: handler)
|
18
22
|
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def handler_arity
|
27
|
+
if handler.respond_to?(:arity)
|
28
|
+
handler.arity
|
29
|
+
else
|
30
|
+
handler.method(:call).arity
|
31
|
+
end
|
32
|
+
end
|
19
33
|
end
|
data/bin/rails
ADDED
data/bin/{r → rails-engine}
RENAMED
File without changes
|
@@ -1,13 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
# frozen_string_literal: true
|
4
|
-
|
5
3
|
app_root = 'sandbox'
|
6
4
|
|
7
5
|
unless File.exist? "#{app_root}/bin/rails"
|
8
6
|
warn 'Creating the sandbox app...'
|
9
7
|
Dir.chdir "#{__dir__}/.." do
|
10
|
-
system "#{__dir__}/sandbox" or begin
|
8
|
+
system "#{__dir__}/sandbox" or begin
|
11
9
|
warn 'Automatic creation of the sandbox app failed'
|
12
10
|
exit 1
|
13
11
|
end
|
data/bin/sandbox
CHANGED
@@ -72,9 +72,11 @@ unbundled bundle exec rails generate spree:install \
|
|
72
72
|
--user_class=Spree::User \
|
73
73
|
--enforce_available_locales=true \
|
74
74
|
--with-authentication=false \
|
75
|
+
--payment-method=none \
|
75
76
|
$@
|
76
77
|
|
77
78
|
unbundled bundle exec rails generate solidus:auth:install
|
79
|
+
unbundled bundle exec rails generate ${extension_name}:install
|
78
80
|
|
79
81
|
echo
|
80
82
|
echo "🚀 Sandbox app successfully created for $extension_name!"
|
@@ -4,15 +4,20 @@ module SolidusWebhooks
|
|
4
4
|
module Generators
|
5
5
|
class InstallGenerator < Rails::Generators::Base
|
6
6
|
class_option :auto_run_migrations, type: :boolean, default: false
|
7
|
+
source_root File.expand_path('templates', __dir__)
|
8
|
+
|
9
|
+
def copy_initializer
|
10
|
+
template 'initializer.rb', 'config/initializers/solidus_webhooks.rb'
|
11
|
+
end
|
7
12
|
|
8
13
|
def add_javascripts
|
9
|
-
append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/solidus_webhooks\n"
|
10
|
-
append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_webhooks\n"
|
14
|
+
append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/solidus_webhooks\n"
|
15
|
+
append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_webhooks\n"
|
11
16
|
end
|
12
17
|
|
13
18
|
def add_stylesheets
|
14
|
-
inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/solidus_webhooks\n", before: %r{\*/}, verbose: true # rubocop:disable
|
15
|
-
inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/solidus_webhooks\n", before: %r{\*/}, verbose: true # rubocop:disable
|
19
|
+
inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/solidus_webhooks\n", before: %r{\*/}, verbose: true # rubocop:disable Layout/LineLength
|
20
|
+
inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/solidus_webhooks\n", before: %r{\*/}, verbose: true # rubocop:disable Layout/LineLength
|
16
21
|
end
|
17
22
|
|
18
23
|
def add_migrations
|
@@ -20,7 +25,7 @@ module SolidusWebhooks
|
|
20
25
|
end
|
21
26
|
|
22
27
|
def run_migrations
|
23
|
-
run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]')) # rubocop:disable
|
28
|
+
run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]')) # rubocop:disable Layout/LineLength
|
24
29
|
if run_migrations
|
25
30
|
run 'bin/rails db:migrate'
|
26
31
|
else
|
data/lib/solidus_webhooks.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'solidus_webhooks/errors'
|
4
|
+
|
1
5
|
module SolidusWebhooks
|
2
6
|
class Configuration
|
3
7
|
def initialize
|
@@ -6,7 +10,7 @@ module SolidusWebhooks
|
|
6
10
|
|
7
11
|
def register_webhook_handler(id, handler)
|
8
12
|
unless handler.respond_to? :call
|
9
|
-
raise
|
13
|
+
raise SolidusWebhooks::InvalidHandler,
|
10
14
|
"Please provide a handler that responds to #call, got: #{handler.inspect}"
|
11
15
|
end
|
12
16
|
|
@@ -18,13 +22,19 @@ module SolidusWebhooks
|
|
18
22
|
end
|
19
23
|
end
|
20
24
|
|
21
|
-
|
22
|
-
|
23
|
-
|
25
|
+
class << self
|
26
|
+
def configuration
|
27
|
+
@configuration ||= Configuration.new
|
28
|
+
end
|
24
29
|
|
25
|
-
|
26
|
-
@config = Configuration.new
|
27
|
-
end
|
30
|
+
alias config configuration
|
28
31
|
|
29
|
-
|
32
|
+
def reset_config!
|
33
|
+
@configuration = nil
|
34
|
+
end
|
35
|
+
|
36
|
+
def configure
|
37
|
+
yield configuration
|
38
|
+
end
|
39
|
+
end
|
30
40
|
end
|
data/solidus_webhooks.gemspec
CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.metadata['source_code_uri'] = 'https://github.com/solidusio-contrib/solidus_webhooks'
|
17
17
|
spec.metadata['changelog_uri'] = 'https://github.com/solidusio-contrib/solidus_webhooks/releases'
|
18
18
|
|
19
|
-
spec.required_ruby_version = Gem::Requirement.new('
|
19
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.5')
|
20
20
|
|
21
21
|
# Specify which files should be added to the gem when it is released.
|
22
22
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -28,8 +28,8 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.executables = files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
29
|
spec.require_paths = ["lib"]
|
30
30
|
|
31
|
-
spec.add_dependency 'solidus_core', ['>= 2.0.0', '<
|
32
|
-
spec.add_dependency 'solidus_support', '~> 0.
|
31
|
+
spec.add_dependency 'solidus_core', ['>= 2.0.0', '< 4']
|
32
|
+
spec.add_dependency 'solidus_support', '~> 0.6'
|
33
33
|
|
34
|
-
spec.add_development_dependency 'solidus_dev_support'
|
34
|
+
spec.add_development_dependency 'solidus_dev_support', '~> 2.2'
|
35
35
|
end
|
@@ -2,46 +2,73 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
RSpec.feature "Can register a handler and receive Webhooks", type: :request do
|
4
4
|
background do
|
5
|
-
SolidusWebhooks.
|
6
|
-
SolidusWebhooks.config.register_webhook_handler :
|
7
|
-
SolidusWebhooks.config.register_webhook_handler :
|
5
|
+
SolidusWebhooks.config.register_webhook_handler :proc, proc_handler
|
6
|
+
SolidusWebhooks.config.register_webhook_handler :method, method_handler
|
7
|
+
SolidusWebhooks.config.register_webhook_handler :user, user_handler
|
8
|
+
SolidusWebhooks.config.register_webhook_handler :splat, splat_handler
|
9
|
+
SolidusWebhooks.config.register_webhook_handler :method_and_user, method_and_user_handler
|
8
10
|
end
|
9
11
|
|
10
|
-
let(:
|
11
|
-
let(:
|
12
|
+
let(:proc_payloads) { [] }
|
13
|
+
let(:method_payloads) { [] }
|
14
|
+
let(:user_payloads) { [] }
|
15
|
+
let(:splat_payloads) { [] }
|
16
|
+
let(:method_and_user_payloads) { [] }
|
12
17
|
|
13
|
-
let(:
|
14
|
-
let(:
|
18
|
+
let(:proc_handler) { ->(payload) { proc_payloads << payload } }
|
19
|
+
let(:method_handler) {
|
20
|
+
Struct.new(:payloads) { def call(payload) payloads << payload end }.new(method_payloads)
|
21
|
+
}
|
22
|
+
let(:user_handler) { ->(payload, user) { user_payloads << [payload, user] } }
|
23
|
+
let(:splat_handler) { ->(*args) { splat_payloads << args } }
|
24
|
+
let(:method_and_user_handler) {
|
25
|
+
Struct.new(:payloads) { def call(payload, user) payloads << [payload, user] end }.new(method_and_user_payloads)
|
26
|
+
}
|
15
27
|
|
16
|
-
let(:
|
17
|
-
let(:
|
28
|
+
let(:authorized_user) { create(:admin_user, spree_api_key: "123") }
|
29
|
+
let(:authorized_token) { authorized_user.spree_api_key }
|
30
|
+
|
31
|
+
let(:unauthorized_user) { create(:user, spree_api_key: "456") }
|
32
|
+
let(:unauthorized_token) { unauthorized_user.spree_api_key }
|
18
33
|
|
19
34
|
scenario "calls the handler passing the payload" do
|
20
|
-
post "/webhooks/
|
35
|
+
post "/webhooks/proc?token=#{authorized_token}", as: :json, params: { a: 123 }
|
36
|
+
expect(response).to have_http_status(:ok)
|
37
|
+
|
38
|
+
post "/webhooks/proc?token=#{authorized_token}", as: :json, params: { b: 456 }
|
39
|
+
expect(response).to have_http_status(:ok)
|
40
|
+
|
41
|
+
post "/webhooks/method?token=#{authorized_token}", as: :json, params: { c: 789 }
|
42
|
+
expect(response).to have_http_status(:ok)
|
43
|
+
|
44
|
+
post "/webhooks/user?token=#{authorized_token}", as: :json, params: { d: 12 }
|
21
45
|
expect(response).to have_http_status(:ok)
|
22
46
|
|
23
|
-
post "/webhooks/
|
47
|
+
post "/webhooks/splat?token=#{authorized_token}", as: :json, params: { e: 345 }
|
24
48
|
expect(response).to have_http_status(:ok)
|
25
49
|
|
26
|
-
post "/webhooks/
|
50
|
+
post "/webhooks/method_and_user?token=#{authorized_token}", as: :json, params: { f: 678 }
|
27
51
|
expect(response).to have_http_status(:ok)
|
28
52
|
|
29
|
-
expect(
|
30
|
-
expect(
|
53
|
+
expect(proc_payloads).to eq([{ 'a' => 123 }, { 'b' => 456 }])
|
54
|
+
expect(method_payloads).to eq([{ 'c' => 789 }])
|
55
|
+
expect(user_payloads).to eq([[{ 'd' => 12 }, authorized_user]])
|
56
|
+
expect(splat_payloads).to eq([[{ 'e' => 345 }, authorized_user]])
|
57
|
+
expect(method_and_user_payloads).to eq([[{ 'f' => 678 }, authorized_user]])
|
31
58
|
end
|
32
59
|
|
33
60
|
scenario "receives a bad handler id" do
|
34
|
-
post "/webhooks/
|
61
|
+
post "/webhooks/abc?token=#{authorized_token}", as: :json, params: { a: 123 }
|
35
62
|
expect(response).to have_http_status(:not_found)
|
36
63
|
end
|
37
64
|
|
38
65
|
scenario "refuses a bad token" do
|
39
|
-
post "/webhooks/
|
66
|
+
post "/webhooks/user?token=b4d-t0k3n", as: :json, params: { a: 123 }
|
40
67
|
expect(response).to have_http_status(:unauthorized)
|
41
68
|
end
|
42
69
|
|
43
70
|
scenario "refuses a token without permissions" do
|
44
|
-
post "/webhooks/
|
71
|
+
post "/webhooks/proc?token=#{unauthorized_token}", as: :json, params: { a: 123 }
|
45
72
|
expect(response).to have_http_status(:unauthorized)
|
46
73
|
end
|
47
74
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Spree::Webhook do
|
4
|
+
describe '.find' do
|
5
|
+
before { SolidusWebhooks.config.register_webhook_handler :foo, ->(payload) {} }
|
6
|
+
|
7
|
+
it 'can find a registered handler' do
|
8
|
+
expect(described_class.find(:foo)).to be_a(described_class)
|
9
|
+
expect{ described_class.find(:bar) }.to raise_error(SolidusWebhooks::WebhookNotFound)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe SolidusWebhooks::Configuration do
|
4
|
+
describe '#register_webhook_handler' do
|
5
|
+
it 'only accepts callable' do
|
6
|
+
expect{ subject.register_webhook_handler(:foo, Object.new) }.to raise_error(SolidusWebhooks::InvalidHandler)
|
7
|
+
expect{ subject.register_webhook_handler(:bar, proc {}) }.not_to raise_error
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,19 +6,26 @@ ENV['RAILS_ENV'] = 'test'
|
|
6
6
|
# Run Coverage report
|
7
7
|
require 'solidus_dev_support/rspec/coverage'
|
8
8
|
|
9
|
-
|
9
|
+
# Create the dummy app if it's still missing.
|
10
|
+
dummy_env = "#{__dir__}/dummy/config/environment.rb"
|
11
|
+
system 'bin/rake extension:test_app' unless File.exist? dummy_env
|
12
|
+
require dummy_env
|
10
13
|
|
11
14
|
# Requires factories and other useful helpers defined in spree_core.
|
12
15
|
require 'solidus_dev_support/rspec/feature_helper'
|
13
16
|
|
14
17
|
# Requires supporting ruby files with custom matchers and macros, etc,
|
15
18
|
# in spec/support/ and its subdirectories.
|
16
|
-
Dir[
|
19
|
+
Dir["#{__dir__}/support/**/*.rb"].sort.each { |f| require f }
|
17
20
|
|
18
|
-
# Requires factories defined in lib/solidus_webhooks/factories.rb
|
19
|
-
require 'solidus_webhooks/factories'
|
21
|
+
# Requires factories defined in lib/solidus_webhooks/testing_support/factories.rb
|
22
|
+
require 'solidus_webhooks/testing_support/factories'
|
20
23
|
|
21
24
|
RSpec.configure do |config|
|
22
25
|
config.infer_spec_type_from_file_location!
|
23
26
|
config.use_transactional_fixtures = false
|
27
|
+
|
28
|
+
if Spree.solidus_gem_version < Gem::Version.new('2.11')
|
29
|
+
config.extend Spree::TestingSupport::AuthorizationHelpers::Request, type: :system
|
30
|
+
end
|
24
31
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solidus_webhooks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elia Schito
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: solidus_core
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: 2.0.0
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '4'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,36 +29,36 @@ dependencies:
|
|
29
29
|
version: 2.0.0
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
32
|
+
version: '4'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: solidus_support
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: 0.
|
39
|
+
version: '0.6'
|
40
40
|
type: :runtime
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: 0.
|
46
|
+
version: '0.6'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: solidus_dev_support
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
|
-
- - "
|
51
|
+
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
53
|
+
version: '2.2'
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
|
-
- - "
|
58
|
+
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: '
|
61
|
-
description:
|
60
|
+
version: '2.2'
|
61
|
+
description:
|
62
62
|
email: contact@solidus.io
|
63
63
|
executables: []
|
64
64
|
extensions: []
|
@@ -67,9 +67,11 @@ files:
|
|
67
67
|
- ".circleci/config.yml"
|
68
68
|
- ".gem_release.yml"
|
69
69
|
- ".github/stale.yml"
|
70
|
+
- ".github_changelog_generator"
|
70
71
|
- ".gitignore"
|
71
72
|
- ".rspec"
|
72
73
|
- ".rubocop.yml"
|
74
|
+
- CHANGELOG.md
|
73
75
|
- Gemfile
|
74
76
|
- LICENSE
|
75
77
|
- README.md
|
@@ -81,22 +83,29 @@ files:
|
|
81
83
|
- app/controllers/spree/webhooks_controller.rb
|
82
84
|
- app/models/spree/webhook.rb
|
83
85
|
- bin/console
|
84
|
-
- bin/
|
86
|
+
- bin/rails
|
87
|
+
- bin/rails-engine
|
88
|
+
- bin/rails-sandbox
|
85
89
|
- bin/rake
|
86
90
|
- bin/sandbox
|
87
|
-
- bin/sandbox_rails
|
88
91
|
- bin/setup
|
89
92
|
- config/locales/en.yml
|
90
93
|
- config/routes.rb
|
91
94
|
- lib/generators/solidus_webhooks/install/install_generator.rb
|
95
|
+
- lib/generators/solidus_webhooks/install/templates/initializer.rb
|
92
96
|
- lib/solidus_webhooks.rb
|
93
97
|
- lib/solidus_webhooks/configuration.rb
|
94
98
|
- lib/solidus_webhooks/engine.rb
|
99
|
+
- lib/solidus_webhooks/errors.rb
|
95
100
|
- lib/solidus_webhooks/factories.rb
|
101
|
+
- lib/solidus_webhooks/testing_support/factories.rb
|
96
102
|
- lib/solidus_webhooks/version.rb
|
97
103
|
- solidus_webhooks.gemspec
|
98
104
|
- spec/features/can_register_a_handler_and_receive_webhooks_spec.rb
|
105
|
+
- spec/models/spree/webhook_spec.rb
|
106
|
+
- spec/solidus_webhooks/configuration_spec.rb
|
99
107
|
- spec/spec_helper.rb
|
108
|
+
- spec/support/reset_config.rb
|
100
109
|
homepage: https://github.com/solidusio-contrib/solidus_webhooks#readme
|
101
110
|
licenses:
|
102
111
|
- BSD-3-Clause
|
@@ -104,25 +113,28 @@ metadata:
|
|
104
113
|
homepage_uri: https://github.com/solidusio-contrib/solidus_webhooks#readme
|
105
114
|
source_code_uri: https://github.com/solidusio-contrib/solidus_webhooks
|
106
115
|
changelog_uri: https://github.com/solidusio-contrib/solidus_webhooks/releases
|
107
|
-
post_install_message:
|
116
|
+
post_install_message:
|
108
117
|
rdoc_options: []
|
109
118
|
require_paths:
|
110
119
|
- lib
|
111
120
|
required_ruby_version: !ruby/object:Gem::Requirement
|
112
121
|
requirements:
|
113
|
-
- - "
|
122
|
+
- - ">="
|
114
123
|
- !ruby/object:Gem::Version
|
115
|
-
version: '2.
|
124
|
+
version: '2.5'
|
116
125
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
126
|
requirements:
|
118
|
-
- - "
|
127
|
+
- - ">="
|
119
128
|
- !ruby/object:Gem::Version
|
120
|
-
version:
|
129
|
+
version: '0'
|
121
130
|
requirements: []
|
122
|
-
rubygems_version: 3.1.
|
123
|
-
signing_key:
|
131
|
+
rubygems_version: 3.1.4
|
132
|
+
signing_key:
|
124
133
|
specification_version: 4
|
125
134
|
summary: Webhooks support for Solidus
|
126
135
|
test_files:
|
127
136
|
- spec/features/can_register_a_handler_and_receive_webhooks_spec.rb
|
137
|
+
- spec/models/spree/webhook_spec.rb
|
138
|
+
- spec/solidus_webhooks/configuration_spec.rb
|
128
139
|
- spec/spec_helper.rb
|
140
|
+
- spec/support/reset_config.rb
|