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 d18a969
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 8 deletions.
2 changes: 0 additions & 2 deletions app/controllers/admin/bsa_protected_domains_controller.rb
Original file line number Diff line number Diff line change
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
8 changes: 7 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 @@ -13,6 +13,8 @@ def perform(status_name = QUEUED_FOR_ACTIVATION)
fetch_block_order_list(offset: 0, status_name: status_name)
end

# rubocop:disable Metrics/CognitiveComplexity
# rubocop:disable Rails::SkipsModelValidations
def fetch_block_order_list(offset:, status_name:)
res = Bsa::BlockOrderListService.call(offset: offset, limit: LIMIT,
q: { 'blockOrderStatus.name' => status_name })
Expand All @@ -28,6 +30,8 @@ def fetch_block_order_list(offset:, status_name:)
offset += 1
fetch_block_order_list(offset: offset, status_name: status_name)
end
# rubocop:enable Metrics/CognitiveComplexity
# rubocop:enable Rails::SkipsModelValidations

def collect_bsa_values(res)
res.body.list.map do |block_order|
Expand All @@ -39,8 +43,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
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
2 changes: 2 additions & 0 deletions 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/UncommunicativeMethodParamName
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/UncommunicativeMethodParamName

def call
http = connect(url: base_url)
Expand Down

0 comments on commit d18a969

Please sign in to comment.