Skip to content

Commit

Permalink
refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegPhenomenon committed Oct 19, 2023
1 parent 2272e9e commit 2c6775e
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ group :test do
gem 'database_cleaner'
gem 'minitest', '~> 5.17'
gem 'minitest-stub_any_instance'
gem 'mock_redis'
gem 'selenium-webdriver'
gem 'simplecov', '0.17.1', require: false # CC last supported v0.17
gem 'spy'
gem 'mock_redis'
gem 'webmock'
end

Expand Down
4 changes: 1 addition & 3 deletions app/controllers/admin/bsa_protected_domains_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Admin
class BsaProtectedDomainsController < BaseController
load_and_authorize_resource
before_action :set_domain, only: [:edit, :update]
before_action :set_domain, only: %i[edit update]

def index
params[:q] ||= {}
Expand Down Expand Up @@ -67,8 +67,6 @@ def release_to_auction
private

def bsa_protected_domain_params
# params.require(:bsa_protected_domain).permit(:domain_name, :registration_code, :order_id, :suborder_id, :create_date, :state)

params.require(:bsa_protected_domain).permit(:domain_name, :registration_code,
:order_id, :suborder_id, :create_date, :state).tap do |whitelisted|
whitelisted[:state] = whitelisted[:state].to_i if whitelisted[:state].is_a?(String)
Expand Down
4 changes: 3 additions & 1 deletion app/jobs/fetch_godaddy_bsa_block_order_list_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ def collect_bsa_values(res)
registration_code: SecureRandom.hex,
create_date: DateTime.parse(block_order['createdDt']),
created_at: Time.zone.now,
updated_at: Time.zone.now
updated_at: Time.zone.now,
}
end
end
end

# rubocop:enable Metrics
2 changes: 2 additions & 0 deletions app/jobs/update_godaddy_domains_status_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ def serialize_suborders_block(suborders_block:, state:)
end
end

# rubocop:disable Rails::SkipsModelValidations
def refresh_statuses(suborders_block:, state:)
suborders_block.update_all(state: state)
end
# rubocop:enable Rails::SkipsModelValidations
end
2 changes: 1 addition & 1 deletion app/models/bsa_protected_domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class BsaProtectedDomain < ApplicationRecord
ACTIVE => 4,
QUEUED_FOR_RELEASE => 5,
RELEASE_IN_PROGRESS => 6,
CLOSED => 7
CLOSED => 7,
}

class << self
Expand Down
1 change: 0 additions & 1 deletion app/models/bsa_protected_domain/ransackable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ def ransackable_attributes(*)
authorizable_ransackable_attributes
end
end

end
6 changes: 4 additions & 2 deletions app/services/bsa/application_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ def connect(url:)

def headers(content_type: 'x-www-form-urlencoded')
{
'Content-Type' => "application/#{content_type}"
'Content-Type' => "application/#{content_type}",
}
end

def token_format(token)
{
'Authorization' => "Bearer #{token}"
'Authorization' => "Bearer #{token}",
}
end

Expand Down Expand Up @@ -54,8 +54,10 @@ def expire_token_at(token)
Time.at(payload['exp']).utc.in_time_zone
end

# rubocop:disable Style/GlobalVars
def redis
@redis ||= Rails.env.test? ? $mock_redis : Redis.new(host: redist_host, port: redis_port, db: redis_db)
end
# rubocop:enable Style/GlobalVars
end
end
2 changes: 1 addition & 1 deletion app/services/bsa/auth_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def check_for_expired_token
def payload
{
'apiKey' => api_key,
'space' => bsa
'space' => bsa,
}
end

Expand Down
4 changes: 3 additions & 1 deletion app/services/bsa/block_order_list_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class BlockOrderListService

attr_reader :sort_by, :order, :offset, :limit, :q

# rubocop:disable Naming/MethodParameterName
def self.call(sort_by: nil, order: nil, offset: nil, limit: nil, q: {})
new(sort_by: sort_by, order: order, offset: offset, limit: limit, q: q).call
end
Expand All @@ -16,6 +17,7 @@ def initialize(sort_by:, order:, offset:, limit:, q:)
@limit = limit
@q = q
end
# rubocop:enable Naming/MethodParameterName

def call
http = connect(url: base_url)
Expand All @@ -35,7 +37,7 @@ def query_string
'sortBy' => sort_by,
'order' => order,
'offset' => offset,
'limit' => limit
'limit' => limit,
}.compact

params['q'] = q.map { |key, value| "#{key}=#{value}" }.join('&') if q.present?
Expand Down
2 changes: 1 addition & 1 deletion app/services/bsa/block_order_view_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def query_string
params = {
'blocksuborderid' => block_suborder_id,
'offset' => offset,
'limit' => limit
'limit' => limit,
}.compact

URI.encode_www_form(params)
Expand Down
2 changes: 1 addition & 1 deletion app/services/bsa/download_non_blocked_name_list_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class DownloadNonBlockedNameListService

attr_reader :suborder_id, :filename

def self.call(suborder_id:, filename: Time.now.strftime('%Y-%m-%d_%H-%M-%S'))
def self.call(suborder_id:, filename: Time.zone.now.strftime('%Y-%m-%d_%H-%M-%S'))
new(suborder_id: suborder_id, filename: filename).call
end

Expand Down
2 changes: 1 addition & 1 deletion app/services/bsa/non_blocked_name_action_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def endpoint
def query_string
params = {
'action' => action,
'suborderid' => suborder_id
'suborderid' => suborder_id,
}.compact

URI.encode_www_form(params)
Expand Down
25 changes: 13 additions & 12 deletions app/services/bsa/upload_unavailable_domain_report_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,17 @@ def initialize(file_path:)

def call
http = connect(url: base_url)
uri = URI("#{base_url}")
uri = URI(base_url.to_s)

request = configure_request(uri: uri)
response = http.request(request)

struct_response(response)
end

private

def configure_request(uri:)
checksum = calculate_checksum(@file_path)

request = Net::HTTP::Post.new(uri)
Expand All @@ -25,34 +34,26 @@ def call

form_data = [
['Zone', { 'checkSum' => checksum }.to_json],
['File', File.open(@file_path)]
['File', File.open(@file_path)],
]

request.set_form form_data, 'multipart/form-data'

response = http.request(request)

struct_response(response)
end

private

def endpoint
'/bsa/api/zonefile'
end

def form_data_headers
{
'Content-Type' => 'multipart/form-data'
'Content-Type' => 'multipart/form-data',
}
end

def calculate_checksum(file_path)
digest = OpenSSL::Digest.new('SHA256')
File.open(file_path, 'rb') do |f|
while chunk = f.read(4096)
digest.update(chunk)
end
digest.update(chunk) while chunk == f.read(4096)
end
digest.hexdigest
end
Expand Down

0 comments on commit 2c6775e

Please sign in to comment.