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 +7 -0
- data/.github/workflows/test.yml +11 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +13 -0
- data/CHANGELOG.md +5 -0
- data/Dockerfile.test +13 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +53 -0
- data/Makefile +14 -0
- data/README.md +19 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/docker-compose.test.yml +14 -0
- data/driven-api.gemspec +33 -0
- data/lib/driven/api.rb +62 -0
- data/lib/driven/api/version.rb +7 -0
- metadata +63 -0
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
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/Dockerfile.test
ADDED
data/Gemfile
ADDED
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
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
data/driven-api.gemspec
ADDED
@@ -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
|
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: []
|