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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e774c44f240b72b6a26583dfed16340bc294a98
4
- data.tar.gz: 9c1622f368447280bbb17aa95a9c74b2fd390b58
3
+ metadata.gz: 3609c46bafae1c25e47554f7d3930e23e71f9b9f
4
+ data.tar.gz: 18eb926d0d1b4ef622f5c331a4c0db33c3bbfc64
5
5
  SHA512:
6
- metadata.gz: 7a28d5ef0d60b2d30009a9d2c72c3457fa06ae6b0f742a9ddf71d45d26d0698205fa522bfc9786a3d09a8590f42ab55d8f9892153bfe4915469fef413e322770
7
- data.tar.gz: 8ed227d7a1518f843778185652e9cc36e3dadb106f2de82869983dd8fbaf2d136cb860270a94eabed6c0b9221a829cd55a00d256129c271066d6f3b7df9c5aff
6
+ metadata.gz: 4045f1202c6d63f893cf279c2c5d73b3915f105f7334d7753e389b7fc1b8b61b38af2a2e69d13a8d437934a27efda3b45fe073771c087a34a4fb8501b18ec2e4
7
+ data.tar.gz: 0a88adb5d33dbeac30fc180d72da67451bf7e0b47b82ed432bf614d8bf3361fa9890ba431065e73fb02e1dbf98a49d684a861ce1cafc9d77d369107b3478c2a3
data/.gitignore CHANGED
@@ -6,3 +6,6 @@ Gemfile.lock
6
6
  bin
7
7
  docs/_build
8
8
  coverage
9
+
10
+ .idea
11
+ .bundle
@@ -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
@@ -2,7 +2,7 @@ module S3MPI
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- PATCH = 6
5
+ PATCH = 7
6
6
  BUILD = 1
7
7
 
8
8
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.');
@@ -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
@@ -0,0 +1,4 @@
1
+ user_id,email
2
+ 1,user1@test.com
3
+ 2,user2@test.com
4
+ 3,user3@test.com
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.6.1
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-05-02 00:00:00.000000000 Z
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