Skip to content

Commit

Permalink
adds file_info endpoint method
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanmartin committed Jul 9, 2024
1 parent 3e8d395 commit bc64990
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 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.1.4)
httparty (~> 0.22.0)
jwt (~> 2.8.0)
redis_stream (~> 0.1.3)
Expand Down
7 changes: 6 additions & 1 deletion lib/skynet/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ 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")
end

def jwt_token(secret:, iss:, exp: nil)
exp ||= (Time.now + (4 * 60 * 60)).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.1.4"
end
15 changes: 15 additions & 0 deletions spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,19 @@
expect(response["file"]["id"]).to eq(file_id)
end
end

describe "#file_info" do
it "returns file info" do
file_id = rand(9999)
response_api = { file: { id: file_id, filename: "test.html", content_type: "text/html", byte_size: 123, url: "http://localhost:5000/..." } }
stub_api = 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(stub_api).to have_been_requested
expect(response["file"]["id"]).to eq(file_id)
expect(response["file"]["content_type"]).to eq("text/html")
end
end
end

0 comments on commit bc64990

Please sign in to comment.