distrito_tracking 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8d99da01296b93d1223fbf8d8dda8be4c9e9cc8684c0b4cba9adee5f4460b02d
4
+ data.tar.gz: ac532d61b0812d6ea68dd721aa2a1537ce731a8ec59ceb86f02ac8a79a715a63
5
+ SHA512:
6
+ metadata.gz: 68d587dfedd6dc9141f60702e8ed5d4f70d461c3808bac91009e277ee786df4b235b891991c16228293b92d5e4a20f37928ecd38c7fc152a1690b4fd64db656d
7
+ data.tar.gz: 8047937cdf3e8eb9db19a580ab3746897ba214a7e6c307a354e19cbb0150bce934f73b6b745b6ec1c35fb0952951ebdb1d08b38ae1e595362bcdb8b6ec944a62
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in distrito_tracking.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.11"
11
+
12
+ gem "rubocop", "~> 1.21"
data/Gemfile.lock ADDED
@@ -0,0 +1,71 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ distrito_tracking (0.1.0)
5
+ aws-sdk-sns
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ aws-eventstream (1.2.0)
12
+ aws-partitions (1.648.0)
13
+ aws-sdk-core (3.162.0)
14
+ aws-eventstream (~> 1, >= 1.0.2)
15
+ aws-partitions (~> 1, >= 1.525.0)
16
+ aws-sigv4 (~> 1.1)
17
+ jmespath (~> 1, >= 1.6.1)
18
+ aws-sdk-sns (1.55.0)
19
+ aws-sdk-core (~> 3, >= 3.127.0)
20
+ aws-sigv4 (~> 1.1)
21
+ aws-sigv4 (1.5.2)
22
+ aws-eventstream (~> 1, >= 1.0.2)
23
+ diff-lcs (1.5.0)
24
+ jmespath (1.6.1)
25
+ json (2.6.2)
26
+ parallel (1.22.1)
27
+ parser (3.1.2.1)
28
+ ast (~> 2.4.1)
29
+ rainbow (3.1.1)
30
+ rake (13.0.6)
31
+ regexp_parser (2.6.0)
32
+ rexml (3.2.5)
33
+ rspec (3.11.0)
34
+ rspec-core (~> 3.11.0)
35
+ rspec-expectations (~> 3.11.0)
36
+ rspec-mocks (~> 3.11.0)
37
+ rspec-core (3.11.0)
38
+ rspec-support (~> 3.11.0)
39
+ rspec-expectations (3.11.1)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.11.0)
42
+ rspec-mocks (3.11.1)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.11.0)
45
+ rspec-support (3.11.1)
46
+ rubocop (1.36.0)
47
+ json (~> 2.3)
48
+ parallel (~> 1.10)
49
+ parser (>= 3.1.2.1)
50
+ rainbow (>= 2.2.2, < 4.0)
51
+ regexp_parser (>= 1.8, < 3.0)
52
+ rexml (>= 3.2.5, < 4.0)
53
+ rubocop-ast (>= 1.20.1, < 2.0)
54
+ ruby-progressbar (~> 1.7)
55
+ unicode-display_width (>= 1.4.0, < 3.0)
56
+ rubocop-ast (1.21.0)
57
+ parser (>= 3.1.1.0)
58
+ ruby-progressbar (1.11.0)
59
+ unicode-display_width (2.3.0)
60
+
61
+ PLATFORMS
62
+ x86_64-linux
63
+
64
+ DEPENDENCIES
65
+ distrito_tracking!
66
+ rake (~> 13.0)
67
+ rspec (~> 3.11)
68
+ rubocop (~> 1.21)
69
+
70
+ BUNDLED WITH
71
+ 2.3.7
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # DistritoTracking
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/distrito_tracking`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'distrito_tracking'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install distrito_tracking
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ DistritoTracking.configure do |config|
27
+ config.region = ENV['AWS_REGION']
28
+ config.access_key_id = ENV['AWS_ACCESS_KEY_ID']
29
+ config.secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
30
+ config.topic_arn = ENV['AWS_TOPIC_ARN']
31
+ end
32
+ ```
33
+
34
+ ## Development
35
+
36
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
37
+
38
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
39
+
40
+ ## Contributing
41
+
42
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/distrito_tracking.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "aws-sdk-sns"
4
+ require "json"
5
+
6
+ module DistritoTracking
7
+ class Client
8
+ attr_reader :client, :configuration
9
+
10
+ def initialize
11
+ @client = Aws::SNS::Client.new(
12
+ region: configuration.region,
13
+ access_key_id: configuration.access_key_id,
14
+ secret_access_key: configuration.secret_access_key
15
+ )
16
+ end
17
+
18
+ def publish(data)
19
+ return false if data.empty?
20
+
21
+ client.publish({
22
+ topic_arn: configuration.topic_arn,
23
+ message: JSON.generate(data)
24
+ })
25
+ end
26
+
27
+ def configuration
28
+ @configuration ||= DistritoTracking.configuration
29
+ end
30
+
31
+ def inspect
32
+ "#<DistritoTracking::Client>"
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DistritoTracking
4
+ class Configuration
5
+ attr_accessor :region, :access_key_id, :secret_access_key, :topic_arn
6
+
7
+ FIELDS = %i[region access_key_id secret_access_key topic_arn].freeze
8
+
9
+ def validate!
10
+ FIELDS.each do |field|
11
+ raise DistritoTracking::Error, "#{field} is missing" unless send(field)
12
+ end
13
+
14
+ true
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DistritoTracking
4
+ class Error < StandardError; end
5
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "date"
4
+
5
+ module DistritoTracking
6
+ class Schema
7
+ DEFAULT_SCHEMA = {
8
+ appName: String,
9
+ event: {
10
+ name: String,
11
+ type: String
12
+ },
13
+ feature: {
14
+ name: String
15
+ },
16
+ time: Time
17
+ }.freeze
18
+
19
+ attr_accessor :errors
20
+
21
+ def initialize
22
+ @errors = {}
23
+ end
24
+
25
+ def validate(data:)
26
+ errors[:data] = "Data provided is invalid" if data.empty? || !data.is_a?(Hash)
27
+
28
+ iterate(data, DEFAULT_SCHEMA)
29
+
30
+ @errors.empty?
31
+ end
32
+
33
+ def inspect
34
+ "#<DistritoTracking::Schema>"
35
+ end
36
+
37
+ private
38
+
39
+ def iterate(obj, schema, old_key = nil)
40
+ schema.each do |key, value|
41
+ error_key = old_key.nil? ? key : old_key
42
+
43
+ if obj.is_a?(Hash) && obj.include?(key)
44
+ if value.is_a?(Hash)
45
+ iterate(obj[key], value, key)
46
+ else
47
+ next if value == obj[key].class
48
+
49
+ errors[error_key] = "The key \"#{key}\" must be a #{value} value"
50
+ end
51
+ else
52
+ errors[error_key] = "The key \"#{key}\" is missing or invalid"
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DistritoTracking
4
+ VERSION = "1.0.0"
5
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "distrito_tracking/version"
4
+
5
+ module DistritoTracking
6
+ autoload :Client, "distrito_tracking/client"
7
+ autoload :Error, "distrito_tracking/error"
8
+ autoload :Configuration, "distrito_tracking/configuration"
9
+ autoload :Schema, "distrito_tracking/schema"
10
+
11
+ def self.configure
12
+ yield(configuration)
13
+ end
14
+
15
+ def self.publish(data:)
16
+ false unless configuration.validate!
17
+
18
+ if schema.validate(data: data)
19
+ client.publish(data)
20
+ else
21
+ { errors: schema.errors }
22
+ end
23
+ end
24
+
25
+ def self.configuration
26
+ @configuration ||= Configuration.new
27
+ end
28
+
29
+ def self.client
30
+ @client ||= Client.new
31
+ end
32
+
33
+ def self.schema
34
+ @schema ||= Schema.new
35
+ end
36
+ end
@@ -0,0 +1,4 @@
1
+ module DistritoTracking
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: distrito_tracking
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jonathan Queiroz
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-11-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk-sns
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description:
28
+ email:
29
+ - jonathan@distrito.me
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".rspec"
35
+ - ".rubocop.yml"
36
+ - Gemfile
37
+ - Gemfile.lock
38
+ - README.md
39
+ - Rakefile
40
+ - lib/distrito_tracking.rb
41
+ - lib/distrito_tracking/client.rb
42
+ - lib/distrito_tracking/configuration.rb
43
+ - lib/distrito_tracking/error.rb
44
+ - lib/distrito_tracking/schema.rb
45
+ - lib/distrito_tracking/version.rb
46
+ - sig/distrito_tracking.rbs
47
+ homepage:
48
+ licenses: []
49
+ metadata: {}
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: 2.6.0
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubygems_version: 3.1.6
66
+ signing_key:
67
+ specification_version: 4
68
+ summary: DistritoTracking is a gem to help to track some data from users on Distrito
69
+ services
70
+ test_files: []