enable export to codeharbor

This commit is contained in:
Karol
2019-09-02 19:03:50 +02:00
parent c006bc3dc8
commit 3c65565b8c
13 changed files with 104 additions and 61 deletions

View File

@ -0,0 +1,28 @@
# frozen_string_literal: true
module ExerciseService
class PushExternal < ServiceBase
CODEHARBOR_PUSH_LINK = 'http://localhost:3001/import_exercise'
def initialize(zip:, codeharbor_link:)
@zip = zip
@codeharbor_link = codeharbor_link
end
def execute
oauth2_client = OAuth2::Client.new(@codeharbor_link.client_id, @codeharbor_link.client_secret, site: CODEHARBOR_PUSH_LINK)
oauth2_token = @codeharbor_link[:oauth2token]
token = OAuth2::AccessToken.from_hash(oauth2_client, access_token: oauth2_token)
body = @zip.string
begin
token.post(
CODEHARBOR_PUSH_LINK,
body: body,
headers: {'Content-Type' => 'application/zip', 'Content-Length' => body.length.to_s}
)
return nil
rescue StandardError => e
return e
end
end
end
end