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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2fc8f406d6187e2707ac993a2fd6d5d4e7ad8d56
4
- data.tar.gz: 6c05dbdaa8a962b0489350230aa445765913e188
3
+ metadata.gz: 71100c6034b020a30b7b13ef4250414818b1c418
4
+ data.tar.gz: 5522044456bb64a338d570764d9fea66e815be9e
5
5
  SHA512:
6
- metadata.gz: 1104d3d4ea17ccba451682038a59041c9e566960733f52cfae89c41e252250f6019f56fb836aabb7fca7bcb0508c17b227d619c5d1a8fe499290afc3f1cc9232
7
- data.tar.gz: 9b64da8f50ac9cb7d6bede77baec4dc1d9000ffe26efd9c018694968ea9ce115a1129a266fabfa56eae59ef54945bd867d3103bf5e8e0f9a62e4c3bdf73e8b03
6
+ metadata.gz: 2893bba8f89e811d70e8f30238cb553fe7045103e4ef009442fe3c40f378cc0da65cb3e13af51e0868cdc7652816444447d03d070288007087bf034256681fe1
7
+ data.tar.gz: 7d12ced6291f3ff5a68885a6f59b673b7dcab12edfcf14b6c3a0c95f63074a34e4edf3b3ae7f740180b5b39f376fdd734b68c95d6a5250e91736278b95b22808
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
+ [![Code Climate](https://codeclimate.com/github/ovenbits/breadbox/badges/gpa.svg)](https://codeclimate.com/github/ovenbits/breadbox)
2
+
1
3
  # Breadbox
2
4
 
3
- A simple wrapper interface for the [DropBox SDK gem](https://github.com/dropbox/dropbox-sdk-ruby).
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
- ### (Optional) Configure your root directory for uploading files
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(file: nil, cleanup: true)
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(path: nil, file: nil, cleanup: false)
40
- if client.upload(path: path, file: file)
41
- cleanup(file: file, cleanup: cleanup)
42
- true
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(path: nil, file: nil)
11
- filepath = filepath_from_paths_and_file(root_path, path, file)
12
- client.put_file(filepath, file)
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
@@ -11,9 +11,16 @@ module Breadbox
11
11
  @bucket ||= AWS::S3.new.buckets[bucket]
12
12
  end
13
13
 
14
- def upload(path: nil, file: nil)
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
@@ -1,3 +1,3 @@
1
1
  module Breadbox
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -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).with("/new-file.jpg", 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 = File.open("./tmp/new-file.jpg")
81
- expect_any_instance_of(AWS::S3::S3Object).to receive(:write).with(file)
82
- client.upload(path: "/", file: file)
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.0.0
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 00:00:00.000000000 Z
11
+ date: 2014-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dropbox-sdk