hasura_handler 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5545c99dae867cb734b8f41b2f2d732021c79305d44d79981ea2e942d2b8e1f2
4
- data.tar.gz: e534b8f0189af06f05b1ce5d6886e3d2b2164a1cb546a9d1ad5bdb4fbccdb8a0
3
+ metadata.gz: 38ae7966df4db82ef068c5a743c58cd3d94083c97b5148eb2e18761cff1586f8
4
+ data.tar.gz: e7cf9a60739d6b26ee14bb8aa469f41908c6818b43fbf570566bc334376917b7
5
5
  SHA512:
6
- metadata.gz: 989ed11a15b84a2855a2df5500cea6cd159f52c40748bc1a9550e18b641b037a9ad25565905518b31ca2cafb164b3150758164dd50ab0bf5e6e8cc39e9826807
7
- data.tar.gz: 0fe5f416522e517d82a64a06d0fea7ad3fa80b064519fdbc6ac73bf8445b4c05a88e65bbc7c25c3b6d2a3c6e37f13d7d82e1806a985824caa09766a82e39e42a
6
+ metadata.gz: b6f3f0219bcd1180003b5662aeb53ec7783a6c7a6cc4296754ae82f96e01d038aed2fe0c36be08e360a815d2e04b20499809aa3a7012ef61bac11df2eede4262
7
+ data.tar.gz: 7567e337ae3eb9ebeb9806a5128c2fa45bba31b7e504d66e5c5bd66cc9e847dde42747aacd4f60e57a5a4359e1264ff41d0ecdbbfd681ddc1b21e352bc5e3d03
@@ -2,14 +2,14 @@ require_dependency 'hasura_handler/application_controller'
2
2
 
3
3
  module HasuraHandler
4
4
  class ActionsController < ApplicationController
5
- def process
6
- unless HasuraHandler::Action.hasura_actions.keys.include?(action_params[:action][:name])
5
+ def index
6
+ unless HasuraHandler::Action.hasura_actions.keys.include?(action_params['action']['name'])
7
7
  render json: { error: true, message: 'action name not registered' }, status: 404
8
8
  return
9
9
  end
10
10
 
11
- klass = HasuraHandler::Action.hasura_actions[action_params[:action][:name]]
12
- action = klass.new(action_params[:session_variables], action_params[:input])
11
+ klass = HasuraHandler::Action.hasura_actions[action_params['action']['name']]
12
+ action = klass.new(action_params['session_variables'].to_h, action_params['input'].to_h)
13
13
  action.run
14
14
 
15
15
  if action.error_message.present?
@@ -20,7 +20,7 @@ module HasuraHandler
20
20
  end
21
21
 
22
22
  def action_params
23
- params.permit(
23
+ full_params.permit(
24
24
  action: [:name],
25
25
  input: {},
26
26
  session_variables: {}
@@ -9,5 +9,9 @@ module HasuraHandler
9
9
  render json: { error: true, message: 'unable to authenticate request' }, status: 401
10
10
  end
11
11
  end
12
+
13
+ def full_params
14
+ ActionController::Parameters.new(JSON.parse(request.body.read))
15
+ end
12
16
  end
13
17
  end
@@ -2,8 +2,8 @@ require_dependency 'hasura_handler/application_controller'
2
2
 
3
3
  module HasuraHandler
4
4
  class EventsController < ApplicationController
5
- def process
6
- processor = HasuraHandler::EventHandler.new(event_params)
5
+ def index
6
+ processor = HasuraHandler::EventHandler.new(event_params.to_h)
7
7
 
8
8
  unless processor.event.valid?
9
9
  error_response(processor.event.errors)
@@ -32,7 +32,7 @@ module HasuraHandler
32
32
  end
33
33
 
34
34
  def event_params
35
- params.permit(
35
+ full_params.permit(
36
36
  :id,
37
37
  :created_at,
38
38
  table: [
@@ -1,9 +1,9 @@
1
1
  HasuraHandler::Engine.routes.draw do
2
2
  if HasuraHandler.events_enabled
3
- post '/events', to: 'events#process'
3
+ post '/events', to: 'events#index'
4
4
  end
5
5
 
6
6
  if HasuraHandler.actions_enabled
7
- post '/actions', to: 'actions#process'
7
+ post '/actions', to: 'actions#index'
8
8
  end
9
9
  end
@@ -15,7 +15,7 @@ module HasuraHandler
15
15
  :fanout_events,
16
16
  :retry_after
17
17
 
18
- self.auth_header = 'X-Hasura-Service-Key'
18
+ self.auth_header = 'HTTP_X_HASURA_SERVICE_KEY'
19
19
  self.events_enabled = true
20
20
  self.async_events = true
21
21
  self.fanout_events = true
@@ -5,7 +5,6 @@ module HasuraHandler
5
5
  attr_reader :hasura_action_name
6
6
 
7
7
  def action_name(action_name)
8
- raise 'run method not defined' unless new(nil, nil).respond_to?(:run)
9
8
  raise 'action_name must be a symbol or string' unless action_name.is_a?(Symbol) || action_name.is_a?(String)
10
9
  raise 'action_name already used' if @@hasura_actions.keys.include?(action_name.to_s)
11
10
 
@@ -10,11 +10,11 @@ module HasuraHandler
10
10
  :valid
11
11
 
12
12
  def initialize(event)
13
- @id = event[:id]
14
- @table = event[:table]
15
- @trigger = event[:trigger]
16
- @event = event[:event]
17
- @created_at = event[:created_at]
13
+ @id = event['id']
14
+ @table = event['table']
15
+ @trigger = event['trigger']
16
+ @event = event['event']
17
+ @created_at = event['created_at']
18
18
  @raw_event = event
19
19
  @errors = {}
20
20
 
@@ -65,7 +65,7 @@ module HasuraHandler
65
65
  return
66
66
  end
67
67
 
68
- @errors['event.session_variables'] = 'not a hash' unless @event[:session_variables].is_a?(Hash)
68
+ @errors['event.session_variables'] = 'not a hash' unless @event['session_variables'].is_a?(Hash)
69
69
  string_fields?(@event, 'event', [:op])
70
70
 
71
71
  [:new, :old].each do |field|
@@ -12,8 +12,6 @@ module HasuraHandler
12
12
  raise 'invalid matcher value' unless matchers[matcher].is_a?(String)
13
13
  end
14
14
 
15
- raise 'run method not defined' unless new(nil).respond_to?(:run)
16
-
17
15
  @hasura_matchers = matchers
18
16
  end
19
17
  end
@@ -1,3 +1,3 @@
1
1
  module HasuraHandler
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hasura_handler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kaz Walker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-25 00:00:00.000000000 Z
11
+ date: 2020-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails