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: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Changelog

## 9.1.0

**Enhancements:**

- Add Events API support (enterprise) — three new client methods for querying event data:
- `events_schema` — `GET /v1/events/schema`
- `query_events` — `POST /v1/events/query`
- `group_events` — `POST /v1/events/group`

**Housekeeping:**

- Remove unused `Castle::Validators::NotSupported` (dead code)
- Remove unused `Session::HTTPS_SCHEME` constant; inline the comparison in `GetConnection`
- Replace deprecated `:mingw, :x64_mingw` Bundler platforms with `:windows`
- Bump Bundler 2.6.9 → 2.7.2
- Bump json 2.19.5 → 2.19.7

## master

- Bump dependencies (rack 3.1.19 → 3.2.6, rake, rspec-\*, timecop, simplecov-html, diff-lcs)
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ group :development do
end

group :development, :test do
gem 'debug', platforms: %i[mri mingw x64_mingw]
gem 'debug', platforms: %i[mri windows]
end

group :test do
Expand Down
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
castle-rb (9.0.0)
castle-rb (9.1.0)
base64 (~> 0.2)

GEM
Expand Down Expand Up @@ -29,7 +29,7 @@ GEM
prism (>= 1.3.0)
rdoc (>= 4.0.0)
reline (>= 0.4.2)
json (2.19.5)
json (2.19.7)
language_server-protocol (3.17.0.5)
lint_roller (1.1.0)
parallel (2.1.0)
Expand Down Expand Up @@ -133,4 +133,4 @@ DEPENDENCIES
webmock

BUNDLED WITH
2.6.9
2.7.2
2 changes: 1 addition & 1 deletion gemfiles/rails_7.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ gem 'rails', '~> 7.0.0'
gem 'rake'

group :development, :test do
gem 'debug', platforms: %i[mri mingw x64_mingw]
gem 'debug', platforms: %i[mri windows]
end

group :test do
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_7.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ gem 'rails', '~> 7.1.0'
gem 'rake'

group :development, :test do
gem 'debug', platforms: %i[mri mingw x64_mingw]
gem 'debug', platforms: %i[mri windows]
end

group :test do
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_7.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ gem 'rails', '~> 7.2.0'
gem 'rake'

group :development, :test do
gem 'debug', platforms: %i[mri mingw x64_mingw]
gem 'debug', platforms: %i[mri windows]
end

group :test do
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_8.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ gem 'rails', '~> 8.0.0'
gem 'rake'

group :development, :test do
gem 'debug', platforms: %i[mri mingw x64_mingw]
gem 'debug', platforms: %i[mri windows]
end

group :test do
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_8.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ gem 'rails', '~> 8.1.0'
gem 'rake'

group :development, :test do
gem 'debug', platforms: %i[mri mingw x64_mingw]
gem 'debug', platforms: %i[mri windows]
end

group :test do
Expand Down
8 changes: 7 additions & 1 deletion lib/castle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
castle/utils/get_timestamp
castle/utils/secure_compare
castle/validators/present
castle/validators/not_supported
castle/webhooks/verify
castle/context/merge
castle/context/sanitize
Expand All @@ -37,6 +36,9 @@
castle/commands/list_items/query
castle/commands/list_items/unarchive
castle/commands/list_items/update
castle/commands/events/schema
castle/commands/events/query
castle/commands/events/group
castle/commands/privacy/request_data
castle/commands/privacy/delete_data
castle/api/filter
Expand All @@ -56,6 +58,9 @@
castle/api/list_items/query
castle/api/list_items/unarchive
castle/api/list_items/update
castle/api/events/schema
castle/api/events/query
castle/api/events/group
castle/api/privacy/request_data
castle/api/privacy/delete_data
castle/payload/prepare
Expand All @@ -64,6 +69,7 @@
castle/logger
castle/failover/prepare_response
castle/failover/strategy
castle/client_actions/events
castle/client_actions/lists
castle/client_actions/list_items
castle/client_actions/privacy
Expand Down
22 changes: 22 additions & 0 deletions lib/castle/api/events/group.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

module Castle
module API
module Events
# Sends POST /events/group request
module Group
class << self
# @param options [Hash]
# @return [Hash]
def call(options = {})
options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
http = options.delete(:http)
config = options.delete(:config) || Castle.config

Castle::API.call(Castle::Commands::Events::Group.build(options), {}, http, config)
end
end
end
end
end
end
22 changes: 22 additions & 0 deletions lib/castle/api/events/query.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

module Castle
module API
module Events
# Sends POST /events/query request
module Query
class << self
# @param options [Hash]
# @return [Hash]
def call(options = {})
options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
http = options.delete(:http)
config = options.delete(:config) || Castle.config

Castle::API.call(Castle::Commands::Events::Query.build(options), {}, http, config)
end
end
end
end
end
end
22 changes: 22 additions & 0 deletions lib/castle/api/events/schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

module Castle
module API
module Events
# Sends GET /events/schema request
module Schema
class << self
# @param options [Hash]
# @return [Hash]
def call(options = {})
options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
http = options.delete(:http)
config = options.delete(:config) || Castle.config

Castle::API.call(Castle::Commands::Events::Schema.build(options), {}, http, config)
end
end
end
end
end
end
1 change: 1 addition & 0 deletions lib/castle/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
module Castle
# Castle's client.
class Client
include Castle::ClientActions::Events
include Castle::ClientActions::ListItems
include Castle::ClientActions::Lists
include Castle::ClientActions::Privacy
Expand Down
23 changes: 23 additions & 0 deletions lib/castle/client_actions/events.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

module Castle
module ClientActions
# Client actions for the Events API
module Events
# @param options [Hash]
def events_schema(options = {})
Castle::API::Events::Schema.call(options)
end

# @param options [Hash]
def query_events(options = {})
Castle::API::Events::Query.call(options)
end

# @param options [Hash]
def group_events(options = {})
Castle::API::Events::Group.call(options)
end
end
end
end
21 changes: 21 additions & 0 deletions lib/castle/commands/events/group.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module Castle
module Commands
module Events
# Builds the command to query aggregated events
class Group
class << self
# @param options [Hash]
# @return [Castle::Command]
def build(options = {})
options[:filters]&.each { |f| Castle::Validators::Present.call(f, %i[field op value]) }
Castle::Validators::Present.call(options[:sort], %i[field order]) if options[:sort]

Castle::Command.new('events/group', options, :post)
end
end
end
end
end
end
21 changes: 21 additions & 0 deletions lib/castle/commands/events/query.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module Castle
module Commands
module Events
# Builds the command to query raw events
class Query
class << self
# @param options [Hash]
# @return [Castle::Command]
def build(options = {})
options[:filters]&.each { |f| Castle::Validators::Present.call(f, %i[field op value]) }
Castle::Validators::Present.call(options[:sort], %i[field order]) if options[:sort]

Castle::Command.new('events/query', options, :post)
end
end
end
end
end
end
18 changes: 18 additions & 0 deletions lib/castle/commands/events/schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

module Castle
module Commands
module Events
# Builds the command to get the events schema
class Schema
class << self
# @param options [Hash]
# @return [Castle::Command]
def build(_options = {})
Castle::Command.new('events/schema', nil, :get)
end
end
end
end
end
end
4 changes: 1 addition & 3 deletions lib/castle/core/get_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ module Castle
module Core
# this module returns a new configured Net::HTTP object
module GetConnection
HTTPS_SCHEME = 'https'

class << self
# @param config [Castle::Configuration, Castle::SingletonConfiguration]
# @return [Net::HTTP]
Expand All @@ -18,7 +16,7 @@ def call(config = nil)
http.open_timeout = timeout_seconds
http.read_timeout = timeout_seconds

if config.base_url.scheme == HTTPS_SCHEME
if config.base_url.scheme == 'https'
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
end
Expand Down
2 changes: 0 additions & 2 deletions lib/castle/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ module Castle
# and provides start method for persistent connection usage
# when there is a need of sending multiple requests at once
module Session
HTTPS_SCHEME = 'https'

class << self
def call(&block)
return unless block
Expand Down
18 changes: 0 additions & 18 deletions lib/castle/validators/not_supported.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/castle/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Castle
VERSION = '9.0.0'
VERSION = '9.1.0'
end
21 changes: 21 additions & 0 deletions spec/lib/castle/api/events/group_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

RSpec.describe Castle::API::Events::Group do
before do
stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(status: 200, body: '{}', headers: {})
end

describe '.call' do
subject(:call) { described_class.call(options) }

let(:options) { { filters: [{ field: 'user.id', op: '$eq', value: 'u-42' }] } }

before { call }

it do
assert_requested :post, 'https://api.castle.io/v1/events/group', times: 1 do |req|
expect(JSON.parse(req.body, symbolize_names: true)).to eq(options)
end
end
end
end
21 changes: 21 additions & 0 deletions spec/lib/castle/api/events/query_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

RSpec.describe Castle::API::Events::Query do
before do
stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(status: 200, body: '{}', headers: {})
end

describe '.call' do
subject(:call) { described_class.call(options) }

let(:options) { { filters: [{ field: 'user.id', op: '$eq', value: 'u-42' }], query_type: '$records' } }

before { call }

it do
assert_requested :post, 'https://api.castle.io/v1/events/query', times: 1 do |req|
expect(JSON.parse(req.body, symbolize_names: true)).to eq(options)
end
end
end
end
Loading
Loading