Skip to content

Commit

Permalink
Add Rubocop (#8)
Browse files Browse the repository at this point in the history
* fix Rubocop offenses

* realease 1.0 and fixed Rubocop offenses

* fix style lint workflow job

* fix workflow Rubocop job name
  • Loading branch information
Pedro Augusto authored Mar 1, 2024
1 parent 9ba2a2e commit b981dbb
Show file tree
Hide file tree
Showing 18 changed files with 136 additions and 100 deletions.
27 changes: 0 additions & 27 deletions .github/main.yml

This file was deleted.

6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
jobs:
build:
runs-on: ubuntu-latest
name: Ruby ${{ matrix.ruby }}
name: Rubocop
strategy:
matrix:
ruby:
Expand All @@ -23,5 +23,5 @@ jobs:
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run the default task
run: bundle exec rake
- name: Run Rubocop
run: bundle exec rake rubocop
24 changes: 24 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require: rubocop-rake

AllCops:
TargetRubyVersion: 3.0
NewCops: enable

Style/StringLiterals:
Enabled: true
EnforcedStyle: double_quotes

Style/StringLiteralsInInterpolation:
Enabled: true
EnforcedStyle: double_quotes

Layout/LineLength:
Max: 120

Naming/FileName:
Exclude:
- Rakefile.rb

# TODO: replace OpenStruct in version 2
Style/OpenStructUse:
Enabled: false
11 changes: 8 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
# frozen_string_literal: true

source 'https://rubygems.org'
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

# Declare your gem's dependencies in cockpit.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group.
gemspec

gem 'activesupport'
gem 'logger'
gem "activesupport"
gem "byebug", "~> 11.1"
gem "logger"
gem "rake", "~> 13.0"
gem "rubocop", "~> 1.21"

gem "rubocop-rake", "~> 0.6.0"
60 changes: 45 additions & 15 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
zspay (0.1.8)
zspay (1.0.0)
http

GEM
Expand All @@ -13,48 +13,78 @@ GEM
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
base64 (0.2.0)
byebug (11.1.3)
concurrent-ruby (1.1.9)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
ffi (1.15.5)
domain_name (0.6.20240107)
ffi (1.16.3)
ffi-compiler (1.0.1)
ffi (>= 1.0.0)
rake
http (5.1.0)
http (5.2.0)
addressable (~> 2.8)
base64 (~> 0.1)
http-cookie (~> 1.0)
http-form_data (~> 2.2)
llhttp-ffi (~> 0.4.0)
llhttp-ffi (~> 0.5.0)
http-cookie (1.0.5)
domain_name (~> 0.5)
http-form_data (2.3.0)
i18n (1.8.11)
concurrent-ruby (~> 1.0)
llhttp-ffi (0.4.0)
json (2.7.1)
language_server-protocol (3.17.0.3)
llhttp-ffi (0.5.0)
ffi-compiler (~> 1.0)
rake (~> 13.0)
logger (1.4.3)
minitest (5.14.4)
public_suffix (4.0.7)
parallel (1.24.0)
parser (3.3.0.5)
ast (~> 2.4.1)
racc
prism (0.24.0)
public_suffix (5.0.4)
racc (1.7.3)
rainbow (3.1.1)
rake (13.0.6)
regexp_parser (2.9.0)
rexml (3.2.6)
rubocop (1.61.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.30.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.0)
parser (>= 3.3.0.4)
prism (>= 0.24.0)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
ruby-progressbar (1.13.0)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
unf (0.1.4)
unf_ext
unf_ext (0.0.8.2)
unicode-display_width (2.5.0)
zeitwerk (2.5.1)

PLATFORMS
x86_64-linux

DEPENDENCIES
activesupport
byebug
byebug (~> 11.1)
logger
rake
rake (~> 13.0)
rubocop (~> 1.21)
rubocop-rake (~> 0.6.0)
zspay!

BUNDLED WITH
Expand Down
10 changes: 7 additions & 3 deletions Rakefile.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# frozen_string_literal: true

task :console do
exec 'irb -r zspay -I ./lib'
end
require "bundler/gem_tasks"

require "rubocop/rake_task"

RuboCop::RakeTask.new

task default: %i[rubocop]
1 change: 1 addition & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "bundler/setup"
require "zspay"
Expand Down
14 changes: 7 additions & 7 deletions lib/zspay.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# frozen_string_literal: true

require 'http'
require 'byebug'
require 'logger'
require 'active_support/hash_with_indifferent_access'
require "http"
require "byebug"
require "logger"
require "active_support/hash_with_indifferent_access"

require 'zspay/configuration'
require "zspay/configuration"

require 'zspay/resource'
require 'zspay/resources'
require "zspay/resource"
require "zspay/resources"

# The Zspay module is the main namespace for the Zspay gem.
# It provides methods to configure and access the gem's settings.
Expand Down
2 changes: 1 addition & 1 deletion lib/zspay/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class << self
#
# @return [String] the base URL of the Zspay API endpoint.
def endpoint
'https://api.zsystems.com.br'
"https://api.zsystems.com.br"
end
end
end
Expand Down
18 changes: 7 additions & 11 deletions lib/zspay/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class << self
# @param custom_token [String, nil] an optional custom token to use for the request.
# @param body [String] the format of the request body, defaults to 'json'.
# @return [OpenStruct] the parsed response.
def post(path, payload = {}, custom_token = nil, body: 'json')
def post(path, payload = {}, custom_token = nil, body: "json")
req(:post, path, payload, custom_token, body: body)
end

Expand Down Expand Up @@ -64,7 +64,7 @@ def put(path, payload = {}, custom_token = nil)
# @param custom_token [String, nil] an optional custom token to use for the request.
# @param body [String] the format of the request body, defaults to 'json'.
# @return [OpenStruct] the parsed response.
def req(method, path, payload = {}, custom_token = nil, body: 'json')
def req(method, path, payload = {}, custom_token = nil, body: "json")
send("req_#{body}", method, path, payload, custom_token)
end

Expand Down Expand Up @@ -94,7 +94,6 @@ def req_form(method, path, payload, custom_token)
parse_body(res)
end


# Parses the response body and returns it as an OpenStruct.
# If the request was successful, returns the JSON parsed body.
# Otherwise, logs the error and returns an error message.
Expand All @@ -110,13 +109,10 @@ def parse_body(response)

OpenStruct.new({ success: false, error: body })
else
error_log = Logger.new(STDERR)
error_log.error("Error while making Zspay request" \
" to: #{response.uri}" \
" body: #{response.body}" \
" status: #{response.code}")
error_log = Logger.new($stderr)
error_log.error("Request error to: #{response.uri}\ncode: #{response.code}\nbody: #{response.body}")

OpenStruct.new({ success: false, message: 'An error occurred while making the request' })
OpenStruct.new({ success: false, message: "An error occurred while making the request" })
end
end

Expand All @@ -135,7 +131,7 @@ def endpoint
def headers(custom_token = nil)
token = custom_token ? "Bearer #{custom_token}" : "Bearer #{Zspay::Configuration.token}"
{
'Authorization': token
Authorization: token
}
end

Expand All @@ -153,7 +149,7 @@ def success_request?(response)
# @return [OpenStruct, String] the parsed JSON or the original string if parsing failed.
def parse_json(json)
JSON.parse(json, object_class: OpenStruct)
rescue JSON::ParserError => e
rescue JSON::ParserError => _e
json
end
end
Expand Down
10 changes: 5 additions & 5 deletions lib/zspay/resources.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require 'zspay/resources/bank_account'
require 'zspay/resources/client'
require 'zspay/resources/establishments'
require 'zspay/resources/sale'
require 'zspay/resources/transfer'
require "zspay/resources/bank_account"
require "zspay/resources/client"
require "zspay/resources/establishments"
require "zspay/resources/sale"
require "zspay/resources/transfer"
4 changes: 2 additions & 2 deletions lib/zspay/resources/bank_account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ class << self
#
# @return [OpenStruct] A list of bank accounts if the request is successful.
def index
get('/estabelecimentos/contas_bancarias')
get("/estabelecimentos/contas_bancarias")
end

# Creates a new bank account for the current establishment.
#
# @param account [Hash] The bank account details required for creation.
# @return [OpenStruct] The created bank account details if the request is successful.
def create(account)
post('/estabelecimentos/contas_bancarias', account)
post("/estabelecimentos/contas_bancarias", account)
end

# Activates a specific bank account for the current establishment.
Expand Down
2 changes: 1 addition & 1 deletion lib/zspay/resources/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class << self
# @param client [Hash] A hash containing the client's information, such as name, email, etc.
# @return [OpenStruct] A structure containing the newly created client's details if successful.
def create(client)
post('/clientes', client)
post("/clientes", client)
end

# Adds a new card for an existing client on the Zspay platform.
Expand Down
16 changes: 10 additions & 6 deletions lib/zspay/resources/establishments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,40 @@

module Zspay
# The Establishments class manages establishment-related actions within the Zspay platform.
# It allows for listing, creating, enabling, disabling establishments, and more, extending the functionality from Zspay::Resource.
# It allows for listing, creating, enabling, disabling establishments, and more, extending the functionality
# from Zspay::Resource.
class Establishments < Zspay::Resource
class << self
# Retrieves a list of child establishments associated with the current establishment.
#
# @return [OpenStruct] A structure containing the list of child establishments if the request is successful.
def index
get('/estabelecimentos/filhos')
get("/estabelecimentos/filhos")
end

# Creates a new establishment on the Zspay platform.
#
# @param establishment [Hash] A hash containing the establishment's information.
# @return [OpenStruct] A structure containing the newly created establishment's details if the request is successful.
# @return [OpenStruct] A structure containing the newly created establishment's details if the request
# is successful.
def create(establishment)
post('/estabelecimentos', establishment, body: 'form')
post("/estabelecimentos", establishment, body: "form")
end

# Activates an existing establishment on the Zspay platform.
#
# @param establishment_id [String] The unique identifier of the establishment to be activated.
# @return [OpenStruct] A structure indicating the activation status of the establishment if the request is successful.
# @return [OpenStruct] A structure indicating the activation status of the establishment if the request
# is successful.
def active(establishment_id)
post("/estabelecimentos/#{establishment_id}/habilitar")
end

# Disables an existing establishment on the Zspay platform.
#
# @param establishment_id [String] The unique identifier of the establishment to be disabled.
# @return [OpenStruct] A structure indicating the disabled status of the establishment if the request is successful.
# @return [OpenStruct] A structure indicating the disabled status of the establishment if the request
# is successful.
def disable(establishment_id)
delete("/estabelecimentos/#{establishment_id}")
end
Expand Down
2 changes: 1 addition & 1 deletion lib/zspay/resources/sale.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class << self
# @param custom_token [String, nil] An optional custom token to use for the request.
# @return [OpenStruct] A structure containing the newly created sale's details if the request is successful.
def create(sale, custom_token = nil)
post('/vendas', sale, custom_token)
post("/vendas", sale, custom_token)
end

# Retrieves details of a specific sale.
Expand Down
Loading

0 comments on commit b981dbb

Please sign in to comment.