Skip to content

Commit

Permalink
Merge pull request #42 from taylorfinnell/changes-for-crystal-0.27.0
Browse files Browse the repository at this point in the history
changes for Crystal 0.27.0
  • Loading branch information
taylorfinnell authored Nov 6, 2018
2 parents 12fa18e + b4bd66f commit 58c0d6c
Show file tree
Hide file tree
Showing 15 changed files with 28 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ end

```crystal
form = Awscr::S3::Presigned::Form.build("us-east-1", "access key", "secret key") do |form|
form.expiration(Time.epoch(Time.now.epoch + 1000))
form.expiration(Time.unix(Time.now.to_unix + 1000))
form.condition("bucket", "mybucket")
form.condition("acl", "public-read")
form.condition("key", SecureRandom.uuid)
Expand Down
3 changes: 1 addition & 2 deletions examples/osx_screenshot_upload.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require "../src/awscr-s3"
require "uuid"
require "tempfile"

BUCKET = ENV["AWS_BUCKET"]
HOST = "#{BUCKET}.s3.amazonaws.com"
Expand All @@ -11,7 +10,7 @@ SECRET = ENV["AWS_SECRET"]
REGION = ENV["AWS_REGION"]

form = Awscr::S3::Presigned::Form.build(REGION, KEY, SECRET) do |f|
f.expiration(Time.epoch(Time.now.epoch + 1000))
f.expiration(Time.unix(Time.now.to_unix + 1000))
f.condition("bucket", BUCKET)
f.condition("acl", "public-read")
f.condition("key", "#{UUID.random}.png"[0...8])
Expand Down
2 changes: 1 addition & 1 deletion examples/presigned_form_html.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ REGION = ENV["AWS_REGION"]

form = Awscr::S3::Presigned::Form.build(region: REGION, aws_access_key: KEY,
aws_secret_key: SECRET) do |f|
f.expiration(Time.epoch(Time.now.epoch + 1000))
f.expiration(Time.unix(Time.now.to_unix + 1000))
f.condition("bucket", BUCKET)
f.condition("acl", "public-read")
f.condition("key", UUID.random.to_s)
Expand Down
4 changes: 2 additions & 2 deletions shard.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: awscr-s3
version: 0.3.2
version: 0.3.3

authors:
- Taylor Finnell <[email protected]>

crystal: 0.25.0
crystal: 0.27.0

license: MIT

Expand Down
2 changes: 1 addition & 1 deletion spec/awscr-s3/bucket_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Awscr::S3
it "not equal to another bucket if name and creation time differ" do
time = Time.now
bucket = Bucket.new("test2", time)
(Bucket.new("test", Time.epoch(Time.now.epoch + 123)) == bucket).should eq(false)
(Bucket.new("test", Time.unix(Time.now.to_unix + 123)) == bucket).should eq(false)
end

it "has a name" do
Expand Down
5 changes: 2 additions & 3 deletions spec/awscr-s3/content_type_spec.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require "../../spec_helper"
require "tempfile"

module Awscr::S3
describe ContentType do
Expand All @@ -13,7 +12,7 @@ module Awscr::S3
describe "when the io is a file" do
it "returns the correct Content-Type" do
ContentType::TYPES.keys.each do |ext|
tempfile = Tempfile.new("foo", ext)
tempfile = File.tempfile("foo", ext)
file = File.open(tempfile.path)
ContentType.get(file).should be(ContentType::TYPES[ext])
tempfile.delete
Expand All @@ -23,7 +22,7 @@ module Awscr::S3

describe "when the io is a file and the extension is unknown" do
it "returns the default Content-Type" do
tempfile = Tempfile.new("foo", ".spicy")
tempfile = File.tempfile("foo", ".spicy")
file = File.open(tempfile.path)
ContentType.get(file).should be(ContentType::DEFAULT)
tempfile.delete
Expand Down
5 changes: 2 additions & 3 deletions spec/awscr-s3/file_uploader_spec.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require "../../spec_helper"
require "tempfile"

module Awscr::S3
describe FileUploader do
Expand Down Expand Up @@ -96,7 +95,7 @@ module Awscr::S3
client = Client.new("us-east-1", "key", "secret")
uploader = FileUploader.new(client)

tempfile = Tempfile.new("foo", ".svg")
tempfile = File.tempfile("foo", ".svg")
file = File.open(tempfile.path)

uploader.upload("bucket", "object", file).should be_true
Expand All @@ -117,7 +116,7 @@ module Awscr::S3
options = FileUploader::Options.new(with_content_types: false)
uploader = FileUploader.new(client, options)

tempfile = Tempfile.new("foo", ".svg")
tempfile = File.tempfile("foo", ".svg")
file = File.open(tempfile.path)

uploader.upload("bucket", "object", file).should be_true
Expand Down
4 changes: 2 additions & 2 deletions spec/awscr-s3/presigned/form_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module Awscr

describe "submit" do
it "sends a reasonable request over http for v2" do
time = Time.epoch(1)
time = Time.unix(1)
Timecop.freeze(time)

post = Post.new(
Expand Down Expand Up @@ -91,7 +91,7 @@ module Awscr
end

it "sends a reasonable request over http for v4" do
time = Time.epoch(1)
time = Time.unix(1)
Timecop.freeze(time)

post = Post.new(
Expand Down
6 changes: 3 additions & 3 deletions spec/awscr-s3/presigned/html_printer_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ module Awscr
module Presigned
describe HtmlPrinter do
Spec.before_each do
Timecop.freeze(Time.epoch(1))
Timecop.freeze(Time.unix(1))
end

Spec.after_each do
Timecop.reset
end

it "generates the same html each call" do
time = Time.epoch(1)
time = Time.unix(1)
post = Post.new(
region: "us-east-1",
aws_access_key: "test",
Expand All @@ -32,7 +32,7 @@ module Awscr
end

it "prints html" do
time = Time.epoch(1)
time = Time.unix(1)

post = Post.new(
region: "region",
Expand Down
4 changes: 2 additions & 2 deletions spec/awscr-s3/presigned/post_policy_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module Awscr
describe "to_s" do
it "returns policy as base64 encoded json" do
policy = Policy.new
policy.expiration(Time.epoch(1_483_859_302))
policy.expiration(Time.unix(1_483_859_302))
policy.condition("test", "test")

policy.to_s.should eq("eyJleHBpcmF0aW9uIjoiMjAxNy0wMS0wOFQwNzowODoyMi4wMDBaIiwiY29uZGl0aW9ucyI6W3sidGVzdCI6InRlc3QifV19")
Expand All @@ -54,7 +54,7 @@ module Awscr

it "can be a hash" do
policy = Policy.new
policy.expiration(Time.epoch(1_483_859_302))
policy.expiration(Time.unix(1_483_859_302))
policy.condition("test", "test")

policy.to_hash.should eq({
Expand Down
14 changes: 7 additions & 7 deletions spec/awscr-s3/presigned/post_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Awscr
module Presigned
describe Post do
Spec.before_each do
Timecop.freeze(Time.epoch(1))
Timecop.freeze(Time.unix(1))
end

Spec.after_each do
Expand Down Expand Up @@ -49,7 +49,7 @@ module Awscr

describe "fields" do
it "generates the same fields each time" do
time = Time.epoch(1)
time = Time.unix(1)
post = Post.new(
region: "us-east-1",
aws_access_key: "test",
Expand All @@ -61,7 +61,7 @@ module Awscr
end

it "contains the policy field" do
time = Time.epoch(1)
time = Time.unix(1)
post = Post.new(
region: "us-east-1",
aws_access_key: "test",
Expand All @@ -75,7 +75,7 @@ module Awscr
end

it "contains the signature field" do
time = Time.epoch(1)
time = Time.unix(1)
post = Post.new(
region: "us-east-1",
aws_access_key: "test",
Expand All @@ -89,7 +89,7 @@ module Awscr
end

it "contains the credential field" do
time = Time.epoch(1)
time = Time.unix(1)
post = Post.new(
region: "us-east-1",
aws_access_key: "test",
Expand All @@ -103,7 +103,7 @@ module Awscr
end

it "contains the algorithm field" do
time = Time.epoch(1)
time = Time.unix(1)
post = Post.new(
region: "us-east-1",
aws_access_key: "test",
Expand All @@ -117,7 +117,7 @@ module Awscr
end

it "contains the date field" do
time = Time.epoch(1)
time = Time.unix(1)
post = Post.new(
region: "us-east-1",
aws_access_key: "test",
Expand Down
2 changes: 1 addition & 1 deletion spec/awscr-s3/presigned/url_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module Awscr

describe "get" do
it "generates correct url for v2" do
time = Time.epoch(1)
time = Time.unix(1)
Timecop.freeze(time)
options = Url::Options.new(
region: "us-east-1",
Expand Down
2 changes: 1 addition & 1 deletion src/awscr-s3/presigned/form.cr
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module Awscr
#
# ```
# Awscr::S3::Presigned::Form.build("us-east-1", "aws key", "aws secret") do |form|
# form.expiration(Time.epoch(Time.now.epoch + 1000))
# form.expiration(Time.unix(Time.now.to_unix + 1000))
# form.condition("bucket", "my bucket")
# form.condition("acl", "public-read")
# form.condition("key", "helloworld.png")
Expand Down
2 changes: 1 addition & 1 deletion src/awscr-s3/presigned/url.cr
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ module Awscr
if @options.signer_version == :v4
request.query_params.add("X-Amz-Expires", @options.expires.to_s)
else
request.query_params.add("Expires", (Time.utc_now.epoch + @options.expires).to_s)
request.query_params.add("Expires", (Time.utc_now.to_unix + @options.expires).to_s)
end

request
Expand Down
2 changes: 1 addition & 1 deletion src/awscr-s3/version.cr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Awscr::S3
MAJOR = "0"
MINOR = "3"
PATCH = "2"
PATCH = "3"

# Current version of Awscr::S3.
VERSION = [MAJOR, MINOR, PATCH].join(".")
Expand Down

0 comments on commit 58c0d6c

Please sign in to comment.