pheme 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/pheme.rb +2 -0
- data/lib/pheme/message_type/aws_event.rb +26 -0
- data/lib/pheme/message_type/sns_message.rb +21 -0
- data/lib/pheme/queue_poller.rb +10 -4
- data/lib/pheme/version.rb +1 -1
- data/spec/message_type/aws_event_spec.rb +26 -0
- data/spec/message_type/sns_message_spec.rb +32 -0
- data/spec/support/example_aws_event_queue_poller.rb +12 -0
- data/spec/support/example_queue_poller.rb +4 -0
- metadata +10 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7162906c4cad8bbe5247f283c06f72ce881effb9
|
|
4
|
+
data.tar.gz: 78694ae2f9a59b2abacc2afc705780ca3190a406
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a4f3c559ebf8db752207b441b43bdd264f1a5489b58719c9613272949cd0061ce11a05809593dacd0903821a303c727443315a82ddf0a7eaa48b0d09b59255a6
|
|
7
|
+
data.tar.gz: 4f99b81c78d8484949f0cdf480deb5434e2eb3716259662588a31aeee1d318f8325d37fcf1400168e2d38c25dfbf6c8a499f954e63d22f0da8607ab767a37616
|
data/lib/pheme.rb
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Poller that consume internal AWS Events,
|
|
3
|
+
# like S3 notifications, CloudWatch events, etc.
|
|
4
|
+
#
|
|
5
|
+
# This poller's output message will be a list of hashes,
|
|
6
|
+
# each containing one event.
|
|
7
|
+
#
|
|
8
|
+
module Pheme
|
|
9
|
+
module MessageType
|
|
10
|
+
module AwsEvent
|
|
11
|
+
extend ActiveSupport::Concern
|
|
12
|
+
|
|
13
|
+
def get_content(body)
|
|
14
|
+
body['Records']
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def format
|
|
18
|
+
:aws_event
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def parse_aws_event(message_contents)
|
|
22
|
+
RecursiveOpenStruct.new({wrapper: message_contents}, recurse_over_arrays: true).wrapper
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Default poller for messages publish through SNS.
|
|
3
|
+
# No need to use this concern unless
|
|
4
|
+
# the default behaviour has been overwritten and you
|
|
5
|
+
# wish to restore it.
|
|
6
|
+
#
|
|
7
|
+
module Pheme
|
|
8
|
+
module MessageType
|
|
9
|
+
module SnsMessage
|
|
10
|
+
extend ActiveSupport::Concern
|
|
11
|
+
|
|
12
|
+
def get_content(body)
|
|
13
|
+
body['Message']
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def format
|
|
17
|
+
:json
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
data/lib/pheme/queue_poller.rb
CHANGED
|
@@ -44,17 +44,23 @@ module Pheme
|
|
|
44
44
|
|
|
45
45
|
def parse_message(message)
|
|
46
46
|
Pheme.log(:info, "Received JSON payload: #{message.body}")
|
|
47
|
-
|
|
47
|
+
content = get_content(JSON.parse(message.body))
|
|
48
48
|
case format
|
|
49
49
|
when :csv
|
|
50
|
-
parse_csv(
|
|
50
|
+
parse_csv(content)
|
|
51
51
|
when :json
|
|
52
|
-
parse_json(
|
|
52
|
+
parse_json(content)
|
|
53
53
|
else
|
|
54
|
-
|
|
54
|
+
method_name = "parse_#{format}".to_sym
|
|
55
|
+
raise ArgumentError.new("Unknown format #{format}") unless self.respond_to?(method_name)
|
|
56
|
+
self.__send__(method_name, content)
|
|
55
57
|
end
|
|
56
58
|
end
|
|
57
59
|
|
|
60
|
+
def get_content(body)
|
|
61
|
+
body['Message']
|
|
62
|
+
end
|
|
63
|
+
|
|
58
64
|
def parse_csv(message_contents)
|
|
59
65
|
parsed_body = SmarterCSV.process(StringIO.new(message_contents))
|
|
60
66
|
parsed_body.map{ |item| RecursiveOpenStruct.new(item, recurse_over_arrays: true) }
|
data/lib/pheme/version.rb
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
describe Pheme::MessageType::AwsEvent do
|
|
2
|
+
subject { ExampleAwsEventQueuePoller.new }
|
|
3
|
+
|
|
4
|
+
let(:poller) do
|
|
5
|
+
poller = double
|
|
6
|
+
allow(poller).to receive(:poll).with(kind_of(Hash))
|
|
7
|
+
allow(poller).to receive(:parse_message)
|
|
8
|
+
allow(poller).to receive(:before_request)
|
|
9
|
+
poller
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
before(:each) do
|
|
13
|
+
use_default_configuration!
|
|
14
|
+
allow(Aws::SQS::QueuePoller).to receive(:new) { poller }
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe "#parse_message" do
|
|
18
|
+
context "with JSON message" do
|
|
19
|
+
let!(:message) { OpenStruct.new({ body: "{\"Records\":[{\"eventVersion\":\"2.0\"}]}" }) }
|
|
20
|
+
|
|
21
|
+
it 'should parse the message correctly' do
|
|
22
|
+
expect(subject.parse_message(message).first.eventVersion).to eq("2.0")
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
describe Pheme::MessageType::SnsMessage do
|
|
2
|
+
module SnsMessage
|
|
3
|
+
class Fixture < ExampleQueuePoller
|
|
4
|
+
include Pheme::MessageType::SnsMessage
|
|
5
|
+
end
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
subject { SnsMessage::Fixture.new }
|
|
9
|
+
|
|
10
|
+
let(:poller) do
|
|
11
|
+
poller = double
|
|
12
|
+
allow(poller).to receive(:poll).with(kind_of(Hash))
|
|
13
|
+
allow(poller).to receive(:parse_message)
|
|
14
|
+
allow(poller).to receive(:before_request)
|
|
15
|
+
poller
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
before(:each) do
|
|
19
|
+
use_default_configuration!
|
|
20
|
+
allow(Aws::SQS::QueuePoller).to receive(:new) { poller }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
describe "#parse_message" do
|
|
24
|
+
context "with JSON message" do
|
|
25
|
+
let!(:message) { OpenStruct.new({ body: '{"Message":"{\"test\":\"test\"}"}' }) }
|
|
26
|
+
|
|
27
|
+
it 'should parse the message correctly' do
|
|
28
|
+
expect(subject.parse_message(message).test).to eq("test")
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require_relative 'example_queue_poller'
|
|
2
|
+
|
|
3
|
+
#
|
|
4
|
+
# Example for pollers that consume internal AWS Events,
|
|
5
|
+
# like S3 notifications, CloudWatch events, etc.
|
|
6
|
+
#
|
|
7
|
+
# This poller's output message will be a list of hashes,
|
|
8
|
+
# each containing one event.
|
|
9
|
+
#
|
|
10
|
+
class ExampleAwsEventQueuePoller < ExampleQueuePoller
|
|
11
|
+
include Pheme::MessageType::AwsEvent
|
|
12
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pheme
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Peter Graham
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2017-11-
|
|
11
|
+
date: 2017-11-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: aws-sdk
|
|
@@ -117,6 +117,8 @@ files:
|
|
|
117
117
|
- lib/pheme/configuration.rb
|
|
118
118
|
- lib/pheme/logger.rb
|
|
119
119
|
- lib/pheme/message_handler.rb
|
|
120
|
+
- lib/pheme/message_type/aws_event.rb
|
|
121
|
+
- lib/pheme/message_type/sns_message.rb
|
|
120
122
|
- lib/pheme/queue_poller.rb
|
|
121
123
|
- lib/pheme/rollbar.rb
|
|
122
124
|
- lib/pheme/topic_publisher.rb
|
|
@@ -124,8 +126,11 @@ files:
|
|
|
124
126
|
- pheme.gemspec
|
|
125
127
|
- spec/configuration_spec.rb
|
|
126
128
|
- spec/message_handler_spec.rb
|
|
129
|
+
- spec/message_type/aws_event_spec.rb
|
|
130
|
+
- spec/message_type/sns_message_spec.rb
|
|
127
131
|
- spec/queue_poller_spec.rb
|
|
128
132
|
- spec/spec_helper.rb
|
|
133
|
+
- spec/support/example_aws_event_queue_poller.rb
|
|
129
134
|
- spec/support/example_message_handler.rb
|
|
130
135
|
- spec/support/example_publisher.rb
|
|
131
136
|
- spec/support/example_queue_poller.rb
|
|
@@ -158,8 +163,11 @@ summary: Ruby SNS publisher + SQS poller & message handler
|
|
|
158
163
|
test_files:
|
|
159
164
|
- spec/configuration_spec.rb
|
|
160
165
|
- spec/message_handler_spec.rb
|
|
166
|
+
- spec/message_type/aws_event_spec.rb
|
|
167
|
+
- spec/message_type/sns_message_spec.rb
|
|
161
168
|
- spec/queue_poller_spec.rb
|
|
162
169
|
- spec/spec_helper.rb
|
|
170
|
+
- spec/support/example_aws_event_queue_poller.rb
|
|
163
171
|
- spec/support/example_message_handler.rb
|
|
164
172
|
- spec/support/example_publisher.rb
|
|
165
173
|
- spec/support/example_queue_poller.rb
|