-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cover all endpoints from documentations
- Loading branch information
1 parent
16a95d1
commit f3a0340
Showing
12 changed files
with
277 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module Bsa | ||
class BlockOrderStatusSettingService | ||
include ApplicationService | ||
include Core::TokenHelper | ||
|
||
attr_reader :payload | ||
|
||
def self.call(payload: []) | ||
new(payload: payload).call | ||
end | ||
|
||
def initialize(payload:) | ||
@payload = payload | ||
end | ||
|
||
def call | ||
http = connect(url: base_url) | ||
response = http.post(endpoint, payload.to_json, headers(content_type: 'json').merge(token_format(token))) | ||
|
||
struct_response(response) | ||
end | ||
|
||
private | ||
|
||
def endpoint | ||
'/bsa/api/blockrsporder/status' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
module Bsa | ||
class BlockOrderViewService | ||
include ApplicationService | ||
include Core::TokenHelper | ||
|
||
attr_reader :block_suborder_id, :offset, :limit | ||
|
||
def self.call(block_suborder_id: nil, offset: nil, limit: nil) | ||
new(block_suborder_id: block_suborder_id, offset: offset, limit: limit).call | ||
end | ||
|
||
def initialize(block_suborder_id:, offset:, limit:) | ||
@block_suborder_id = block_suborder_id | ||
@offset = offset | ||
@limit = limit | ||
end | ||
|
||
def call | ||
http = connect(url: base_url) | ||
response = http.get(endpoint, headers.merge(token_format(token))) | ||
|
||
struct_response(response) | ||
end | ||
|
||
private | ||
|
||
def endpoint | ||
"/bsa/api/blockrsporder/labels?#{query_string}" | ||
end | ||
|
||
def query_string | ||
params = { | ||
'blocksuborderid' => block_suborder_id, | ||
'offset' => offset, | ||
'limit' => limit | ||
}.compact | ||
|
||
URI.encode_www_form(params) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Bsa | ||
module Core | ||
module Errors | ||
class AuthError < StandardError; end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module Bsa | ||
module Core | ||
module Settings | ||
def bsa | ||
'BSA' | ||
end | ||
|
||
def api_key | ||
ENV['bsa_api_key'] | ||
end | ||
|
||
def base_url | ||
ENV['bsa_base_url'] | ||
end | ||
|
||
def redist_host | ||
ENV['bsa_redis_host'] || 'redis' | ||
end | ||
|
||
def redis_port | ||
ENV['bsa_redis_port'] || 6379 | ||
end | ||
|
||
def redis_db | ||
ENV['bsa_redis_db'] || 7 | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Bsa | ||
module Core | ||
module TokenHelper | ||
def token | ||
response = Bsa::AuthService.call | ||
|
||
if response.result? | ||
response.body.id_token | ||
else | ||
raise Bsa::AuthError, "#{response.error.message}: #{response.error.description}" | ||
end | ||
end | ||
end | ||
end | ||
end |
35 changes: 35 additions & 0 deletions
35
app/services/bsa/download_non_blocked_name_list_service.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module Bsa | ||
class DownloadNonBlockedNameListService | ||
include ApplicationService | ||
include Core::TokenHelper | ||
|
||
attr_reader :suborder_id, :filename | ||
|
||
def self.call(suborder_id:, filename: Time.now.strftime("%Y-%m-%d_%H-%M-%S")) | ||
new(suborder_id: suborder_id, filename: filename).call | ||
end | ||
|
||
def initialize(suborder_id:, filename:) | ||
@suborder_id = suborder_id | ||
@filename = filename | ||
end | ||
|
||
def call | ||
http = connect(url: base_url) | ||
response = http.get(endpoint, headers.merge(token_format(token))) | ||
|
||
File.open("#{filename}.csv", 'wb') do |file| | ||
file.write(response.body) | ||
end | ||
|
||
# TODO: finish with response | ||
# struct_response(response) | ||
end | ||
|
||
private | ||
|
||
def endpoint | ||
"/bsa/api/blockrsporder/#{suborder_id}/nonblockednames" | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
module Bsa | ||
class NonBlockedNameActionService | ||
include ApplicationService | ||
include Core::TokenHelper | ||
|
||
attr_reader :action, :suborder_id, :payload | ||
|
||
# Actions: | ||
# - add | ||
# - remove | ||
# - remove_all | ||
|
||
def self.call(action:, suborder_id:, payload:) | ||
new(action: action, suborder_id: suborder_id, payload: payload).call | ||
end | ||
|
||
def initialize(action:, suborder_id:, payload:) | ||
@action = action | ||
@suborder_id = suborder_id | ||
@payload = payload | ||
end | ||
|
||
def call | ||
http = connect(url: base_url) | ||
response = http.post(endpoint, payload.to_json, headers(content_type: 'json').merge(token_format(token))) | ||
|
||
struct_response(response) | ||
end | ||
|
||
private | ||
|
||
def endpoint | ||
if action == 'remove_all' | ||
"/bsa/api/blockrsporder/#{suborder_id}/nonblockednames?action=remove" | ||
else | ||
"/bsa/api/blockrsporder/nonblockednames?#{query_string}" | ||
end | ||
end | ||
|
||
def query_string | ||
params = { | ||
'action' => action, | ||
'suborderid' => suborder_id, | ||
}.compact | ||
|
||
URI.encode_www_form(params) | ||
end | ||
end | ||
end |
60 changes: 60 additions & 0 deletions
60
app/services/bsa/upload_unavailable_domain_report_service.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
module Bsa | ||
class UploadUnavailableDomainReportService | ||
include ApplicationService | ||
include Core::TokenHelper | ||
|
||
attr_reader :file_path | ||
|
||
def self.call(file_path:) | ||
new(file_path: file_path).call | ||
end | ||
|
||
def initialize(file_path:) | ||
@file_path = file_path | ||
end | ||
|
||
def call | ||
http = connect(url: base_url) | ||
uri = URI("#{base_url}") | ||
|
||
checksum = calculate_checksum(@file_path) | ||
|
||
request = Net::HTTP::Post.new(uri) | ||
request['Authorization'] = "Bearer #{token}" | ||
request['Content-Type'] = 'multipart/form-data' | ||
|
||
form_data = [ | ||
['Zone', { "checkSum" => checksum }.to_json ], | ||
['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', | ||
} | ||
end | ||
|
||
def calculate_checksum(file_path) | ||
digest = OpenSSL::Digest::SHA256.new | ||
File.open(file_path, 'rb') do |f| | ||
while chunk = f.read(4096) | ||
digest.update(chunk) | ||
end | ||
end | ||
digest.hexdigest | ||
end | ||
end | ||
end |
Empty file.