Skip to content

Commit

Permalink
[FEATURE] Add info to skynet (#6)
Browse files Browse the repository at this point in the history
* [FEATURE] Add info to skynet
Add file info to skynet
  • Loading branch information
garciaf authored Jul 9, 2024
1 parent 3e8d395 commit 615df28
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
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

0 comments on commit 615df28

Please sign in to comment.