breadbox 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +7 -6
- data/lib/breadbox.rb +8 -5
- data/lib/breadbox/dropbox_client.rb +14 -3
- data/lib/breadbox/s3_client.rb +9 -2
- data/lib/breadbox/version.rb +1 -1
- data/spec/breadbox/dropbox_client_spec.rb +2 -1
- data/spec/breadbox/s3_client_spec.rb +5 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71100c6034b020a30b7b13ef4250414818b1c418
|
4
|
+
data.tar.gz: 5522044456bb64a338d570764d9fea66e815be9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2893bba8f89e811d70e8f30238cb553fe7045103e4ef009442fe3c40f378cc0da65cb3e13af51e0868cdc7652816444447d03d070288007087bf034256681fe1
|
7
|
+
data.tar.gz: 7d12ced6291f3ff5a68885a6f59b673b7dcab12edfcf14b6c3a0c95f63074a34e4edf3b3ae7f740180b5b39f376fdd734b68c95d6a5250e91736278b95b22808
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
[](https://codeclimate.com/github/ovenbits/breadbox)
|
2
|
+
|
1
3
|
# Breadbox
|
2
4
|
|
3
|
-
A simple wrapper interface for
|
5
|
+
A simple wrapper interface for uploading files to Dropbox or Amazon S3
|
4
6
|
|
5
7
|
## Disclaimer
|
6
8
|
|
@@ -21,7 +23,7 @@ Or install it yourself as:
|
|
21
23
|
|
22
24
|
$ gem install breadbox
|
23
25
|
|
24
|
-
|
26
|
+
|
25
27
|
## Setup for Dropbox
|
26
28
|
|
27
29
|
### 1. Get a [Dropbox Access Token](https://www.dropbox.com/developers/blog/94/generate-an-access-token-for-your-own-account)
|
@@ -36,7 +38,7 @@ Breadbox.configure do |config|
|
|
36
38
|
end
|
37
39
|
```
|
38
40
|
|
39
|
-
|
41
|
+
|
40
42
|
## Setup for S3
|
41
43
|
|
42
44
|
### 1. Get your [AWS Credentials](http://infinitewp.com/knowledge-base/where-are-my-amazon-s3-credentials/)
|
@@ -54,7 +56,7 @@ Breadbox.configure do |config|
|
|
54
56
|
end
|
55
57
|
```
|
56
58
|
|
57
|
-
|
59
|
+
## (Optional) Configure your root directory for uploading files
|
58
60
|
|
59
61
|
> By default - the root path will be the root directory of your [DropBox folder or S3 Bucket].
|
60
62
|
You can, however, change the root path to be anything you want.
|
@@ -79,8 +81,7 @@ end
|
|
79
81
|
to your `root_path`, which if you didn't configure in your initializer, will be your root Dropbox
|
80
82
|
folder `/`.
|
81
83
|
- `file`: The file object that you are uploading, ex: `file = File.open('./path-to-local-file').
|
82
|
-
- `cleanup`: defaults to `false`, but if you pass `true` - it will remove the local file after uploading
|
83
|
-
to DropBox
|
84
|
+
- `cleanup`: defaults to `false`, but if you pass `true` - it will remove the local file after uploading.
|
84
85
|
|
85
86
|
```ruby
|
86
87
|
# to upload a file to [Dropbox Folder or S3 Bucket]/uploads/my-cool-file.jpg
|
data/lib/breadbox.rb
CHANGED
@@ -13,7 +13,10 @@ module Breadbox
|
|
13
13
|
attr_writer :configuration
|
14
14
|
end
|
15
15
|
|
16
|
-
def self.cleanup(
|
16
|
+
def self.cleanup(options = {})
|
17
|
+
file = options[:file]
|
18
|
+
cleanup = options[:cleanup]
|
19
|
+
|
17
20
|
if cleanup && File.exists?(file)
|
18
21
|
File.delete(file)
|
19
22
|
end
|
@@ -36,10 +39,10 @@ module Breadbox
|
|
36
39
|
@configuration = Configuration.new
|
37
40
|
end
|
38
41
|
|
39
|
-
def self.upload(
|
40
|
-
if client.upload(
|
41
|
-
cleanup(
|
42
|
-
|
42
|
+
def self.upload(options = {})
|
43
|
+
if result = client.upload(options)
|
44
|
+
cleanup(options)
|
45
|
+
result
|
43
46
|
end
|
44
47
|
end
|
45
48
|
end
|
@@ -7,9 +7,20 @@ module Breadbox
|
|
7
7
|
configuration.dropbox_access_token
|
8
8
|
end
|
9
9
|
|
10
|
-
def upload(
|
11
|
-
|
12
|
-
|
10
|
+
def upload(options = {})
|
11
|
+
path = options[:path]
|
12
|
+
file = options[:file]
|
13
|
+
overwrite = options[:overwrite] || false
|
14
|
+
share = options[:share]
|
15
|
+
filepath = filepath_from_paths_and_file(root_path, path, file)
|
16
|
+
result = client.put_file(filepath, file, overwrite)
|
17
|
+
|
18
|
+
if share && result
|
19
|
+
share_hash = client.shares(result["path"])
|
20
|
+
share_hash["url"]
|
21
|
+
elsif result
|
22
|
+
result["path"]
|
23
|
+
end
|
13
24
|
end
|
14
25
|
|
15
26
|
protected
|
data/lib/breadbox/s3_client.rb
CHANGED
@@ -11,9 +11,16 @@ module Breadbox
|
|
11
11
|
@bucket ||= AWS::S3.new.buckets[bucket]
|
12
12
|
end
|
13
13
|
|
14
|
-
def upload(
|
14
|
+
def upload(options = {})
|
15
|
+
path = options[:path]
|
16
|
+
file = options[:file]
|
17
|
+
acl = options[:public] ? :public_read : nil
|
15
18
|
filepath = filepath_from_paths_and_file(root_path, path, file)[1..-1]
|
16
|
-
s3_bucket_object.objects[filepath].write(file)
|
19
|
+
result = s3_bucket_object.objects[filepath].write(file, acl: acl)
|
20
|
+
|
21
|
+
if result
|
22
|
+
result.public_url.to_s
|
23
|
+
end
|
17
24
|
end
|
18
25
|
|
19
26
|
protected
|
data/lib/breadbox/version.rb
CHANGED
@@ -58,7 +58,8 @@ module Breadbox
|
|
58
58
|
client = DropboxClient.new(configuration)
|
59
59
|
dropbox_client = instance_double(::DropboxClient)
|
60
60
|
allow(client).to receive(:client).and_return(dropbox_client)
|
61
|
-
expect(dropbox_client).to receive(:put_file)
|
61
|
+
expect(dropbox_client).to receive(:put_file)
|
62
|
+
.with("/new-file.jpg", file, false)
|
62
63
|
|
63
64
|
client.upload(path: "/", file: file)
|
64
65
|
end
|
@@ -77,9 +77,11 @@ module Breadbox
|
|
77
77
|
let(:client) { S3Client.new(configuration) }
|
78
78
|
|
79
79
|
it "writes a file to an S3 Bucket Object" do
|
80
|
-
file
|
81
|
-
|
82
|
-
|
80
|
+
file = File.open("./tmp/new-file.jpg")
|
81
|
+
options = { acl: :public_read }
|
82
|
+
expect_any_instance_of(AWS::S3::S3Object).to receive(:write)
|
83
|
+
.with(file, options)
|
84
|
+
client.upload(path: "/", file: file, public: true)
|
83
85
|
end
|
84
86
|
end
|
85
87
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: breadbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathaniel Watts
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dropbox-sdk
|