rails_s3_uploader 0.1.0 → 0.1.2

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
  SHA256:
3
- metadata.gz: 1f23f923809dc8d672c33ee8c1c48ff01e7c03d7e2013f3819e471d7826c3100
4
- data.tar.gz: f6c227b065a2269416735f4f10659d1af450c00582d1f45d50e2594322890e7f
3
+ metadata.gz: d98b82fb4e84cc13bc28e6b39406244b3f1fc90e2907a83dd362d50690d4323f
4
+ data.tar.gz: 9cca5b7570b4a62a6cf287b90e744f196d285bb799c0178a295e383973a10a33
5
5
  SHA512:
6
- metadata.gz: ad71e6375a1b30237d80932fcfdd25a4dd7317ebf433ead960be20ea3f89346023f571d492cfb7085d8d3d98dff76d5626b8444ba8f159d4321f2de0bd9f4c60
7
- data.tar.gz: e74b90b556676661e329e2af7e0e7121103b243be520bb0ce052aec3b37b4ce7fbbd94a54e5f99b0dca64a77766afc284ded82edc1c430c637bc31ec9130ebbf
6
+ metadata.gz: a0a025d7dc499fec9bae84f6317e90de047b2d5be99cd73b74f1df7c506175fb5745b1d6cd44e02068cecf651480dbedf43f84e87f97e20bb4442092abe5247a
7
+ data.tar.gz: b2b76b8f7dde18c7fa6bdda4fa1201e0d01b0555462fc34e3922dc863877234ad775b50a9e768785ccf371bed27f1036e4965dbbddbe4c56ef3de7dc7c705d32
data/.env.sample ADDED
@@ -0,0 +1,4 @@
1
+ AWS_ACCESS_KEY_ID=your_access_key_id
2
+ AWS_SECRET_ACCESS_KEY=your_secret_access_key
3
+ AWS_REGION=your_region
4
+ AWS_BUCKET=your_bucket
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ # CHANGE LOG
2
+
data/README.md CHANGED
@@ -1,31 +1,98 @@
1
- # RailsS3Uploader
1
+ # Rails S3 Uploader
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
3
+ Rails S3 Uploader is a gem in development to facilitate file uploads to Amazon S3 using Active Storage in Rails applications.
4
4
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rails_s3_uploader`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+ ---
6
6
 
7
7
  ## Installation
8
8
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
9
+ **Note:** This gem is currently in development and your final version has not yet been released on RubyGems.org.
10
10
 
11
- Install the gem and add to the application's Gemfile by executing:
11
+ To use the development version, add this line to your Gemfile:
12
12
 
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
13
+ ```ruby
14
+ gem 'rails_s3_uploader', git: 'https://github.com/eltonsantos/rails_s3_uploader.git'
14
15
 
15
- If bundler is not being used to manage dependencies, install the gem by executing:
16
-
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
16
+ ```
17
+ And run: **bundle install**
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ **Note:** Full usage documentation will be provided in future versions.
22
+
23
+ Rails S3 Uploader was developed to facilitate the file upload process to AWS S3 in Ruby on Rails projects. It can be especially useful in projects that need to store and manage files efficiently in the AWS cloud.
24
+
25
+ ### Recommended Project Types
26
+
27
+ - **Web Applications:** Easily integrate image, document, and other file uploads in web applications built with Ruby on Rails.
28
+
29
+ - **E-commerce Applications:** Manage product images, catalogs, and media files on e-commerce platforms.
30
+
31
+ - **Content Management Systems (CMS):** Allow users to upload and manage multimedia content in Rails-based CMS systems.
32
+
33
+ - **Collaboration Projects:** Facilitate document sharing among users on collaborative platforms.
34
+
35
+ ## Initial Configuration
36
+
37
+ #### Environment Variables
38
+
39
+ Create a **.env** file at the root of your Rails project and add your AWS credentials:
40
+
41
+ ```sh
42
+ AWS_ACCESS_KEY_ID=your_access_key_id
43
+ AWS_SECRET_ACCESS_KEY=your_secret_access_key
44
+ AWS_REGION=your_region
45
+ AWS_BUCKET=your_bucket
46
+ ```
47
+
48
+ ### Initializer
49
+
50
+ Create an initializer in *config/initializers/rails_s3_uploader.rb*:
51
+
52
+ ```ruby
53
+ RailsS3Uploader.configure do |config|
54
+ config.access_key_id = ENV['AWS_ACCESS_KEY_ID']
55
+ config.secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
56
+ config.region = ENV['AWS_REGION']
57
+ config.bucket = ENV['AWS_BUCKET']
58
+ end
59
+ ```
60
+
61
+ ### Development
62
+
63
+ To set up the development environment, clone the repository and install the dependencies:
64
+
65
+ ```sh
66
+ git clone https://github.com/eltonsantos/rails_s3_uploader.git
67
+
68
+ cd rails_s3_uploader
69
+
70
+ bin/setup
71
+ ```
72
+
73
+ You can use *bin/console* for an interactive prompt that allows you to test the code.
74
+
75
+ To install this gem locally, run:
76
+
77
+ ```sh
78
+ bundle exec rake install
79
+ ```
80
+
81
+ Contributions are welcome! Bug reports and pull requests are welcome on GitHub at *https://github.com/eltonsantos/rails_s3_uploader*.
82
+
83
+ ## Requirements
84
+
85
+ - Ruby >= 2.6.0 (recommended 2.7+)
86
+
87
+ - Rails >= 6.0 (compatible up to Rails 7)
88
+
89
+ - AWS S3 Account: You need an S3 bucket and access credentials to use the rails_s3_uploader gem.
90
+
91
+ ## Licence
92
+
93
+ This gem is available as open-source under the terms of the MIT license.
22
94
 
23
- ## Development
24
95
 
25
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
96
 
27
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
97
 
29
- ## Contributing
30
98
 
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rails_s3_uploader.
@@ -0,0 +1,7 @@
1
+ RailsS3Uploader.configure do |config|
2
+ config.access_key_id = ENV['AWS_ACCESS_KEY_ID']
3
+ config.secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
4
+ config.region = ENV['AWS_REGION']
5
+ config.bucket = ENV['AWS_BUCKET']
6
+ end
7
+
@@ -0,0 +1,6 @@
1
+ amazon:
2
+ service: S3
3
+ access_key_id: <%= ENV['AWS_ACCESS_KEY_ID'] %>
4
+ secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %>
5
+ region: <%= ENV['AWS_REGION'] %>
6
+ bucket: <%= ENV['AWS_BUCKET'] %>
@@ -0,0 +1,13 @@
1
+ module RailsS3Uploader
2
+ class Configuration
3
+ attr_accessor :access_key_id, :secret_access_key, :region, :bucket
4
+
5
+ def initialize
6
+ @access_key_id = ENV['AWS_ACCESS_KEY_ID']
7
+ @secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
8
+ @region = ENV['AWS_REGION']
9
+ @bucket = ENV['AWS_BUCKET']
10
+ end
11
+ end
12
+ end
13
+
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsS3Uploader
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
@@ -1,8 +1,22 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "rails_s3_uploader/version"
4
-
1
+ require 'aws-sdk-s3'
5
2
  module RailsS3Uploader
6
- class Error < StandardError; end
7
- # Your code goes here...
3
+ class S3Uploader
4
+ def initialize
5
+ @s3_client = Aws::S3::Client.new(
6
+ access_key_id: RailsS3Uploader.configuration.access_key_id,
7
+ secret_access_key: RailsS3Uploader.configuration.secret_access_key,
8
+ region: RailsS3Uploader.configuration.region
9
+ )
10
+ @bucket = RailsS3Uploader.configuration.bucket
11
+ end
12
+
13
+ def upload(file, key)
14
+ obj = Aws::S3::Object.new(bucket_name: @bucket, key: key, client: @s3_client)
15
+ obj.upload_file(file.path)
16
+ obj.public_url
17
+ rescue StandardError => e
18
+ puts "Error uploading file: #{e.message}"
19
+ nil
20
+ end
21
+ end
8
22
  end
@@ -1,39 +1,34 @@
1
- # frozen_string_literal: true
2
1
 
3
2
  require_relative "lib/rails_s3_uploader/version"
4
3
 
5
4
  Gem::Specification.new do |spec|
6
- spec.name = "rails_s3_uploader"
7
- spec.version = RailsS3Uploader::VERSION
8
- spec.authors = ["Elton Santos", "Raquel Fonseca"]
9
- spec.email = ["eltonaxl@hotmail.com", "raque-leto@hotmail.com"]
10
- spec.summary = "Gem that makes it easy to integrate and upload files with AWS S3 using active storage"
11
- spec.description = "Gem that makes it easy to integrate and upload files with AWS S3 using active storage. Pay Attention: this gem still is in development. Please CONTRIBUTE!"
12
- spec.homepage = "https://github.com/eltonsantos/rails_s3_uploader"
5
+ spec.name = "rails_s3_uploader"
6
+ spec.version = RailsS3Uploader::VERSION
7
+ spec.authors = ["Elton Santos", "Raquel Fonseca"]
8
+ spec.email = ["eltonaxl@hotmail.com", "raque-leto@hotmail.com"]
9
+ spec.summary = "Gem that makes it easy to integrate and upload files with AWS S3 using Active Storage"
10
+ spec.description = "Gem that makes it easy to integrate and upload files to AWS S3 using Active Storage. Pay attention: this gem is still in development. Please CONTRIBUTE!"
11
+ spec.homepage = "https://github.com/eltonsantos/rails_s3_uploader"
13
12
  spec.required_ruby_version = ">= 2.6.0"
14
- spec.license = "MIT"
13
+ spec.license = "MIT"
15
14
 
16
15
  spec.metadata = {
17
- "homepage_uri" => spec.homepage,
18
- "source_code_uri" => "https://github.com/eltonsantos/rails_s3_uploader",
19
- "changelog_uri" => "https://github.com/eltonsantos/rails_s3_uploader/blob/master/CHANGELOG.md",
16
+ "homepage_uri" => spec.homepage,
17
+ "source_code_uri"=> "https://github.com/eltonsantos/rails_s3_uploader",
18
+ "changelog_uri" => "https://github.com/eltonsantos/rails_s3_uploader/blob/master/CHANGELOG.md",
20
19
  }
21
20
 
22
- # Specify which files should be added to the gem when it is released.
23
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
- spec.files = Dir.chdir(__dir__) do
21
+ spec.files = Dir.chdir(__dir__) do
25
22
  `git ls-files -z`.split("\x0").reject do |f|
26
23
  (File.expand_path(f) == __FILE__) ||
27
24
  f.start_with?(*%w[bin/ test/ spec/ features/ .git appveyor Gemfile])
28
25
  end
29
26
  end
30
- spec.bindir = "exe"
31
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
- spec.require_paths = ["lib"]
33
27
 
34
- # Uncomment to register a new dependency of your gem
35
- # spec.add_dependency "example-gem", "~> 1.0"
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
36
31
 
37
- # For more information and examples about making a new gem, check out our
38
- # guide at: https://bundler.io/guides/creating_gem.html
32
+ spec.add_dependency "rails", ">= 6.0"
33
+ spec.add_dependency "aws-sdk-s3", "~> 1.0"
39
34
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_s3_uploader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elton Santos
@@ -10,9 +10,37 @@ autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
12
  date: 2024-06-23 00:00:00.000000000 Z
13
- dependencies: []
14
- description: 'Gem that makes it easy to integrate and upload files with AWS S3 using
15
- active storage. Pay Attention: this gem still is in development. Please CONTRIBUTE!'
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '6.0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '6.0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: aws-sdk-s3
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.0'
42
+ description: 'Gem that makes it easy to integrate and upload files to AWS S3 using
43
+ Active Storage. Pay attention: this gem is still in development. Please CONTRIBUTE!'
16
44
  email:
17
45
  - eltonaxl@hotmail.com
18
46
  - raque-leto@hotmail.com
@@ -20,9 +48,14 @@ executables: []
20
48
  extensions: []
21
49
  extra_rdoc_files: []
22
50
  files:
51
+ - ".env.sample"
52
+ - CHANGELOG.md
23
53
  - README.md
24
54
  - Rakefile
55
+ - config/initializers/rails_s3_uploader.rb
56
+ - config/storage.yml
25
57
  - lib/rails_s3_uploader.rb
58
+ - lib/rails_s3_uploader/configuration.rb
26
59
  - lib/rails_s3_uploader/version.rb
27
60
  - rails_s3_uploader.gemspec
28
61
  - sig/rails_s3_uploader.rbs
@@ -51,6 +84,6 @@ requirements: []
51
84
  rubygems_version: 3.5.3
52
85
  signing_key:
53
86
  specification_version: 4
54
- summary: Gem that makes it easy to integrate and upload files with AWS S3 using active
55
- storage
87
+ summary: Gem that makes it easy to integrate and upload files with AWS S3 using Active
88
+ Storage
56
89
  test_files: []