Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a80ec7d
Create lint workflow
helderhp Aug 20, 2022
db091c9
Adiciona o Gemfile
Aug 21, 2022
c05f363
fix gemspec
Aug 21, 2022
1ae3b17
fix rubocop
Aug 22, 2022
bcb2ac6
Adiciona os arquivos de exemplo
Aug 20, 2022
2a6d7f8
adiciona script para o build da gem e instalação para testes
Aug 23, 2022
2809be3
Adiciona alguns campos faltantes
Aug 23, 2022
c5e0a43
adiciona o model para o konduto_destination_account.rb
Aug 27, 2022
59e366f
adiciona o model konduto_origin_account.rb
Aug 27, 2022
d48d9db
adiciona o model konduto_agent.rb
Aug 27, 2022
27c382b
adiciona os models para o nó evento
Aug 27, 2022
ac666df
adiciona o model para o nó external_device
Aug 27, 2022
d9d7d79
adiciona os models para o nó options
Aug 27, 2022
be3d16e
adiciona os models para o nó point_of_sale
Aug 27, 2022
6d46053
adiciona os models para o nó tenant
Aug 27, 2022
c38bac2
adiciona os models para o nó vehicle
Aug 27, 2022
8864b9f
Adiciona os models para o nó hotel
Aug 27, 2022
f19c811
ajustes na geração do pedido completo
Aug 27, 2022
b16d3ac
fix rubocop
Aug 27, 2022
4d1866d
adiciona o step para os tests no workflow
Aug 27, 2022
eb469b1
ajuste no gemspec
Aug 27, 2022
e3e9cec
adiciona alguns testes
Jan 20, 2023
700b651
adiciona os itens triggered_rules, triggered_decision_list e analysis…
Jan 20, 2023
39254a1
fix rubocop
Jan 20, 2023
32d82ed
atualiza o readme
Mar 6, 2023
efc688e
chore: update minitest to 5.25
MrChampz Jul 25, 2025
3613cbe
chore: update rubocop and fixed linter issues
MrChampz Jul 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Github workflow gem develop

on: [push]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@477b21f02be01bcb8030d50f37cfec92bfa615b6
with:
ruby-version: 2.7
- run: bundle install
- name: Rubocop
run: rubocop
test:
needs: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@477b21f02be01bcb8030d50f37cfec92bfa615b6
with:
ruby-version: 2.7
- name: Bundle install
run: bundle install
- name: Gem build
run: gem build
- name: Gem install
run: gem install konduto-ruby --local konduto-ruby-*.gem
- name: Run Tests
run: rake test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
.idea/
*/**/coverage/
/coverage/
*.gem

25 changes: 25 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
plugins: rubocop-minitest

AllCops:
SuggestExtensions: false

Naming/VariableName:
Enabled: false
Metrics/AbcSize:
Enabled: false
Metrics/MethodLength:
Enabled: false
Metrics/BlockLength:
Enabled: false
Metrics/PerceivedComplexity:
Enabled: false
Style/Documentation:
Enabled: false
Style/GuardClause:
Enabled: false
Naming/FileName:
Enabled: false
Metrics/CyclomaticComplexity:
Enabled: false
Naming/PredicatePrefix:
Enabled: false
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

source 'https://rubygems.org'

# Specify your gem's dependencies in konduto-ruby.gemspec
gemspec
97 changes: 97 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
PATH
remote: .
specs:
konduto-ruby (2.2.0)

GEM
remote: https://rubygems.org/
specs:
activesupport (7.1.5.1)
base64
benchmark (>= 0.3)
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
logger (>= 1.4.2)
minitest (>= 5.1)
mutex_m
securerandom (>= 0.3)
tzinfo (~> 2.0)
ast (2.4.3)
base64 (0.3.0)
benchmark (0.4.1)
bigdecimal (3.2.2)
concurrent-ruby (1.3.5)
connection_pool (2.5.3)
docile (1.4.1)
drb (2.2.3)
factory_girl (4.9.0)
activesupport (>= 3.0.0)
i18n (1.14.7)
concurrent-ruby (~> 1.0)
json (2.13.1)
language_server-protocol (3.17.0.5)
lint_roller (1.1.0)
logger (1.7.0)
minitest (5.25.5)
mutex_m (0.3.0)
parallel (1.27.0)
parser (3.3.9.0)
ast (~> 2.4.1)
racc
prism (1.4.0)
racc (1.8.1)
rainbow (3.1.1)
rake (12.3.3)
regexp_parser (2.10.0)
rubocop (1.79.0)
json (~> 2.3)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.1.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.46.0, < 2.0)
ruby-progressbar (~> 1.7)
tsort (>= 0.2.0)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.46.0)
parser (>= 3.3.7.2)
prism (~> 1.4)
rubocop-minitest (0.38.1)
lint_roller (~> 1.1)
rubocop (>= 1.75.0, < 2.0)
rubocop-ast (>= 1.38.0, < 2.0)
ruby-progressbar (1.13.0)
securerandom (0.3.2)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.13.2)
simplecov_json_formatter (0.1.4)
tsort (0.2.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (3.1.4)
unicode-emoji (~> 4.0, >= 4.0.4)
unicode-emoji (4.0.4)

PLATFORMS
ruby
x64-mingw32

DEPENDENCIES
factory_girl (~> 4.9)
konduto-ruby!
minitest (~> 5.25)
rake (~> 12.3.3)
rubocop (~> 1.79)
rubocop-minitest (~> 0.38.1)
simplecov

BUNDLED WITH
2.1.4
415 changes: 319 additions & 96 deletions README.md

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'rake/testtask'

Rake::TestTask.new do |t|
Expand All @@ -6,5 +8,5 @@ Rake::TestTask.new do |t|
t.verbose = true
end

desc "Run tests"
desc 'Run tests'
task default: :test
15 changes: 15 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'bundler/setup'
require 'konduto-ruby'

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.

# (If you use this, don't forget to add pry to your Gemfile!)
# require "pry"
# Pry.start

require 'irb'
IRB.start(__FILE__)
8 changes: 8 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
set -vx

bundle install

# Do any other automated setup that you need to do here
6 changes: 6 additions & 0 deletions build_and_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
rvm use ruby-2.7.0@konduto-ruby
gem uninstall konduto-ruby
bundle install
gem build
gem install konduto-ruby --local konduto-ruby-2.2.0.gem
20 changes: 15 additions & 5 deletions konduto-ruby.gemspec
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
# frozen_string_literal: true

require_relative 'lib/konduto-ruby'

Gem::Specification.new do |spec|
spec.name = 'konduto-ruby'
spec.version = '2.1.2'
spec.version = KondutoRuby::VERSION
spec.authors = ['Gabriel Custodio', 'Jonathan Cardoso de Campos', 'Konduto Development Team']
spec.date = Time.now.utc.strftime('%Y-%m-%d')
spec.email = [%(gcmartins93@gmail.com jonathancardosodecampos@gmail.com support@konduto.com)]
spec.homepage = 'https://github.com/konduto/konduto-ruby'
spec.summary = ''
spec.description = 'A wrapper for konduto antifraud API'

spec.files = Dir["{lib}/**/*.rb", "bin/*", "LICENSE", "*.md"]
spec.required_ruby_version = Gem::Requirement.new('>= 2.7.0')
spec.files = Dir['{lib}/**/*.rb', 'LICENSE', '*.md']
spec.require_path = 'lib'

spec.license = 'MIT'

spec.add_development_dependency 'factory_girl', '~> 4.7'
# tests
spec.add_development_dependency 'factory_girl', '~> 4.9'
spec.add_development_dependency 'minitest', '~> 5.25'
spec.add_development_dependency 'rake', '~> 12.3.3'
spec.add_development_dependency 'rubocop', '~> 1.79'
spec.add_development_dependency 'rubocop-minitest', '~> 0.38.1'
spec.add_development_dependency 'simplecov'
end
74 changes: 40 additions & 34 deletions lib/konduto-ruby.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# frozen_string_literal: true

require 'json'
require 'date'
require 'konduto-ruby/konduto_base'
require 'konduto-ruby/konduto_travel_leg'
require_relative 'konduto-ruby/konduto_base'
require_relative 'konduto-ruby/konduto_travel_leg'

Dir[__dir__ + '/konduto-ruby/*.rb'].each { |file| require file }
Dir["#{__dir__}/konduto-ruby/*.rb"].sort.each { |file| require file }

class KondutoRuby
require 'uri'
Expand All @@ -12,95 +14,99 @@ class KondutoRuby
attr_accessor :request_body, :response_body, :endpoint
attr_reader :api_key

def initialize api_key, endpoint = 'https://api.konduto.com/v1'
VERSION = '2.2.0'

def initialize(api_key, endpoint = 'https://api.konduto.com/v1')
@endpoint = URI.parse(endpoint)
@http_client = Net::HTTP.new(@endpoint.host, @endpoint.port)
@api_key = api_key
end

def api_key= api_key
def api_key=(api_key)
if api_key.length == 21
@api_key = api_key
else
raise ArgumentError.new "Invalid key: #{api_key}! API key length must be of 21"
raise ArgumentError, "Invalid key: #{api_key}! API key length must be of 21"
end
end

def proxy
return @proxy if @proxy
URI.parse(ENV['http_proxy']) rescue nil

begin
URI.parse(ENV['http_proxy'])
rescue StandardError
nil
end
end

def proxy= proxy_url
def proxy=(proxy_url)
@proxy = URI.parse(proxy_url)
end

def order_url order_id=''
def order_url(order_id = '')
url = "#{@endpoint}/orders"
url += "/#{order_id}" unless order_id == ''
URI.parse(url)
end

def send_request http_method, request_body=''
def send_request(http_method, request_body = '')
headers = {
'Authorization' => "Basic #{Base64.encode64(@api_key)}",
'Content-Type' =>'application/json',
'Content-Type' => 'application/json',
'Referer' => @endpoint.path
}
http_method.initialize_http_header headers
http_method.body = request_body
if proxy
http = Net::HTTP::Proxy(proxy.host, proxy.port).new(@endpoint.host, @endpoint.port)
else
http = Net::HTTP.new(@endpoint.host, @endpoint.port)
end
http = if proxy
Net::HTTP::Proxy(proxy.host, proxy.port).new(@endpoint.host, @endpoint.port)
else
Net::HTTP.new(@endpoint.host, @endpoint.port)
end
http.use_ssl = true
response = http.request(http_method)

response
http.request(http_method)
end

def get_order order_id
def get_order(order_id)
get = Net::HTTP::Get.new(order_url(order_id))
response = send_request(get)

if response.kind_of? Net::HTTPSuccess
if response.is_a? Net::HTTPSuccess
order = KondutoOrder.new JSON.parse(response.entity)['order']
order.id = order_id unless order.id
return order
order
else
raise (JSON.parse(response.body)['message']).to_s
raise JSON.parse(response.body)['message'].to_s
end


end

def analyze order
def analyze(order)
post = Net::HTTP::Post.new(order_url)
response = send_request(post, order.to_json)

if response.kind_of? Net::HTTPSuccess
return KondutoOrder.new JSON.parse(response.entity)['order']
if response.is_a? Net::HTTPSuccess
KondutoOrder.new JSON.parse(response.entity)['order']
else
raise (JSON.parse(response.body)['message']).to_s
raise JSON.parse(response.body)['message'].to_s
end
end

def update_order_status order, new_status, comments
def update_order_status(order, new_status, comments)
raise ArgumentError("Illegal status #{new_status}") unless KondutoOrderStatus.allowed_status.include? new_status
raise ArgumentError("Commets can't be nil") unless comments

put = Net::HTTP::Put.new(order_url(order.id))
body = {status: new_status.downcase, comments: comments}.to_json
body = { status: new_status.downcase, comments: comments }.to_json
response = send_request(put, body)

if response.kind_of? Net::HTTPSuccess
if response.is_a? Net::HTTPSuccess
resposta = JSON.parse(response.entity)['order']
raise 'Update order status can\'t be done' if resposta['old_status'].nil? && resposta['new_status'].nil?

order.status = resposta['new_status']
return order
order
else
raise (JSON.parse(response.body)['message']).to_s
raise JSON.parse(response.body)['message'].to_s
end
end

Expand Down
Loading