Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/apartmenttherapy/siftsciex_plug
A Plug for processing Sift Science Web Hooks
https://github.com/apartmenttherapy/siftsciex_plug
elixir elixir-plug sift-science
Last synced: 20 days ago
JSON representation
A Plug for processing Sift Science Web Hooks
- Host: GitHub
- URL: https://github.com/apartmenttherapy/siftsciex_plug
- Owner: apartmenttherapy
- License: lgpl-3.0
- Created: 2018-07-05T16:57:09.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-08-21T16:33:21.000Z (over 6 years ago)
- Last Synced: 2024-09-17T00:04:30.590Z (4 months ago)
- Topics: elixir, elixir-plug, sift-science
- Language: Elixir
- Size: 25.4 KB
- Stars: 1
- Watchers: 8
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Siftsciex Plug
The Siftsciex Plug provides a very small API and logic for helping process Sift Science Decisions. If you need to handle a Decision Web Hook from Sift Science then you may find this useful.
The Decision Plug really does three things:
1. Checks for the Sift Science Signature in the request
2. Processes the body and transforms it into a `Siftsciex.Decision.t` struct
3. Maps specific endpoints to specific handlers## Installation
[Available in Hex](https://hex.pm/packages/siftsciex_plug), the package can be installed
by adding `siftsciex_plug` to your list of dependencies in `mix.exs`:```elixir
def deps do
[
{:siftsciex_plug, "~> 0.1.0"}
]
end
```## Example
The first thing you need to do is configure the expected Signature key from Sift Science, as well as the header where the signature should be found:
```elixir
config :siftsciex_plug,
hook_key: ,
sig_header: "x-sift-science-signature"
```Then you can configure the `Plug` to process and route specific paths for you.
```elixir
alias Siftsciex.DecisionPlugforward "/sift_science", DecisionPlug, %{
"bad_user" => {User, :sift_ban},
"bad_listing" => {Listing, :sift_delete}
}
```## Note
If you are using any `Plug.Parsers` then you will need to make sure that `siftsciex_plug` checks the body before the parser consumes it. To do this simply add the following to your Parser opts:
```
body_reader: {Siftsciex.HookValidator, :validate, []}
```In the case of a `JSON` parser the full config would look something like this:
```
plug Plug.Parsers,
parsers: [:urlencoded, :multipart, :json],
pass: ["*/*"],
body_reader: {Siftsciex.HookValidator, :validate, []},
json_decoder: Poison
```Doing this allows `siftsciex_plug` to calculate the signature against the raw body.
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/siftsciex_plug](https://hexdocs.pm/siftsciex_plug).