capriza-aws 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capriza-aws.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Alon Becker
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # Capriza::Aws
2
+
3
+ Capriza::Aws is a helper gem for AWS tasks. Currently there is one class Capriza::Aws::S3File which can upload, download, add metadata and compare local and S3 files.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'capriza-aws'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install capriza-aws
18
+
19
+ ## Usage
20
+
21
+ To use first create a config.yaml file with the following content
22
+
23
+ access_key_id: YOUR_ACCESS_KEY_ID
24
+ secret_access_key: YOUR_SECRET_ACCESS_KEY
25
+ s3_endpoint: YOUR_S3_ENDPOINT
26
+
27
+ Once configured run the following to instantiate:
28
+
29
+ $ require 'capriza-aws'
30
+
31
+ $ s3 = Capriza::Aws::S3File('BUCKET_NAME','S3_FILE_NAME','CONFIG_FILE_NAME_FULL_PATH')
32
+
33
+ To Upload:
34
+
35
+ $ s3.upload('Hello World')
36
+
37
+ or
38
+
39
+ $ s3.upload(File.read('FILE_NAME'))
40
+
41
+ To Download:
42
+
43
+ $ data = s3.download
44
+ or
45
+
46
+ $ File.write('FILE_NAME', s3.download)
47
+
48
+ To Upload file metadata to S3
49
+
50
+ $ s3.set_metadata(key,value)
51
+
52
+ To Download file metadata from S3
53
+
54
+ $ data = s3.get_metadata(key)
55
+
56
+ To Compare a file to the S3 File
57
+
58
+ $ s3 <=> 'FILE_NAME'
59
+
60
+
61
+ ## Contributing
62
+
63
+ 1. Fork it
64
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
65
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
66
+ 4. Push to the branch (`git push origin my-new-feature`)
67
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capriza-aws/version'
5
+ require 'aws-sdk'
6
+ require 'yaml'
7
+ require 'rubygems'
8
+
9
+ Gem::Specification.new do |gem|
10
+ gem.name = "capriza-aws"
11
+ gem.version = Capriza::Aws::VERSION
12
+ gem.authors = ["Alon Becker"]
13
+ gem.email = ["alon@alonbecker.com"]
14
+ gem.description = %q{AWS Helper Files}
15
+ gem.summary = %q{AWS Helper Files}
16
+ gem.homepage = "http://rubygems.org/gems/capriza-aws"
17
+
18
+ gem.files = `git ls-files`.split($/)
19
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
20
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
21
+ gem.require_paths = ["lib"]
22
+ end
@@ -0,0 +1,62 @@
1
+ require "capriza-aws/version"
2
+ require 'rubygems'
3
+ require 'yaml'
4
+ require 'aws-sdk'
5
+
6
+ module Capriza
7
+ module Aws
8
+
9
+ class S3connect
10
+
11
+ def initialize (config_file)
12
+ unless File.exist?(config_file)
13
+ raise "Config file #{config_file} not found"
14
+ end
15
+ config = YAML.load(File.read(config_file))
16
+ unless config.kind_of?(Hash)
17
+ raise "Config file #{config_file} is formatted incorrectly. Please use the following format:" +
18
+ "access_key_id: YOUR_ACCESS_KEY_ID" +
19
+ "secret_access_key: YOUR_SECRET_ACCESS_KEY" +
20
+ "s3_endpoint: YOUR_S3_ENDPOINT"
21
+ end
22
+ AWS.config(config)
23
+ end
24
+
25
+ end
26
+
27
+ class S3file
28
+ def initialize(bucket, file_name, config_file)
29
+ S3connect.new(config_file)
30
+ s3 = AWS::S3.new()
31
+ @obj = s3.buckets[bucket].objects[file_name]
32
+ end
33
+
34
+ def upload(data)
35
+ @data = data
36
+ @obj.write(@data)
37
+ end
38
+
39
+ def download()
40
+ @data = @obj.read
41
+ end
42
+
43
+ def set_metadata(key,value)
44
+ @obj.metadata[key] = value
45
+ end
46
+
47
+ def get_metadata(key)
48
+ @obj.metadata[key]
49
+ end
50
+
51
+ def <=> (local_file)
52
+ if ! File.exist?(local_file)
53
+ raise "File #{local_file} does not exist"
54
+ end
55
+ @obj.etag.gsub(/\"/,"") == Digest::MD5.hexdigest(File.read(local_file))
56
+ end
57
+
58
+ end
59
+
60
+ end
61
+
62
+ end
@@ -0,0 +1,5 @@
1
+ module Capriza
2
+ module Aws
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capriza-aws
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alon Becker
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-28 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: AWS Helper Files
15
+ email:
16
+ - alon@alonbecker.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - capriza-aws.gemspec
27
+ - lib/capriza-aws.rb
28
+ - lib/capriza-aws/version.rb
29
+ homepage: http://rubygems.org/gems/capriza-aws
30
+ licenses: []
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 1.8.24
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: AWS Helper Files
53
+ test_files: []