Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 13 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ on:
branches: [main]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.4"
bundler-cache: true
- name: Run rubocop
run: bundle exec rubocop

test:
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -42,7 +54,7 @@ jobs:
run: bundle exec rake spec

typing:
name: "Typing & lint"
name: "Typing"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
59 changes: 52 additions & 7 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,63 @@
require:
plugins:
- rubocop-performance
- rubocop-rspec

AllCops:
NewCops: enable
TargetRubyVersion: 3.0
Exclude:
- 'vendor/**/*'
- 'spec/spec_helper.rb'

Layout/LineLength:
Max: 120
- 'spec/**/*'
- 'bin/**/*'
- 'gemfiles/**/*'

Style/Documentation:
Enabled: false

Style/FrozenStringLiteralComment:
Enabled: true
Enabled: false
Style/StringLiterals:
Enabled: false
Layout/LineLength:
Enabled: false
Metrics/MethodLength:
Enabled: false
Metrics/ParameterLists:
Enabled: false
Metrics/AbcSize:
Enabled: false
Metrics/CyclomaticComplexity:
Enabled: false
Metrics/PerceivedComplexity:
Enabled: false
Layout/TrailingWhitespace:
Enabled: false
Metrics/ClassLength:
Enabled: false
Gemspec/RequireMFA:
Enabled: false
Gemspec/OrderedDependencies:
Enabled: false
Gemspec/DevelopmentDependencies:
Enabled: false
Gemspec/RequiredRubyVersion:
Enabled: false
Style/IfUnlessModifier:
Enabled: false
Layout/EmptyLineAfterGuardClause:
Enabled: false
Layout/EmptyLinesAroundModuleBody:
Enabled: false
Lint/MissingSuper:
Enabled: false
Naming/MethodParameterName:
Enabled: false
Layout/IndentationWidth:
Enabled: false
Style/Proc:
Enabled: false
Style/FetchEnvVar:
Enabled: false
Style/MutableConstant:
Enabled: false
Bundler/OrderedGems:
Enabled: false
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ gem "rspec"
gem "testcontainers"
gem "base64"

gem 'tapioca', require: false, group: [:development, :test]
gem 'tapioca', require: false, group: %i[development test]
18 changes: 4 additions & 14 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,13 @@ GEM
rubocop-ast (1.49.0)
parser (>= 3.3.7.2)
prism (~> 1.7)
rubocop-capybara (2.22.1)
lint_roller (~> 1.1)
rubocop (~> 1.72, >= 1.72.1)
rubocop-factory_bot (2.28.0)
lint_roller (~> 1.1)
rubocop (~> 1.72, >= 1.72.1)
rubocop-performance (1.26.1)
lint_roller (~> 1.1)
rubocop (>= 1.75.0, < 2.0)
rubocop-ast (>= 1.47.1, < 2.0)
rubocop-rspec (2.31.0)
rubocop (~> 1.40)
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
rubocop-rspec_rails (~> 2.28)
rubocop-rspec_rails (2.29.1)
rubocop (~> 1.61)
rubocop-rspec (3.9.0)
lint_roller (~> 1.1)
rubocop (~> 1.81)
ruby-progressbar (1.13.0)
sorbet (0.6.12997)
sorbet-static (= 0.6.12997)
Expand Down Expand Up @@ -162,7 +152,7 @@ DEPENDENCIES
rspec (~> 3.0, >= 0)
rubocop (~> 1.0)
rubocop-performance (~> 1.0)
rubocop-rspec (~> 2.0)
rubocop-rspec (~> 3.0)
sorbet
sorbet-runtime
tapioca
Expand Down
4 changes: 3 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

require "rspec/core/rake_task"
require "bundler/gem_tasks"
require "rubocop/rake_task"

RSpec::Core::RakeTask.new(:spec)
RuboCop::RakeTask.new(:rubocop)

task default: :spec
task default: %i[spec rubocop]
2 changes: 1 addition & 1 deletion altertable.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "rubocop", "~> 1.0"
spec.add_development_dependency "rubocop-performance", "~> 1.0"
spec.add_development_dependency "rubocop-rspec", "~> 2.0"
spec.add_development_dependency "rubocop-rspec", "~> 3.0"
spec.add_development_dependency "testcontainers"
spec.add_development_dependency "rbs"
spec.add_development_dependency "sorbet"
Expand Down
6 changes: 3 additions & 3 deletions lib/altertable/adapters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def initialize(base_url:, timeout:, headers: {})
end
end

def post(path, body: nil, params: {}, &block)
def post(path, body: nil, params: {})
resp = @conn.post(path) do |req|
req.params = params
req.body = body
Expand Down Expand Up @@ -59,7 +59,7 @@ def initialize(base_url:, timeout:, headers: {})
)
end

def post(path, body: nil, params: {}, &block)
def post(path, body: nil, params: {})
resp = @client.post(path, body: body, params: params)
wrap_response(resp)
rescue HTTPX::Error => e
Expand All @@ -84,7 +84,7 @@ def initialize(base_url:, timeout:, headers: {})
@uri = URI.parse(@base_url)
end

def post(path, body: nil, params: {}, &block)
def post(path, body: nil, params: {})
uri = URI.join(@uri, path)
uri.query = URI.encode_www_form(params) unless params.empty?

Expand Down
20 changes: 14 additions & 6 deletions lib/altertable/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def track(event, distinct_id, **options)
environment: @environment,
distinct_id: distinct_id,
properties: {
"$lib": "altertable-ruby",
"$lib_version": Altertable::VERSION
'$lib': "altertable-ruby",
'$lib_version': Altertable::VERSION
}.merge(properties)
}
payload[:properties]["$release"] = @release if @release
Expand Down Expand Up @@ -117,10 +117,18 @@ def post(path, payload)
def handle_response(res)
case res.status
when 200..299
JSON.parse(res.body) rescue {}
begin
JSON.parse(res.body)
rescue StandardError
{}
end
when 422
error_data = JSON.parse(res.body) rescue {}
raise ApiError.new("Unprocessable Entity: #{error_data["message"]}", res.status, error_data)
error_data = begin
JSON.parse(res.body)
rescue StandardError
{}
end
raise ApiError.new("Unprocessable Entity: #{error_data['message']}", res.status, error_data)
else
raise ApiError.new("HTTP Error: #{res.status}", res.status)
end
Expand All @@ -133,7 +141,7 @@ def handle_error(error)
AltertableError.new(error.message, error)
end

@on_error&.call(wrapped_error) if @on_error
@on_error&.call(wrapped_error)
raise wrapped_error
end
end
Expand Down