s3mpi 0.0.6.1 → 0.0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/lib/s3mpi/interface.rb +35 -3
- data/lib/s3mpi/version.rb +1 -1
- data/spec/s3mpi/interface_spec.rb +30 -0
- data/spec/support/test.csv +4 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3609c46bafae1c25e47554f7d3930e23e71f9b9f
|
4
|
+
data.tar.gz: 18eb926d0d1b4ef622f5c331a4c0db33c3bbfc64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4045f1202c6d63f893cf279c2c5d73b3915f105f7334d7753e389b7fc1b8b61b38af2a2e69d13a8d437934a27efda3b45fe073771c087a34a4fb8501b18ec2e4
|
7
|
+
data.tar.gz: 0a88adb5d33dbeac30fc180d72da67451bf7e0b47b82ed432bf614d8bf3361fa9890ba431065e73fb02e1dbf98a49d684a861ce1cafc9d77d369107b3478c2a3
|
data/.gitignore
CHANGED
data/lib/s3mpi/interface.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 's3mpi/format'
|
3
3
|
require 's3mpi/s3'
|
4
|
+
require 'csv'
|
4
5
|
|
5
6
|
module S3MPI
|
6
7
|
class Interface
|
@@ -16,7 +17,7 @@ module S3MPI
|
|
16
17
|
#
|
17
18
|
# @return [String]
|
18
19
|
attr_reader :path
|
19
|
-
|
20
|
+
|
20
21
|
# Create a new S3MPI object that responds to #read and #store.
|
21
22
|
#
|
22
23
|
# @return [S3MPI::Interface]
|
@@ -24,7 +25,7 @@ module S3MPI
|
|
24
25
|
# @api public
|
25
26
|
def initialize _bucket, path = ''
|
26
27
|
@bucket = _bucket
|
27
|
-
@path = path
|
28
|
+
@path = path
|
28
29
|
end
|
29
30
|
|
30
31
|
# Store a Ruby object in an S3 bucket.
|
@@ -37,10 +38,32 @@ module S3MPI
|
|
37
38
|
# The number of times to attempt to store the object.
|
38
39
|
def store(obj, key = SecureRandom.uuid, try = 1)
|
39
40
|
s3_object(key).write(obj.to_json)
|
40
|
-
rescue
|
41
|
+
rescue # This should really rescue specific errors
|
41
42
|
(try -= 1) > 0 ? retry : raise
|
42
43
|
end
|
43
44
|
|
45
|
+
|
46
|
+
# Load a CSV file, and store the contents in S3
|
47
|
+
# Proxies to store
|
48
|
+
#
|
49
|
+
# @param [String] csv_file_path path to the CSV file.
|
50
|
+
# Passed to CSV.read
|
51
|
+
#
|
52
|
+
# @param [Hash] options Options hash.
|
53
|
+
# Passed to CSV.read
|
54
|
+
def store_csv(csv_file_path, options = Hash.new)
|
55
|
+
store _load_csv(csv_file_path, options)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Store a raw object
|
59
|
+
# @param [Object] obj
|
60
|
+
# The object to store.
|
61
|
+
# @param [String] key
|
62
|
+
# The key under which to save the object in the S3 bucket.
|
63
|
+
def store_raw(obj, key)
|
64
|
+
s3_object(key).write(obj)
|
65
|
+
end
|
66
|
+
|
44
67
|
# Read a JSON-serialized Ruby object from an S3 bucket.
|
45
68
|
#
|
46
69
|
# @param [String] key
|
@@ -75,6 +98,15 @@ module S3MPI
|
|
75
98
|
@_bucket ||= parse_bucket @bucket
|
76
99
|
end
|
77
100
|
|
101
|
+
private
|
102
|
+
def _load_csv(csv_file_path, options)
|
103
|
+
options = options.merge({
|
104
|
+
headers: true,
|
105
|
+
converters: :all
|
106
|
+
|
107
|
+
})
|
108
|
+
CSV.read(csv_file_path, options).map(&:to_hash)
|
109
|
+
end
|
78
110
|
end
|
79
111
|
end
|
80
112
|
|
data/lib/s3mpi/version.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module S3MPI
|
4
|
+
|
5
|
+
describe Interface do
|
6
|
+
|
7
|
+
let(:bucket) { 'some_bucket' }
|
8
|
+
let(:path) { 'some_folder' }
|
9
|
+
let(:csv_file_path) {'spec/support/test.csv'}
|
10
|
+
let(:csv_as_array_of_hashes) {
|
11
|
+
[
|
12
|
+
{'user_id' => 1, 'email' => 'user1@test.com'},
|
13
|
+
{'user_id' => 2, 'email' => 'user2@test.com'},
|
14
|
+
{'user_id' => 3, 'email' => 'user3@test.com'},
|
15
|
+
]
|
16
|
+
}
|
17
|
+
|
18
|
+
subject { described_class.new(bucket: bucket, path: path ) }
|
19
|
+
|
20
|
+
describe '.store_csv' do
|
21
|
+
it 'sends the CSV as a row of hashes to .store' do
|
22
|
+
expect(subject).to receive(:store).with(csv_as_array_of_hashes)
|
23
|
+
|
24
|
+
subject.store_csv csv_file_path
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: s3mpi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Krzyzanowski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-v1
|
@@ -75,8 +75,10 @@ files:
|
|
75
75
|
- lib/s3mpi/s3.rb
|
76
76
|
- lib/s3mpi/version.rb
|
77
77
|
- s3mpi.gemspec
|
78
|
+
- spec/s3mpi/interface_spec.rb
|
78
79
|
- spec/s3mpi/s3_spec.rb
|
79
80
|
- spec/spec_helper.rb
|
81
|
+
- spec/support/test.csv
|
80
82
|
homepage: https://github.com/robertzk/s3mpi-ruby
|
81
83
|
licenses:
|
82
84
|
- MIT
|
@@ -102,5 +104,7 @@ signing_key:
|
|
102
104
|
specification_version: 4
|
103
105
|
summary: Upload and download files to S3 using a very convenient API.
|
104
106
|
test_files:
|
107
|
+
- spec/s3mpi/interface_spec.rb
|
105
108
|
- spec/s3mpi/s3_spec.rb
|
106
109
|
- spec/spec_helper.rb
|
110
|
+
- spec/support/test.csv
|