jackal-assets 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: 442d2cbf6b9fd0b6efa1123a1331a87d42814180
4
+ data.tar.gz: 3cd7bb3f70a8b8ff56cd1576d1f327353a41ddd7
5
+ SHA512:
6
+ metadata.gz: 6a5a1521f5a4be2df8b8953982fac97188fb137b6451dd94d605b47af47e694b9ea39b024be32e6f878c3ea6b671cc62753b0bcea69f5f6ba68ce7d780231529
7
+ data.tar.gz: 2ab1b4eacc496ba34bf3f93d74d86880088f47760112126d7ce8b9ed8777e03ade358b650f61e08b722b322427a5fa58987f6787ff21d5a388f2f0ef753df193
@@ -0,0 +1,2 @@
1
+ ## v0.1.0
2
+ * Initial release
@@ -0,0 +1,40 @@
1
+ # Jackal Assets
2
+
3
+ Simple API to store and retrieve objects.
4
+
5
+ ## Usage
6
+
7
+ ```ruby
8
+
9
+ require 'jackal-assets'
10
+
11
+ object_store = Jackal::Assets::Store.new
12
+ object = object_store.get('item/i/want.json')
13
+
14
+ File.open('/tmp/fubar', 'w') do |f|
15
+ f.write object.readpartial
16
+ f.puts 'YAY'
17
+ end
18
+
19
+ object_store.put('my/updated/file.json', '/tmp/fubar')
20
+ ```
21
+
22
+ ## Configuration
23
+
24
+ Configure
25
+
26
+ ```json
27
+ {
28
+ "jackal": {
29
+ "assets": {
30
+ "provider": "aws",
31
+ "credentials": {
32
+ },
33
+ "bucket": "BUCKET_NAME"
34
+ }
35
+ }
36
+ }
37
+ ```
38
+
39
+ # Info
40
+ * Repository: https://github.com/carnivore-rb/jackal-assets
@@ -0,0 +1,17 @@
1
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__)) + '/lib/'
2
+ require 'jackal-assets/version'
3
+ Gem::Specification.new do |s|
4
+ s.name = 'jackal-assets'
5
+ s.version = Jackal::Assets::VERSION.version
6
+ s.summary = 'Jackal Asset Interface'
7
+ s.author = 'Chris Roberts'
8
+ s.email = 'code@chrisroberts.org'
9
+ s.homepage = 'http://github.com/carnivore-rb/jackal-assets'
10
+ s.description = 'Jackal Assets'
11
+ s.license = 'Apache 2.0'
12
+ s.require_path = 'lib'
13
+ s.add_dependency 'jackal'
14
+ s.add_dependency 'miasma'
15
+ s.add_dependency 'miasma-local'
16
+ s.files = Dir['{lib}/**/**/*'] + %w(jackal-assets.gemspec README.md CHANGELOG.md)
17
+ end
@@ -0,0 +1,12 @@
1
+ require 'miasma'
2
+ require 'miasma-local'
3
+
4
+ module Jackal
5
+ # Asset storage helper
6
+ module Assets
7
+ autoload :Store, 'jackal-assets/store'
8
+ autoload :Error, 'jackal-assets/errors'
9
+ end
10
+ end
11
+
12
+ require 'jackal-assets/version'
@@ -0,0 +1,12 @@
1
+ require 'jackal-assets'
2
+
3
+ module Jackal
4
+ module Assets
5
+ # General error
6
+ class Error < StandardError
7
+ # Object not found
8
+ class NotFound < Error
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,109 @@
1
+ require 'jackal-assets'
2
+
3
+ module Jackal
4
+ module Assets
5
+ # Object storage helper
6
+ class Store
7
+
8
+ # @return [String] bucket name
9
+ attr_accessor :bucket
10
+ # @return [Hash] initializer arguments
11
+ attr_reader :arguments
12
+ # @return [Object] remote connection if applicable
13
+ attr_reader :connection
14
+
15
+ # Create new instance
16
+ #
17
+ # @param args [Hash]
18
+ # @option args [String] :bucket bucket name
19
+ # @option args [String] :provider provider name
20
+ def initialize(args={})
21
+ @arguments = args.to_smash
22
+ @connection_arguments = args[:connection]
23
+ @bucket_name = args[:bucket]
24
+ setup
25
+ end
26
+
27
+ # @return [String] name of bucket
28
+ def bucket_name
29
+ @bucket_name ||
30
+ Carnivore::Config.get(:jackal, :assets, :bucket)
31
+ end
32
+
33
+ # @return [Smash] connection arguments
34
+ def connection_arguments
35
+ (@connection_arguments ||
36
+ Carnivore::Config.get(:jackal, :assets, :connection) ||
37
+ Smash.new).to_smash
38
+ end
39
+
40
+ # Setup API connection and storage bucket
41
+ def setup
42
+ Carnivore.configure!(:verify)
43
+ @connection = Miasma.api(
44
+ connection_arguments.deep_merge(
45
+ Smash.new(
46
+ :type => :storage
47
+ )
48
+ )
49
+ )
50
+ @bucket = @connection.buckets.build(:name => bucket_name).save
51
+ end
52
+
53
+ # Fetch object
54
+ #
55
+ # @param key [String]
56
+ # @return [File]
57
+ def get(key)
58
+ remote_file = bucket.files.reload.get(key)
59
+ if(remote_file)
60
+ remote_file.body
61
+ else
62
+ raise Error::NotFound.new "Remote file does not exist! (<#{bucket}>:#{key})"
63
+ end
64
+ end
65
+
66
+ # Store object
67
+ #
68
+ # @param key [String]
69
+ # @param file [File]
70
+ # @return [TrueClass]
71
+ def put(key, file)
72
+ remote_file = bucket.files.reload.get(key) ||
73
+ bucket.files.build(:name => key)
74
+ remote_file.body = file
75
+ remote_file.save
76
+ true
77
+ end
78
+
79
+ # Delete object
80
+ #
81
+ # @param key [String]
82
+ # @return [TrueClass, FalseClass]
83
+ def delete(key)
84
+ remote_file = bucket.files.reload.get(key)
85
+ if(remote_file)
86
+ remote_file.destroy
87
+ true
88
+ else
89
+ false
90
+ end
91
+ end
92
+
93
+ # URL for object
94
+ #
95
+ # @param key [String]
96
+ # @param expires_in [Numeric] number of seconds url is valid
97
+ # @return [String]
98
+ def url(key, expires_in=nil)
99
+ remote_file = bucket.files.reload.get(key)
100
+ if(remote_file)
101
+ remote_file.url(expires_in)
102
+ else
103
+ raise Error::NotFound.new "Remote file does not exist! (<#{bucket}>:#{key})"
104
+ end
105
+ end
106
+
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,6 @@
1
+ module Jackal
2
+ module Assets
3
+ # Current library version
4
+ VERSION = Gem::Version.new('0.1.0')
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jackal-assets
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris Roberts
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jackal
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: miasma
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: miasma-local
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Jackal Assets
56
+ email: code@chrisroberts.org
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - CHANGELOG.md
62
+ - README.md
63
+ - jackal-assets.gemspec
64
+ - lib/jackal-assets.rb
65
+ - lib/jackal-assets/errors.rb
66
+ - lib/jackal-assets/store.rb
67
+ - lib/jackal-assets/version.rb
68
+ homepage: http://github.com/carnivore-rb/jackal-assets
69
+ licenses:
70
+ - Apache 2.0
71
+ metadata: {}
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 2.2.2
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: Jackal Asset Interface
92
+ test_files: []
93
+ has_rdoc: