s3cabinet 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ef369a4f26d3558df17209b4c13cc9b0e56d9550
4
+ data.tar.gz: 14effa00d4a34b44dc5cb007e82aa254c7a0f7b5
5
+ SHA512:
6
+ metadata.gz: 474199fc791591b787d290c47d00a03134370e1fa9417d29914bba6546ed8e4eec805e7358bf0261225d24f63e57b58e1b1852babadc848a74cc6baddb30d292
7
+ data.tar.gz: aa3a5f28bece6251e255a2fb014ae7895d5b00d6c3eca840728c624b2701928a494a71dbd23f34495086177638e35dc0f35218d4bc3560d912306a107e9e1323
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ before_install: gem install bundler -v 1.10.2
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in s3cabinet.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 David Siaw (via Travis CI)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,43 @@
1
+ # S3cabinet
2
+
3
+ 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/s3cabinet`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ ![Circle CI](https://circleci.com/gh/davidsiaw/s3cabinet/tree/master.svg?style=shield&circle-token=:circle-token)
6
+
7
+ TODO: Delete this and the text above, and describe your gem
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 's3cabinet'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install s3cabinet
24
+
25
+ ## Usage
26
+
27
+ TODO: Write usage instructions here
28
+
29
+ ## Development
30
+
31
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
+
33
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/s3cabinet. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
38
+
39
+
40
+ ## License
41
+
42
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
43
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "s3cabinet"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,6 @@
1
+ machine:
2
+ ruby:
3
+ version: ruby-2.0.0
4
+ dependencies:
5
+ pre:
6
+ - gem install bundler -v 1.10.2
@@ -0,0 +1,92 @@
1
+ require "s3cabinet/version"
2
+
3
+ require "aws-sdk-core"
4
+ require "json"
5
+
6
+ module S3Cabinet
7
+
8
+ class S3Cabinet
9
+ def initialize(access_id, access_key, bucket, region)
10
+ @access_id = access_id
11
+ @access_key = access_key
12
+ @bucket = bucket
13
+ @region = region
14
+
15
+ @region_to_bucket_endpoint = {
16
+ "us-east-1" => "https://s3.amazonaws.com",
17
+ "us-west-2" => "https://s3-us-west-2.amazonaws.com",
18
+ "us-west-1" => "https://s3-us-west-1.amazonaws.com",
19
+ "eu-west-1" => "https://s3-eu-west-1.amazonaws.com",
20
+ "eu-central-1" => "https://s3.eu-central-1.amazonaws.com",
21
+ "ap-southeast-1" => "https://s3-ap-southeast-1.amazonaws.com",
22
+ "ap-southeast-2" => "https://s3-ap-southeast-2.amazonaws.com",
23
+ "ap-northeast-1" => "https://s3-ap-northeast-1.amazonaws.com",
24
+ "sa-east-1" => "https://s3-sa-east-1.amazonaws.com",
25
+ "cn-north-1" => "https://s3.cn-north-1.amazonaws.com.cn"
26
+ }
27
+
28
+ if access_id.is_a? Hash
29
+ hash = @access_id
30
+ @access_id = hash[:access_id]
31
+ @access_key = hash[:access_key]
32
+ @bucket = hash[:bucket]
33
+ @region = hash[:region]
34
+ end
35
+ end
36
+
37
+ def s3
38
+ if @s3 == nil
39
+ endpoint = @region_to_bucket_endpoint[@region]
40
+ if endpoint
41
+ @s3 = Aws::S3::Client.new(access_key_id: @access_id, secret_access_key: @access_key, region: @region)
42
+ else
43
+ @s3 = Aws::S3::Client.new(access_key_id: @access_id, secret_access_key: @access_key, region: "us-east-1", endpoint: @region, force_path_style: true)
44
+ end
45
+ end
46
+ @s3
47
+ end
48
+
49
+ def url(key)
50
+
51
+ the_url = @region_to_bucket_endpoint[@region]
52
+
53
+ if the_url
54
+ "#{the_url}/#{@bucket}/#{key}"
55
+ else
56
+ "#{@region}/#{@bucket}/#{key}"
57
+ end
58
+
59
+ end
60
+
61
+ def set(key, value)
62
+ val_str = { value: value, date: Time.now.to_i }.to_json
63
+ set_raw(key, val_str)
64
+ end
65
+
66
+ def get(key)
67
+ begin
68
+ JSON.parse(get_raw(key))["value"]
69
+ rescue
70
+ end
71
+ end
72
+
73
+ def set_raw(key, value_string)
74
+ s3.put_object(bucket: @bucket, key: key, body: value_string )
75
+ end
76
+
77
+ def get_raw(key)
78
+ resp = s3.get_object(bucket: @bucket, key: key)
79
+ resp.body.read
80
+ end
81
+
82
+ def del(key)
83
+ resp = s3.delete_object(bucket: @bucket, key: key)
84
+ end
85
+
86
+ def list(prefix)
87
+ resp = s3.list_objects(bucket: @bucket, prefix: prefix)
88
+ resp.contents.map { |x| x.key }
89
+ end
90
+
91
+ end
92
+ end
@@ -0,0 +1,3 @@
1
+ module S3Cabinet
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 's3cabinet/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "s3cabinet"
8
+ spec.version = S3Cabinet::VERSION
9
+ spec.authors = ["David Siaw (via Travis CI)"]
10
+ spec.email = ["david.siaw@mobingi.com"]
11
+
12
+ spec.summary = "S3 as a key value store"
13
+ spec.description = "Well actually S3 IS a key value store"
14
+ spec.homepage = "https://github.com/davidsiaw/s3cabinet"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency "aws-sdk-core"
31
+ spec.add_dependency "json"
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.10"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec"
36
+ spec.add_development_dependency "fakes3"
37
+ spec.add_development_dependency 'rspec_junit_formatter', '0.2.2'
38
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: s3cabinet
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - David Siaw (via Travis CI)
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-01-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: fakes3
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec_junit_formatter
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 0.2.2
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 0.2.2
111
+ description: Well actually S3 IS a key value store
112
+ email:
113
+ - david.siaw@mobingi.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - .rspec
120
+ - .travis.yml
121
+ - CODE_OF_CONDUCT.md
122
+ - Gemfile
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - bin/console
127
+ - bin/setup
128
+ - circle.yml
129
+ - lib/s3cabinet.rb
130
+ - lib/s3cabinet/version.rb
131
+ - s3cabinet.gemspec
132
+ homepage: https://github.com/davidsiaw/s3cabinet
133
+ licenses:
134
+ - MIT
135
+ metadata:
136
+ allowed_push_host: https://rubygems.org
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - '>='
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubyforge_project:
153
+ rubygems_version: 2.4.7
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: S3 as a key value store
157
+ test_files: []