stream_data 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/aws_stream_service.rb +30 -30
- data/lib/config.rb +26 -0
- data/lib/stream.rb +31 -0
- data/lib/stream_config.yml +5 -0
- data/lib/stream_data.rb +8 -35
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4544dba104783a1fdf056cd2df75947827503ef16bf2d2424815b873dd32720e
|
4
|
+
data.tar.gz: 1b9e0b2c210e566e13d80db9d486f9949da34e75e776511136b766a041b3389a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e83934966c5134bda2f600ba46a4a72d7cf64b386d6007b6c9020d2a4618fb739cf92ac621880e1d4debb40600678573684ace2e42c6113d4eba45c2872b101
|
7
|
+
data.tar.gz: 9c68253bbc23f49c8b5ef677af6cc16b299e9fb9c477a7ad527786f32a88a0716e4e83fdc71cb640550a536e40984ae9fe20a679d1b613c577fa6393048bbe28
|
data/lib/aws_stream_service.rb
CHANGED
@@ -1,37 +1,37 @@
|
|
1
|
-
module StreamData
|
2
|
-
|
3
|
-
|
1
|
+
# module StreamData
|
2
|
+
# require 'aws-sdk'
|
3
|
+
# # require 'aws-sdk-firehose'
|
4
4
|
|
5
|
-
|
5
|
+
# class AwsStreamService
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
# def initialize(config,opts)
|
8
|
+
# set_connection(config,opts)
|
9
|
+
# end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
# def send_stream(raw_data)
|
12
|
+
# begin
|
13
|
+
# @firehose.put_record({ delivery_stream_name: @config[:delivery_stream_name], record: { data: raw_data}})
|
14
|
+
# rescue Aws::Errors::MissingCredentialsError => e
|
15
|
+
# raise (StandardError.new("Error with the connection. Check the config. Error message === #{e.message}"))
|
16
|
+
# end
|
17
|
+
# end
|
18
18
|
|
19
|
-
|
19
|
+
# private
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
21
|
+
# def set_connection(config,opts)
|
22
|
+
# @config = config || {}
|
23
|
+
# @opts = opts || {}
|
24
|
+
# begin
|
25
|
+
# @firehose = Aws::Firehose::Client.new(
|
26
|
+
# access_key_id: config[:service_key],
|
27
|
+
# secret_access_key: config[:service_secret],
|
28
|
+
# region: config[:region]
|
29
|
+
# )
|
30
|
+
# rescue Exception => e
|
31
|
+
# raise (StandardError.new("Could not establish a connection. Check the config. Error message === #{e.message}"))
|
32
|
+
# end
|
33
33
|
|
34
|
-
|
34
|
+
# end
|
35
35
|
|
36
|
-
|
37
|
-
end
|
36
|
+
# end
|
37
|
+
# end
|
data/lib/config.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module StreamData
|
2
|
+
class Config
|
3
|
+
require 'aws_stream_service'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
def self.read_config
|
7
|
+
@config = YAML.load_file('lib/stream_config.yml')
|
8
|
+
end
|
9
|
+
|
10
|
+
ALLOWED_SERVICE_TYPES = ["azure","aws"]
|
11
|
+
|
12
|
+
def self.validate_config
|
13
|
+
begin
|
14
|
+
@config["type_of_service"] || raise(StandardError.new('Specify the servcie type'))
|
15
|
+
@config["service_key"] || raise(StandardError.new('Service Key is missing, please specify in config'))
|
16
|
+
@config["service_secret"] || raise(StandardError.new('Service Secret is missing, please specify in config'))
|
17
|
+
@config["delivery_stream_name"] || raise(StandardError.new('Delivery Stream Name is missing, please specify in config'))
|
18
|
+
@config["region"] || raise(StandardError.new('Specify the Region'))
|
19
|
+
raise(StandardError.new('This type of servcie is not supported')) unless ALLOWED_SERVICE_TYPES.include?(@config["type_of_service"])
|
20
|
+
rescue Exception => e
|
21
|
+
raise(StandardError.new("Not a valid config, #{e.message}"))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
data/lib/stream.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module StreamData
|
2
|
+
class Stream
|
3
|
+
|
4
|
+
def self.send_stream(config,raw_data)
|
5
|
+
set_connection(config)
|
6
|
+
send_raw_data(raw_data)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.set_connection(config)
|
10
|
+
@config = config || {}
|
11
|
+
begin
|
12
|
+
@firehose = Aws::Firehose::Client.new(
|
13
|
+
access_key_id: @config["service_key"],
|
14
|
+
secret_access_key: @config["service_secret"],
|
15
|
+
region: @config["region"]
|
16
|
+
)
|
17
|
+
rescue Exception => e
|
18
|
+
raise (StandardError.new("Could not establish a connection. Check the config. Error message === #{e.message}"))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.send_raw_data(raw_data)
|
23
|
+
begin
|
24
|
+
@firehose.put_record({ delivery_stream_name: @config["delivery_stream_name"], record: { data: raw_data}})
|
25
|
+
rescue Aws::Errors::MissingCredentialsError => e
|
26
|
+
raise (StandardError.new("Error with the connection. Check the config. Error message === #{e.message}"))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
data/lib/stream_data.rb
CHANGED
@@ -1,40 +1,13 @@
|
|
1
1
|
require 'aws_stream_service'
|
2
|
+
require 'config'
|
3
|
+
require 'stream'
|
2
4
|
module StreamData
|
3
|
-
|
4
|
-
|
5
|
-
ALLOWED_SERVICE_TYPES = ["azure","aws"]
|
6
|
-
|
7
|
-
def initialize(config,opts={})
|
8
|
-
initialize_config(config,opts)
|
9
|
-
end
|
10
|
-
|
11
|
-
def send_stream(raw_data)
|
12
|
-
return "String data can only be sent via this service" unless raw_data.is_a? String
|
13
|
-
case @config[:type_of_service]
|
14
|
-
when "aws"
|
15
|
-
aws_firehose = StreamData::AwsStreamService.new(@config,@opts)
|
16
|
-
aws_firehose.send_stream(raw_data)
|
17
|
-
else
|
18
|
-
return "No data sent"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def initialize_config(config,opts)
|
25
|
-
begin
|
26
|
-
@config = config || {}
|
27
|
-
@opts = opts || {}
|
28
|
-
@config[:type_of_service] || raise(StandardError.new('Specify the servcie type'))
|
29
|
-
@config[:service_key] || raise(StandardError.new('Service Key is missing, please specify in config'))
|
30
|
-
@config[:service_secret] || raise(StandardError.new('Service Secret is missing, please specify in config'))
|
31
|
-
@config[:delivery_stream_name] || raise(StandardError.new('Delivery Stream Name is missing, please specify in config'))
|
32
|
-
@config[:region] || raise(StandardError.new('Specify the Region'))
|
33
|
-
raise(StandardError.new('This type of servcie is not supported')) unless ALLOWED_SERVICE_TYPES.include?(@config[:type_of_service])
|
34
|
-
rescue Exception => e
|
35
|
-
raise(StandardError.new("Not a valid config, #{e.message}"))
|
36
|
-
end
|
37
|
-
end
|
5
|
+
|
6
|
+
@config = StreamData::Config.read_config
|
38
7
|
|
8
|
+
def self.send(raw_data)
|
9
|
+
StreamData::Config.validate_config
|
10
|
+
StreamData::Stream.send_stream(@config,raw_data)
|
39
11
|
end
|
12
|
+
|
40
13
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stream_data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Saran
|
@@ -37,6 +37,9 @@ extensions: []
|
|
37
37
|
extra_rdoc_files: []
|
38
38
|
files:
|
39
39
|
- lib/aws_stream_service.rb
|
40
|
+
- lib/config.rb
|
41
|
+
- lib/stream.rb
|
42
|
+
- lib/stream_config.yml
|
40
43
|
- lib/stream_data.rb
|
41
44
|
homepage: ''
|
42
45
|
licenses:
|