Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ class WebhooksController < ApplicationController
SyncProductsJob.perform_later
when Pobo::WebhookEvent::CATEGORIES_UPDATE
SyncCategoriesJob.perform_later
when Pobo::WebhookEvent::BLOGS_UPDATE
SyncBlogsJob.perform_later
end

render json: { status: 'ok' }
Expand All @@ -273,7 +275,7 @@ payload = handler.handle(
### Webhook Payload

```ruby
payload.event # String: "products.update" or "categories.update"
payload.event # String: "products.update", "categories.update", or "blogs.update"
payload.timestamp # Time
payload.eshop_id # Integer
```
Expand Down Expand Up @@ -336,6 +338,19 @@ name.to_hash # => { 'default' => '...', 'cs' => '...', ...
| `each_category(last_update_from:, is_edited:)` | Iterate all categories |
| `each_blog(last_update_from:, is_edited:)` | Iterate all blogs |

## Limits

| Limit | Value |
|------------------------------|--------------|
| Max items per import request | 100 |
| Max items per export page | 100 |
| Product/Category ID length | 255 chars |
| Name length | 250 chars |
| URL length | 255 chars |
| Image URL length | 650 chars |
| Description length | 65,000 chars |
| SEO description length | 500 chars |

## Development

After checking out the repo, run `bundle install` to install dependencies. Then, run `rake spec` to run the tests.
Expand Down
3 changes: 2 additions & 1 deletion lib/pobo/enum/webhook_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ module Pobo
module WebhookEvent
PRODUCTS_UPDATE = "products.update"
CATEGORIES_UPDATE = "categories.update"
BLOGS_UPDATE = "blogs.update"

ALL = [PRODUCTS_UPDATE, CATEGORIES_UPDATE].freeze
ALL = [PRODUCTS_UPDATE, CATEGORIES_UPDATE, BLOGS_UPDATE].freeze

def self.valid?(event)
ALL.include?(event)
Expand Down
2 changes: 1 addition & 1 deletion lib/pobo/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Pobo
VERSION = "1.0.0"
VERSION = "1.1.0"
end
41 changes: 41 additions & 0 deletions spec/pobo/enum/webhook_event_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# frozen_string_literal: true

require "spec_helper"

RSpec.describe Pobo::WebhookEvent do
describe "constants" do
it "defines PRODUCTS_UPDATE" do
expect(described_class::PRODUCTS_UPDATE).to eq("products.update")
end

it "defines CATEGORIES_UPDATE" do
expect(described_class::CATEGORIES_UPDATE).to eq("categories.update")
end

it "defines BLOGS_UPDATE" do
expect(described_class::BLOGS_UPDATE).to eq("blogs.update")
end

it "includes all events in ALL" do
expect(described_class::ALL).to contain_exactly(
"products.update",
"categories.update",
"blogs.update"
)
end
end

describe ".valid?" do
it "returns true for valid events" do
expect(described_class.valid?("products.update")).to be true
expect(described_class.valid?("categories.update")).to be true
expect(described_class.valid?("blogs.update")).to be true
end

it "returns false for invalid events" do
expect(described_class.valid?("invalid.event")).to be false
expect(described_class.valid?("")).to be false
expect(described_class.valid?(nil)).to be false
end
end
end
22 changes: 21 additions & 1 deletion spec/pobo/webhook_handler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def sign(payload)
end

describe "#handle" do
it "validates and parses webhook payload" do
it "validates and parses products.update webhook payload" do
payload = { event: "products.update", timestamp: 1704067200, eshop_id: 123 }.to_json
signature = sign(payload)

Expand All @@ -23,6 +23,26 @@ def sign(payload)
expect(result.timestamp).to be_a(Time)
end

it "validates and parses categories.update webhook payload" do
payload = { event: "categories.update", timestamp: 1704067200, eshop_id: 456 }.to_json
signature = sign(payload)

result = handler.handle(payload: payload, signature: signature)

expect(result.event).to eq("categories.update")
expect(result.eshop_id).to eq(456)
end

it "validates and parses blogs.update webhook payload" do
payload = { event: "blogs.update", timestamp: 1704067200, eshop_id: 789 }.to_json
signature = sign(payload)

result = handler.handle(payload: payload, signature: signature)

expect(result.event).to eq("blogs.update")
expect(result.eshop_id).to eq(789)
end

it "raises error for missing signature" do
payload = { event: "products.update" }.to_json

Expand Down