storage_room 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +3 -0
- data/README.rdoc +1 -1
- data/Rakefile +1 -0
- data/TODO +2 -3
- data/VERSION +1 -1
- data/examples/upload_remove_image.rb +27 -0
- data/lib/storage_room/embeddeds/fields/compound/image_field.rb +1 -1
- data/lib/storage_room/embeddeds/file.rb +22 -0
- data/lib/storage_room/embeddeds/image.rb +23 -1
- data/lib/storage_room/embeddeds/image_version.rb +12 -0
- data/lib/storage_room.rb +5 -2
- data/spec/fixtures/image.png +0 -0
- data/spec/storage_room/embeddeds/file_spec.rb +40 -1
- data/spec/storage_room/embeddeds/image_spec.rb +54 -0
- data/spec/storage_room/embeddeds/image_version_spec.rb +19 -0
- data/storage_room.gemspec +10 -2
- metadata +21 -3
data/History.txt
CHANGED
data/README.rdoc
CHANGED
@@ -8,7 +8,7 @@ This gem provides read and write access to the StorageRoom API (http://storagero
|
|
8
8
|
* Automatic creation of Entry Classes from a Collection, you don't have to configure anything
|
9
9
|
* Supports lazy-loading of associations (e.g. post.category will fetch a category transparently if it has not yet been loaded)
|
10
10
|
* Supports caching through an identity map, so that Resources don't have to be loaded multiple times
|
11
|
-
|
11
|
+
* Easy file uploads and removals
|
12
12
|
|
13
13
|
== Installation
|
14
14
|
|
data/Rakefile
CHANGED
data/TODO
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.2
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby -rubygems
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/authentication'
|
4
|
+
|
5
|
+
path = ::File.expand_path(File.dirname(__FILE__) + '/../spec/fixtures/image.png')
|
6
|
+
collection = StorageRoom::Collection.find('4e034b8db65245b72600002b')
|
7
|
+
|
8
|
+
# Upload Image or File
|
9
|
+
entry = collection.entry_class.new(:name => "StorageRoom Logo", :image => StorageRoom::Image.new_with_filename(path))
|
10
|
+
|
11
|
+
if entry.save
|
12
|
+
puts "Entry saved (#{entry[:@url]})"
|
13
|
+
puts "URL of the uploaded image is #{entry.image.url}"
|
14
|
+
puts "URL of the automatically generated thumbnail is #{entry.image.url(:thumbnail)}" # Multiple Image Versions can be specified in the interface
|
15
|
+
else
|
16
|
+
puts "Entry could not be saved: #{entry.errors.join(', ')}"
|
17
|
+
end
|
18
|
+
|
19
|
+
# Remove Image or File
|
20
|
+
|
21
|
+
entry.image.remove = true
|
22
|
+
|
23
|
+
if entry.save
|
24
|
+
puts "The Image of the Entry has been removed"
|
25
|
+
else
|
26
|
+
puts "The Image of the Entry could not be removed: #{entry.errors.join(', ')}"
|
27
|
+
end
|
@@ -1,6 +1,28 @@
|
|
1
|
+
|
1
2
|
module StorageRoom
|
2
3
|
# Any file
|
3
4
|
class File < Embedded
|
5
|
+
key :filename
|
6
|
+
key :content_type
|
7
|
+
key :data
|
8
|
+
key :remove
|
4
9
|
|
10
|
+
class << self
|
11
|
+
# Create a new File and set attributes from local file
|
12
|
+
def new_with_filename(path)
|
13
|
+
new.tap{|f| f.set_with_filename(path)}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Sets the filename, content_type and data attributes from a local filename so that a File can be uploaded through the API
|
18
|
+
def set_with_filename(path)
|
19
|
+
return if path.blank?
|
20
|
+
|
21
|
+
self.filename = ::File.basename(path)
|
22
|
+
self.content_type = ::MIME::Types.type_for(path).first.content_type
|
23
|
+
self.data = ::Base64.encode64(::File.read(path))
|
24
|
+
end
|
25
|
+
|
26
|
+
|
5
27
|
end
|
6
28
|
end
|
@@ -1,6 +1,28 @@
|
|
1
1
|
module StorageRoom
|
2
2
|
# An Image with optional thumbnails
|
3
|
-
class Image <
|
3
|
+
class Image < File
|
4
|
+
# Returns all valid ImageVersion identifiers for this Image
|
5
|
+
def version_identifiers
|
6
|
+
self[:@versions].keys
|
7
|
+
end
|
8
|
+
|
9
|
+
# Returns the URL of an Image or the URL of a version if a string or symbol is passed
|
10
|
+
def url(name = nil)
|
11
|
+
if name
|
12
|
+
if version_identifiers.include?(name.to_s)
|
13
|
+
self[:@versions][name.to_s][:@url]
|
14
|
+
else
|
15
|
+
raise "Invalid Image Version identifier: '#{name}' (must be #{version_identifiers.join(', ')})"
|
16
|
+
end
|
17
|
+
else
|
18
|
+
self[:@url]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Are versions of the Image still being processed on the server?
|
23
|
+
def processing?
|
24
|
+
self[:@processing]
|
25
|
+
end
|
4
26
|
|
5
27
|
end
|
6
28
|
end
|
data/lib/storage_room.rb
CHANGED
@@ -4,6 +4,8 @@ $:.unshift(File.dirname(__FILE__)) unless
|
|
4
4
|
begin; require 'rubygems'; rescue LoadError; end
|
5
5
|
|
6
6
|
require 'httparty'
|
7
|
+
require 'mime/types'
|
8
|
+
require 'base64'
|
7
9
|
require 'active_support/all'
|
8
10
|
require 'storage_room/extensions/const_defined'
|
9
11
|
|
@@ -55,6 +57,7 @@ module StorageRoom
|
|
55
57
|
autoload :File, 'storage_room/embeddeds/file'
|
56
58
|
autoload :Image, 'storage_room/embeddeds/image'
|
57
59
|
autoload :Location, 'storage_room/embeddeds/location'
|
60
|
+
autoload :ImageVersion, 'storage_room/embeddeds/image_version'
|
58
61
|
|
59
62
|
|
60
63
|
class << self
|
@@ -117,8 +120,8 @@ module StorageRoom
|
|
117
120
|
name_with_mapping = entry_class_for_name(name)
|
118
121
|
|
119
122
|
begin
|
120
|
-
if StorageRoom.is_constant_defined?(
|
121
|
-
return "StorageRoom::#{
|
123
|
+
if StorageRoom.is_constant_defined?(name_with_mapping)
|
124
|
+
return "StorageRoom::#{name_with_mapping}".constantize
|
122
125
|
end
|
123
126
|
rescue NameError # could contain spaces etc.
|
124
127
|
end
|
Binary file
|
@@ -1,5 +1,44 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
2
|
|
3
3
|
describe StorageRoom::File do
|
4
|
-
|
4
|
+
before(:each) do
|
5
|
+
@file = StorageRoom::File.new
|
6
|
+
@name = ::File.expand_path(File.dirname(__FILE__) + '/../../fixtures/image.png')
|
7
|
+
end
|
8
|
+
|
9
|
+
context "Class Methods" do
|
10
|
+
describe "#new_with_filename" do
|
11
|
+
it "return a new file object" do
|
12
|
+
file = StorageRoom::File.new_with_filename(@name)
|
13
|
+
file.should be_an_instance_of(StorageRoom::File)
|
14
|
+
file.content_type.should == 'image/png'
|
15
|
+
file.filename.should == 'image.png'
|
16
|
+
file.data.should == ::Base64.encode64(::File.read(@name))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "Methods" do
|
22
|
+
describe "#set_with_filename" do
|
23
|
+
it "should set with filename" do
|
24
|
+
@file.set_with_filename(@name)
|
25
|
+
|
26
|
+
@file.content_type.should == 'image/png'
|
27
|
+
@file.filename.should == 'image.png'
|
28
|
+
@file.data.should == ::Base64.encode64(::File.read(@name))
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#as_json" do
|
32
|
+
it "should return hash" do
|
33
|
+
@file.set_with_filename(@name)
|
34
|
+
|
35
|
+
hash = @file.as_json.with_indifferent_access
|
36
|
+
hash[:content_type].should == @file.content_type
|
37
|
+
hash[:filename].should == @file.filename
|
38
|
+
hash[:data].should == @file.data
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
5
44
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe StorageRoom::Image do
|
4
|
+
before(:each) do
|
5
|
+
@image = StorageRoom::Image.new
|
6
|
+
@image.response_data = {
|
7
|
+
'@type' => 'Image',
|
8
|
+
'@url' => 'URL',
|
9
|
+
'@processing' => false,
|
10
|
+
'@versions' => {
|
11
|
+
'thumbnail' => {
|
12
|
+
'@url' => 'THUMBNAIL_URL'
|
13
|
+
}
|
14
|
+
}
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
context "Methods" do
|
19
|
+
describe "#image_versions" do
|
20
|
+
it "should return array" do
|
21
|
+
@image.version_identifiers.should == ['thumbnail']
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#url" do
|
26
|
+
it "should return URL for the image" do
|
27
|
+
@image.url.should == 'URL'
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should return URL for a version" do
|
31
|
+
@image.url(:thumbnail).should == 'THUMBNAIL_URL'
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should raise error on invalid version" do
|
35
|
+
lambda {
|
36
|
+
@image.url(:asdf)
|
37
|
+
}.should raise_error
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#processing?" do
|
42
|
+
it "should return true" do
|
43
|
+
@image.response_data['@processing'] = true
|
44
|
+
@image.should be_processing
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should return false" do
|
48
|
+
@image.response_data['@processing'] = false
|
49
|
+
@image.should_not be_processing
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe StorageRoom::ImageVersion do
|
4
|
+
before(:each) do
|
5
|
+
@image_version = StorageRoom::ImageVersion.new(:identifier => 'thumb', :format => 'png', :resize_mode => 'fit', :width => 100, :height => 200)
|
6
|
+
end
|
7
|
+
|
8
|
+
context "Configuration" do
|
9
|
+
describe "#keys" do
|
10
|
+
it "should have keys" do
|
11
|
+
@image_version.identifier.should == 'thumb'
|
12
|
+
@image_version.format.should == 'png'
|
13
|
+
@image_version.resize_mode.should == 'fit'
|
14
|
+
@image_version.width.should == 100
|
15
|
+
@image_version.height.should == 200
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/storage_room.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{storage_room}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Sascha Konietzke"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-07-04}
|
13
13
|
s.description = %q{StorageRoom is a CMS system for Mobile Applications (iPhone, Android, BlackBerry, ...). This library gives you an ActiveModel-like interface to your data.}
|
14
14
|
s.email = %q{sascha@thriventures.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
|
|
32
32
|
"examples/import_csv.rb",
|
33
33
|
"examples/search_entries.rb",
|
34
34
|
"examples/update_entry.rb",
|
35
|
+
"examples/upload_remove_image.rb",
|
35
36
|
"lib/console.rb",
|
36
37
|
"lib/storage_room.rb",
|
37
38
|
"lib/storage_room/accessors.rb",
|
@@ -57,6 +58,7 @@ Gem::Specification.new do |s|
|
|
57
58
|
"lib/storage_room/embeddeds/fields/compound_field.rb",
|
58
59
|
"lib/storage_room/embeddeds/file.rb",
|
59
60
|
"lib/storage_room/embeddeds/image.rb",
|
61
|
+
"lib/storage_room/embeddeds/image_version.rb",
|
60
62
|
"lib/storage_room/embeddeds/location.rb",
|
61
63
|
"lib/storage_room/extensions/const_defined.rb",
|
62
64
|
"lib/storage_room/identity_map.rb",
|
@@ -68,6 +70,7 @@ Gem::Specification.new do |s|
|
|
68
70
|
"lib/storage_room/resource.rb",
|
69
71
|
"spec/fixtures/collection.json",
|
70
72
|
"spec/fixtures/collections.json",
|
73
|
+
"spec/fixtures/image.png",
|
71
74
|
"spec/fixtures/validation_error.json",
|
72
75
|
"spec/spec_helper.rb",
|
73
76
|
"spec/storage_room/accessors_spec.rb",
|
@@ -92,6 +95,8 @@ Gem::Specification.new do |s|
|
|
92
95
|
"spec/storage_room/embeddeds/fields/compound/location_field_spec.rb",
|
93
96
|
"spec/storage_room/embeddeds/fields/compound_field_spec.rb",
|
94
97
|
"spec/storage_room/embeddeds/file_spec.rb",
|
98
|
+
"spec/storage_room/embeddeds/image_spec.rb",
|
99
|
+
"spec/storage_room/embeddeds/image_version_spec.rb",
|
95
100
|
"spec/storage_room/embeddeds/location_spec.rb",
|
96
101
|
"spec/storage_room/identity_map_spec.rb",
|
97
102
|
"spec/storage_room/model_spec.rb",
|
@@ -117,17 +122,20 @@ Gem::Specification.new do |s|
|
|
117
122
|
s.add_development_dependency(%q<webmock>, [">= 0"])
|
118
123
|
s.add_runtime_dependency(%q<httparty>, [">= 0.6.1"])
|
119
124
|
s.add_runtime_dependency(%q<activesupport>, [">= 3.0.0"])
|
125
|
+
s.add_runtime_dependency(%q<mime-types>, [">= 0"])
|
120
126
|
else
|
121
127
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
122
128
|
s.add_dependency(%q<webmock>, [">= 0"])
|
123
129
|
s.add_dependency(%q<httparty>, [">= 0.6.1"])
|
124
130
|
s.add_dependency(%q<activesupport>, [">= 3.0.0"])
|
131
|
+
s.add_dependency(%q<mime-types>, [">= 0"])
|
125
132
|
end
|
126
133
|
else
|
127
134
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
128
135
|
s.add_dependency(%q<webmock>, [">= 0"])
|
129
136
|
s.add_dependency(%q<httparty>, [">= 0.6.1"])
|
130
137
|
s.add_dependency(%q<activesupport>, [">= 3.0.0"])
|
138
|
+
s.add_dependency(%q<mime-types>, [">= 0"])
|
131
139
|
end
|
132
140
|
end
|
133
141
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 2
|
9
|
+
version: 0.3.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Sascha Konietzke
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-
|
17
|
+
date: 2011-07-04 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -75,6 +75,19 @@ dependencies:
|
|
75
75
|
version: 3.0.0
|
76
76
|
type: :runtime
|
77
77
|
version_requirements: *id004
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: mime-types
|
80
|
+
prerelease: false
|
81
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
89
|
+
type: :runtime
|
90
|
+
version_requirements: *id005
|
78
91
|
description: StorageRoom is a CMS system for Mobile Applications (iPhone, Android, BlackBerry, ...). This library gives you an ActiveModel-like interface to your data.
|
79
92
|
email: sascha@thriventures.com
|
80
93
|
executables: []
|
@@ -100,6 +113,7 @@ files:
|
|
100
113
|
- examples/import_csv.rb
|
101
114
|
- examples/search_entries.rb
|
102
115
|
- examples/update_entry.rb
|
116
|
+
- examples/upload_remove_image.rb
|
103
117
|
- lib/console.rb
|
104
118
|
- lib/storage_room.rb
|
105
119
|
- lib/storage_room/accessors.rb
|
@@ -125,6 +139,7 @@ files:
|
|
125
139
|
- lib/storage_room/embeddeds/fields/compound_field.rb
|
126
140
|
- lib/storage_room/embeddeds/file.rb
|
127
141
|
- lib/storage_room/embeddeds/image.rb
|
142
|
+
- lib/storage_room/embeddeds/image_version.rb
|
128
143
|
- lib/storage_room/embeddeds/location.rb
|
129
144
|
- lib/storage_room/extensions/const_defined.rb
|
130
145
|
- lib/storage_room/identity_map.rb
|
@@ -136,6 +151,7 @@ files:
|
|
136
151
|
- lib/storage_room/resource.rb
|
137
152
|
- spec/fixtures/collection.json
|
138
153
|
- spec/fixtures/collections.json
|
154
|
+
- spec/fixtures/image.png
|
139
155
|
- spec/fixtures/validation_error.json
|
140
156
|
- spec/spec_helper.rb
|
141
157
|
- spec/storage_room/accessors_spec.rb
|
@@ -160,6 +176,8 @@ files:
|
|
160
176
|
- spec/storage_room/embeddeds/fields/compound/location_field_spec.rb
|
161
177
|
- spec/storage_room/embeddeds/fields/compound_field_spec.rb
|
162
178
|
- spec/storage_room/embeddeds/file_spec.rb
|
179
|
+
- spec/storage_room/embeddeds/image_spec.rb
|
180
|
+
- spec/storage_room/embeddeds/image_version_spec.rb
|
163
181
|
- spec/storage_room/embeddeds/location_spec.rb
|
164
182
|
- spec/storage_room/identity_map_spec.rb
|
165
183
|
- spec/storage_room/model_spec.rb
|