Skip to content

Commit

Permalink
rubocop -a go brr
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan Pulsifer <[email protected]>
  • Loading branch information
Jonathan Pulsifer committed Dec 7, 2020
1 parent 76f05fb commit d23040a
Show file tree
Hide file tree
Showing 16 changed files with 320 additions and 320 deletions.
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
8 changes: 4 additions & 4 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.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
38 changes: 19 additions & 19 deletions spec/client/admin_roles_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,101 +7,101 @@

describe '#list_roles_assigned_to_user' do
it 'returns array of role' do
VCR.use_cassette 'list_roles_assigned_to_user' do
VCR.use_cassette('list_roles_assigned_to_user') do
resp, = client.list_roles_assigned_to_user(ADMIN_ROLES_USER_ID)
expect(resp).to be_a(Array)
expect(resp).to(be_a(Array))
end
end
end

describe '#assign_role_to_user' do
it 'returns assigned role' do
VCR.use_cassette 'assign_role_to_user' do
VCR.use_cassette('assign_role_to_user') do
resp, = client.assign_role_to_user(ADMIN_ROLES_USER_ID, type: 'SUPER_ADMIN')
expected_hash = {
id: "ra16nmck9rsYOQiqi0h7",
label: "Super Organization Administrator",
type: "SUPER_ADMIN",
status: "ACTIVE",
created: "2016-07-14T03:21:12.000Z",
lastUpdated: "2016-07-14T03:21:12.000Z"
lastUpdated: "2016-07-14T03:21:12.000Z",
}
expect(resp.to_h).to be == expected_hash
expect(resp.to_h).to(be == expected_hash)
end
end
end

describe '#unassign_role_from_user' do
it 'returns http 204 no content' do
VCR.use_cassette 'unassign_role_from_user' do
VCR.use_cassette('unassign_role_from_user') do
_, status = client.unassign_role_from_user(ADMIN_ROLES_USER_ID, 'ra16nmck9rsYOQiqi0h7')
expect(status).to be(204)
expect(status).to(be(204))
end
end
end

describe '#list_group_targets_for_user_admin_role' do
it 'returns array of groups' do
VCR.use_cassette 'list_group_targets_for_user_admin_role' do
VCR.use_cassette('list_group_targets_for_user_admin_role') do
resp, = client.list_group_targets_for_user_admin_role(ADMIN_ROLES_USER_ID, 'ra16nlr5esxo0o0TI0h7')
expect(resp).to be_a(Array)
expect(resp).to(be_a(Array))
end
end
end

describe '#add_group_target_to_user_admin_role' do
it 'returns http 204 no content' do
VCR.use_cassette 'add_group_target_to_user_admin_role' do
VCR.use_cassette('add_group_target_to_user_admin_role') do
_, status = client.add_group_target_to_user_admin_role(
ADMIN_ROLES_USER_ID,
'ra16nmg6csiUalQhH0h7',
ADMIN_ROLES_GROUP_ID
)
expect(status).to be(204)
expect(status).to(be(204))
end
end
end

describe '#remove_group_target_from_user_admin_role' do
it 'returns http 204 no content' do
VCR.use_cassette 'remove_group_target_from_user_admin_role' do
VCR.use_cassette('remove_group_target_from_user_admin_role') do
_, status = client.remove_group_target_from_user_admin_role(
ADMIN_ROLES_USER_ID,
'role_id',
ADMIN_ROLES_GROUP_ID
)
expect(status).to be(204)
expect(status).to(be(204))
end
end
end

describe '#list_app_targets_for_app_admin_role' do
it 'returns array of catalog apps' do
VCR.use_cassette 'list_app_targets_for_app_admin_role' do
VCR.use_cassette('list_app_targets_for_app_admin_role') do
resp, = client.list_app_targets_for_app_admin_role(ADMIN_ROLES_USER_ID, 'ra16nmg6csiUalQhH0h7')
expect(resp).to be_a(Array)
expect(resp).to(be_a(Array))
end
end
end

describe '#add_app_target_to_app_admin_role' do
it 'returns http 204 no content' do
VCR.use_cassette 'add_app_target_to_app_admin_role' do
VCR.use_cassette('add_app_target_to_app_admin_role') do
_, status = client.add_app_target_to_app_admin_role(
ADMIN_ROLES_USER_ID,
'ra16nmg6csiUalQhH0h7',
ADMIN_ROLES_APP_NAME
)
expect(status).to be(204)
expect(status).to(be(204))
end
end
end

describe '#remove_app_target_from_app_admin_role' do
it 'returns http 204 no content' do
VCR.use_cassette 'remove_app_target_from_app_admin_role' do
VCR.use_cassette('remove_app_target_from_app_admin_role') do
_, status = client.remove_app_target_from_app_admin_role(ADMIN_ROLES_USER_ID, 'role_id', ADMIN_ROLES_APP_NAME)
expect(status).to be(204)
expect(status).to(be(204))
end
end
end
Expand Down
Loading

0 comments on commit d23040a

Please sign in to comment.