miasma 0.2.4 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/miasma/contrib/aws/storage.rb +32 -2
- data/lib/miasma/error.rb +5 -6
- data/lib/miasma/models/storage/buckets.rb +0 -9
- data/lib/miasma/models/storage/files.rb +6 -1
- data/lib/miasma/types/api.rb +19 -14
- data/lib/miasma/types/collection.rb +15 -2
- data/lib/miasma/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aebc0393d265e3f5dfa814404af11e3668e2bb82
|
4
|
+
data.tar.gz: d72c1b1bd1d3727a0693c9e81c50d14ac502bd0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b09ca540d448dfbb34d93abfc431bf96165dc44e237dd96e7eb3f6a2899c54ca5c537edba9be292e9f34c5e05dc725d024055de4e5bcff172dea33cffb0f8afd
|
7
|
+
data.tar.gz: 00b056a517c7dfb837c2c68874ed343ca3c9c25604d7a75d7a03101105a4dbfbd665891c84dfa46162a389ce18dafc3c5b72c78c167cff15d43dae3fbb41f122
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
# v0.2.6
|
2
|
+
* Add default filter implementation on collection
|
3
|
+
* Allow disable of automatic body extraction
|
4
|
+
* Always return streamish object store file body
|
5
|
+
|
1
6
|
# v0.2.4
|
2
7
|
* Make `Storage::File#body` setup provider responsibility
|
3
8
|
* Fix module usage within RS to properly squash existing methods
|
@@ -128,6 +128,33 @@ module Miasma
|
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
131
|
+
# Return filtered files
|
132
|
+
#
|
133
|
+
# @param args [Hash] filter options
|
134
|
+
# @return [Array<Models::Storage::File>]
|
135
|
+
def file_filter(bucket, args)
|
136
|
+
if(args[:prefix])
|
137
|
+
result = request(
|
138
|
+
:path => '/',
|
139
|
+
:endpoint => bucket_endpoint(bucket),
|
140
|
+
:params => Smash.new(
|
141
|
+
:prefix => args[:prefix]
|
142
|
+
)
|
143
|
+
)
|
144
|
+
[result.get(:body, 'ListBucketResult', 'Contents')].flatten.compact.map do |file|
|
145
|
+
File.new(
|
146
|
+
bucket,
|
147
|
+
:id => ::File.join(bucket.name, file['Key']),
|
148
|
+
:name => file['Key'],
|
149
|
+
:updated => file['LastModified'],
|
150
|
+
:size => file['Size'].to_i
|
151
|
+
).valid_state
|
152
|
+
end
|
153
|
+
else
|
154
|
+
bucket_all
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
131
158
|
# Return all files within bucket
|
132
159
|
#
|
133
160
|
# @param bucket [Bucket]
|
@@ -323,14 +350,17 @@ module Miasma
|
|
323
350
|
if(file.persisted?)
|
324
351
|
result = request(
|
325
352
|
:path => file_path(file),
|
326
|
-
:endpoint => bucket_endpoint(file.bucket)
|
353
|
+
:endpoint => bucket_endpoint(file.bucket),
|
354
|
+
:disable_body_extraction => true
|
327
355
|
)
|
328
356
|
content = result[:body]
|
329
357
|
begin
|
330
358
|
if(content.is_a?(String))
|
331
359
|
StringIO.new(content)
|
332
360
|
else
|
333
|
-
content.stream!
|
361
|
+
if(content.respond_to?(:stream!))
|
362
|
+
content.stream!
|
363
|
+
end
|
334
364
|
content
|
335
365
|
end
|
336
366
|
rescue HTTP::StateError
|
data/lib/miasma/error.rb
CHANGED
@@ -46,12 +46,11 @@ module Miasma
|
|
46
46
|
begin
|
47
47
|
begin
|
48
48
|
content = MultiJson.load(response.body.to_s).to_smash
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
49
|
+
@response_error_msg = [[:error, :message]].map do |path|
|
50
|
+
if(result = content.get(*path))
|
51
|
+
"#{content[:code]}: #{result}"
|
52
|
+
end
|
53
|
+
end.flatten.compact.first
|
55
54
|
rescue MultiJson::ParseError
|
56
55
|
begin
|
57
56
|
content = MultiXml.parse(response.body.to_s).to_smash
|
@@ -8,15 +8,6 @@ module Miasma
|
|
8
8
|
# Abstract bucket collection
|
9
9
|
class Buckets < Types::Collection
|
10
10
|
|
11
|
-
# Return buckets matching given filter
|
12
|
-
#
|
13
|
-
# @param options [Hash] filter options
|
14
|
-
# @return [Array<Bucket>]
|
15
|
-
# @option options [String] :prefix key prefix
|
16
|
-
def filter(options={})
|
17
|
-
raise NotImplementedError
|
18
|
-
end
|
19
|
-
|
20
11
|
# @return [Bucket] new unsaved instance
|
21
12
|
def build(args={})
|
22
13
|
Bucket.new(api, args.to_smash)
|
@@ -25,7 +25,7 @@ module Miasma
|
|
25
25
|
# @return [Array<File>]
|
26
26
|
# @option options [String] :prefix key prefix
|
27
27
|
def filter(options={})
|
28
|
-
|
28
|
+
super
|
29
29
|
end
|
30
30
|
|
31
31
|
# @return [File] new unsaved instance
|
@@ -50,6 +50,11 @@ module Miasma
|
|
50
50
|
api.file_all(bucket)
|
51
51
|
end
|
52
52
|
|
53
|
+
# @return [Array<File>]
|
54
|
+
def perform_filter(args)
|
55
|
+
api.file_filter(bucket, args)
|
56
|
+
end
|
57
|
+
|
53
58
|
end
|
54
59
|
|
55
60
|
end
|
data/lib/miasma/types/api.rb
CHANGED
@@ -66,6 +66,7 @@ module Miasma
|
|
66
66
|
# @option args [String, Symbol] :method HTTP request method
|
67
67
|
# @option args [String] :path request path
|
68
68
|
# @option args [Integer] :expects expected response status code
|
69
|
+
# @option args [TrueClass, FalseClass] :disable_body_extraction do not auto-parse response body
|
69
70
|
# @return [Smash] {:result => HTTP::Response, :headers => Smash, :body => Object}
|
70
71
|
# @raises [Error::ApiError::RequestError]
|
71
72
|
def request(args)
|
@@ -96,7 +97,7 @@ module Miasma
|
|
96
97
|
unless(result.code == args.fetch(:expects, 200).to_i)
|
97
98
|
raise Error::ApiError::RequestError.new(result.reason, :response => result)
|
98
99
|
end
|
99
|
-
format_response(result)
|
100
|
+
format_response(result, !args[:disable_body_extraction])
|
100
101
|
end
|
101
102
|
|
102
103
|
# Perform request
|
@@ -115,22 +116,26 @@ module Miasma
|
|
115
116
|
# Makes best attempt at formatting response
|
116
117
|
#
|
117
118
|
# @param result [HTTP::Response]
|
119
|
+
# @param extract_body [TrueClass, FalseClass] automatically extract body
|
118
120
|
# @return [Smash]
|
119
|
-
def format_response(result)
|
121
|
+
def format_response(result, extract_body=true)
|
120
122
|
extracted_headers = Smash[result.headers.map{|k,v| [Utils.snake(k), v]}]
|
121
|
-
if(
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
123
|
+
if(extract_body)
|
124
|
+
if(extracted_headers[:content_type].to_s.include?('json'))
|
125
|
+
begin
|
126
|
+
extracted_body = MultiJson.load(result.body.to_s).to_smash
|
127
|
+
rescue MultiJson::ParseError
|
128
|
+
extracted_body = result.body.to_s
|
129
|
+
end
|
130
|
+
elsif(extracted_headers[:content_type].to_s.include?('xml'))
|
131
|
+
begin
|
132
|
+
extracted_body = MultiXml.parse(result.body.to_s).to_smash
|
133
|
+
rescue MultiXml::ParseError
|
134
|
+
extracted_body = result.body.to_s
|
135
|
+
end
|
132
136
|
end
|
133
|
-
|
137
|
+
end
|
138
|
+
unless(extracted_body)
|
134
139
|
# @note if body is over 100KB, do not extract
|
135
140
|
if(extracted_headers[:content_length].to_i < 102400)
|
136
141
|
extracted_body = result.body.to_s
|
@@ -48,8 +48,10 @@ module Miasma
|
|
48
48
|
# @todo need to add helper to deep sort args, convert to string
|
49
49
|
# and hash to use as memoization key
|
50
50
|
def filter(args={})
|
51
|
-
|
52
|
-
|
51
|
+
key = "filter_#{args.to_smash.checksum}"
|
52
|
+
memoize(key) do
|
53
|
+
perform_filter(args)
|
54
|
+
end
|
53
55
|
end
|
54
56
|
|
55
57
|
# Build a new model
|
@@ -111,6 +113,17 @@ module Miasma
|
|
111
113
|
raise NotImplementedError
|
112
114
|
end
|
113
115
|
|
116
|
+
# @return [Array<Model>]
|
117
|
+
def perform_filter(args)
|
118
|
+
if(args[:prefix])
|
119
|
+
all.find_all do |item|
|
120
|
+
item.name.start_with?(args[:prefix])
|
121
|
+
end
|
122
|
+
else
|
123
|
+
all
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
114
127
|
end
|
115
128
|
end
|
116
129
|
end
|
data/lib/miasma/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: miasma
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Roberts
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|