Skip to content

Commit

Permalink
Merge pull request Shopify#33 from Shopify/ruby-26
Browse files Browse the repository at this point in the history
Ruby 2.6 and better rubocop
  • Loading branch information
Jonathan Pulsifer authored Dec 8, 2020
2 parents 5d344dc + 6b4124a commit ed1d092
Show file tree
Hide file tree
Showing 21 changed files with 331 additions and 408 deletions.
83 changes: 3 additions & 80 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,93 +1,16 @@
# This file strictly follows the rules defined in the Ruby style guide:
# http://shopify.github.io/ruby-style-guide/
inherit_gem:
rubocop-shopify: rubocop.yml

AllCops:
TargetRubyVersion: 2.6
SuggestExtensions: false

# Allow .ruby-version and spec.required_ruby_version to differ
# to run a newer Ruby version for Rubocop, but don't force users to upgrade
Gemspec/RequiredRubyVersion:
Enabled: false

Rails:
Enabled: false

Lint/AssignmentInCondition:
Enabled: false

Style/Documentation:
Enabled: false

Layout/MultilineOperationIndentation:
Enabled: false

Layout/AlignParameters:
EnforcedStyle: with_fixed_indentation

Layout/IndentFirstArgument:
EnforcedStyle: consistent

Style/TrailingCommaInArrayLiteral:
Enabled: false

Style/SignalException:
EnforcedStyle: only_raise

Style/NumericLiterals:
Enabled: false

Layout/CaseIndentation:
EnforcedStyle: end

Layout/IndentFirstHashElement:
EnforcedStyle: consistent

Style/WordArray:
Enabled: false

Metrics/AbcSize:
Enabled: false

Metrics/CyclomaticComplexity:
Enabled: false

Style/StringLiterals:
Enabled: false

Metrics/LineLength:
Max: 120

Metrics/ClassLength:
Enabled: false

Metrics/MethodLength:
Enabled: false

Metrics/BlockLength:
Exclude:
- "**/*_spec.rb"

Metrics/ParameterLists:
Max: 5
CountKeywordArgs: false

Metrics/PerceivedComplexity:
Enabled: false

Layout/EndAlignment:
EnforcedStyleAlignWith: variable

Style/FrozenStringLiteralComment:
Enabled: false

Style/Alias:
EnforcedStyle: prefer_alias_method

Style/MutableConstant:
Enabled: false

Performance/Casecmp:
Enabled: false

Style/GuardClause:
Enabled: false
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.6.0
2.6.6
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
sudo: false
language: ruby
os: linux
before_install: gem install bundler
rvm:
- '2.3.8'
- '2.5.3'
- '2.6.0'

4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# frozen_string_literal: true
source 'https://rubygems.org'

gem 'byebug'
gem 'rake'
gem 'rubocop'
gem 'yard'

group :test do
gem 'rubocop'
gem 'rubocop-shopify', require: false
gem 'rspec', '~> 3.2'
gem 'vcr', '~> 2.9', github: 'vcr/vcr', branch: 'master', ref: '480304be6d73803e6c4a0eb21a4ab4091da558d8'
end
Expand Down
2 changes: 1 addition & 1 deletion dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
name: oktakit

up:
- ruby: 2.3.1
- ruby: 2.6.6
- bundler

commands:
Expand Down
36 changes: 18 additions & 18 deletions lib/oktakit/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class Client

# Default Faraday middleware stack
MIDDLEWARE = RACK_BUILDER_CLASS.new do |builder|
builder.use Oktakit::Response::RaiseError
builder.adapter Faraday.default_adapter
builder.use(Oktakit::Response::RaiseError)
builder.adapter(Faraday.default_adapter)
end

def initialize(token: nil, access_token: nil, organization: nil, api_endpoint: nil)
Expand Down Expand Up @@ -68,16 +68,16 @@ def get(url, options = {})
accept: options.delete(:accept),
content_type: options.delete(:content_type),
paginate: should_paginate,
data: options
data: options,
}

resp, status, next_page = request :get, url, **request_options
resp, status, next_page = request(:get, url, **request_options)

# If request succeeded and we should paginate, then automatically traverse all next_pages
if status == 200 && should_paginate
all_objs = [resp]
while next_page
resp, status, next_page = request :get, next_page, **request_options
resp, status, next_page = request(:get, next_page, **request_options)
break unless status == 200 # Return early if page request fails

all_objs << resp
Expand All @@ -98,9 +98,9 @@ def get(url, options = {})
# @param options [Hash] Optional. Body params for request.
# @return [Sawyer::Resource]
def post(url, options = {})
request :post, url, query: options.delete(:query), headers: options.delete(:headers),
request(:post, url, query: options.delete(:query), headers: options.delete(:headers),
accept: options.delete(:accept), content_type: options.delete(:content_type),
data: options
data: options)
end

# Make a HTTP PUT request
Expand All @@ -113,9 +113,9 @@ def post(url, options = {})
# @param options [Hash] Optional. Body params for request.
# @return [Sawyer::Resource]
def put(url, options = {})
request :put, url, query: options.delete(:query), headers: options.delete(:headers),
request(:put, url, query: options.delete(:query), headers: options.delete(:headers),
accept: options.delete(:accept), content_type: options.delete(:content_type),
data: options
data: options)
end

# Make a HTTP PATCH request
Expand All @@ -128,9 +128,9 @@ def put(url, options = {})
# @param options [Hash] Optional. Body params for request.
# @return [Sawyer::Resource]
def patch(url, options = {})
request :patch, url, query: options.delete(:query), headers: options.delete(:headers),
request(:patch, url, query: options.delete(:query), headers: options.delete(:headers),
accept: options.delete(:accept), content_type: options.delete(:content_type),
data: options
data: options)
end

# Make a HTTP DELETE request
Expand All @@ -143,9 +143,9 @@ def patch(url, options = {})
# @param options [Hash] Optional. Body params for request.
# @return [Sawyer::Resource]
def delete(url, options = {})
request :delete, url, query: options.delete(:query), headers: options.delete(:headers),
request(:delete, url, query: options.delete(:query), headers: options.delete(:headers),
accept: options.delete(:accept), content_type: options.delete(:content_type),
data: options
data: options)
end

# Make a HTTP HEAD request
Expand All @@ -158,9 +158,9 @@ def delete(url, options = {})
# @param options [Hash] Optional. Body params for request.
# @return [Sawyer::Resource]
def head(url, options = {})
request :head, url, query: options.delete(:query), headers: options.delete(:headers),
request(:head, url, query: options.delete(:query), headers: options.delete(:headers),
accept: options.delete(:accept), content_type: options.delete(:content_type),
data: options
data: options)
end

attr_reader :last_response
Expand All @@ -187,15 +187,15 @@ def sawyer_agent
http.headers[:accept] = 'application/json'
http.headers[:content_type] = 'application/json'
http.headers[:user_agent] = "Oktakit v#{Oktakit::VERSION}"
http.authorization 'SSWS ', @token if @token
http.authorization :Bearer, @access_token if @access_token
http.authorization('SSWS ', @token) if @token
http.authorization(:Bearer, @access_token) if @access_token
end
end

def sawyer_options
{
links_parser: Sawyer::LinkParsers::Simple.new,
faraday: Faraday.new(builder: MIDDLEWARE)
faraday: Faraday.new(builder: MIDDLEWARE),
}
end

Expand Down
4 changes: 2 additions & 2 deletions lib/oktakit/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Error < StandardError
# @return [Oktakit::Error]
def self.from_response(response)
status = response[:status].to_i
if klass = error(status)
if (klass = error(status))
klass.new(response)
end
end
Expand Down Expand Up @@ -89,7 +89,7 @@ def build_error_message

def redact_url(url_string)
%w[client_secret access_token].each do |token|
url_string.gsub!(/#{token}=\S+/, "#{token}=(redacted)") if url_string.include? token
url_string.gsub!(/#{token}=\S+/, "#{token}=(redacted)") if url_string.include?(token)
end
url_string
end
Expand Down
2 changes: 1 addition & 1 deletion lib/oktakit/response/raise_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class RaiseError < Faraday::Response::Middleware
private

def on_complete(response)
if error = Oktakit::Error.from_response(response)
if (error = Oktakit::Error.from_response(response))
raise error
end
end
Expand Down
10 changes: 5 additions & 5 deletions oktakit.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ Gem::Specification.new do |spec|
spec.email = ['[email protected]', '[email protected]']

spec.summary = 'Ruby toolkit for working with the Okta API'
spec.homepage = 'https://github.com/shopify/oktakit'
spec.homepage = 'https://github.com/Shopify/oktakit'
spec.license = 'MIT'

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.files = %x(git ls-files -z).split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.required_ruby_version = '>= 2.2'
spec.required_ruby_version = '>= 2.6'

spec.add_dependency 'sawyer', '~> 0.8.1'
spec.add_development_dependency 'bundler'
spec.add_dependency('sawyer', '~> 0.8.1')
spec.add_development_dependency('bundler')
end
Loading

0 comments on commit ed1d092

Please sign in to comment.