Skip to content
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

[FEATURE] Add info to skynet #6

Merged
merged 4 commits into from
Jul 9, 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
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ GIT
PATH
remote: .
specs:
skynet (0.1.2)
skynet (0.2.0)
httparty (~> 0.22.0)
jwt (~> 2.8.0)
redis_stream (~> 0.1.3)
Expand Down
9 changes: 7 additions & 2 deletions lib/skynet/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@ def agent_session(agent_session_id)
end

def upload(file)
self.class.post("/uploads", body: {file: file})
self.class.post("/uploads", body: {file: file})["file"]
end

def download(uuid)
self.class.get("/uploads/#{uuid}")
end

def jwt_token(secret:, iss:, exp: 4.hours.from_now.to_i)
def file_info(uuid)
self.class.get("/uploads/#{uuid}/info")["file"]
end

def jwt_token(secret:, iss:)
exp = (Time.now + 4 * 3600).to_i
payload = {iss: iss, exp: exp}
header_fields = {alg: "HS256"}
::JWT.encode payload, secret, "HS256", header_fields
Expand Down
2 changes: 1 addition & 1 deletion lib/skynet/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Skynet
VERSION = "0.1.3"
VERSION = "0.2.0"
end
29 changes: 28 additions & 1 deletion spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,34 @@
response = described_class.new.upload(file)

expect(stub_api).to have_been_requested
expect(response["file"]["id"]).to eq(file_id)
expect(response["id"]).to eq(file_id)
end
end

describe "#file_info" do
let(:file_id) { SecureRandom.uuid }
let(:response_api) do
{
file: {
id: file_id,
name: "file.txt",
size: 1024,
mime_type: "text/plain",
url: "https://www.skynet.com/uploads/#{file_id}"
}
}
end

it "return the info of the file" do
stub_request(:get, "https://www.skynet.com/uploads/#{file_id}/info")
.to_return(status: 200, body: response_api.to_json)

response = described_class.new.file_info(file_id)
expect(response["id"]).to eq(file_id)
expect(response["name"]).to eq("file.txt")
expect(response["size"]).to eq(1024)
expect(response["mime_type"]).to eq("text/plain")
expect(response["url"]).to eq("https://www.skynet.com/uploads/#{file_id}")
end
end
end