Skip to content

Autofix minor safe offenses #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 20, 2024
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
71 changes: 0 additions & 71 deletions .rubocop_todo.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 21 additions & 21 deletions lib/sharepoint/client.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require "ostruct"
require "ethon"
require "uri"
require "json"
require "time"
require 'ostruct'
require 'ethon'
require 'uri'
require 'json'
require 'time'

require 'active_support/core_ext/string/inflections'
require 'active_support/core_ext/object/blank'
Expand Down Expand Up @@ -50,7 +50,7 @@ def documents_for(path, site_path = '')
created_at: Time.parse(file['TimeCreated']),
updated_at: Time.parse(file['TimeLastModified']),
record_type: nil,
date_of_issue: nil,
date_of_issue: nil
)

threads << Thread.new {
Expand Down Expand Up @@ -91,7 +91,7 @@ def document_exists?(file_path, site_path = nil)
exists = true
end
end
return exists
exists
end

# Get a document's metadata
Expand Down Expand Up @@ -237,7 +237,7 @@ def list_documents_page(url)
ethon.perform
check_and_raise_failure(ethon)

return JSON.parse(ethon.response_body)
JSON.parse(ethon.response_body)
end

# Get a document's file contents. If it's a link to another document, it's followed.
Expand Down Expand Up @@ -382,7 +382,7 @@ def update_metadata(filename, metadata, path, site_path = nil)
'content-type' => 'application/json;odata=verbose',
'X-RequestDigest' => xrequest_digest(site_path),
'X-Http-Method' => 'PATCH',
'If-Match' => "*" }
'If-Match' => '*' }
easy.http_request(update_metadata_url,
:post,
{ body: prepared_metadata })
Expand Down Expand Up @@ -426,7 +426,7 @@ def lists(site_path = '', query = {})
def index(list_name, site_path = '', fields = [])
url = computed_web_api_url(site_path)
url = "#{url}lists/GetByTitle('#{odata_escape_single_quote(list_name)}')/items"
url += "?$select=#{fields.join(",")}" if fields
url += "?$select=#{fields.join(',')}" if fields

process_url(uri_escape(url), fields)
end
Expand Down Expand Up @@ -460,10 +460,10 @@ def process_url(url, fields)
parsed_response_body = JSON.parse(easy.response_body)

page_content = if fields
parsed_response_body['d']['results'].map { |v| v.fetch_values(*fields) }
else
parsed_response_body['d']['results']
end
parsed_response_body['d']['results'].map { |v| v.fetch_values(*fields) }
else
parsed_response_body['d']['results']
end

if next_url = parsed_response_body['d']['__next']
page_content + process_url(next_url, fields)
Expand Down Expand Up @@ -520,7 +520,7 @@ def xrequest_digest(site_path = nil)
url = remove_double_slashes("#{computed_api_url(site_path)}/contextinfo")
easy.http_request(url, :post, { body: '' })
easy.perform
JSON.parse(easy.response_body)['d']["GetContextWebInformation"]["FormDigestValue"]
JSON.parse(easy.response_body)['d']['GetContextWebInformation']['FormDigestValue']
end

def last_location_header(ethon)
Expand All @@ -543,7 +543,7 @@ def prepare_metadata(metadata, type)
key = element[0]
value = element[1]
result += ", '#{json_escape_single_quote(key.to_s)}': '#{json_escape_single_quote(value.to_s)}'"
} + " }"
} + ' }'
end

def json_escape_single_quote(s)
Expand All @@ -564,7 +564,7 @@ def split_path(file_path)

def extract_paths(url)
unescaped_url = string_unescape(url)
uri = URI(uri_escape unescaped_url)
uri = URI(uri_escape(unescaped_url))
path = utf8_encode uri_unescape(uri.path)
sites_match = /\/sites\/[^\/]+/.match(path)
site_path = sites_match[0] unless sites_match.nil?
Expand All @@ -586,7 +586,7 @@ def validate_config!
end

def string_not_blank?(object)
!object.nil? && object != "" && object.is_a?(String)
!object.nil? && object != '' && object.is_a?(String)
end

def valid_config_uri?
Expand Down Expand Up @@ -636,8 +636,8 @@ def sanitize_filename(filename)

def build_search_kql_conditions(options)
conditions = []
conditions << "IsContainer<>true"
conditions << "contentclass:STS_ListItem"
conditions << 'IsContainer<>true'
conditions << 'contentclass:STS_ListItem'
conditions << "WebId=#{options[:web_id]}" unless options[:web_id].nil?
conditions << "ListId:#{options[:list_id]}" unless options[:list_id].nil?
"'#{conditions.join('+')}'"
Expand Down Expand Up @@ -751,7 +751,7 @@ def update_object_metadata(metadata, new_metadata, site_path = '')
'content-type' => 'application/json;odata=verbose',
'X-RequestDigest' => xrequest_digest(site_path),
'X-Http-Method' => 'PATCH',
'If-Match' => "*" }
'If-Match' => '*' }

easy.http_request(update_metadata_url,
:post,
Expand Down
8 changes: 4 additions & 4 deletions lib/sharepoint/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@ module Sharepoint
module Errors
class UsernameConfigurationError < StandardError
def initialize
super "Invalid Username Configuration"
super('Invalid Username Configuration')
end
end

class PasswordConfigurationError < StandardError
def initialize
super "Invalid Password configuration"
super('Invalid Password configuration')
end
end

class UriConfigurationError < StandardError
def initialize
super "Invalid Uri configuration"
super('Invalid Uri configuration')
end
end

class EthonOptionsConfigurationError < StandardError
def initialize
super "Invalid ethon easy options"
super('Invalid ethon easy options')
end
end
end
Expand Down
14 changes: 7 additions & 7 deletions lib/sharepoint/spec_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ module Sharepoint
module SpecHelpers
def value_to_string(value)
case value
when nil
"nil"
when ""
"blank"
else
value
when nil
'nil'
when ''
'blank'
else
value
end
end

Expand All @@ -24,7 +24,7 @@ def mock_responses(fixture_file)
allow_any_instance_of(Ethon::Easy)
.to receive(:response_body)
.and_return(
File.open("spec/fixtures/responses/#{fixture_file}").read
File.read("spec/fixtures/responses/#{fixture_file}")
)
end
end
Expand Down