driven-api 0.1.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: 6df6d9e99c5f42847288d508a5ce56a4439bd7467b76f2af0e700b7a6645ea12
4
+ data.tar.gz: a169ea717f4f60bba6589f6b26377141d61226f0ac68bd23e5037c4281cbcb83
5
+ SHA512:
6
+ metadata.gz: 967ad3b0decbd0e8fcc037f64a61a80bcaf2ab2c67dcaa6aec2b2169bb0396c861cf0b7d4854f2b43f10c103bf1ad4252dc9df45064aa8d1c813d80af62f43c9
7
+ data.tar.gz: 1ac1c52ccb3c52491bdb9a5a27904fe6a18278da287d8a09afd08315a26f24dfedd509835ce684431cd58f8e4c6d9f952351ae3c27d95035810e075bffc3bb3e
@@ -0,0 +1,11 @@
1
+ name: Test
2
+ on:
3
+ pull_request:
4
+ branches: [main]
5
+ jobs:
6
+ test:
7
+ runs-on: ubuntu-20.04
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Build test compose
11
+ run: make test
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /.idea
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
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.4
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/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-07-01
4
+
5
+ - Initial release
data/Dockerfile.test ADDED
@@ -0,0 +1,13 @@
1
+ FROM ruby:2.7.3
2
+
3
+ WORKDIR /usr/src/gem
4
+
5
+ RUN gem install bundler
6
+
7
+ COPY ./Gemfile .
8
+ COPY ./Gemfile.lock .
9
+ COPY ./driven-api.gemspec .
10
+ COPY ./lib/driven/api/version.rb ./lib/driven/api/version.rb
11
+ RUN bundle
12
+
13
+ COPY . .
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in driven-api.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ group :test do
13
+ gem "webmock"
14
+ gem 'faker'
15
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,53 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ driven-api (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.7.0)
10
+ public_suffix (>= 2.0.2, < 5.0)
11
+ concurrent-ruby (1.1.9)
12
+ crack (0.4.5)
13
+ rexml
14
+ diff-lcs (1.4.4)
15
+ faker (2.18.0)
16
+ i18n (>= 1.6, < 2)
17
+ hashdiff (1.0.1)
18
+ i18n (1.8.10)
19
+ concurrent-ruby (~> 1.0)
20
+ public_suffix (4.0.6)
21
+ rake (13.0.3)
22
+ rexml (3.2.5)
23
+ rspec (3.10.0)
24
+ rspec-core (~> 3.10.0)
25
+ rspec-expectations (~> 3.10.0)
26
+ rspec-mocks (~> 3.10.0)
27
+ rspec-core (3.10.1)
28
+ rspec-support (~> 3.10.0)
29
+ rspec-expectations (3.10.1)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.10.0)
32
+ rspec-mocks (3.10.2)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.10.0)
35
+ rspec-support (3.10.2)
36
+ webmock (3.13.0)
37
+ addressable (>= 2.3.6)
38
+ crack (>= 0.3.2)
39
+ hashdiff (>= 0.4.0, < 2.0.0)
40
+
41
+ PLATFORMS
42
+ arm64-darwin-20
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ driven-api!
47
+ faker
48
+ rake (~> 13.0)
49
+ rspec (~> 3.0)
50
+ webmock
51
+
52
+ BUNDLED WITH
53
+ 2.2.21
data/Makefile ADDED
@@ -0,0 +1,14 @@
1
+ # TEST
2
+ test_compose = docker-compose -f docker-compose.test.yml
3
+
4
+ .PRONY: test-build
5
+ test-build:
6
+ $(test_compose) build
7
+
8
+ .PRONY: test
9
+ test:
10
+ make test-build && $(test_compose) run driven-gem && make test-down
11
+
12
+ .PRONY: test-down
13
+ test-down:
14
+ $(test_compose) down
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # Driven::Api
2
+
3
+ Gem file to connect user events with driven network.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'driven-api'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install driven-api
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]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "driven/api"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,14 @@
1
+ version: '3.8'
2
+ services:
3
+ driven-gem:
4
+ build:
5
+ context: .
6
+ dockerfile: Dockerfile.test
7
+ container_name: drivengem-gem
8
+ logging:
9
+ driver: 'json-file'
10
+ options:
11
+ max-size: '10m'
12
+ max-file: '5'
13
+ working_dir: /usr/src/gem
14
+ command: rspec
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/driven/api/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "driven-api"
7
+ spec.version = Driven::Api::VERSION
8
+ spec.authors = ["Alexandre Nunes"]
9
+ spec.email = ["alexandrenunes@poli.ufrj.br"]
10
+
11
+ spec.summary = "Driven gateway gem interface to handle user events"
12
+ spec.homepage = "https://driveneducation.com.br"
13
+ spec.required_ruby_version = ">= 2.4.0"
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = "https://github.com/driven-education/driven-gem"
17
+ spec.metadata["changelog_uri"] = "https://github.com/driven-education/driven-gem/blob/main/CHANGELOG.md"
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ # Uncomment to register a new dependency of your gem
29
+ # spec.add_dependency "example-gem", "~> 1.0"
30
+
31
+ # For more information and examples about making a new gem, checkout our
32
+ # guide at: https://bundler.io/guides/creating_gem.html
33
+ end
data/lib/driven/api.rb ADDED
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+ require 'uri'
3
+ require 'net/http'
4
+ require 'faker'
5
+
6
+ require_relative "api/version"
7
+
8
+ module Driven
9
+ class Api
10
+ def initialize(base_url, auth)
11
+ @base_url = base_url
12
+ @auth = auth
13
+ end
14
+
15
+ def send_event(name, events_properties, user_properties)
16
+ begin
17
+ res = post('/events', {
18
+ name: name,
19
+ userProperties: user_properties,
20
+ eventProperties: events_properties
21
+ })
22
+ if (200..300) === res.code.to_i
23
+ return res.code
24
+ else
25
+ raise RequestError.new res.code
26
+ end
27
+ rescue => e
28
+ begin
29
+ post('/reports', { error: e.to_s })
30
+ return nil
31
+ rescue
32
+ nil
33
+ end
34
+ end
35
+ end
36
+
37
+ private
38
+ def post(path, body)
39
+ uri = uri(path)
40
+ http = Net::HTTP.new uri.host
41
+
42
+ req = Net::HTTP::Post.new uri.path, self.header
43
+ req.body = body.to_json
44
+
45
+ http.request req
46
+ end
47
+
48
+ def uri(path)
49
+ URI(@base_url + path)
50
+ end
51
+
52
+ def header
53
+ { 'Content-type' => 'application/json', 'X-Api-Key' => "Bearer #{@auth}" }
54
+ end
55
+ end
56
+
57
+ class RequestError < StandardError
58
+ def initialize(code)
59
+ super "Request failed with status #{code}"
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Driven
4
+ class Api
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: driven-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alexandre Nunes
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-07-02 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - alexandrenunes@poli.ufrj.br
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".github/workflows/test.yml"
21
+ - ".gitignore"
22
+ - ".idea/modules.xml"
23
+ - ".rspec"
24
+ - ".rubocop.yml"
25
+ - CHANGELOG.md
26
+ - Dockerfile.test
27
+ - Gemfile
28
+ - Gemfile.lock
29
+ - Makefile
30
+ - README.md
31
+ - Rakefile
32
+ - bin/console
33
+ - bin/setup
34
+ - docker-compose.test.yml
35
+ - driven-api.gemspec
36
+ - lib/driven/api.rb
37
+ - lib/driven/api/version.rb
38
+ homepage: https://driveneducation.com.br
39
+ licenses: []
40
+ metadata:
41
+ homepage_uri: https://driveneducation.com.br
42
+ source_code_uri: https://github.com/driven-education/driven-gem
43
+ changelog_uri: https://github.com/driven-education/driven-gem/blob/main/CHANGELOG.md
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 2.4.0
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubygems_version: 3.1.6
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Driven gateway gem interface to handle user events
63
+ test_files: []