storage_room 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -15,7 +15,7 @@ To install the library execute:
15
15
  This is a walkthrough with all steps you need to setup a devise entry, including model, migration, route files, and optional configuration.
16
16
 
17
17
  StorageRoom.authenticate(YOUR_ACCOUNT_ID, YOUR_APPLICATION_API_KEY)
18
- collection = StorageRoom::Collection.find('guidebooks')
18
+ collection = StorageRoom::Collection.find('4ddaf68b4d085d374a000003')
19
19
 
20
20
  entries = collection.entries
21
21
  entry = entries.resources.first
data/Rakefile CHANGED
@@ -23,18 +23,15 @@ rescue LoadError
23
23
  puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
24
24
  end
25
25
 
26
- require 'spec/rake/spectask'
27
- Spec::Rake::SpecTask.new(:spec) do |spec|
28
- spec.libs << 'lib' << 'spec'
29
- spec.spec_files = FileList['spec/**/*_spec.rb']
30
- end
31
26
 
32
- Spec::Rake::SpecTask.new(:rcov) do |spec|
33
- spec.libs << 'lib' << 'spec'
34
- spec.pattern = 'spec/**/*_spec.rb'
35
- spec.rcov = true
27
+ require 'rspec/core/rake_task'
28
+
29
+ RSpec::Core::RakeTask.new do |t|
30
+ t.rspec_opts = ["-c", "-f progress", "-r ./spec/spec_helper.rb"]
31
+ t.pattern = 'spec/**/*_spec.rb'
36
32
  end
37
33
 
34
+
38
35
  task :spec => :check_dependencies
39
36
 
40
37
  task :default => :spec
data/TODO CHANGED
@@ -1,3 +1,4 @@
1
+
1
2
  == Version X
2
3
 
3
4
  - have collection fields
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.2.0
@@ -1,6 +1,11 @@
1
1
  require File.dirname(__FILE__) + '/../lib/storage_room'
2
2
 
3
- ACCOUNT_ID = '4cef9a8c425071fa6900002f' # your account id
4
- APPLICATION_API_KEY = 'c499kx9L6aBfvJlvSKbF' # your application's API key with read/write access
3
+ # ACCOUNT_ID = '4cef9a8c425071fa6900002f' # your account id
4
+ # APPLICATION_API_KEY = 'c499kx9L6aBfvJlvSKbF' # your application's API key with read/write access
5
5
 
6
+ ACCOUNT_ID = '4d13574cba05613d25000004'
7
+ APPLICATION_API_KEY = 'Tg_2oR2aBc83_BJa4k0Y'
8
+
9
+ # StorageRoom.server = 'api.lvh.me:3000'
10
+ StorageRoom.http_proxy('localhost', '8888')
6
11
  StorageRoom.authenticate(ACCOUNT_ID, APPLICATION_API_KEY)
@@ -2,18 +2,8 @@
2
2
 
3
3
  require File.dirname(__FILE__) + '/authentication'
4
4
 
5
- # create a entry without fetching the collection
6
- klass = StorageRoom.class_for_name('Guidebook')
7
- entry1 = klass.new(:title => 'Foo', :price => 1.23)
8
-
9
- if entry1.save
10
- puts "Entry saved"
11
- else
12
- puts "Entry could not be saved: #{entry1.errors.join(', ')}"
13
- end
14
-
15
5
  # fetch the collection first
16
- collection = StorageRoom::Collection.find('guidebooks')
6
+ collection = StorageRoom::Collection.find('4ddaf68b4d085d374a000003')
17
7
 
18
8
  entry2 = collection.entry_class.new(:title => 'Bar', :price => 2.23)
19
9
 
@@ -2,10 +2,10 @@
2
2
 
3
3
  require File.dirname(__FILE__) + '/authentication'
4
4
 
5
- collection = StorageRoom::Collection.find('guidebooks')
5
+ collection = StorageRoom::Collection.find('4ddaf68b4d085d374a000003')
6
6
 
7
7
  entry = collection.entries.resources.first
8
8
 
9
9
  entry.destroy
10
10
 
11
- puts "Destroyed #{entry[:name]}"
11
+ puts "Destroyed #{entry[:title]}"
@@ -2,13 +2,14 @@
2
2
 
3
3
  require File.dirname(__FILE__) + '/authentication'
4
4
 
5
- require 'faster_csv'
5
+ require "csv" # faster_csv (ruby 1.9)
6
6
 
7
- lines = FasterCSV.read(File.dirname(__FILE__) + '/guidebooks.csv') # Exported an Excel file as CSV
7
+ lines = CSV.read(File.dirname(__FILE__) + '/guidebooks.csv') # Exported an Excel file as CSV
8
8
 
9
9
  lines.slice!(0) # remove header line
10
10
 
11
- klass = StorageRoom.class_for_name('Guidebook')
11
+ collection = StorageRoom::Collection.find('4ddaf68b4d085d374a000003')
12
+ klass = collection.entry_class
12
13
 
13
14
  lines.each do |row|
14
15
  guidebook = klass.new(:title => row[0], :price => row[1].to_f)
@@ -2,12 +2,12 @@
2
2
 
3
3
  require File.dirname(__FILE__) + '/authentication'
4
4
 
5
- collection = StorageRoom::Collection.find('guidebooks')
5
+ collection = StorageRoom::Collection.find('4ddaf68b4d085d374a000003')
6
6
 
7
- entries = collection.entry_class.search(:title => 'Name 2')
7
+ entries = collection.entry_class.search(:title => 'Hitchhikers Guide to the Galaxy')
8
8
 
9
- puts "Entries with title 'Name 2':"
9
+ puts "Entries with title 'Hitchhikers Guide to the Galaxy':"
10
10
 
11
11
  entries.resources.each do |entry|
12
- puts "- #{entry[:title]}"
12
+ puts "- #{entry[:title]} : #{entry.url}"
13
13
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  require File.dirname(__FILE__) + '/authentication'
4
4
 
5
- collection = StorageRoom::Collection.find('guidebooks')
5
+ collection = StorageRoom::Collection.find('4ddaf68b4d085d374a000003')
6
6
 
7
7
  entry = collection.entries.resources.first
8
8
 
data/lib/storage_room.rb CHANGED
@@ -72,10 +72,12 @@ module StorageRoom
72
72
  end
73
73
 
74
74
  # Return a Ruby class for a StorageRoom type
75
- def class_for_name(name)
76
- if StorageRoom.const_defined?(name)
75
+ def class_for_name(name)
76
+ is_ruby_19 = method(:const_defined?).arity == 1 # ruby 1.9 check
77
+
78
+ if is_ruby_19 ? StorageRoom.const_defined?(name) : StorageRoom.const_defined?(name, false)
77
79
  "StorageRoom::#{name}".constantize
78
- elsif Object.const_defined?(name)
80
+ elsif is_ruby_19 ? Object.const_defined?(name) : Object.const_defined?(name, false)
79
81
  name.constantize
80
82
  else
81
83
  klass = Class.new(Entry)
@@ -33,7 +33,7 @@ module StorageRoom
33
33
  object = case type
34
34
  when 'Array' then Array.new
35
35
  when 'Collection' then Collection.new
36
- else
36
+ else # entry
37
37
  StorageRoom.class_for_name(type.classify).new
38
38
  end
39
39
 
@@ -58,6 +58,10 @@ module StorageRoom
58
58
  def url
59
59
  self[:@url]
60
60
  end
61
-
61
+
62
+ def version
63
+ self[:@version]
64
+ end
65
+
62
66
  end
63
67
  end
@@ -97,7 +97,7 @@ module StorageRoom
97
97
  end
98
98
 
99
99
  def as_json(args = {}) # :nodoc:
100
- {self.class.json_name => self.attributes.reject{|k, v| self.class.meta_data?(k)}}
100
+ {self.class.json_name => self.attributes.reject{|k, v| self.class.meta_data?(k) && k.to_s != '@version'}}
101
101
  end
102
102
 
103
103
  # The validation errors that were returned by the server
@@ -26,7 +26,7 @@ module StorageRoom
26
26
 
27
27
  # The class of the collection's objects
28
28
  def entry_class
29
- StorageRoom.class_for_name(self[:identifier].classify)
29
+ StorageRoom::Entry.class_with_options(self[:name].classify, :collection_path => self.url)
30
30
  end
31
31
 
32
32
 
@@ -1,22 +1,26 @@
1
1
  module StorageRoom
2
2
  class Entry < Model
3
- class << self
4
- def index_path # :nodoc:
5
- "/collections/#{collection_id}/entries"
3
+ class_inheritable_accessor :collection_path
4
+
5
+ class << self
6
+ def class_with_options(name, options = {})
7
+ # TODO_SK: check options
8
+
9
+ klass = StorageRoom.class_for_name(name)
10
+
11
+ klass.collection_path = options[:collection_path]
12
+
13
+ klass
6
14
  end
7
15
 
16
+ def index_path
17
+ "#{collection_path}/entries"
18
+ end
19
+
8
20
  def show_path(entry_id) # :nodoc:
9
21
  "#{index_path}/#{entry_id}"
10
22
  end
11
-
12
- def collection_path # :nodoc:
13
- "/collections/#{collection_id}"
14
- end
15
-
16
- def collection_id # :nodoc:
17
- self.name.gsub('StorageRoom::', '').tableize
18
- end
19
-
23
+
20
24
  def json_name # :nodoc:
21
25
  'entry'
22
26
  end
@@ -2,8 +2,9 @@
2
2
  "collection": {
3
3
  "name": "Guidebooks",
4
4
  "@updated_at": "2010-11-05T12:55:04Z",
5
- "@entries_url": "http://api.storageroomapp.com/accounts/4c8fd48542507175aa00002f/collections/guidebooks/entries",
5
+ "@entries_url": "http://api.storageroomapp.com/accounts/4c8fd48542507175aa00002f/collections/4ddaf68b4d085d374a000003/entries",
6
6
  "@created_at": "2010-09-14T20:01:13Z",
7
+ "@version": 2,
7
8
  "fields": [{
8
9
  "name": "Title",
9
10
  "required": true,
@@ -32,7 +33,6 @@
32
33
  "identifier": "location"
33
34
  }],
34
35
  "@type": "Collection",
35
- "@url": "http://api.storageroomapp.com/accounts/4c8fd48542507175aa00002f/collections/guidebooks",
36
- "identifier": "guidebooks"
36
+ "@url": "http://api.storageroomapp.com/accounts/4c8fd48542507175aa00002f/collections/4ddaf68b4d085d374a000003"
37
37
  }
38
38
  }
@@ -5,8 +5,9 @@
5
5
  "resources": [{
6
6
  "name": "Guidebooks",
7
7
  "@updated_at": "2010-11-05T12:55:04Z",
8
- "@entries_url": "http://api.storageroomapp.com/accounts/4c8fd48542507175aa00002f/collections/guidebooks/entries",
8
+ "@entries_url": "http://api.storageroomapp.com/accounts/4c8fd48542507175aa00002f/collections/4ddaf68b4d085d374a000003/entries",
9
9
  "@created_at": "2010-09-14T20:01:13Z",
10
+ "@version": 2,
10
11
  "fields": [{
11
12
  "name": "Title",
12
13
  "required": true,
@@ -35,8 +36,7 @@
35
36
  "identifier": "location"
36
37
  }],
37
38
  "@type": "Collection",
38
- "@url": "http://api.storageroomapp.com/accounts/4c8fd48542507175aa00002f/collections/guidebooks",
39
- "identifier": "guidebooks"
39
+ "@url": "http://api.storageroomapp.com/accounts/4c8fd48542507175aa00002f/collections/4ddaf68b4d085d374a000003"
40
40
  }]
41
41
  }
42
42
  }
data/spec/spec_helper.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
3
  require 'storage_room'
4
- require 'spec'
5
- require 'spec/autorun'
4
+ # require 'spec'
5
+ # require 'spec/autorun'
6
6
  require 'webmock/rspec'
7
7
 
8
- Spec::Runner.configure do |config|
8
+ RSpec.configure do |config|
9
9
  config.include WebMock::API
10
10
 
11
11
  config.before(:each) do
@@ -104,6 +104,14 @@ describe StorageRoom::Base do
104
104
  end
105
105
  end
106
106
 
107
+ describe "#version" do
108
+ it "should return version" do
109
+ @base.version.should be_nil
110
+ @base[:@version] = 1
111
+ @base.version.should == 1
112
+ end
113
+ end
114
+
107
115
 
108
116
  end
109
117
 
@@ -175,20 +175,22 @@ describe StorageRoom::Model do
175
175
 
176
176
  describe "#create" do
177
177
  it "should create" do
178
- klass = StorageRoom.class_for_name('Guidebook')
178
+ collection_path = '/collections/4ddaf68b4d085d374a000003'
179
+ klass = StorageRoom::Entry.class_with_options('Guidebook', :collection_path => collection_path)
179
180
  guidebook = klass.new
180
181
 
181
- stub_request(:post, stub_url('/collections/guidebooks/entries')).to_return(:body => fixture_file('collection.json'), :status => 200)
182
+ stub_request(:post, stub_url(klass.index_path)).to_return(:body => fixture_file('collection.json'), :status => 200)
182
183
 
183
184
  guidebook.create
184
185
  guidebook[:name].should == 'Guidebooks'
185
186
  end
186
187
 
187
188
  it "should have errors on validation error" do
188
- klass = StorageRoom.class_for_name('Guidebook')
189
+ collection_path = '/collections/4ddaf68b4d085d374a000003'
190
+ klass = StorageRoom::Entry.class_with_options('Guidebook', :collection_path => collection_path)
189
191
  guidebook = klass.new
190
192
 
191
- stub_request(:post, stub_url('/collections/guidebooks/entries')).to_return(:body => fixture_file('validation_error.json'), :status => 422)
193
+ stub_request(:post, stub_url('/collections/4ddaf68b4d085d374a000003/entries')).to_return(:body => fixture_file('validation_error.json'), :status => 422)
192
194
 
193
195
  guidebook.create
194
196
  guidebook[:name].should be_nil
@@ -44,7 +44,7 @@ describe StorageRoom::Collection do
44
44
 
45
45
  describe "#entry_class" do
46
46
  it "should return class" do
47
- @collection[:identifier] = 'guidebook'
47
+ @collection[:name] = 'guidebook'
48
48
  klass = @collection.entry_class
49
49
  klass.should == Guidebook
50
50
  end
@@ -4,30 +4,30 @@ describe StorageRoom::Entry do
4
4
  context "Class" do
5
5
  context "Methods" do
6
6
  before(:each) do
7
- StorageRoom.class_for_name('Guidebook')
7
+ StorageRoom::Entry.class_with_options('Guidebook', :collection_path => '/collections/4ddaf68b4d085d374a000003')
8
8
  end
9
9
 
10
10
  describe "#show_path" do
11
11
  it "should be defined" do
12
- Guidebook.show_path(1).should == '/collections/guidebooks/entries/1'
12
+ Guidebook.show_path(1).should == '/collections/4ddaf68b4d085d374a000003/entries/1'
13
13
  end
14
14
  end
15
15
 
16
16
  describe "#index_path" do
17
17
  it "should be defined" do
18
- Guidebook.index_path.should == '/collections/guidebooks/entries'
18
+ Guidebook.index_path.should == '/collections/4ddaf68b4d085d374a000003/entries'
19
19
  end
20
20
  end
21
21
 
22
22
  describe "#collection_path" do
23
23
  it "should be defined" do
24
- Guidebook.collection_path.should == '/collections/guidebooks'
24
+ Guidebook.collection_path.should == '/collections/4ddaf68b4d085d374a000003'
25
25
  end
26
26
  end
27
27
 
28
28
  describe "#search_path" do
29
29
  it "should be defined" do
30
- Guidebook.search_path(:test =>1).should == '/collections/guidebooks/entries?test=1'
30
+ Guidebook.search_path(:test =>1).should == '/collections/4ddaf68b4d085d374a000003/entries?test=1'
31
31
  end
32
32
  end
33
33
 
@@ -38,12 +38,6 @@ describe StorageRoom::Entry do
38
38
  end
39
39
  end
40
40
 
41
- describe "#collection_id" do
42
- it "should be defined" do
43
- Guidebook.collection_id.should == 'guidebooks'
44
- end
45
- end
46
-
47
41
  describe "#search" do
48
42
  it "should load" do
49
43
  pending
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.1.4"
8
+ s.version = "0.2.0"
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-01-17}
12
+ s.date = %q{2011-05-23}
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 = [
@@ -64,27 +64,6 @@ Gem::Specification.new do |s|
64
64
  s.require_paths = ["lib"]
65
65
  s.rubygems_version = %q{1.3.7}
66
66
  s.summary = %q{StorageRoom API Wrapper (ActiveModel style)}
67
- s.test_files = [
68
- "examples/authentication.rb",
69
- "examples/create_entry.rb",
70
- "examples/destroy_entry.rb",
71
- "examples/get_collections.rb",
72
- "examples/import_csv.rb",
73
- "examples/search_entries.rb",
74
- "examples/update_entry.rb",
75
- "spec/spec_helper.rb",
76
- "spec/storage_room/array_spec.rb",
77
- "spec/storage_room/attributes_spec.rb",
78
- "spec/storage_room/base_spec.rb",
79
- "spec/storage_room/embedded_spec.rb",
80
- "spec/storage_room/embeddeds/file_spec.rb",
81
- "spec/storage_room/embeddeds/location_spec.rb",
82
- "spec/storage_room/field_spec.rb",
83
- "spec/storage_room/model_spec.rb",
84
- "spec/storage_room/models/collection_spec.rb",
85
- "spec/storage_room/models/entry_spec.rb",
86
- "spec/storage_room_spec.rb"
87
- ]
88
67
 
89
68
  if s.respond_to? :specification_version then
90
69
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: storage_room
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
- - 1
9
- - 4
10
- version: 0.1.4
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
11
10
  platform: ruby
12
11
  authors:
13
12
  - Sascha Konietzke
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2011-01-17 00:00:00 +01:00
17
+ date: 2011-05-23 00:00:00 -03:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,7 +25,6 @@ dependencies:
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
- hash: 13
30
28
  segments:
31
29
  - 1
32
30
  - 2
@@ -42,7 +40,6 @@ dependencies:
42
40
  requirements:
43
41
  - - ">="
44
42
  - !ruby/object:Gem::Version
45
- hash: 3
46
43
  segments:
47
44
  - 0
48
45
  version: "0"
@@ -56,7 +53,6 @@ dependencies:
56
53
  requirements:
57
54
  - - ">="
58
55
  - !ruby/object:Gem::Version
59
- hash: 5
60
56
  segments:
61
57
  - 0
62
58
  - 6
@@ -72,7 +68,6 @@ dependencies:
72
68
  requirements:
73
69
  - - ">="
74
70
  - !ruby/object:Gem::Version
75
- hash: 7
76
71
  segments:
77
72
  - 3
78
73
  - 0
@@ -146,7 +141,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
146
141
  requirements:
147
142
  - - ">="
148
143
  - !ruby/object:Gem::Version
149
- hash: 3
150
144
  segments:
151
145
  - 0
152
146
  version: "0"
@@ -155,7 +149,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
149
  requirements:
156
150
  - - ">="
157
151
  - !ruby/object:Gem::Version
158
- hash: 3
159
152
  segments:
160
153
  - 0
161
154
  version: "0"
@@ -166,23 +159,5 @@ rubygems_version: 1.3.7
166
159
  signing_key:
167
160
  specification_version: 3
168
161
  summary: StorageRoom API Wrapper (ActiveModel style)
169
- test_files:
170
- - examples/authentication.rb
171
- - examples/create_entry.rb
172
- - examples/destroy_entry.rb
173
- - examples/get_collections.rb
174
- - examples/import_csv.rb
175
- - examples/search_entries.rb
176
- - examples/update_entry.rb
177
- - spec/spec_helper.rb
178
- - spec/storage_room/array_spec.rb
179
- - spec/storage_room/attributes_spec.rb
180
- - spec/storage_room/base_spec.rb
181
- - spec/storage_room/embedded_spec.rb
182
- - spec/storage_room/embeddeds/file_spec.rb
183
- - spec/storage_room/embeddeds/location_spec.rb
184
- - spec/storage_room/field_spec.rb
185
- - spec/storage_room/model_spec.rb
186
- - spec/storage_room/models/collection_spec.rb
187
- - spec/storage_room/models/entry_spec.rb
188
- - spec/storage_room_spec.rb
162
+ test_files: []
163
+